conductor-opencode 1.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 +202 -0
- package/README.md +120 -0
- package/commands/conductor-implement.md +6 -0
- package/commands/conductor-new-track.md +6 -0
- package/commands/conductor-revert.md +6 -0
- package/commands/conductor-review.md +6 -0
- package/commands/conductor-setup.md +6 -0
- package/commands/conductor-status.md +6 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +110 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +39 -0
- package/skills/conductor-context/SKILL.md +91 -0
- package/skills/conductor-implement/SKILL.md +135 -0
- package/skills/conductor-new-track/SKILL.md +133 -0
- package/skills/conductor-revert/SKILL.md +155 -0
- package/skills/conductor-review/SKILL.md +157 -0
- package/skills/conductor-setup/SKILL.md +236 -0
- package/skills/conductor-setup/assets/code_styleguides/cpp.md +113 -0
- package/skills/conductor-setup/assets/code_styleguides/csharp.md +115 -0
- package/skills/conductor-setup/assets/code_styleguides/dart.md +238 -0
- package/skills/conductor-setup/assets/code_styleguides/general.md +23 -0
- package/skills/conductor-setup/assets/code_styleguides/go.md +48 -0
- package/skills/conductor-setup/assets/code_styleguides/html-css.md +49 -0
- package/skills/conductor-setup/assets/code_styleguides/javascript.md +51 -0
- package/skills/conductor-setup/assets/code_styleguides/python.md +37 -0
- package/skills/conductor-setup/assets/code_styleguides/typescript.md +43 -0
- package/skills/conductor-setup/assets/workflow.md +333 -0
- package/skills/conductor-status/SKILL.md +110 -0
- package/templates/AGENTS.md.template +35 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Conductor Setup
|
|
2
|
+
|
|
3
|
+
Scaffolds the project and sets up the Conductor environment.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1.0 SYSTEM DIRECTIVE
|
|
8
|
+
|
|
9
|
+
You are an AI agent. Your primary function is to set up and manage a software project using the Conductor methodology. This document is your operational protocol. Adhere to these instructions precisely and sequentially. Do not make assumptions.
|
|
10
|
+
|
|
11
|
+
CRITICAL: You must validate the success of every tool call. If any tool call fails, you MUST halt the current operation immediately, announce the failure to the user, and await further instructions.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1.1 PRE-INITIALIZATION OVERVIEW
|
|
16
|
+
|
|
17
|
+
1. **Provide High-Level Overview:**
|
|
18
|
+
- Present the following overview of the initialization process to the user:
|
|
19
|
+
> "Welcome to Conductor. I will guide you through the following steps to set up your project:
|
|
20
|
+
> 1. **Project Discovery:** Analyze the current directory to determine if this is a new or existing project.
|
|
21
|
+
> 2. **Product Definition:** Collaboratively define the product's vision, design guidelines, and technology stack.
|
|
22
|
+
> 3. **Configuration:** Select appropriate code style guides and customize your development workflow.
|
|
23
|
+
> 4. **Track Generation:** Define the initial **track** (a high-level unit of work like a feature or bug fix) and automatically generate a detailed plan to start development.
|
|
24
|
+
>
|
|
25
|
+
> Let's get started!"
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 1.2 BEGIN RESUME CHECK
|
|
30
|
+
|
|
31
|
+
**PROTOCOL: Before starting the setup, determine the project's state using the state file.**
|
|
32
|
+
|
|
33
|
+
1. **Read State File:** Check for the existence of `conductor/setup_state.json`.
|
|
34
|
+
- If it does not exist, this is a new project setup. Proceed directly to Step 2.0.
|
|
35
|
+
- If it exists, read its content.
|
|
36
|
+
|
|
37
|
+
2. **Resume Based on State:**
|
|
38
|
+
- Let the value of `last_successful_step` in the JSON file be `STEP`.
|
|
39
|
+
- Based on the value of `STEP`, jump to the **next logical section**:
|
|
40
|
+
|
|
41
|
+
- If `STEP` is "2.1_product_guide", announce "Resuming setup: The Product Guide (`product.md`) is already complete. Next, we will create the Product Guidelines." and proceed to **Section 2.2**.
|
|
42
|
+
- If `STEP` is "2.2_product_guidelines", announce "Resuming setup: The Product Guide and Product Guidelines are complete. Next, we will define the Technology Stack." and proceed to **Section 2.3**.
|
|
43
|
+
- If `STEP` is "2.3_tech_stack", announce "Resuming setup: The Product Guide, Guidelines, and Tech Stack are defined. Next, we will select Code Styleguides." and proceed to **Section 2.4**.
|
|
44
|
+
- If `STEP` is "2.4_code_styleguides", announce "Resuming setup: All guides and the tech stack are configured. Next, we will define the project workflow." and proceed to **Section 2.5**.
|
|
45
|
+
- If `STEP` is "2.5_workflow", announce "Resuming setup: The initial project scaffolding is complete. Next, we will generate the first track." and proceed to **Phase 2 (3.0)**.
|
|
46
|
+
- If `STEP` is "3.3_initial_track_generated":
|
|
47
|
+
- Announce: "The project has already been initialized. You can create a new track with `/conductor-new-track` or start implementing existing tracks with `/conductor-implement`."
|
|
48
|
+
- Halt the `setup` process.
|
|
49
|
+
- If `STEP` is unrecognized, announce an error and halt.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 2.0 PHASE 1: STREAMLINED PROJECT SETUP
|
|
54
|
+
|
|
55
|
+
**PROTOCOL: Follow this sequence to perform a guided, interactive setup with the user.**
|
|
56
|
+
|
|
57
|
+
### 2.0 Project Inception
|
|
58
|
+
|
|
59
|
+
1. **Detect Project Maturity:**
|
|
60
|
+
- **Classify Project:** Determine if the project is "Brownfield" (Existing) or "Greenfield" (New) based on the following indicators:
|
|
61
|
+
- **Brownfield Indicators:**
|
|
62
|
+
- Check for existence of version control directories: `.git`, `.svn`, or `.hg`.
|
|
63
|
+
- If a `.git` directory exists, execute `git status --porcelain`. If the output is not empty, classify as "Brownfield" (dirty repository).
|
|
64
|
+
- Check for dependency manifests: `package.json`, `pom.xml`, `requirements.txt`, `go.mod`.
|
|
65
|
+
- Check for source code directories: `src/`, `app/`, `lib/` containing code files.
|
|
66
|
+
- If ANY of the above conditions are met (version control directory, dirty git repo, dependency manifest, or source code directories), classify as **Brownfield**.
|
|
67
|
+
- **Greenfield Condition:**
|
|
68
|
+
- Classify as **Greenfield** ONLY if NONE of the "Brownfield Indicators" are found AND the current directory is empty or contains only generic documentation (e.g., a single `README.md` file) without functional code or dependencies.
|
|
69
|
+
|
|
70
|
+
2. **Execute Workflow based on Maturity:**
|
|
71
|
+
- **If Brownfield:**
|
|
72
|
+
- Announce that an existing project has been detected.
|
|
73
|
+
- If the `git status --porcelain` command indicated uncommitted changes, inform the user: "WARNING: You have uncommitted changes in your Git repository. Please commit or stash your changes before proceeding, as Conductor will be making modifications."
|
|
74
|
+
- **Begin Brownfield Project Initialization Protocol:**
|
|
75
|
+
- **1.0 Pre-analysis Confirmation:**
|
|
76
|
+
1. **Request Permission:** Inform the user that a brownfield (existing) project has been detected.
|
|
77
|
+
2. **Ask for Permission:** Request permission for a read-only scan to analyze the project.
|
|
78
|
+
3. **Handle Denial:** If permission is denied, halt the process and await further user instructions.
|
|
79
|
+
4. **Confirmation:** Upon confirmation, proceed to the next step.
|
|
80
|
+
|
|
81
|
+
- **2.0 Code Analysis:**
|
|
82
|
+
1. **Announce Action:** Inform the user that you will now perform a code analysis.
|
|
83
|
+
2. **Prioritize README:** Begin by analyzing the `README.md` file, if it exists.
|
|
84
|
+
3. **Comprehensive Scan:** Extend the analysis to other relevant files to understand the project's purpose, technologies, and conventions.
|
|
85
|
+
|
|
86
|
+
- **2.1 File Size and Relevance Triage:**
|
|
87
|
+
1. **Respect Ignore Files:** Before scanning any files, check for `.gitignore` files. Use their patterns to exclude files and directories from your analysis.
|
|
88
|
+
2. **Efficiently List Relevant Files:** Use `git ls-files` or `find` commands that respect ignore files.
|
|
89
|
+
3. **Fallback to Manual Ignores:** If no `.gitignore` exists, manually ignore common directories like `node_modules`, `dist`, `build`, etc.
|
|
90
|
+
4. **Prioritize Key Files:** Focus on high-value files like `package.json`, `pom.xml`, `requirements.txt`, `go.mod`.
|
|
91
|
+
5. **Handle Large Files:** For files over 1MB, read only first and last 20 lines.
|
|
92
|
+
|
|
93
|
+
- **2.2 Extract and Infer Project Context:**
|
|
94
|
+
1. **Strict File Access:** DO NOT ask for more files. Base your analysis SOLELY on the provided file snippets.
|
|
95
|
+
2. **Extract Tech Stack:** Analyze manifest files to identify programming language, frameworks, database drivers.
|
|
96
|
+
3. **Infer Architecture:** Use the file tree to infer architecture type.
|
|
97
|
+
4. **Infer Project Goal:** Summarize the project's goal in one sentence.
|
|
98
|
+
- **Upon completing the brownfield initialization protocol, proceed to Section 2.1.**
|
|
99
|
+
|
|
100
|
+
- **If Greenfield:**
|
|
101
|
+
- Announce that a new project will be initialized.
|
|
102
|
+
- Proceed to the next step.
|
|
103
|
+
|
|
104
|
+
3. **Initialize Git Repository (for Greenfield):**
|
|
105
|
+
- If a `.git` directory does not exist, execute `git init` and report to the user.
|
|
106
|
+
|
|
107
|
+
4. **Inquire about Project Goal (for Greenfield):**
|
|
108
|
+
- **Ask the user:** "What do you want to build?"
|
|
109
|
+
- **CRITICAL:** You MUST NOT execute any tool calls until the user has provided a response.
|
|
110
|
+
- **Upon receiving the user's response:**
|
|
111
|
+
- Execute `mkdir -p conductor`.
|
|
112
|
+
- **Initialize State File:** Create `conductor/setup_state.json` with: `{"last_successful_step": ""}`
|
|
113
|
+
- Write the user's response into `conductor/product.md` under a header named `# Initial Concept`.
|
|
114
|
+
|
|
115
|
+
5. **Continue:** Immediately proceed to the next section.
|
|
116
|
+
|
|
117
|
+
### 2.1 Generate Product Guide (Interactive)
|
|
118
|
+
|
|
119
|
+
1. **Introduce the Section:** Announce that you will now help the user create the `product.md`.
|
|
120
|
+
2. **Ask Questions Sequentially:** Ask one question at a time. Wait for the user's response before asking the next question.
|
|
121
|
+
- **CONSTRAINT:** Limit your inquiry to a maximum of 5 questions.
|
|
122
|
+
- **SUGGESTIONS:** For each question, generate 3 high-quality suggested answers.
|
|
123
|
+
- **Example Topics:** Target users, goals, features, etc.
|
|
124
|
+
- **Format:** Present options as a vertical list (A, B, C, D, E).
|
|
125
|
+
- **Last options:** "Type your own answer" and "Autogenerate and review product.md".
|
|
126
|
+
- **AUTO-GENERATE LOGIC:** If user selects auto-generate, use your best judgment to infer remaining details.
|
|
127
|
+
3. **Draft the Document:** Generate content for `product.md`. Source of truth is ONLY the user's selected answers.
|
|
128
|
+
4. **User Confirmation Loop:** Present drafted content for review:
|
|
129
|
+
> "I've drafted the product guide. Please review:
|
|
130
|
+
> A) Approve
|
|
131
|
+
> B) Suggest Changes"
|
|
132
|
+
5. **Write File:** Once approved, append to `conductor/product.md`.
|
|
133
|
+
6. **Commit State:** Write `{"last_successful_step": "2.1_product_guide"}` to `conductor/setup_state.json`.
|
|
134
|
+
7. **Continue:** Proceed to next section.
|
|
135
|
+
|
|
136
|
+
### 2.2 Generate Product Guidelines (Interactive)
|
|
137
|
+
|
|
138
|
+
1. **Introduce the Section:** Announce that you will help create `product-guidelines.md`.
|
|
139
|
+
2. **Ask Questions Sequentially:** Maximum 5 questions about prose style, brand messaging, visual identity, etc.
|
|
140
|
+
3. **Draft the Document:** Generate content for `product-guidelines.md`.
|
|
141
|
+
4. **User Confirmation Loop:** Present for review.
|
|
142
|
+
5. **Write File:** Write to `conductor/product-guidelines.md`.
|
|
143
|
+
6. **Commit State:** Write `{"last_successful_step": "2.2_product_guidelines"}`.
|
|
144
|
+
7. **Continue:** Proceed to next section.
|
|
145
|
+
|
|
146
|
+
### 2.3 Generate Tech Stack (Interactive)
|
|
147
|
+
|
|
148
|
+
1. **Introduce the Section:** Announce that you will define the technology stacks.
|
|
149
|
+
2. **Ask Questions Sequentially:** Maximum 5 questions about languages, frameworks, databases.
|
|
150
|
+
3. **For Brownfield:** State the inferred stack and ask for confirmation.
|
|
151
|
+
4. **Draft the Document:** Generate content for `tech-stack.md`.
|
|
152
|
+
5. **User Confirmation Loop:** Present for review.
|
|
153
|
+
6. **Write File:** Write to `conductor/tech-stack.md`.
|
|
154
|
+
7. **Commit State:** Write `{"last_successful_step": "2.3_tech_stack"}`.
|
|
155
|
+
8. **Continue:** Proceed to next section.
|
|
156
|
+
|
|
157
|
+
### 2.4 Select Code Styleguides (Interactive)
|
|
158
|
+
|
|
159
|
+
1. **Initiate Dialogue:** Announce that you need user input to select style guides.
|
|
160
|
+
2. **Select Code Style Guides:**
|
|
161
|
+
- List available style guides from the skill's assets.
|
|
162
|
+
- **For Greenfield:** Recommend based on Tech Stack, ask for confirmation or edit.
|
|
163
|
+
- **For Brownfield:** Infer from code analysis, ask for confirmation.
|
|
164
|
+
- **Action:** Copy selected files to `conductor/code_styleguides/`.
|
|
165
|
+
3. **Commit State:** Write `{"last_successful_step": "2.4_code_styleguides"}`.
|
|
166
|
+
|
|
167
|
+
### 2.5 Select Workflow (Interactive)
|
|
168
|
+
|
|
169
|
+
1. **Copy Initial Workflow:** Copy the workflow template from skill assets to `conductor/workflow.md`.
|
|
170
|
+
2. **Customize Workflow:** Ask user:
|
|
171
|
+
- A) Default (80% coverage, commit after each task, git notes)
|
|
172
|
+
- B) Customize
|
|
173
|
+
3. **If Customize:** Ask about coverage percentage, commit frequency, summary method.
|
|
174
|
+
4. **Commit State:** Write `{"last_successful_step": "2.5_workflow"}`.
|
|
175
|
+
|
|
176
|
+
### 2.6 Finalization
|
|
177
|
+
|
|
178
|
+
1. **Generate Index File:** Create `conductor/index.md`:
|
|
179
|
+
```markdown
|
|
180
|
+
# Project Context
|
|
181
|
+
|
|
182
|
+
## Definition
|
|
183
|
+
- [Product Definition](./product.md)
|
|
184
|
+
- [Product Guidelines](./product-guidelines.md)
|
|
185
|
+
- [Tech Stack](./tech-stack.md)
|
|
186
|
+
|
|
187
|
+
## Workflow
|
|
188
|
+
- [Workflow](./workflow.md)
|
|
189
|
+
- [Code Style Guides](./code_styleguides/)
|
|
190
|
+
|
|
191
|
+
## Management
|
|
192
|
+
- [Tracks Registry](./tracks.md)
|
|
193
|
+
- [Tracks Directory](./tracks/)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
2. **Summarize Actions:** Present summary of all actions taken.
|
|
197
|
+
3. **Transition:** Announce proceeding to initial track generation.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 3.0 INITIAL PLAN AND TRACK GENERATION
|
|
202
|
+
|
|
203
|
+
**PROTOCOL: Interactively define project requirements, propose a single track, and automatically create track artifacts.**
|
|
204
|
+
|
|
205
|
+
### 3.1 Generate Product Requirements (Greenfield Only)
|
|
206
|
+
|
|
207
|
+
1. **Transition to Requirements:** Announce defining high-level product requirements.
|
|
208
|
+
2. **Analyze Context:** Read `conductor/product.md`.
|
|
209
|
+
3. **Ask Questions Sequentially:** Maximum 5 questions about user stories, functional/non-functional requirements.
|
|
210
|
+
4. **Continue:** Proceed to next section.
|
|
211
|
+
|
|
212
|
+
### 3.2 Propose Initial Track (Automated + Approval)
|
|
213
|
+
|
|
214
|
+
1. **State Your Goal:** Announce proposing an initial track.
|
|
215
|
+
2. **Generate Track Title:** Based on project context, generate a track title.
|
|
216
|
+
3. **User Confirmation:** Present for approval. If declined, ask for clarification.
|
|
217
|
+
|
|
218
|
+
### 3.3 Create Track Artifacts (Automated)
|
|
219
|
+
|
|
220
|
+
1. **State Your Goal:** Announce creating track artifacts.
|
|
221
|
+
2. **Initialize Tracks File:** Create `conductor/tracks.md` with the first track.
|
|
222
|
+
3. **Generate Track Artifacts:**
|
|
223
|
+
a. **Generate Track ID:** Format `shortname_YYYYMMDD`.
|
|
224
|
+
b. **Create Directory:** `conductor/tracks/<track_id>/`.
|
|
225
|
+
c. **Create metadata.json:** With track_id, type, status, timestamps, description.
|
|
226
|
+
d. **Write spec.md:** Track specification.
|
|
227
|
+
e. **Write plan.md:** Implementation plan with tasks following workflow methodology.
|
|
228
|
+
f. **Write index.md:** Track context index.
|
|
229
|
+
4. **Commit State:** Write `{"last_successful_step": "3.3_initial_track_generated"}`.
|
|
230
|
+
5. **Announce Progress:** Announce track creation.
|
|
231
|
+
|
|
232
|
+
### 3.4 Final Announcement
|
|
233
|
+
|
|
234
|
+
1. **Announce Completion:** Project setup and initial track generation complete.
|
|
235
|
+
2. **Save Conductor Files:** Commit all files with message `conductor(setup): Add conductor setup files`.
|
|
236
|
+
3. **Next Steps:** Inform user to run `/conductor-implement` to begin work.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Google C++ Style Guide Summary
|
|
2
|
+
|
|
3
|
+
## 1. Naming
|
|
4
|
+
- **General:** Optimize for readability. Be descriptive but concise. Use inclusive language.
|
|
5
|
+
- **Files:** `.h` (headers), `.cc` (source). Lowercase with underscores (`_`) or dashes (`-`). Be consistent.
|
|
6
|
+
- **Types:** PascalCase (`MyClass`, `MyEnum`). Use `int` by default; use `<cstdint>` (`int32_t`) if size matters.
|
|
7
|
+
- **Concepts:** PascalCase (`MyConcept`).
|
|
8
|
+
- **Variables:** snake_case (`my_var`). Class members end with underscore (`my_member_`), struct members do not.
|
|
9
|
+
- **Constants/Enumerators:** `k` + PascalCase (`kDays`, `kOk`).
|
|
10
|
+
- **Template Parameters:** PascalCase for types (`T`, `MyType`), snake_case/kPascalCase for non-types (`N`, `kLimit`).
|
|
11
|
+
- **Functions:** PascalCase (`GetValue()`).
|
|
12
|
+
- **Accessors/Mutators:** snake_case. `count()` (not `GetCount`), `set_count(v)`.
|
|
13
|
+
- **Namespaces:** lowercase (`web_search`).
|
|
14
|
+
- **Macros:** ALL_CAPS (`MY_MACRO`).
|
|
15
|
+
|
|
16
|
+
## 2. Header Files
|
|
17
|
+
- **General:** Every `.cc` usually has a `.h`. Headers must be self-contained.
|
|
18
|
+
- **Guards:** Use `#define <PROJECT>_<PATH>_<FILE>_H_`.
|
|
19
|
+
- **IWYU:** Direct includes only. Do not rely on transitive includes.
|
|
20
|
+
- **Forward Decls:** Avoid. Include headers instead. **Never** forward declare `std::` symbols.
|
|
21
|
+
- **Inline Definitions:** Only short functions (<10 lines) in headers. Must be ODR-safe (`inline` or templates).
|
|
22
|
+
- **Include Order:**
|
|
23
|
+
1. Related header (`foo.h`)
|
|
24
|
+
2. C system (`<unistd.h>`)
|
|
25
|
+
3. C++ standard (`<vector>`)
|
|
26
|
+
4. Other libraries (`<Python.h>`)
|
|
27
|
+
5. Project headers (`"base/logging.h"`)
|
|
28
|
+
*Separate groups with blank lines. Alphabetical within groups.*
|
|
29
|
+
|
|
30
|
+
## 3. Formatting
|
|
31
|
+
- **Indentation:** 2 spaces. **Line Length:** 80 chars.
|
|
32
|
+
- **Non-ASCII:** Rare, use UTF-8. Avoid `u8` prefix if possible.
|
|
33
|
+
- **Braces:** `if (cond) { ... }`. **Exception:** Function definition open brace goes on the **next line**.
|
|
34
|
+
- **Switch:** Always include `default`. Use `[[fallthrough]]` for explicit fallthrough.
|
|
35
|
+
- **Literals:** Floating-point must have radix point (`1.0f`).
|
|
36
|
+
- **Calls:** Wrap arguments at paren or 4-space indent.
|
|
37
|
+
- **Init Lists:** Colon on new line, indent 4 spaces.
|
|
38
|
+
- **Namespaces:** No indentation.
|
|
39
|
+
- **Vertical Whitespace:** Use sparingly. Separate related chunks, not code blocks.
|
|
40
|
+
- **Loops/Branching:** Use braces (optional if single line). No space after `(`, space before `{`.
|
|
41
|
+
- **Return:** No parens `return result;`.
|
|
42
|
+
- **Preprocessor:** `#` always at line start.
|
|
43
|
+
- **Pointers:** `char* c` (attached to type).
|
|
44
|
+
- **Templates:** No spaces inside `< >` (`vector<int>`).
|
|
45
|
+
- **Operators:** Space around assignment/binary, no space for unary.
|
|
46
|
+
- **Class Order:** `public`, `protected`, `private`.
|
|
47
|
+
- **Parameter Wrapping:** Wrap parameter lists that don't fit. Use 4-space indent for wrapped parameters.
|
|
48
|
+
|
|
49
|
+
## 4. Classes
|
|
50
|
+
- **Constructors:** `explicit` for single-arg and conversion operators. **Exception:** `std::initializer_list`. No virtual calls in ctors. Use factories for fallible init.
|
|
51
|
+
- **Structs:** Only for passive data. Prefer `struct` over `std::pair` or `std::tuple`.
|
|
52
|
+
- **Copy/Move:** Explicitly `= default` or `= delete`. **Rule of 5:** If defining one, declare all.
|
|
53
|
+
- **Inheritance:** `public` only. Composition > Inheritance. Use `override` (omit `virtual`). No multiple implementation inheritance.
|
|
54
|
+
- **Operator Overloading:** Judicious use only. Binary ops as non-members. Never overload `&&`, `||`, `,`, or unary `&`. No User-Defined Literals.
|
|
55
|
+
- **Access:** Data members `private` (except structs/constants).
|
|
56
|
+
- **Declaration Order:** `public` before `protected` before `private`. Within sections: Types, Constants, Factory, Constructors, Destructor, Methods, Data Members.
|
|
57
|
+
|
|
58
|
+
## 5. Functions
|
|
59
|
+
- **Params:** Inputs (`const T&`, `std::string_view`, `std::span` or value) first, then outputs. **Ordering:** Inputs before outputs.
|
|
60
|
+
- **Outputs:** Prefer return values/`std::optional`. For non-optional outputs, use references. For optional outputs, use pointers.
|
|
61
|
+
- **Optional Inputs:** Use `std::optional` for by-value, `const T*` for reference.
|
|
62
|
+
- **Nonmember vs Static:** Prefer nonmember functions in namespaces over static member functions.
|
|
63
|
+
- **Length:** Prefer small (<40 lines).
|
|
64
|
+
- **Overloading:** Use only when behavior is obvious. Document overload sets with a single umbrella comment.
|
|
65
|
+
- **Default Args:** Allowed on non-virtual functions only (value must be fixed/constant).
|
|
66
|
+
- **Trailing Return:** Only when necessary (lambdas).
|
|
67
|
+
|
|
68
|
+
## 6. Scoping
|
|
69
|
+
- **Namespaces:** No `using namespace`. Use `using std::string`. Never add to `namespace std`.
|
|
70
|
+
- **Internal:** Use anonymous namespaces or `static` in `.cc` files. Avoid in headers.
|
|
71
|
+
- **Locals:** Narrowest scope. Initialize at declaration. **Exception:** Declare complex objects outside loops.
|
|
72
|
+
- **Static/Global:** Must be **trivially destructible** (e.g., `constexpr`, raw pointers, arrays). No global `std::string`, `std::map`, smart pointers. Dynamic initialization allowed only for function-static variables.
|
|
73
|
+
- **Thread Local:** `thread_local` must be `constinit` if global. Prefer `thread_local` over other mechanisms.
|
|
74
|
+
|
|
75
|
+
## 7. Modern C++ Features
|
|
76
|
+
- **Version:** Target **C++20**. Do not use C++23. Consider portability for C++17/20 features. No non-standard extensions.
|
|
77
|
+
- **Modules:** Do not use C++20 Modules.
|
|
78
|
+
- **Coroutines:** Use approved libraries only. Do not roll your own promise or awaitable types.
|
|
79
|
+
- **Concepts:** Prefer C++20 Concepts (`requires`) over `std::enable_if`. Use `requires(Concept<T>)`, not `template<Concept T>`.
|
|
80
|
+
- **R-Value References:** Use only for move ctors/assignment, perfect forwarding, or consuming `*this`.
|
|
81
|
+
- **Smart Pointers:** `std::unique_ptr` (exclusive), `std::shared_ptr` (shared). No `std::auto_ptr`.
|
|
82
|
+
- **Auto:** Use when type is obvious (`make_unique`, iterators). Avoid for public APIs.
|
|
83
|
+
- **CTAD:** Use only if explicitly supported (deduction guides exist).
|
|
84
|
+
- **Structured Bindings:** Use for pairs/tuples. Comment aliased field names.
|
|
85
|
+
- **Nullptr:** Use `nullptr`, never `NULL` or `0`.
|
|
86
|
+
- **Constexpr:** Use `constexpr`/`consteval` for constants/functions whenever possible. Use `constinit` for static initialization.
|
|
87
|
+
- **Noexcept:** Specify when useful/correct. Prefer unconditional `noexcept` if exceptions are disabled.
|
|
88
|
+
- **Lambdas:** Prefer explicit captures (`[&x]`) if escaping scope. Avoid `std::bind`.
|
|
89
|
+
- **Initialization:** Prefer brace init. **Designated Initializers:** Allowed (C++20 ordered form only).
|
|
90
|
+
- **Casts:** Use C++ casts (`static_cast`). Use `std::bit_cast` for type punning.
|
|
91
|
+
- **Loops:** Prefer range-based `for`.
|
|
92
|
+
|
|
93
|
+
## 8. Best Practices
|
|
94
|
+
- **Const:** Mark methods/variables `const` whenever possible. `const` methods must be thread-safe.
|
|
95
|
+
- **Exceptions:** **Forbidden**.
|
|
96
|
+
- **RTTI:** Avoid `dynamic_cast`/`typeid`. Allowed in unit tests. Do not hand-implement workarounds.
|
|
97
|
+
- **Macros:** Avoid. Use `constexpr`/`inline`. If needed, define close to use and `#undef` immediately. Do not define in headers.
|
|
98
|
+
- **0 and nullptr:** Use `nullptr` for pointers, `\0` for chars, not `0`.
|
|
99
|
+
- **Streams:** Use streams primarily for logging. Prefer printf-style formatting or absl::StrCat.
|
|
100
|
+
- **Types:** Avoid `unsigned` for non-negativity. No `long double`.
|
|
101
|
+
- **Pre-increment:** Prefer `++i` over `i++`.
|
|
102
|
+
- **Sizeof:** Prefer `sizeof(varname)` over `sizeof(type)`.
|
|
103
|
+
- **Friends:** Allowed, usually defined in the same file.
|
|
104
|
+
- **Boost:** Use only approved libraries (e.g., Call Traits, Compressed Pair, BGL, Property Map, Iterator, etc.).
|
|
105
|
+
- **Aliases:** Use `using` instead of `typedef`. Public aliases must be documented.
|
|
106
|
+
- **Ownership:** Single fixed owner. Transfer via smart pointers.
|
|
107
|
+
- **Aliases:** Document intent. Don't use in public API for convenience. `using` > `typedef`.
|
|
108
|
+
- **Switch:** Always include `default`. Use `[[fallthrough]]` for explicit fallthrough.
|
|
109
|
+
- **Comments:** Document File, Class, Function (params/return). Use `//` or `/* */`. Implementation comments for tricky code. `TODO(user):` format.
|
|
110
|
+
|
|
111
|
+
**BE CONSISTENT.** Follow existing code style.
|
|
112
|
+
|
|
113
|
+
*Source: [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)*
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Google C# Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the Google C# Style Guide.
|
|
4
|
+
|
|
5
|
+
## 1. Naming Conventions
|
|
6
|
+
- **PascalCase:** For class names, method names, constants, properties, namespaces, and public fields.
|
|
7
|
+
- Example: `MyClass`, `GetValue()`, `MaxValue`
|
|
8
|
+
- **_camelCase:** For private, internal, and protected fields (with leading underscore).
|
|
9
|
+
- Example: `_myField`, `_internalState`
|
|
10
|
+
- **camelCase:** For local variables and parameters.
|
|
11
|
+
- Example: `localVariable`, `methodParameter`
|
|
12
|
+
- **Interfaces:** Prefix with `I` (e.g., `IMyInterface`).
|
|
13
|
+
- **Type Parameters:** Use descriptive names prefixed with `T` (e.g., `TValue`, `TKey`), or just `T` for simple cases.
|
|
14
|
+
|
|
15
|
+
## 2. Formatting Rules
|
|
16
|
+
- **Indentation:** Use 2 spaces (never tabs).
|
|
17
|
+
- **Braces:** K&R style—no line break before the opening brace; keep `} else` on one line; braces required even when optional.
|
|
18
|
+
```csharp
|
|
19
|
+
if (condition) {
|
|
20
|
+
DoSomething();
|
|
21
|
+
} else {
|
|
22
|
+
DoSomethingElse();
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
- **Line Length:** Column limit 100.
|
|
26
|
+
- **One Statement Per Line:** Each statement on its own line.
|
|
27
|
+
|
|
28
|
+
## 3. Declaration Order
|
|
29
|
+
Class member ordering:
|
|
30
|
+
- Group members in this order:
|
|
31
|
+
1. Nested classes, enums, delegates, and events
|
|
32
|
+
2. Static, const, and readonly fields
|
|
33
|
+
3. Fields and properties
|
|
34
|
+
4. Constructors and finalizers
|
|
35
|
+
5. Methods
|
|
36
|
+
- Within each group, order by accessibility:
|
|
37
|
+
1. Public
|
|
38
|
+
2. Internal
|
|
39
|
+
3. Protected internal
|
|
40
|
+
4. Protected
|
|
41
|
+
5. Private
|
|
42
|
+
- Where possible, group interface implementations together.
|
|
43
|
+
|
|
44
|
+
## 4. Language Features
|
|
45
|
+
- **var:** Use of `var` is encouraged if it aids readability by avoiding type names that are noisy, obvious, or unimportant. Prefer explicit types when it improves clarity.
|
|
46
|
+
```csharp
|
|
47
|
+
var apple = new Apple(); // Good - type is obvious
|
|
48
|
+
bool success = true; // Preferred over var for basic types
|
|
49
|
+
```
|
|
50
|
+
- **Expression-bodied Members:** Use sparingly for simple properties and lambdas; don't use on method definitions.
|
|
51
|
+
```csharp
|
|
52
|
+
public int Age => _age;
|
|
53
|
+
// Methods: prefer block bodies.
|
|
54
|
+
```
|
|
55
|
+
- **String Interpolation:** In general, use whatever is easiest to read, particularly for logging and assert messages.
|
|
56
|
+
- Be aware that chained `operator+` concatenations can be slower and cause memory churn.
|
|
57
|
+
- If performance is a concern, `StringBuilder` can be faster for multiple concatenations.
|
|
58
|
+
```csharp
|
|
59
|
+
var message = $"Hello, {name}!";
|
|
60
|
+
```
|
|
61
|
+
- **Collection Initializers:** Use collection and object initializers when appropriate.
|
|
62
|
+
```csharp
|
|
63
|
+
var list = new List<int> { 1, 2, 3 };
|
|
64
|
+
```
|
|
65
|
+
- **Null-conditional Operators:** Use `?.` and `??` to simplify null checks.
|
|
66
|
+
```csharp
|
|
67
|
+
var length = text?.Length ?? 0;
|
|
68
|
+
```
|
|
69
|
+
- **Pattern Matching:** Use pattern matching for type checks and casts.
|
|
70
|
+
```csharp
|
|
71
|
+
if (obj is string str) { /* use str */ }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 5. Best Practices
|
|
75
|
+
- **Structs vs Classes**:
|
|
76
|
+
- Almost always use a class.
|
|
77
|
+
- Consider structs only for small, value-like types that are short-lived or frequently embedded.
|
|
78
|
+
- Performance considerations may justify deviations from this guidance.
|
|
79
|
+
- **Access Modifiers:** Always explicitly declare access modifiers (don't rely on defaults).
|
|
80
|
+
- **Ordering Modifiers:** Use standard order: `public protected internal private new abstract virtual override sealed static readonly extern unsafe volatile async`.
|
|
81
|
+
- **Namespace Imports:** Place `using` directives at the top of the file (outside namespaces); `System` first, then alphabetical.
|
|
82
|
+
- **Constants:** Always make variables `const` when possible; if not, use `readonly`. Prefer named constants over magic numbers.
|
|
83
|
+
- **IEnumerable vs IList vs IReadOnlyList:** When method inputs are intended to be immutable, prefer the most restrictive collection type possible (e.g., IEnumerable, IReadOnlyList); for return values, prefer IList when transferring ownership of a mutable collection, and otherwise prefer the most restrictive option.
|
|
84
|
+
- **Array vs List:** Prefer `List<>` for public variables, properties, and return types. Use arrays when size is fixed and known at construction time, or for multidimensional arrays.
|
|
85
|
+
- **Extension Methods:** Only use when the source is unavailable or changing it is infeasible. Only for core, general features. Be aware they obfuscate code.
|
|
86
|
+
- **LINQ:** Use LINQ for readability, but be mindful of performance in hot paths.
|
|
87
|
+
|
|
88
|
+
## 6. File Organization
|
|
89
|
+
- **One Class Per File:** Typically one class, interface, enum, or struct per file.
|
|
90
|
+
- **File Name:** Prefer the file name to match the name of the primary type it contains.
|
|
91
|
+
- **Folders and File Locations:**
|
|
92
|
+
- Be consistent within the project.
|
|
93
|
+
- Prefer a flat folder structure where possible.
|
|
94
|
+
- Don’t force file/folder layout to match namespaces.
|
|
95
|
+
- **Namespaces:**
|
|
96
|
+
- In general, namespaces should be no more than 2 levels deep.
|
|
97
|
+
- For shared library/module code, use namespaces.
|
|
98
|
+
- For leaf application code, namespaces are not necessary.
|
|
99
|
+
- New top-level namespace names must be globally unique and recognizable.
|
|
100
|
+
|
|
101
|
+
## 7. Parameters and Returns
|
|
102
|
+
- **out Parameters:** Permitted for output-only values; place `out` parameters after all other parameters. Prefer tuples or return types when they improve clarity.
|
|
103
|
+
- **Argument Clarity:** When argument meaning is nonobvious, use named constants, replace `bool` with `enum`, use named arguments, or create a configuration class/struct.
|
|
104
|
+
```csharp
|
|
105
|
+
// Bad
|
|
106
|
+
DecimalNumber product = CalculateProduct(values, 7, false, null);
|
|
107
|
+
|
|
108
|
+
// Good
|
|
109
|
+
var options = new ProductOptions { PrecisionDecimals = 7, UseCache = CacheUsage.DontUseCache };
|
|
110
|
+
DecimalNumber product = CalculateProduct(values, options, completionDelegate: null);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**BE CONSISTENT.** When editing code, follow the existing style in the codebase.
|
|
114
|
+
|
|
115
|
+
*Source: [Google C# Style Guide](https://google.github.io/styleguide/csharp-style.html)*
|