@mindfoldhq/trellis 0.1.3 → 0.1.5
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/README.md +757 -135
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +38 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +6 -8
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/update.d.ts +11 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +357 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/configurators/claude.d.ts +2 -5
- package/dist/configurators/claude.d.ts.map +1 -1
- package/dist/configurators/claude.js +49 -12
- package/dist/configurators/claude.js.map +1 -1
- package/dist/configurators/cursor.d.ts +1 -4
- package/dist/configurators/cursor.d.ts.map +1 -1
- package/dist/configurators/cursor.js +42 -11
- package/dist/configurators/cursor.js.map +1 -1
- package/dist/configurators/templates.d.ts +15 -0
- package/dist/configurators/templates.d.ts.map +1 -0
- package/dist/configurators/templates.js +30 -0
- package/dist/configurators/templates.js.map +1 -0
- package/dist/configurators/workflow.d.ts.map +1 -1
- package/dist/configurators/workflow.js +10 -8
- package/dist/configurators/workflow.js.map +1 -1
- package/dist/{.claude → templates/claude}/agents/check.md +32 -8
- package/dist/{.claude → templates/claude}/agents/debug.md +6 -9
- package/dist/{.claude → templates/claude}/agents/dispatch.md +8 -3
- package/dist/{.claude → templates/claude}/agents/implement.md +1 -6
- package/dist/{.cursor → templates/claude}/commands/finish-work.md +1 -1
- package/dist/{.claude → templates/claude}/commands/onboard-developer.md +3 -3
- package/dist/{.claude → templates/claude}/commands/parallel.md +46 -53
- package/dist/{.claude → templates/claude}/commands/record-agent-flow.md +1 -1
- package/dist/{.claude → templates/claude}/commands/start.md +4 -5
- package/dist/{.claude → templates/claude}/hooks/inject-subagent-context.py +82 -4
- package/dist/templates/claude/hooks/ralph-loop.py +374 -0
- package/dist/templates/claude/index.d.ts +52 -0
- package/dist/templates/claude/index.d.ts.map +1 -0
- package/dist/templates/claude/index.js +83 -0
- package/dist/templates/claude/index.js.map +1 -0
- package/dist/{.claude → templates/claude}/settings.json +12 -0
- package/dist/{.claude → templates/cursor}/commands/finish-work.md +1 -1
- package/dist/{.cursor → templates/cursor}/commands/onboard-developer.md +3 -3
- package/dist/{.cursor → templates/cursor}/commands/record-agent-flow.md +1 -1
- package/dist/{.cursor → templates/cursor}/commands/start.md +4 -5
- package/dist/templates/cursor/index.d.ts +22 -0
- package/dist/templates/cursor/index.d.ts.map +1 -0
- package/dist/templates/cursor/index.js +42 -0
- package/dist/templates/cursor/index.js.map +1 -0
- package/dist/templates/extract.d.ts +22 -24
- package/dist/templates/extract.d.ts.map +1 -1
- package/dist/templates/extract.js +44 -60
- package/dist/templates/extract.js.map +1 -1
- package/dist/templates/markdown/index.d.ts +3 -7
- package/dist/templates/markdown/index.d.ts.map +1 -1
- package/dist/templates/markdown/index.js +6 -17
- package/dist/templates/markdown/index.js.map +1 -1
- package/dist/templates/trellis/backlog/.gitkeep +0 -0
- package/dist/templates/trellis/gitignore.txt +5 -0
- package/dist/templates/trellis/index.d.ts +37 -0
- package/dist/templates/trellis/index.d.ts.map +1 -0
- package/dist/templates/trellis/index.js +68 -0
- package/dist/templates/trellis/index.js.map +1 -0
- package/dist/templates/trellis/scripts/common/backlog.sh +220 -0
- package/dist/templates/trellis/scripts/common/feature-utils.sh +194 -0
- package/dist/{.trellis → templates/trellis}/scripts/common/git-context.sh +51 -0
- package/dist/{.trellis → templates/trellis}/scripts/common/paths.sh +17 -0
- package/dist/templates/trellis/scripts/common/registry.sh +247 -0
- package/dist/{.trellis → templates/trellis}/scripts/common/worktree.sh +0 -10
- package/dist/{.trellis → templates/trellis}/scripts/feature.sh +113 -42
- package/dist/{.trellis → templates/trellis}/scripts/multi-agent/cleanup.sh +56 -76
- package/dist/{.trellis → templates/trellis}/scripts/multi-agent/plan.sh +2 -1
- package/dist/{.trellis → templates/trellis}/scripts/multi-agent/start.sh +4 -35
- package/dist/{.trellis → templates/trellis}/scripts/multi-agent/status.sh +35 -9
- package/dist/{.trellis → templates/trellis}/workflow.md +85 -10
- package/dist/{.trellis → templates/trellis}/worktree.yaml +6 -8
- package/package.json +1 -1
- package/dist/.trellis/structure/backend/database-guidelines.md +0 -51
- package/dist/.trellis/structure/backend/directory-structure.md +0 -209
- package/dist/.trellis/structure/backend/error-handling.md +0 -278
- package/dist/.trellis/structure/backend/index.md +0 -38
- package/dist/.trellis/structure/backend/logging-guidelines.md +0 -266
- package/dist/.trellis/structure/backend/quality-guidelines.md +0 -313
- package/dist/.trellis/structure/frontend/component-guidelines.md +0 -59
- package/dist/.trellis/structure/frontend/directory-structure.md +0 -54
- package/dist/.trellis/structure/frontend/hook-guidelines.md +0 -51
- package/dist/.trellis/structure/frontend/index.md +0 -39
- package/dist/.trellis/structure/frontend/quality-guidelines.md +0 -51
- package/dist/.trellis/structure/frontend/state-management.md +0 -51
- package/dist/.trellis/structure/frontend/type-safety.md +0 -51
- package/dist/.trellis/structure/guides/code-reuse-thinking-guide.md +0 -92
- package/dist/.trellis/structure/guides/cross-layer-thinking-guide.md +0 -94
- package/dist/.trellis/structure/guides/index.md +0 -79
- package/dist/templates/markdown/init-agent.md +0 -315
- /package/dist/{.claude → templates/claude}/agents/plan.md +0 -0
- /package/dist/{.claude → templates/claude}/agents/research.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/before-backend-dev.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/before-frontend-dev.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/break-loop.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/check-backend.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/check-cross-layer.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/check-frontend.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/create-command.md +0 -0
- /package/dist/{.claude → templates/claude}/commands/integrate-skill.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/before-backend-dev.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/before-frontend-dev.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/break-loop.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/check-backend.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/check-cross-layer.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/check-frontend.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/create-command.md +0 -0
- /package/dist/{.cursor → templates/cursor}/commands/integrate-skill.md +0 -0
- /package/dist/{.trellis/agent-traces/index.md → templates/markdown/agent-traces-index.md} +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/add-session.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/common/developer.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/common/phase.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/create-bootstrap.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/get-context.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/get-developer.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/init-developer.sh +0 -0
- /package/dist/{.trellis → templates/trellis}/scripts/multi-agent/create-pr.sh +0 -0
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
# Directory Structure
|
|
2
|
-
|
|
3
|
-
> How backend/CLI code is organized in this project.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This project is a **TypeScript CLI tool** using ES modules. The source code follows a **dogfooding architecture** - Trellis uses its own configuration files (`.cursor/`, `.claude/`, `.trellis/`) as templates for new projects.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Directory Layout
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
src/
|
|
17
|
-
├── cli/ # CLI entry point and argument parsing
|
|
18
|
-
│ └── index.ts # Main CLI entry (Commander.js setup)
|
|
19
|
-
├── commands/ # Command implementations
|
|
20
|
-
│ └── init.ts # Each command in its own file
|
|
21
|
-
├── configurators/ # Configuration generators
|
|
22
|
-
│ ├── claude.ts # Copies .claude/ directory
|
|
23
|
-
│ ├── cursor.ts # Copies .cursor/ directory
|
|
24
|
-
│ ├── opencode.ts # OpenCode configuration (TODO)
|
|
25
|
-
│ └── workflow.ts # Creates .trellis/ structure
|
|
26
|
-
├── constants/ # Shared constants and paths
|
|
27
|
-
│ └── paths.ts # Path constants (centralized)
|
|
28
|
-
├── templates/ # Template utilities and generic templates
|
|
29
|
-
│ ├── markdown/ # Generic markdown templates
|
|
30
|
-
│ │ ├── structure/ # Structure templates (*.md.txt)
|
|
31
|
-
│ │ ├── init-agent.md # Project root file template
|
|
32
|
-
│ │ ├── agents.md # Project root file template
|
|
33
|
-
│ │ ├── worktree.yaml.txt # Generic worktree config
|
|
34
|
-
│ │ └── index.ts # Template exports
|
|
35
|
-
│ └── extract.ts # Template extraction utilities
|
|
36
|
-
├── types/ # TypeScript type definitions
|
|
37
|
-
│ └── ai-tools.ts # AI tool types and registry
|
|
38
|
-
├── utils/ # Shared utility functions
|
|
39
|
-
│ ├── file-writer.ts # File writing with conflict handling
|
|
40
|
-
│ └── project-detector.ts # Project type detection
|
|
41
|
-
└── index.ts # Package entry point (exports public API)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Dogfooding Directories (Project Root)
|
|
45
|
-
|
|
46
|
-
These directories are copied to `dist/` during build and used as templates:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
.cursor/ # Cursor configuration (dogfooded)
|
|
50
|
-
├── commands/ # Slash commands for Cursor
|
|
51
|
-
│ ├── start.md
|
|
52
|
-
│ ├── finish-work.md
|
|
53
|
-
│ └── ...
|
|
54
|
-
|
|
55
|
-
.claude/ # Claude Code configuration (dogfooded)
|
|
56
|
-
├── commands/ # Slash commands
|
|
57
|
-
├── agents/ # Multi-agent pipeline agents
|
|
58
|
-
├── hooks/ # Context injection hooks
|
|
59
|
-
└── settings.json # Hook configuration
|
|
60
|
-
|
|
61
|
-
.trellis/ # Trellis workflow (partially dogfooded)
|
|
62
|
-
├── scripts/ # Shell scripts (dogfooded)
|
|
63
|
-
│ ├── common/ # Shared utilities
|
|
64
|
-
│ ├── multi-agent/ # Pipeline scripts
|
|
65
|
-
│ └── *.sh # Main scripts
|
|
66
|
-
├── agent-traces/ # Developer progress tracking
|
|
67
|
-
│ └── index.md # Index template (dogfooded)
|
|
68
|
-
├── structure/ # Project guidelines (NOT dogfooded)
|
|
69
|
-
│ ├── backend/ # Backend development docs
|
|
70
|
-
│ ├── frontend/ # Frontend development docs
|
|
71
|
-
│ └── guides/ # Thinking guides
|
|
72
|
-
├── workflow.md # Workflow documentation (dogfooded)
|
|
73
|
-
├── worktree.yaml # Worktree config (Trellis-specific)
|
|
74
|
-
└── .gitignore # Git ignore rules (dogfooded)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
## Dogfooding Architecture
|
|
80
|
-
|
|
81
|
-
### What is Dogfooded
|
|
82
|
-
|
|
83
|
-
Files that are copied directly from Trellis project to user projects:
|
|
84
|
-
|
|
85
|
-
| Source | Destination | Description |
|
|
86
|
-
|--------|-------------|-------------|
|
|
87
|
-
| `.cursor/` | `.cursor/` | Entire directory copied |
|
|
88
|
-
| `.claude/` | `.claude/` | Entire directory copied |
|
|
89
|
-
| `.trellis/scripts/` | `.trellis/scripts/` | All scripts copied |
|
|
90
|
-
| `.trellis/workflow.md` | `.trellis/workflow.md` | Direct copy |
|
|
91
|
-
| `.trellis/.gitignore` | `.trellis/.gitignore` | Direct copy |
|
|
92
|
-
| `.trellis/agent-traces/index.md` | `.trellis/agent-traces/index.md` | Direct copy |
|
|
93
|
-
|
|
94
|
-
### What is NOT Dogfooded
|
|
95
|
-
|
|
96
|
-
Files that use generic templates (in `src/templates/`):
|
|
97
|
-
|
|
98
|
-
| Template Source | Destination | Reason |
|
|
99
|
-
|----------------|-------------|--------|
|
|
100
|
-
| `src/templates/markdown/structure/**/*.md.txt` | `.trellis/structure/**/*.md` | User fills with project-specific content |
|
|
101
|
-
| `src/templates/markdown/worktree.yaml.txt` | `.trellis/worktree.yaml` | Language-agnostic template |
|
|
102
|
-
| `src/templates/markdown/init-agent.md` | `init-agent.md` | Project root file |
|
|
103
|
-
| `src/templates/markdown/agents.md` | `AGENTS.md` | Project root file |
|
|
104
|
-
|
|
105
|
-
### Build Process
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
# scripts/copy-templates.js copies dogfooding sources to dist/
|
|
109
|
-
pnpm build
|
|
110
|
-
|
|
111
|
-
# Result:
|
|
112
|
-
dist/
|
|
113
|
-
├── .cursor/ # From project root .cursor/
|
|
114
|
-
├── .claude/ # From project root .claude/
|
|
115
|
-
├── .trellis/ # From project root .trellis/ (filtered)
|
|
116
|
-
│ ├── scripts/ # All scripts
|
|
117
|
-
│ ├── agent-traces/
|
|
118
|
-
│ │ └── index.md # Only index.md, no developer subdirs
|
|
119
|
-
│ ├── workflow.md
|
|
120
|
-
│ ├── worktree.yaml
|
|
121
|
-
│ └── .gitignore
|
|
122
|
-
└── templates/ # From src/templates/ (no .ts files)
|
|
123
|
-
└── markdown/
|
|
124
|
-
└── structure/ # Generic templates
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
## Module Organization
|
|
130
|
-
|
|
131
|
-
### Layer Responsibilities
|
|
132
|
-
|
|
133
|
-
| Layer | Directory | Responsibility |
|
|
134
|
-
|-------|-----------|----------------|
|
|
135
|
-
| CLI | `cli/` | Parse arguments, display help, call commands |
|
|
136
|
-
| Commands | `commands/` | Implement CLI commands, orchestrate actions |
|
|
137
|
-
| Configurators | `configurators/` | Copy/generate configuration for tools |
|
|
138
|
-
| Templates | `templates/` | Extract template content, provide utilities |
|
|
139
|
-
| Types | `types/` | TypeScript type definitions |
|
|
140
|
-
| Utils | `utils/` | Reusable utility functions |
|
|
141
|
-
| Constants | `constants/` | Shared constants (paths, names) |
|
|
142
|
-
|
|
143
|
-
### Configurator Pattern
|
|
144
|
-
|
|
145
|
-
Configurators use `cpSync` for direct directory copy (dogfooding):
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
// configurators/cursor.ts
|
|
149
|
-
export async function configureCursor(cwd: string): Promise<void> {
|
|
150
|
-
const sourcePath = getCursorSourcePath(); // dist/.cursor/ or .cursor/
|
|
151
|
-
const destPath = path.join(cwd, ".cursor");
|
|
152
|
-
cpSync(sourcePath, destPath, { recursive: true });
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Template Extraction
|
|
157
|
-
|
|
158
|
-
`extract.ts` provides utilities for reading dogfooded files:
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
// Get path to .trellis/ (works in dev and production)
|
|
162
|
-
getTrellisSourcePath(): string
|
|
163
|
-
|
|
164
|
-
// Read file from .trellis/
|
|
165
|
-
readTrellisFile(relativePath: string): string
|
|
166
|
-
|
|
167
|
-
// Copy directory from .trellis/ with executable scripts
|
|
168
|
-
copyTrellisDir(srcRelativePath: string, destPath: string, options?: { executable?: boolean }): void
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
---
|
|
172
|
-
|
|
173
|
-
## Naming Conventions
|
|
174
|
-
|
|
175
|
-
### Files and Directories
|
|
176
|
-
|
|
177
|
-
| Convention | Example | Usage |
|
|
178
|
-
|------------|---------|-------|
|
|
179
|
-
| `kebab-case` | `file-writer.ts` | All TypeScript files |
|
|
180
|
-
| `kebab-case` | `multi-agent/` | All directories |
|
|
181
|
-
| `*.ts` | `init.ts` | TypeScript source files |
|
|
182
|
-
| `*.md.txt` | `index.md.txt` | Template files for markdown |
|
|
183
|
-
| `*.yaml.txt` | `worktree.yaml.txt` | Template files for yaml |
|
|
184
|
-
|
|
185
|
-
### Why `.txt` Extension for Templates
|
|
186
|
-
|
|
187
|
-
Templates use `.txt` extension to:
|
|
188
|
-
- Prevent IDE markdown preview from rendering templates
|
|
189
|
-
- Make clear these are template sources, not actual docs
|
|
190
|
-
- Avoid confusion with actual markdown files
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## DO / DON'T
|
|
195
|
-
|
|
196
|
-
### DO
|
|
197
|
-
|
|
198
|
-
- Dogfood from project's own config files when possible
|
|
199
|
-
- Use `cpSync` for copying entire directories
|
|
200
|
-
- Keep generic templates in `src/templates/markdown/`
|
|
201
|
-
- Use `.md.txt` or `.yaml.txt` for template files
|
|
202
|
-
- Update dogfooding sources (`.cursor/`, `.claude/`, `.trellis/scripts/`) when making changes
|
|
203
|
-
|
|
204
|
-
### DON'T
|
|
205
|
-
|
|
206
|
-
- Don't hardcode file lists - copy entire directories instead
|
|
207
|
-
- Don't duplicate content between templates and dogfooding sources
|
|
208
|
-
- Don't put project-specific content in generic templates
|
|
209
|
-
- Don't use dogfooding for structure/ (users fill these in)
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
# Error Handling
|
|
2
|
-
|
|
3
|
-
> How errors are handled in this CLI project.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This CLI project uses a **top-level catch pattern** where errors bubble up to command handlers and are displayed to users with colored output. The approach prioritizes user-friendly error messages while maintaining proper exit codes for scripting.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Error Handling Strategy
|
|
14
|
-
|
|
15
|
-
### Top-Level Catch Pattern
|
|
16
|
-
|
|
17
|
-
All command actions are wrapped in try-catch at the CLI level:
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
// cli/index.ts
|
|
21
|
-
program
|
|
22
|
-
.command("init")
|
|
23
|
-
.action(async (options: Record<string, unknown>) => {
|
|
24
|
-
try {
|
|
25
|
-
await init(options);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error(
|
|
28
|
-
chalk.red("Error:"),
|
|
29
|
-
error instanceof Error ? error.message : error,
|
|
30
|
-
);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Key Principles
|
|
37
|
-
|
|
38
|
-
1. **Let errors bubble up** - Don't catch errors in utility functions unless you can handle them meaningfully
|
|
39
|
-
2. **Type guard for error messages** - Always use `error instanceof Error ? error.message : error`
|
|
40
|
-
3. **Exit with code 1** - All errors should result in `process.exit(1)` for scripting
|
|
41
|
-
4. **User-friendly messages** - Display only the message, not the full stack trace
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Error Patterns
|
|
46
|
-
|
|
47
|
-
### Pattern 1: Top-Level Command Catch
|
|
48
|
-
|
|
49
|
-
Used at the CLI command level to catch all errors:
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
.action(async (options) => {
|
|
53
|
-
try {
|
|
54
|
-
await commandAction(options);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(
|
|
57
|
-
chalk.red("Error:"),
|
|
58
|
-
error instanceof Error ? error.message : error,
|
|
59
|
-
);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Pattern 2: Silent Failure for Optional Operations
|
|
66
|
-
|
|
67
|
-
When an operation is optional and failure is acceptable:
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
// Git config might not be available
|
|
71
|
-
let developerName: string | undefined;
|
|
72
|
-
try {
|
|
73
|
-
developerName = execSync("git config user.name", {
|
|
74
|
-
encoding: "utf-8",
|
|
75
|
-
}).trim();
|
|
76
|
-
} catch {
|
|
77
|
-
// Git not available or no user.name configured - silently ignore
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Pattern 3: Graceful Degradation with Warning
|
|
82
|
-
|
|
83
|
-
When operation fails but we can continue:
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
try {
|
|
87
|
-
execSync(`bash "${scriptPath}" "${developerName}"`, { cwd, stdio: "inherit" });
|
|
88
|
-
developerInitialized = true;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
console.log(
|
|
91
|
-
chalk.yellow(
|
|
92
|
-
`Warning: Failed to initialize developer: ${error instanceof Error ? error.message : error}`,
|
|
93
|
-
),
|
|
94
|
-
);
|
|
95
|
-
// Continue without developer initialization
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Pattern 4: Return-Based Error Signaling
|
|
100
|
-
|
|
101
|
-
For functions that check conditions, return a result object or boolean:
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
function checkPackageJson(cwd: string): { hasFrontend: boolean; hasBackend: boolean } {
|
|
105
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
106
|
-
return { hasFrontend: false, hasBackend: false };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const content = fs.readFileSync(packageJsonPath, "utf-8");
|
|
111
|
-
const pkg = JSON.parse(content);
|
|
112
|
-
// ... analysis logic
|
|
113
|
-
return { hasFrontend, hasBackend };
|
|
114
|
-
} catch {
|
|
115
|
-
return { hasFrontend: false, hasBackend: false };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## Type Guard for Errors
|
|
123
|
-
|
|
124
|
-
Always use the type guard pattern when accessing error properties:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
// Correct: Type guard for error.message
|
|
128
|
-
catch (error) {
|
|
129
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
130
|
-
console.error(chalk.red("Error:"), message);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Incorrect: Assuming error is Error
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error(error.message); // TypeScript error: 'error' is 'unknown'
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## Exit Codes
|
|
142
|
-
|
|
143
|
-
| Code | Meaning | Usage |
|
|
144
|
-
|------|---------|-------|
|
|
145
|
-
| `0` | Success | Normal completion (implicit) |
|
|
146
|
-
| `1` | Error | Any error condition |
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
// Error: exit with code 1
|
|
150
|
-
process.exit(1);
|
|
151
|
-
|
|
152
|
-
// Success: no explicit exit needed, or:
|
|
153
|
-
process.exit(0);
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
---
|
|
157
|
-
|
|
158
|
-
## DO / DON'T
|
|
159
|
-
|
|
160
|
-
### DO
|
|
161
|
-
|
|
162
|
-
- Catch errors at the top level (command handlers)
|
|
163
|
-
- Use `error instanceof Error ? error.message : error` type guard
|
|
164
|
-
- Exit with code 1 on errors for proper scripting
|
|
165
|
-
- Use empty catch for truly optional operations
|
|
166
|
-
- Show user-friendly messages, not stack traces
|
|
167
|
-
- Use `chalk.red()` for error prefixes
|
|
168
|
-
- Use `chalk.yellow()` for warnings
|
|
169
|
-
|
|
170
|
-
### DON'T
|
|
171
|
-
|
|
172
|
-
- Don't catch errors in utility functions unless you can handle them
|
|
173
|
-
- Don't assume `error` is an `Error` type
|
|
174
|
-
- Don't log full stack traces to users (unless in debug mode)
|
|
175
|
-
- Don't use exit code 0 for error conditions
|
|
176
|
-
- Don't swallow errors silently without a comment explaining why
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## Common Mistakes
|
|
181
|
-
|
|
182
|
-
### Mistake 1: Not using type guard
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
// Bad: TypeScript error, runtime risk
|
|
186
|
-
catch (error) {
|
|
187
|
-
console.error(error.message);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Good: Type guard
|
|
191
|
-
catch (error) {
|
|
192
|
-
console.error(error instanceof Error ? error.message : error);
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Mistake 2: Catching too early
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
// Bad: Error caught and re-thrown, losing context
|
|
200
|
-
function readConfig(path: string): Config {
|
|
201
|
-
try {
|
|
202
|
-
return JSON.parse(fs.readFileSync(path, "utf-8"));
|
|
203
|
-
} catch (error) {
|
|
204
|
-
throw new Error("Failed to read config"); // Lost original error
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Good: Let it bubble up with original error
|
|
209
|
-
function readConfig(path: string): Config {
|
|
210
|
-
return JSON.parse(fs.readFileSync(path, "utf-8")); // Caller handles
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### Mistake 3: Silent failure without comment
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
// Bad: Why is this ignored?
|
|
218
|
-
try {
|
|
219
|
-
doSomething();
|
|
220
|
-
} catch {
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Good: Explain why it's safe to ignore
|
|
224
|
-
try {
|
|
225
|
-
doSomething();
|
|
226
|
-
} catch {
|
|
227
|
-
// Optional operation - safe to ignore if it fails
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
## Examples
|
|
234
|
-
|
|
235
|
-
### Complete Command Handler
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
import chalk from "chalk";
|
|
239
|
-
|
|
240
|
-
program
|
|
241
|
-
.command("init")
|
|
242
|
-
.description("Initialize the project")
|
|
243
|
-
.action(async (options: InitOptions) => {
|
|
244
|
-
try {
|
|
245
|
-
await init(options);
|
|
246
|
-
} catch (error) {
|
|
247
|
-
console.error(
|
|
248
|
-
chalk.red("Error:"),
|
|
249
|
-
error instanceof Error ? error.message : error,
|
|
250
|
-
);
|
|
251
|
-
process.exit(1);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### Function with Optional Operation
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
async function init(options: InitOptions): Promise<void> {
|
|
260
|
-
const cwd = process.cwd();
|
|
261
|
-
|
|
262
|
-
// Optional: detect developer name from git
|
|
263
|
-
let developerName = options.user;
|
|
264
|
-
if (!developerName) {
|
|
265
|
-
try {
|
|
266
|
-
developerName = execSync("git config user.name", {
|
|
267
|
-
cwd,
|
|
268
|
-
encoding: "utf-8",
|
|
269
|
-
}).trim();
|
|
270
|
-
} catch {
|
|
271
|
-
// Git not available - will prompt user later
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Required operation - let errors bubble up
|
|
276
|
-
await createWorkflowStructure(cwd, options);
|
|
277
|
-
}
|
|
278
|
-
```
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Backend Development Guidelines
|
|
2
|
-
|
|
3
|
-
> Best practices for backend development in this project.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This directory contains guidelines for backend development. Fill in each file with your project's specific conventions.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Guidelines Index
|
|
14
|
-
|
|
15
|
-
| Guide | Description | Status |
|
|
16
|
-
|-------|-------------|--------|
|
|
17
|
-
| [Directory Structure](./directory-structure.md) | Module organization and file layout | Done |
|
|
18
|
-
| [Database Guidelines](./database-guidelines.md) | ORM patterns, queries, migrations | N/A (CLI project) |
|
|
19
|
-
| [Error Handling](./error-handling.md) | Error types, handling strategies | Done |
|
|
20
|
-
| [Quality Guidelines](./quality-guidelines.md) | Code standards, forbidden patterns | Done |
|
|
21
|
-
| [Logging Guidelines](./logging-guidelines.md) | Structured logging, log levels | Done |
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## How to Fill These Guidelines
|
|
26
|
-
|
|
27
|
-
For each guideline file:
|
|
28
|
-
|
|
29
|
-
1. Document your project's **actual conventions** (not ideals)
|
|
30
|
-
2. Include **code examples** from your codebase
|
|
31
|
-
3. List **forbidden patterns** and why
|
|
32
|
-
4. Add **common mistakes** your team has made
|
|
33
|
-
|
|
34
|
-
The goal is to help AI assistants and new team members understand how YOUR project works.
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
**Language**: All documentation should be written in **English**.
|