@esotech/contextuate 2.0.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 +21 -0
- package/README.md +287 -0
- package/dist/commands/context.js +80 -0
- package/dist/commands/create.js +93 -0
- package/dist/commands/index.js +46 -0
- package/dist/commands/init.js +452 -0
- package/dist/commands/install.js +359 -0
- package/dist/commands/remove.js +77 -0
- package/dist/commands/run.js +205 -0
- package/dist/index.js +96 -0
- package/dist/runtime/driver.js +64 -0
- package/dist/runtime/tools.js +48 -0
- package/dist/templates/README.md +152 -0
- package/dist/templates/agents/aegis.md +366 -0
- package/dist/templates/agents/archon.md +247 -0
- package/dist/templates/agents/atlas.md +326 -0
- package/dist/templates/agents/canvas.md +19 -0
- package/dist/templates/agents/chronicle.md +424 -0
- package/dist/templates/agents/chronos.md +20 -0
- package/dist/templates/agents/cipher.md +360 -0
- package/dist/templates/agents/crucible.md +375 -0
- package/dist/templates/agents/echo.md +297 -0
- package/dist/templates/agents/forge.md +613 -0
- package/dist/templates/agents/ledger.md +317 -0
- package/dist/templates/agents/meridian.md +281 -0
- package/dist/templates/agents/nexus.md +600 -0
- package/dist/templates/agents/oracle.md +281 -0
- package/dist/templates/agents/scribe.md +612 -0
- package/dist/templates/agents/sentinel.md +312 -0
- package/dist/templates/agents/unity.md +17 -0
- package/dist/templates/agents/vox.md +19 -0
- package/dist/templates/agents/weaver.md +334 -0
- package/dist/templates/framework-agents/base.md +166 -0
- package/dist/templates/framework-agents/documentation-expert.md +292 -0
- package/dist/templates/framework-agents/tools-expert.md +245 -0
- package/dist/templates/standards/agent-roles.md +34 -0
- package/dist/templates/standards/agent-workflow.md +170 -0
- package/dist/templates/standards/behavioral-guidelines.md +145 -0
- package/dist/templates/standards/coding-standards.md +171 -0
- package/dist/templates/standards/task-workflow.md +246 -0
- package/dist/templates/templates/context.md +33 -0
- package/dist/templates/templates/contextuate.md +109 -0
- package/dist/templates/templates/platforms/AGENTS.md +5 -0
- package/dist/templates/templates/platforms/CLAUDE.md +5 -0
- package/dist/templates/templates/platforms/GEMINI.md +5 -0
- package/dist/templates/templates/platforms/clinerules.md +5 -0
- package/dist/templates/templates/platforms/copilot.md +5 -0
- package/dist/templates/templates/platforms/cursor.mdc +9 -0
- package/dist/templates/templates/platforms/windsurf.md +5 -0
- package/dist/templates/templates/standards/go.standards.md +167 -0
- package/dist/templates/templates/standards/java.standards.md +167 -0
- package/dist/templates/templates/standards/javascript.standards.md +292 -0
- package/dist/templates/templates/standards/php.standards.md +181 -0
- package/dist/templates/templates/standards/python.standards.md +175 -0
- package/dist/templates/tools/agent-creator.tool.md +252 -0
- package/dist/templates/tools/quickref.tool.md +216 -0
- package/dist/templates/tools/spawn.tool.md +31 -0
- package/dist/templates/tools/standards-detector.tool.md +301 -0
- package/dist/templates/version.json +8 -0
- package/dist/utils/git.js +62 -0
- package/dist/utils/tokens.js +74 -0
- package/package.json +59 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Contextuate Task Workflow Standard
|
|
2
|
+
|
|
3
|
+
> **Purpose:** Standardized structure for multi-session AI tasks that persist across conversations.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use Task Workflow
|
|
8
|
+
|
|
9
|
+
Use this workflow when:
|
|
10
|
+
- Task spans multiple AI sessions
|
|
11
|
+
- Multiple phases of work required
|
|
12
|
+
- Need to track progress over time
|
|
13
|
+
- Collaborating with multiple AI agents/platforms
|
|
14
|
+
- **Complex Orchestration**: For multi-agent teams, see [Agentic Workflow](agent-workflow.md)
|
|
15
|
+
- Complex project requiring documentation
|
|
16
|
+
|
|
17
|
+
Don't use for:
|
|
18
|
+
- Simple, single-session tasks
|
|
19
|
+
- Quick questions or lookups
|
|
20
|
+
- Minor code changes
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Agentic Orchestration
|
|
25
|
+
|
|
26
|
+
For complex tasks requiring specialized roles (Archon, Chronos, etc.), this Task Workflow serves as the **Session Governance** layer.
|
|
27
|
+
|
|
28
|
+
* **Relationship**: The `task.md` file becomes the "Shared State" (or blackboard) for the Agentic Workflow.
|
|
29
|
+
* **Orchestrator**: The **Archon** agent manages the `task.md` file, while sub-agents focus on their specific files.
|
|
30
|
+
* **Reference**: See **[Agentic Workflow Standard](agent-workflow.md)** for the full dispatch protocol.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Directory Structure
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
docs/ai/tasks/{task-name}/
|
|
38
|
+
├── 00-project-scope.md # Task definition (required)
|
|
39
|
+
├── 01-{phase-name}.md # Phase documentation (as needed)
|
|
40
|
+
├── 02-{phase-name}.md
|
|
41
|
+
├── ...
|
|
42
|
+
├── files/ # Input files, specs, references
|
|
43
|
+
│ └── {relevant-files}
|
|
44
|
+
└── logs/ # Progress tracking
|
|
45
|
+
└── {number}-{date}-{summary}.md
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Location
|
|
49
|
+
- All tasks live in `docs/ai/tasks/`
|
|
50
|
+
- This folder is gitignored (user-specific)
|
|
51
|
+
- Each task gets its own subfolder
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## File Templates
|
|
56
|
+
|
|
57
|
+
### 00-project-scope.md (Required)
|
|
58
|
+
|
|
59
|
+
```markdown
|
|
60
|
+
# {Task Name}
|
|
61
|
+
|
|
62
|
+
> **Status:** {Planning | In Progress | Blocked | Complete}
|
|
63
|
+
> **Created:** {YYYY-MM-DD}
|
|
64
|
+
> **Updated:** {YYYY-MM-DD}
|
|
65
|
+
|
|
66
|
+
## Objective
|
|
67
|
+
|
|
68
|
+
{One paragraph describing what this task accomplishes}
|
|
69
|
+
|
|
70
|
+
## Requirements
|
|
71
|
+
|
|
72
|
+
- [ ] {Requirement 1}
|
|
73
|
+
- [ ] {Requirement 2}
|
|
74
|
+
- [ ] {Requirement 3}
|
|
75
|
+
|
|
76
|
+
## Success Criteria
|
|
77
|
+
|
|
78
|
+
- {Measurable outcome 1}
|
|
79
|
+
- {Measurable outcome 2}
|
|
80
|
+
|
|
81
|
+
## Phases
|
|
82
|
+
|
|
83
|
+
| Phase | Description | Status |
|
|
84
|
+
| ----- | -------------- | ------------------------- |
|
|
85
|
+
| 1 | {Phase 1 name} | {Pending/Active/Complete} |
|
|
86
|
+
| 2 | {Phase 2 name} | {Pending/Active/Complete} |
|
|
87
|
+
|
|
88
|
+
## Constraints
|
|
89
|
+
|
|
90
|
+
- {Technical constraint}
|
|
91
|
+
- {Timeline constraint}
|
|
92
|
+
- {Resource constraint}
|
|
93
|
+
|
|
94
|
+
## Open Questions
|
|
95
|
+
|
|
96
|
+
- [ ] {Question needing resolution}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Phase Files (01-{name}.md, 02-{name}.md, ...)
|
|
100
|
+
|
|
101
|
+
```markdown
|
|
102
|
+
# Phase {N}: {Phase Name}
|
|
103
|
+
|
|
104
|
+
> **Status:** {Pending | Active | Complete}
|
|
105
|
+
> **Started:** {YYYY-MM-DD}
|
|
106
|
+
> **Completed:** {YYYY-MM-DD or blank}
|
|
107
|
+
|
|
108
|
+
## Objectives
|
|
109
|
+
|
|
110
|
+
- {Phase objective 1}
|
|
111
|
+
- {Phase objective 2}
|
|
112
|
+
|
|
113
|
+
## Approach
|
|
114
|
+
|
|
115
|
+
{Description of how this phase will be executed}
|
|
116
|
+
|
|
117
|
+
## Deliverables
|
|
118
|
+
|
|
119
|
+
- [ ] {Deliverable 1}
|
|
120
|
+
- [ ] {Deliverable 2}
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
{Working notes, decisions made, issues encountered}
|
|
125
|
+
|
|
126
|
+
## Outcome
|
|
127
|
+
|
|
128
|
+
{Summary of what was accomplished - filled in when complete}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Log Files (logs/{number}-{date}-{summary}.md)
|
|
132
|
+
|
|
133
|
+
```markdown
|
|
134
|
+
# Log: {Summary}
|
|
135
|
+
|
|
136
|
+
> **Date:** {YYYY-MM-DD}
|
|
137
|
+
> **Session:** {number}
|
|
138
|
+
> **Platform:** {Claude Code | Cursor | Copilot | etc.}
|
|
139
|
+
|
|
140
|
+
## Work Completed
|
|
141
|
+
|
|
142
|
+
- {Action taken 1}
|
|
143
|
+
- {Action taken 2}
|
|
144
|
+
|
|
145
|
+
## Decisions Made
|
|
146
|
+
|
|
147
|
+
- {Decision and rationale}
|
|
148
|
+
|
|
149
|
+
## Blockers/Issues
|
|
150
|
+
|
|
151
|
+
- {Issue encountered}
|
|
152
|
+
|
|
153
|
+
## Next Steps
|
|
154
|
+
|
|
155
|
+
- {What should be done next}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Naming Conventions
|
|
161
|
+
|
|
162
|
+
### Task Folders
|
|
163
|
+
- Use lowercase
|
|
164
|
+
- Use hyphens for spaces
|
|
165
|
+
- Be descriptive but concise
|
|
166
|
+
- Examples: `user-auth-refactor`, `api-v2-migration`, `performance-audit`
|
|
167
|
+
|
|
168
|
+
### Phase Files
|
|
169
|
+
- Prefix with two-digit number: `01-`, `02-`, etc.
|
|
170
|
+
- Use descriptive names: `01-analysis.md`, `02-design.md`
|
|
171
|
+
|
|
172
|
+
### Log Files
|
|
173
|
+
- Format: `{number}-{YYYY-MM-DD}-{summary}.md`
|
|
174
|
+
- Example: `01-2024-01-15-initial-analysis.md`
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Workflow Process
|
|
179
|
+
|
|
180
|
+
### Starting a Task
|
|
181
|
+
|
|
182
|
+
1. Create task folder: `docs/ai/tasks/{task-name}/`
|
|
183
|
+
2. Create `00-project-scope.md` with objectives and requirements
|
|
184
|
+
3. Create `files/` folder if you have input materials
|
|
185
|
+
4. Create first log entry
|
|
186
|
+
|
|
187
|
+
### During Work
|
|
188
|
+
|
|
189
|
+
1. Update phase files as work progresses
|
|
190
|
+
2. Create log entries for each significant session
|
|
191
|
+
3. Check off requirements as completed
|
|
192
|
+
4. Update status in scope file
|
|
193
|
+
|
|
194
|
+
### Completing a Task
|
|
195
|
+
|
|
196
|
+
1. Mark all requirements complete
|
|
197
|
+
2. Update scope status to "Complete"
|
|
198
|
+
3. Write final log entry with summary
|
|
199
|
+
4. Archive or delete if no longer needed
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Cross-Platform Considerations
|
|
204
|
+
|
|
205
|
+
### Platform Detection
|
|
206
|
+
Log entries should note which AI platform performed the work. This helps when:
|
|
207
|
+
- Debugging issues
|
|
208
|
+
- Understanding context limitations
|
|
209
|
+
- Coordinating between platforms
|
|
210
|
+
|
|
211
|
+
### Context Limits
|
|
212
|
+
Different AI platforms have different context windows. Structure files so:
|
|
213
|
+
- Scope file is self-contained and readable alone
|
|
214
|
+
- Phase files focus on single phases
|
|
215
|
+
- Log files are chronological and scannable
|
|
216
|
+
|
|
217
|
+
### Handoff
|
|
218
|
+
When switching platforms mid-task:
|
|
219
|
+
1. Create a log entry summarizing current state
|
|
220
|
+
2. Note any platform-specific context
|
|
221
|
+
3. List explicit next steps
|
|
222
|
+
4. Reference relevant files
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Best Practices
|
|
227
|
+
|
|
228
|
+
### Keep It Updated
|
|
229
|
+
- Update scope status regularly
|
|
230
|
+
- Create log entries for significant sessions
|
|
231
|
+
- Check off requirements as completed
|
|
232
|
+
|
|
233
|
+
### Be Specific
|
|
234
|
+
- Use concrete, measurable requirements
|
|
235
|
+
- Document decisions and rationale
|
|
236
|
+
- Include file paths and code references
|
|
237
|
+
|
|
238
|
+
### Stay Focused
|
|
239
|
+
- One task per folder
|
|
240
|
+
- Don't mix unrelated work
|
|
241
|
+
- Split large tasks into subtasks if needed
|
|
242
|
+
|
|
243
|
+
### Clean Up
|
|
244
|
+
- Archive completed tasks periodically
|
|
245
|
+
- Remove obsolete files from `files/`
|
|
246
|
+
- Delete tasks that were abandoned
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
> **Purpose:** Master index for AI assistants working with this project. This is the primary entry point for all AI context.
|
|
4
|
+
> **Directive:** Read this file first. It is the "Brain" of the project.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Project Identity
|
|
9
|
+
|
|
10
|
+
**Project Name:** {YOUR_PROJECT_NAME}
|
|
11
|
+
|
|
12
|
+
**Description:** {Brief description of what this project does}
|
|
13
|
+
|
|
14
|
+
**Tech Stack:**
|
|
15
|
+
- **Languages:** {Language 1}, {Language 2}
|
|
16
|
+
- **Frameworks:** {Framework 1}, {Framework 2}
|
|
17
|
+
- **Infrastructure:** {Database}, {Cloud Provider}
|
|
18
|
+
|
|
19
|
+
## 2. Key Concepts
|
|
20
|
+
|
|
21
|
+
### {Concept 1}
|
|
22
|
+
{Explanation of important concept}
|
|
23
|
+
|
|
24
|
+
### {Concept 2}
|
|
25
|
+
{Explanation of important concept}
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 3. Resources
|
|
30
|
+
|
|
31
|
+
- **Repository:** {URL}
|
|
32
|
+
- **Issue Tracker:** {URL}
|
|
33
|
+
- **Staging/Prod:** {URL}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Contextuate
|
|
2
|
+
|
|
3
|
+
<!--
|
|
4
|
+
CONTEXTUATE MANAGED FILE - DO NOT MODIFY
|
|
5
|
+
This file is generated by the Esotech Framework and will be overwritten during updates.
|
|
6
|
+
Customize your project context in: docs/ai/context.md
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
> **Purpose:** Master entry point for AI assistants. This file bootstraps the Esotech Framework.
|
|
10
|
+
> **Directive:** Read this file first, then follow instructions to load project context.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Project Context
|
|
15
|
+
|
|
16
|
+
**Read the project-specific context file for details about this project:**
|
|
17
|
+
|
|
18
|
+
[Project Context](../context.md)
|
|
19
|
+
|
|
20
|
+
> If `context.md` exists, it contains project identity, tech stack, and custom configurations.
|
|
21
|
+
|
|
22
|
+
## Framework Usage Guide
|
|
23
|
+
|
|
24
|
+
This folder (`docs/ai/.contextuate/`) contains the immutable framework definitions. You should use references to these files to "pull in" capabilities only when needed, maintaining token efficiency.
|
|
25
|
+
|
|
26
|
+
**Do not read all files in this directory at once.**
|
|
27
|
+
|
|
28
|
+
1. **Discover**: Read this file (`contextuate.md`) to map the available resources.
|
|
29
|
+
2. **Select**: Identify the specific agent, tool, or standard relevant to your current task.
|
|
30
|
+
3. **Load**: Read only that specific file.
|
|
31
|
+
|
|
32
|
+
For example, if you need to create a new agent, read `docs/ai/.contextuate/tools/agent-creator.tool.md`. You do not need to read the entire standards library unless you are writing code that specifically requires it.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 2. Agent Framework
|
|
37
|
+
|
|
38
|
+
> **Rule:** If a specialized agent exists for your task, you MUST adopt that persona and read its specific context.
|
|
39
|
+
|
|
40
|
+
### Agent Registry
|
|
41
|
+
| Task Domain | Agent | Context File |
|
|
42
|
+
| -------------- | ------------ | ---------------------------------------------------------------------------------------- |
|
|
43
|
+
| General Coding | Base Agent | [.contextuate/agents/base.md](.contextuate/agents/base.md) |
|
|
44
|
+
| Documentation | Docs Expert | [.contextuate/agents/documentation-expert.md](.contextuate/agents/documentation-expert.md) |
|
|
45
|
+
| Tools Expert | Tools Expert | [.contextuate/agents/tools-expert.md](.contextuate/agents/tools-expert.md) |
|
|
46
|
+
|
|
47
|
+
### Custom Agents
|
|
48
|
+
Custom agents are stored in `docs/ai/agents/`. Create new agents using the Agent Creator tool.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 3. Tooling Ecosystem
|
|
53
|
+
|
|
54
|
+
### Framework Tools
|
|
55
|
+
| Tool | Purpose | Instruction Guide |
|
|
56
|
+
| ---------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
57
|
+
| **Standards Detector** | Analyze code to find patterns | [.contextuate/tools/standards-detector.tool.md](.contextuate/tools/standards-detector.tool.md) |
|
|
58
|
+
| **Quickref Generator** | Condense docs for AI usage | [.contextuate/tools/quickref.tool.md](.contextuate/tools/quickref.tool.md) |
|
|
59
|
+
| **Agent Creator** | Generate new agent personas | [.contextuate/tools/agent-creator.tool.md](.contextuate/tools/agent-creator.tool.md) |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 4. Standards & Conventions
|
|
64
|
+
|
|
65
|
+
### Coding Standards
|
|
66
|
+
| Language | Standards File |
|
|
67
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| PHP | [.contextuate/templates/standards/php.standards.md](.contextuate/templates/standards/php.standards.md) |
|
|
69
|
+
| JavaScript/TypeScript | [.contextuate/templates/standards/javascript.standards.md](.contextuate/templates/standards/javascript.standards.md) |
|
|
70
|
+
| Python | [.contextuate/templates/standards/python.standards.md](.contextuate/templates/standards/python.standards.md) |
|
|
71
|
+
| Go | [.contextuate/templates/standards/go.standards.md](.contextuate/templates/standards/go.standards.md) |
|
|
72
|
+
| Java | [.contextuate/templates/standards/java.standards.md](.contextuate/templates/standards/java.standards.md) |
|
|
73
|
+
|
|
74
|
+
Custom standards can be added in `docs/ai/standards/`.
|
|
75
|
+
|
|
76
|
+
### Behavioral Guidelines
|
|
77
|
+
**[Behavioral Guidelines](.contextuate/standards/behavioral-guidelines.md)**
|
|
78
|
+
- Verified Truth: Do not speculate.
|
|
79
|
+
- Minimal Intervention: Only change what is requested.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 5. Documentation Strategy
|
|
84
|
+
|
|
85
|
+
> **Rule:** Store knowledge where it belongs. Do not rely on chat history.
|
|
86
|
+
|
|
87
|
+
| Content Type | Location |
|
|
88
|
+
| ----------------------- | -------------------- |
|
|
89
|
+
| **AI Context** | `docs/ai/` |
|
|
90
|
+
| **Custom Agents** | `docs/ai/agents/` |
|
|
91
|
+
| **Custom Standards** | `docs/ai/standards/` |
|
|
92
|
+
| **Quick References** | `docs/ai/quickrefs/` |
|
|
93
|
+
| **Multi-Session Tasks** | `docs/ai/tasks/` |
|
|
94
|
+
| **Custom Commands** | `docs/ai/commands/` |
|
|
95
|
+
|
|
96
|
+
### Multi-Session Tasks
|
|
97
|
+
For complex tasks that span multiple sessions:
|
|
98
|
+
1. Read **[Task Workflow](.contextuate/standards/task-workflow.md)**.
|
|
99
|
+
2. Create a folder in `docs/ai/tasks/{task-name}/`.
|
|
100
|
+
3. Maintain a `00-project-scope.md` and log files.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 6. Framework Information
|
|
105
|
+
|
|
106
|
+
**Esotech Framework** is a standardized AI context framework.
|
|
107
|
+
|
|
108
|
+
- **Documentation:** https://contextuate.md
|
|
109
|
+
- **Version:** Check `.contextuate/version.json`
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Go Coding Standards
|
|
2
|
+
|
|
3
|
+
> **Language:** Go
|
|
4
|
+
> **Generated:** {DATE}
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Formatting
|
|
9
|
+
|
|
10
|
+
### Tooling
|
|
11
|
+
- **Required:** `gofmt` (or `goimports`) must be applied to all files.
|
|
12
|
+
|
|
13
|
+
### Indentation
|
|
14
|
+
- **Style:** Tabs (Standard Go behavior)
|
|
15
|
+
|
|
16
|
+
### Line Length
|
|
17
|
+
- **Guideline:** No strict limit, but prefer readability (80-120 chars).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Naming Conventions
|
|
22
|
+
|
|
23
|
+
### General Rule
|
|
24
|
+
- Use `MixedCaps` or `mixedCaps` (CamelCase).
|
|
25
|
+
- Keep names short and concise.
|
|
26
|
+
|
|
27
|
+
### Packages
|
|
28
|
+
- **Style:** lowercase, single word
|
|
29
|
+
- **Avoid:** snake_case, camelCase in package names
|
|
30
|
+
- **Example:** `package user`, not `package user_service`
|
|
31
|
+
|
|
32
|
+
### Interfaces
|
|
33
|
+
- **Style:** Method name + "er" (if single method)
|
|
34
|
+
- **Example:** `Reader`, `Writer`, `Formatter`
|
|
35
|
+
|
|
36
|
+
### Structs/Interfaces
|
|
37
|
+
- **Exported:** PascalCase (`User`)
|
|
38
|
+
- **Unexported:** camelCase (`userHelper`)
|
|
39
|
+
|
|
40
|
+
### Functions/Methods
|
|
41
|
+
- **Exported:** PascalCase (`GetUser`)
|
|
42
|
+
- **Unexported:** camelCase (`parseData`)
|
|
43
|
+
|
|
44
|
+
### Constants
|
|
45
|
+
- **Style:** PascalCase (for exported) or camelCase
|
|
46
|
+
- **Avoid:** UPPER_SNAKE_CASE (unlike other languages)
|
|
47
|
+
- **Example:** `MaxRetries`, not `MAX_RETRIES`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Structure
|
|
52
|
+
|
|
53
|
+
### File Organization
|
|
54
|
+
```go
|
|
55
|
+
package main
|
|
56
|
+
|
|
57
|
+
// 1. Imports (grouped: stdlib, third-party, local)
|
|
58
|
+
import (
|
|
59
|
+
"fmt"
|
|
60
|
+
"os"
|
|
61
|
+
|
|
62
|
+
"github.com/pkg/errors"
|
|
63
|
+
|
|
64
|
+
"myproject/internal/user"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// 2. Constants
|
|
68
|
+
const DefaultTimeout = 30
|
|
69
|
+
|
|
70
|
+
// 3. Types (Structs/Interfaces)
|
|
71
|
+
type Service interface {
|
|
72
|
+
Do() error
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 4. Factory Functions
|
|
76
|
+
func NewService() Service {
|
|
77
|
+
return &serviceImpl{}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 5. Methods
|
|
81
|
+
func (s *serviceImpl) Do() error {
|
|
82
|
+
return nil
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Error Handling
|
|
89
|
+
|
|
90
|
+
### Pattern
|
|
91
|
+
- **Style:** Check errors immediately. Avoid nesting.
|
|
92
|
+
|
|
93
|
+
```go
|
|
94
|
+
// GOOD
|
|
95
|
+
f, err := os.Open("file.txt")
|
|
96
|
+
if err != nil {
|
|
97
|
+
return err
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// BAD
|
|
101
|
+
if f, err := os.Open("file.txt"); err == nil {
|
|
102
|
+
// ...
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Wrapping
|
|
107
|
+
- **Guideline:** Wrap errors with context when passing up the stack.
|
|
108
|
+
- **Example:** `fmt.Errorf("failed to open config: %w", err)`
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Documentation
|
|
113
|
+
|
|
114
|
+
### Comments
|
|
115
|
+
- **Exported identifiers:** MUST have a doc comment starting with the name.
|
|
116
|
+
- **Format:** Complete sentences.
|
|
117
|
+
|
|
118
|
+
```go
|
|
119
|
+
// User represents a system user.
|
|
120
|
+
type User struct { ... }
|
|
121
|
+
|
|
122
|
+
// Fetch retrieves the user by ID.
|
|
123
|
+
func (u *User) Fetch(id int) error { ... }
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Common Patterns
|
|
129
|
+
|
|
130
|
+
### Options Pattern
|
|
131
|
+
```go
|
|
132
|
+
// Preferred for complex constructors
|
|
133
|
+
type Option func(*Server)
|
|
134
|
+
|
|
135
|
+
func WithPort(port int) Option {
|
|
136
|
+
return func(s *Server) { s.port = port }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
func NewServer(opts ...Option) *Server { ... }
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Context
|
|
143
|
+
- **Guideline:** Pass `context.Context` as the first argument to functions performing I/O.
|
|
144
|
+
|
|
145
|
+
```go
|
|
146
|
+
func (s *Service) GetData(ctx context.Context, id string) error { ... }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Anti-Patterns
|
|
152
|
+
|
|
153
|
+
```go
|
|
154
|
+
// BAD: Panic in libraries
|
|
155
|
+
func Parse() {
|
|
156
|
+
if err != nil {
|
|
157
|
+
panic(err) // Return error instead
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// BAD: Global state
|
|
162
|
+
var db *sql.DB // Use dependency injection
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
*This file should be customized for your project. Replace placeholders with actual values.*
|