@laxture/vibe-pm 0.1.0
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/LICENSE +190 -0
- package/README.md +120 -0
- package/README.zh-CN.md +119 -0
- package/dist/core/commands.d.ts +17 -0
- package/dist/core/config.d.ts +12 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/logger.d.ts +23 -0
- package/dist/core/plugin.d.ts +2 -0
- package/dist/core/types.d.ts +42 -0
- package/dist/docs/template/_coding_style/general.md +114 -0
- package/dist/docs/template/_coding_style/go.md +158 -0
- package/dist/docs/template/_coding_style/java.md +154 -0
- package/dist/docs/template/_coding_style/python.md +195 -0
- package/dist/docs/template/_coding_style/rust.md +161 -0
- package/dist/docs/template/_coding_style/sql.md +321 -0
- package/dist/docs/template/_coding_style/typescript.md +237 -0
- package/dist/docs/template/agents-template.md +38 -0
- package/dist/docs/template/bug-fix/flow.md +189 -0
- package/dist/docs/template/constitution-template.md +119 -0
- package/dist/docs/template/design-spec/flow.md +194 -0
- package/dist/docs/template/dictionary-template.md +40 -0
- package/dist/docs/template/large-refactor/flow.md +242 -0
- package/dist/docs/template/large-refactor/regulations/migration-checklist.md +28 -0
- package/dist/docs/template/research/flow.md +161 -0
- package/dist/docs/template/side-job/flow.md +147 -0
- package/dist/docs/template/spec-driven-dev/flow.md +420 -0
- package/dist/docs/template/spec-template.md +190 -0
- package/dist/engine/errors.d.ts +28 -0
- package/dist/engine/flow-engine.d.ts +32 -0
- package/dist/engine/index.d.ts +3 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/loader.d.ts +23 -0
- package/dist/i18n/prompts-en-US.d.ts +47 -0
- package/dist/i18n/prompts-zh-CN.d.ts +50 -0
- package/dist/i18n/types.d.ts +51 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4886 -0
- package/dist/integration/dcp.d.ts +7 -0
- package/dist/integration/index.d.ts +1 -0
- package/dist/memory/errors.d.ts +11 -0
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/memory-system.d.ts +80 -0
- package/dist/memory/types.d.ts +157 -0
- package/dist/template/index.d.ts +3 -0
- package/dist/template/template-manager.d.ts +26 -0
- package/dist/template/types.d.ts +16 -0
- package/dist/token/backends/anthropic.d.ts +5 -0
- package/dist/token/backends/llama.d.ts +7 -0
- package/dist/token/backends/tiktoken.d.ts +7 -0
- package/dist/token/index.d.ts +3 -0
- package/dist/token/model-registry.d.ts +9 -0
- package/dist/token/token-counter.d.ts +17 -0
- package/dist/token/types.d.ts +39 -0
- package/dist/tui/components/collapsible.d.ts +9 -0
- package/dist/tui/components/empty-state.d.ts +7 -0
- package/dist/tui/data/task-status.d.ts +16 -0
- package/dist/tui/data/token-data.d.ts +16 -0
- package/dist/tui/index.d.ts +13 -0
- package/dist/tui/index.js +3293 -0
- package/dist/tui/slots/sidebar-content.d.ts +10 -0
- package/dist/tui/tui-plugin.d.ts +9 -0
- package/dist/tui/types.d.ts +63 -0
- package/package.json +63 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Go Coding Style
|
|
2
|
+
|
|
3
|
+
## General Format
|
|
4
|
+
|
|
5
|
+
- Use UTF-8 encoding uniformly, with LF line endings
|
|
6
|
+
- Use gofmt / goimports to auto-format code (run automatically on save)
|
|
7
|
+
- Use Tab for indentation
|
|
8
|
+
- Recommended line length: no more than 120 characters
|
|
9
|
+
- Keep one blank line at the end of the file
|
|
10
|
+
|
|
11
|
+
## File Organization
|
|
12
|
+
|
|
13
|
+
### Naming
|
|
14
|
+
|
|
15
|
+
- Source files use `snake_case` (lowercase + underscores)
|
|
16
|
+
- Directory names use `snake_case` (lowercase, concise)
|
|
17
|
+
- Test files are named: `*_test.go`, in the same directory as the file under test
|
|
18
|
+
- Package names use short lowercase words, avoid underscores
|
|
19
|
+
|
|
20
|
+
### Import Grouping
|
|
21
|
+
|
|
22
|
+
```go
|
|
23
|
+
import (
|
|
24
|
+
// 1. Standard library
|
|
25
|
+
"fmt"
|
|
26
|
+
"os"
|
|
27
|
+
|
|
28
|
+
// 2. Third-party libraries
|
|
29
|
+
"github.com/gin-gonic/gin"
|
|
30
|
+
|
|
31
|
+
// 3. Internal project packages
|
|
32
|
+
"example.com/project/internal/models"
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### File Structure
|
|
37
|
+
|
|
38
|
+
- One package per directory, package name matches directory name
|
|
39
|
+
- Each file should ideally have only one primary export
|
|
40
|
+
- Helper types/functions use named exports
|
|
41
|
+
|
|
42
|
+
## Naming Conventions
|
|
43
|
+
|
|
44
|
+
### Variables
|
|
45
|
+
|
|
46
|
+
- Use `camelCase` (exported: `PascalCase`)
|
|
47
|
+
- Short scope → short names: `i`, `item`, `ctx`
|
|
48
|
+
- Long scope → descriptive names: `taskConfig`, `messageCount`
|
|
49
|
+
- Boolean variables use question-word prefixes: `isActive`, `hasPlan`, `canProceed`
|
|
50
|
+
|
|
51
|
+
### Constants
|
|
52
|
+
|
|
53
|
+
- `PascalCase` or `camelCase` (exported: `PascalCase`)
|
|
54
|
+
- Go does not use UPPER_SNAKE_CASE
|
|
55
|
+
|
|
56
|
+
### Functions
|
|
57
|
+
|
|
58
|
+
- Use `camelCase` (exported: `PascalCase`)
|
|
59
|
+
- Start with a verb: `getTask`, `findFlow`, `createPlan`, `parseSpec`
|
|
60
|
+
|
|
61
|
+
### Types and Structs
|
|
62
|
+
|
|
63
|
+
- Use `PascalCase`
|
|
64
|
+
- Interface names typically end with `-er` (e.g., `Reader`, `Writer`)
|
|
65
|
+
- Go has no classes; use `PascalCase` for struct names
|
|
66
|
+
|
|
67
|
+
### Enums
|
|
68
|
+
|
|
69
|
+
Go has no native enums; use `const` + `iota`:
|
|
70
|
+
|
|
71
|
+
```go
|
|
72
|
+
type TaskStatus int
|
|
73
|
+
|
|
74
|
+
const (
|
|
75
|
+
TaskStatusRunning TaskStatus = iota
|
|
76
|
+
TaskStatusCompleted
|
|
77
|
+
TaskStatusClosed
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Type Safety
|
|
82
|
+
|
|
83
|
+
### Rules
|
|
84
|
+
|
|
85
|
+
- ✅ Use strong typing; avoid `interface{}` (prefer generics or concrete types)
|
|
86
|
+
- ✅ Explicit error handling: check `if err != nil` for every call that may fail
|
|
87
|
+
- ✅ Use `go vet` and `staticcheck` for static analysis
|
|
88
|
+
- ❌ Never ignore returned error values
|
|
89
|
+
|
|
90
|
+
## Function Design
|
|
91
|
+
|
|
92
|
+
### Parameters
|
|
93
|
+
|
|
94
|
+
- Use a struct parameter when there are more than 3 parameters
|
|
95
|
+
|
|
96
|
+
### Return Values
|
|
97
|
+
|
|
98
|
+
- `(T, error)` tuple
|
|
99
|
+
|
|
100
|
+
## Control Flow
|
|
101
|
+
|
|
102
|
+
- Prefer early returns to reduce nesting
|
|
103
|
+
- `switch` does not need `break`; use `fallthrough` for explicit fall-through
|
|
104
|
+
|
|
105
|
+
## Async Handling
|
|
106
|
+
|
|
107
|
+
- Use goroutine + channel for concurrency
|
|
108
|
+
- Use `context.Context` to propagate cancellation signals and timeouts
|
|
109
|
+
- Use `sync.WaitGroup` / `errgroup` to manage concurrency
|
|
110
|
+
|
|
111
|
+
```go
|
|
112
|
+
func LoadTask(ctx context.Context, sessionID string) (*Task, error) {
|
|
113
|
+
// ...
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Error Handling
|
|
118
|
+
|
|
119
|
+
- Explicitly handle errors for every call that may fail
|
|
120
|
+
- Error messages start with a lowercase letter and do not end with punctuation
|
|
121
|
+
- Use `fmt.Errorf` to wrap errors
|
|
122
|
+
|
|
123
|
+
```go
|
|
124
|
+
data, err := db.Query("SELECT * FROM tasks WHERE session_id = ?", sessionID)
|
|
125
|
+
if err != nil {
|
|
126
|
+
return nil, fmt.Errorf("failed to load task: %w", err)
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Logging
|
|
131
|
+
|
|
132
|
+
- Use structured logging libraries (e.g., `slog`, `zap`)
|
|
133
|
+
- Log messages use English
|
|
134
|
+
|
|
135
|
+
```go
|
|
136
|
+
slog.Info("task created", "sessionID", sessionID)
|
|
137
|
+
slog.Error("failed to load task", "error", err)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Comments and Documentation
|
|
141
|
+
|
|
142
|
+
- Code comments use English
|
|
143
|
+
- Exported types/functions must have doc comments (starting with the name)
|
|
144
|
+
- Add explanatory comments for complex logic
|
|
145
|
+
|
|
146
|
+
## Placeholder Code
|
|
147
|
+
|
|
148
|
+
```go
|
|
149
|
+
// TODO(username): Needs API integration — planned for v1.1
|
|
150
|
+
// FIXME(username): Possible data race under concurrency — needs locking
|
|
151
|
+
// HACK(username): Temporary workaround — replace after v1.0
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Export Conventions
|
|
155
|
+
|
|
156
|
+
- Capitalized first letter = exported (public)
|
|
157
|
+
- Lowercase first letter = package-private (private)
|
|
158
|
+
- Avoid exporting unnecessary symbols
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Java Coding Style
|
|
2
|
+
|
|
3
|
+
## General Format
|
|
4
|
+
|
|
5
|
+
- Use UTF-8 encoding uniformly, LF for line endings
|
|
6
|
+
- Use Spotless / google-java-format for automatic code formatting
|
|
7
|
+
- Use 4 spaces for indentation, no tabs
|
|
8
|
+
- Recommended line length: max 120 characters
|
|
9
|
+
- Keep one blank line at end of file
|
|
10
|
+
|
|
11
|
+
## File Organization
|
|
12
|
+
|
|
13
|
+
### Naming
|
|
14
|
+
|
|
15
|
+
- Source files use `PascalCase` (one public class per file)
|
|
16
|
+
- Directory names use `snake_case` or follow package naming conventions
|
|
17
|
+
- Test file naming: `*Test.java`, mirroring `src/main/` structure under `src/test/`
|
|
18
|
+
- Package names are all lowercase, using reverse domain notation (e.g. `com.example.project`)
|
|
19
|
+
|
|
20
|
+
### Import Grouping
|
|
21
|
+
|
|
22
|
+
```java
|
|
23
|
+
// 1. Static imports
|
|
24
|
+
import static org.junit.Assert.*;
|
|
25
|
+
|
|
26
|
+
// 2. Java standard library
|
|
27
|
+
import java.util.List;
|
|
28
|
+
import java.util.Optional;
|
|
29
|
+
|
|
30
|
+
// 3. Third-party libraries
|
|
31
|
+
import com.google.common.collect.ImmutableList;
|
|
32
|
+
|
|
33
|
+
// 4. Project internals
|
|
34
|
+
import com.example.project.core.TaskState;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### File Structure
|
|
38
|
+
|
|
39
|
+
- One top-level class per file, class name matches file name
|
|
40
|
+
- Each file should ideally have only one main export
|
|
41
|
+
- Helper types/functions use named exports
|
|
42
|
+
|
|
43
|
+
## Naming Conventions
|
|
44
|
+
|
|
45
|
+
### Variables
|
|
46
|
+
|
|
47
|
+
- Use `camelCase`
|
|
48
|
+
- Short scope: short names, e.g. `i`, `item`, `ctx`
|
|
49
|
+
- Long scope: descriptive names, e.g. `taskConfig`, `messageCount`
|
|
50
|
+
- Boolean variables: question-word prefix, e.g. `isActive`, `hasPlan`, `canProceed`
|
|
51
|
+
|
|
52
|
+
### Constants
|
|
53
|
+
|
|
54
|
+
- `UPPER_SNAKE_CASE` (`static final` fields)
|
|
55
|
+
|
|
56
|
+
### Functions
|
|
57
|
+
|
|
58
|
+
- Use `camelCase`
|
|
59
|
+
- Verb-prefixed: `getTask`, `findFlow`, `createPlan`, `parseSpec`
|
|
60
|
+
|
|
61
|
+
### Types and Interfaces
|
|
62
|
+
|
|
63
|
+
- Use `PascalCase`
|
|
64
|
+
- No `I` prefix for interface names
|
|
65
|
+
|
|
66
|
+
### Enums
|
|
67
|
+
|
|
68
|
+
Use `enum`, members in `UPPER_SNAKE_CASE`:
|
|
69
|
+
|
|
70
|
+
```java
|
|
71
|
+
public enum TaskStatus {
|
|
72
|
+
RUNNING,
|
|
73
|
+
COMPLETED,
|
|
74
|
+
CLOSED
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Type Safety
|
|
79
|
+
|
|
80
|
+
### Rules
|
|
81
|
+
|
|
82
|
+
- ✅ Use generics to avoid raw types
|
|
83
|
+
- ✅ Use `Optional<T>` instead of returning null
|
|
84
|
+
- ✅ Use `final` for immutable fields
|
|
85
|
+
- ❌ Never catch `Exception` and swallow it
|
|
86
|
+
|
|
87
|
+
## Function Design
|
|
88
|
+
|
|
89
|
+
### Parameters
|
|
90
|
+
|
|
91
|
+
- Use Builder pattern for complex construction when exceeding 3 parameters
|
|
92
|
+
|
|
93
|
+
### Return Values
|
|
94
|
+
|
|
95
|
+
- `Optional<T>` or custom `Result<T, E>`
|
|
96
|
+
|
|
97
|
+
## Async Handling
|
|
98
|
+
|
|
99
|
+
- Use `CompletableFuture<T>` or reactive frameworks
|
|
100
|
+
- Async methods return `Future<T>`
|
|
101
|
+
|
|
102
|
+
```java
|
|
103
|
+
public CompletableFuture<Optional<Task>> loadTask(String sessionId) {
|
|
104
|
+
return db.queryAsync("SELECT * FROM tasks WHERE session_id = ?", sessionId)
|
|
105
|
+
.thenApply(data -> data != null ? Task.fromRow(data) : null);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Error Handling
|
|
110
|
+
|
|
111
|
+
- Catch specific exception types
|
|
112
|
+
- Use custom exception classes
|
|
113
|
+
- Release resources in `finally` (or use try-with-resources)
|
|
114
|
+
|
|
115
|
+
```java
|
|
116
|
+
try {
|
|
117
|
+
var result = riskyOperation();
|
|
118
|
+
} catch (IOException e) {
|
|
119
|
+
logger.error("Operation failed", e);
|
|
120
|
+
throw new OperationException("Failed to complete operation", e);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Logging
|
|
125
|
+
|
|
126
|
+
- Use SLF4J + Logback
|
|
127
|
+
- Log messages in English
|
|
128
|
+
|
|
129
|
+
```java
|
|
130
|
+
import org.slf4j.Logger;
|
|
131
|
+
import org.slf4j.LoggerFactory;
|
|
132
|
+
|
|
133
|
+
private static final Logger logger = LoggerFactory.getLogger(TaskService.class);
|
|
134
|
+
logger.info("Task created, sessionId={}", sessionId);
|
|
135
|
+
logger.error("Failed to load task", e);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Comments and Documentation
|
|
139
|
+
|
|
140
|
+
- Code comments in English
|
|
141
|
+
- Use Javadoc for public APIs
|
|
142
|
+
- Add explanatory comments for complex logic
|
|
143
|
+
|
|
144
|
+
## Placeholder Code
|
|
145
|
+
|
|
146
|
+
```java
|
|
147
|
+
// TODO(username): Need to integrate API — estimated v1.1
|
|
148
|
+
// FIXME(username): Possible data race in concurrent scenario — need locking
|
|
149
|
+
// HACK(username): Temporary workaround — replace after v1.0
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Export Conventions
|
|
153
|
+
|
|
154
|
+
Use `public` / `protected` / package-private to control visibility
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Python Coding Style
|
|
2
|
+
|
|
3
|
+
## General Formatting
|
|
4
|
+
|
|
5
|
+
- Use UTF-8 encoding with LF line endings
|
|
6
|
+
- Use Black + isort for automatic code formatting (run on save)
|
|
7
|
+
- Indent with 4 spaces, do not use tabs
|
|
8
|
+
- Recommended line length: no more than 88 characters
|
|
9
|
+
- Keep one blank line at the end of the file
|
|
10
|
+
|
|
11
|
+
## File Organization
|
|
12
|
+
|
|
13
|
+
### Naming
|
|
14
|
+
|
|
15
|
+
- Source files use `snake_case`
|
|
16
|
+
- Directory names use `snake_case`
|
|
17
|
+
- Test file naming: `test_*.py` or `*_test.py`
|
|
18
|
+
|
|
19
|
+
### Import Grouping
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
# 1. Standard library
|
|
23
|
+
import os
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# 2. Third-party libraries
|
|
27
|
+
import requests
|
|
28
|
+
from pydantic import BaseModel
|
|
29
|
+
|
|
30
|
+
# 3. Project internal modules
|
|
31
|
+
from app.core.config import settings
|
|
32
|
+
from app.models.user import User
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### File Structure
|
|
36
|
+
|
|
37
|
+
- Each file should ideally have one main export
|
|
38
|
+
- Use named exports for helper types/functions
|
|
39
|
+
- Modules should expose a clean public API
|
|
40
|
+
|
|
41
|
+
## Naming Conventions
|
|
42
|
+
|
|
43
|
+
### Variables
|
|
44
|
+
|
|
45
|
+
- Use `snake_case`
|
|
46
|
+
- Short scope uses short names: `i`, `item`, `ctx`
|
|
47
|
+
- Long scope uses descriptive names: `task_config`, `message_count`
|
|
48
|
+
- Boolean variables use interrogative prefixes: `is_active`, `has_plan`, `can_proceed`
|
|
49
|
+
- Do not use Hungarian notation
|
|
50
|
+
|
|
51
|
+
### Constants
|
|
52
|
+
|
|
53
|
+
- `UPPER_SNAKE_CASE`
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
DEFAULT_LANGUAGE = "zh-CN"
|
|
57
|
+
MAX_RETRY_COUNT = 3
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Functions
|
|
61
|
+
|
|
62
|
+
- Use `snake_case`
|
|
63
|
+
- Start with a verb: `get_task`, `find_flow`, `create_plan`, `parse_spec`
|
|
64
|
+
- Event handler functions: `handle_xxx` or `on_xxx`
|
|
65
|
+
|
|
66
|
+
### Types and Classes
|
|
67
|
+
|
|
68
|
+
- Use `PascalCase`
|
|
69
|
+
- Follow PEP 8, class names use CapWords
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
class TaskState:
|
|
73
|
+
session_id: str
|
|
74
|
+
flow: str
|
|
75
|
+
current_step: str
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Enums
|
|
79
|
+
|
|
80
|
+
Use `Enum`, members use `UPPER_SNAKE_CASE`
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from enum import Enum
|
|
84
|
+
|
|
85
|
+
class TaskStatus(Enum):
|
|
86
|
+
RUNNING = "running"
|
|
87
|
+
COMPLETED = "completed"
|
|
88
|
+
CLOSED = "closed"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Type Safety
|
|
92
|
+
|
|
93
|
+
### Recommended Practices
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# ✅ Use type annotations
|
|
97
|
+
def process(data: dict[str, object]) -> Result:
|
|
98
|
+
if not isinstance(data, dict) or "id" not in data:
|
|
99
|
+
raise TypeError("Invalid data")
|
|
100
|
+
...
|
|
101
|
+
|
|
102
|
+
# ✅ Use mypy / pyright for static checking
|
|
103
|
+
# ✅ Use dataclass / Pydantic to define data structures
|
|
104
|
+
from dataclasses import dataclass
|
|
105
|
+
|
|
106
|
+
@dataclass
|
|
107
|
+
class TaskState:
|
|
108
|
+
session_id: str
|
|
109
|
+
flow: str
|
|
110
|
+
current_step: str
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Prohibitions
|
|
114
|
+
|
|
115
|
+
- ❌ No bare except (at minimum catch Exception)
|
|
116
|
+
- ❌ Do not use print() instead of logging in production code
|
|
117
|
+
- ❌ No mutable default arguments
|
|
118
|
+
|
|
119
|
+
## Function Design
|
|
120
|
+
|
|
121
|
+
### Parameters
|
|
122
|
+
|
|
123
|
+
- Use object/struct parameters when exceeding 3 arguments
|
|
124
|
+
|
|
125
|
+
### Return Values
|
|
126
|
+
|
|
127
|
+
- Prefer concrete types, avoid None
|
|
128
|
+
- For "empty" return scenarios, use the `Result` pattern (e.g., returns library) or `Optional[T]`
|
|
129
|
+
|
|
130
|
+
## Async Handling
|
|
131
|
+
|
|
132
|
+
- Use `async/await` (asyncio)
|
|
133
|
+
- Use `async def` for async functions
|
|
134
|
+
- Avoid mixing synchronous and asynchronous code
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
async def load_task(session_id: str) -> Task | None:
|
|
138
|
+
data = await db.fetch_one("SELECT * FROM tasks WHERE session_id = ?", session_id)
|
|
139
|
+
return Task.from_row(data) if data else None
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Error Handling
|
|
143
|
+
|
|
144
|
+
- Catch specific exception types, do not use bare `except:`
|
|
145
|
+
- Validate inputs at system boundaries
|
|
146
|
+
- Use custom exception classes
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
try:
|
|
150
|
+
result = await risky_operation()
|
|
151
|
+
except ConnectionError as e:
|
|
152
|
+
logger.error("Operation failed", extra={"error": str(e)})
|
|
153
|
+
raise OperationError("Failed to complete operation") from e
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Logging
|
|
157
|
+
|
|
158
|
+
- Use the `logging` module, do not use `print()` directly
|
|
159
|
+
- Log messages in English
|
|
160
|
+
- Record info/debug logs on critical paths
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import logging
|
|
164
|
+
|
|
165
|
+
logger = logging.getLogger(__name__)
|
|
166
|
+
logger.info("Task created", extra={"session_id": session_id})
|
|
167
|
+
logger.error("Failed to load task", extra={"error": str(e)})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Comments and Documentation
|
|
171
|
+
|
|
172
|
+
- Code comments in English
|
|
173
|
+
- Public APIs use docstrings (Google or NumPy style)
|
|
174
|
+
- Add explanatory comments for complex logic
|
|
175
|
+
|
|
176
|
+
## Placeholder Code
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
# TODO(username): Need to integrate API — expected v1.1
|
|
180
|
+
# FIXME(username): Possible data race under concurrency — needs locking
|
|
181
|
+
# HACK(username): Temporary workaround — replace after v1.0
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Export Conventions
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# Control exports in __init__.py
|
|
188
|
+
__all__ = ["FlowParser", "parse_flow", "FlowDefinition"]
|
|
189
|
+
|
|
190
|
+
# Main export
|
|
191
|
+
class FlowParser: ...
|
|
192
|
+
|
|
193
|
+
# Helper functions use named exports
|
|
194
|
+
def parse_flow(path: str) -> FlowDefinition: ...
|
|
195
|
+
```
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Rust Coding Style
|
|
2
|
+
|
|
3
|
+
## General Format
|
|
4
|
+
|
|
5
|
+
- Use UTF-8 encoding consistently, LF for line endings
|
|
6
|
+
- Use rustfmt for automatic code formatting (runs on save)
|
|
7
|
+
- Use 4 spaces for indentation, no tabs
|
|
8
|
+
- Line length recommended not to exceed 100 characters
|
|
9
|
+
- Keep one blank line at the end of files
|
|
10
|
+
|
|
11
|
+
## File Organization
|
|
12
|
+
|
|
13
|
+
### Naming
|
|
14
|
+
|
|
15
|
+
- Source files use `snake_case`
|
|
16
|
+
- Directory names use `snake_case`
|
|
17
|
+
- Test file naming: inline `#[cfg(test)]` modules or `tests/` directory
|
|
18
|
+
|
|
19
|
+
### Import Grouping
|
|
20
|
+
|
|
21
|
+
```rust
|
|
22
|
+
// 1. Standard library
|
|
23
|
+
use std::collections::HashMap;
|
|
24
|
+
use std::path::PathBuf;
|
|
25
|
+
|
|
26
|
+
// 2. Third-party crates
|
|
27
|
+
use serde::{Deserialize, Serialize};
|
|
28
|
+
use tokio::sync::Mutex;
|
|
29
|
+
|
|
30
|
+
// 3. Project internal modules
|
|
31
|
+
use crate::core::config::Config;
|
|
32
|
+
use crate::models::user::User;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### File Structure
|
|
36
|
+
|
|
37
|
+
- Prefer one primary export per file
|
|
38
|
+
- Use named exports for auxiliary types/functions
|
|
39
|
+
- Expose a clear public API from modules
|
|
40
|
+
|
|
41
|
+
## Naming Conventions
|
|
42
|
+
|
|
43
|
+
### Variables
|
|
44
|
+
|
|
45
|
+
- Use `snake_case`
|
|
46
|
+
- Short names for short scopes: `i`, `item`, `ctx`
|
|
47
|
+
- Descriptive names for longer scopes: `task_config`, `message_count`
|
|
48
|
+
|
|
49
|
+
### Constants
|
|
50
|
+
|
|
51
|
+
- `UPPER_SNAKE_CASE`
|
|
52
|
+
- Static variables use `SCREAMING_SNAKE_CASE`
|
|
53
|
+
|
|
54
|
+
### Functions
|
|
55
|
+
|
|
56
|
+
- Use `snake_case`
|
|
57
|
+
- Start with a verb: `get_task`, `find_flow`, `create_plan`, `parse_spec`
|
|
58
|
+
|
|
59
|
+
### Types
|
|
60
|
+
|
|
61
|
+
- Use `PascalCase`
|
|
62
|
+
- Trait names use PascalCase, avoid `-able` suffix
|
|
63
|
+
- Rust has no classes; struct/enum use `PascalCase`
|
|
64
|
+
|
|
65
|
+
### Enums
|
|
66
|
+
|
|
67
|
+
Use `enum` with `#[derive(...)]`:
|
|
68
|
+
|
|
69
|
+
```rust
|
|
70
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
71
|
+
enum TaskStatus {
|
|
72
|
+
Running,
|
|
73
|
+
Completed,
|
|
74
|
+
Closed,
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Type Safety
|
|
79
|
+
|
|
80
|
+
### Rules
|
|
81
|
+
|
|
82
|
+
- ✅ Leverage Rust's ownership and borrowing system; avoid unnecessary `.clone()`
|
|
83
|
+
- ✅ Use `Result<T, E>` and `Option<T>` instead of null
|
|
84
|
+
- ✅ Use `clippy` for lint checks
|
|
85
|
+
- ❌ Do not use `unsafe` (unless with a strong justification and comments)
|
|
86
|
+
- ❌ Do not use `unwrap()` or `expect()` in production paths
|
|
87
|
+
|
|
88
|
+
## Function Design
|
|
89
|
+
|
|
90
|
+
### Parameters
|
|
91
|
+
|
|
92
|
+
- Use struct parameters when exceeding 3 parameters
|
|
93
|
+
- Use the builder pattern for complex construction
|
|
94
|
+
|
|
95
|
+
### Return Values
|
|
96
|
+
|
|
97
|
+
- `Result<T, E>` and `Option<T>`
|
|
98
|
+
|
|
99
|
+
## Control Flow
|
|
100
|
+
|
|
101
|
+
- Use `match` for pattern matching
|
|
102
|
+
- Use `if let` to simplify single-branch matches
|
|
103
|
+
- Use the `?` operator to propagate errors
|
|
104
|
+
|
|
105
|
+
## Async Handling
|
|
106
|
+
|
|
107
|
+
- Use the `tokio` runtime
|
|
108
|
+
- Async functions return `impl Future<Output = T>` or are annotated with `async fn`
|
|
109
|
+
|
|
110
|
+
```rust
|
|
111
|
+
async fn load_task(session_id: &str) -> Result<Option<Task>, DbError> {
|
|
112
|
+
let data = db.query("SELECT * FROM tasks WHERE session_id = ?", session_id).await?;
|
|
113
|
+
Ok(data.map(Task::from_row))
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Error Handling
|
|
118
|
+
|
|
119
|
+
- Use `thiserror` to define error types
|
|
120
|
+
- Use the `?` operator to propagate errors
|
|
121
|
+
- Use `anyhow` for application-level errors
|
|
122
|
+
|
|
123
|
+
```rust
|
|
124
|
+
use thiserror::Error;
|
|
125
|
+
|
|
126
|
+
#[derive(Error, Debug)]
|
|
127
|
+
enum AppError {
|
|
128
|
+
#[error("failed to load task: {0}")]
|
|
129
|
+
DbError(#[from] DbError),
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Logging
|
|
134
|
+
|
|
135
|
+
- Use the `tracing` / `log` crate
|
|
136
|
+
- Log messages in English
|
|
137
|
+
|
|
138
|
+
```rust
|
|
139
|
+
tracing::info!(session_id = %session_id, "task created");
|
|
140
|
+
tracing::error!(error = %e, "failed to load task");
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Comments & Documentation
|
|
144
|
+
|
|
145
|
+
- Code comments in English
|
|
146
|
+
- Use `///` doc comments for public API
|
|
147
|
+
- Use `//!` comments for modules
|
|
148
|
+
|
|
149
|
+
## Placeholder Code
|
|
150
|
+
|
|
151
|
+
```rust
|
|
152
|
+
// TODO(username): Needs API integration — planned for v1.1
|
|
153
|
+
// FIXME(username): Possible data race in concurrent scenarios — needs locking
|
|
154
|
+
// HACK(username): Temporary workaround — replace after v1.0
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Export Conventions
|
|
158
|
+
|
|
159
|
+
- Use `pub` to control visibility
|
|
160
|
+
- `pub(crate)` restricts visibility to within the crate
|
|
161
|
+
- Organize modules via `mod.rs` or same-name files
|