|
7 | 7 | **Key Customization Mechanisms:** |
8 | 8 |
|
9 | 9 | * **Workspace Instructions (`.github/copilot-instructions.md`):** General project context. |
10 | | -* **Custom Instructions (VS Code Settings / Files):** Specific guidelines for code generation, test generation, etc., configured via `settings.json` often by referencing external `.md` instruction files. |
| 10 | +* **Custom Instructions (VS Code Settings / Files):** Specific guidelines for code generation, test generation, etc., configured via `settings.json` often by referencing external `.md` instruction files (e.g., from a `docs/instructions/` folder). |
11 | 11 | * **Reusable Prompts (`*.prompt.md`):** Parameterized instructions for common, limited-scope tasks. |
12 | 12 | * **Agent Workflow Instructions (Separate `.md` File):** Detailed, multi-step instructions for complex agent tasks. |
13 | 13 |
|
|
178 | 178 | ### Exercise 3.2: Define Custom Code Generation Instructions (via File Reference) |
179 | 179 |
|
180 | 180 | * **Purpose:** To guide Copilot towards generating code that meets specific quality standards, especially for error handling and style, using a referenced instruction file. |
181 | | -* **Aim:** Create a `.md` instruction file for Java code generation guidelines and reference it in workspace `settings.json`. |
| 181 | +* **Aim:** Create a `.md` instruction file for Java code generation guidelines in `docs/instructions/` and reference it in workspace `settings.json`. |
182 | 182 | * **Steps:** |
183 | 183 | 1. **Create Instruction File:** |
184 | | - * Create a folder `.vscode` in your workspace root if it doesn't exist. |
185 | | - * Inside `.vscode`, create a file named `copilot_codegen_java_instructions.md`. |
| 184 | + * Create a folder `docs/instructions/` in your workspace root (create `docs` and `instructions` folders if they don't exist). |
| 185 | + * Inside `docs/instructions/`, create a file named `copilot_codegen_java_instructions.md`. |
186 | 186 | * Add the following content to this new file: |
187 | 187 | ```markdown |
188 | 188 | ## Java Code Generation Guidelines (HangpersonApp) |
|
195 | 195 | - Add comments explaining non-obvious logic. |
196 | 196 | - Adhere to Java 1.8 syntax compatibility. |
197 | 197 | ``` |
198 | | - * Save `copilot_codegen_java_instructions.md`. |
| 198 | + * Save `docs/instructions/copilot_codegen_java_instructions.md`. |
199 | 199 | 2. **Open Workspace Settings (JSON):** Use the Command Palette (`Cmd+Shift+P` / `Ctrl+Shift+P`) and search for `Preferences: Open Workspace Settings (JSON)`. |
200 | | - 3. **Reference Instruction File:** Add or modify the relevant setting for code generation instructions (e.g., `github.copilot.editor.instructions` or `github.copilot.chat.codeGeneration.instructions` - check documentation for the exact key name as it might evolve). Reference the file you created: |
| 200 | + 3. **Reference Instruction File:** Add or modify the relevant setting for code generation instructions (e.g., `github.copilot.chat.codeGeneration.instructions` - check documentation for the exact key name). Reference the file you created: |
201 | 201 | ```json |
202 | 202 | { |
203 | 203 | // ... other settings ... |
204 | | - // Example using hypothetical 'github.copilot.chat.codeGeneration.instructions' |
205 | 204 | "github.copilot.chat.codeGeneration.instructions": [ |
206 | 205 | { |
207 | | - "file": ".vscode/copilot_codegen_java_instructions.md" |
| 206 | + // Use relative path from workspace root |
| 207 | + "file": "docs/instructions/copilot_codegen_java_instructions.md" |
208 | 208 | // You could add more { "text": "..." } or { "file": "..." } entries here |
209 | 209 | } |
210 | | - ], |
211 | | - // Example using hypothetical 'github.copilot.editor.instructions' |
212 | | - // "github.copilot.editor.instructions": { |
213 | | - // "language": { // Note: This language nesting might not be supported per latest schema, |
214 | | - // // prefer the array approach above if possible. |
215 | | - // "java": { |
216 | | - // "uri": "file:///${workspaceFolder}/.vscode/copilot_codegen_java_instructions.md" |
217 | | - // } |
218 | | - // } |
219 | | - // } |
| 210 | + ] |
220 | 211 | // ... other settings ... |
221 | 212 | } |
222 | 213 | ``` |
223 | | - *Choose the setting key that best matches the feature you want to influence (general chat generation vs. inline editor suggestions). The array format (`github.copilot.chat.codeGeneration.instructions` example) is generally more flexible.* |
| 214 | + *Note: Ensure the setting key used corresponds to the Copilot feature you want to influence (e.g., chat suggestions, inline completions). Refer to current Copilot documentation.* |
224 | 215 | 4. Save `settings.json`. |
225 | | - 5. **Verification:** Perform the verification steps from the previous version of this exercise (asking Copilot to generate code involving potential I/O) and check if the output adheres to the rules defined in your `.md` file. |
| 216 | + 5. **Verification:** Perform the verification steps from the previous version of this exercise (asking Copilot to generate code involving potential I/O) and check if the output adheres to the rules defined in your `docs/instructions/copilot_codegen_java_instructions.md` file. |
226 | 217 |
|
227 | 218 | ### Exercise 3.3: Define Custom Test Generation Instructions (via File Reference) |
228 | 219 |
|
229 | 220 | * **Purpose:** To ensure generated unit tests follow consistent standards using a referenced instruction file. |
230 | | -* **Aim:** Create a `.md` instruction file for Java test generation guidelines and reference it in workspace `settings.json`. |
| 221 | +* **Aim:** Create a `.md` instruction file for Java test generation guidelines in `docs/instructions/` and reference it in workspace `settings.json`. |
231 | 222 | * **Steps:** |
232 | 223 | 1. **Create Instruction File:** |
233 | | - * Inside the `.vscode` folder, create a file named `copilot_testgen_java_instructions.md`. |
| 224 | + * Inside the `docs/instructions/` folder, create a file named `copilot_testgen_java_instructions.md`. |
234 | 225 | * Add the following content: |
235 | 226 | ```markdown |
236 | 227 | ## Java Test Generation Guidelines (HangpersonApp) |
|
242 | 233 | - **Mocking:** Use Mockito if dependencies need mocking (though initial tests might not require it). |
243 | 234 | - **Structure:** Include clear Arrange, Act, Assert sections commented as `// Arrange`, `// Act`, `// Assert`. |
244 | 235 | ``` |
245 | | - * Save `copilot_testgen_java_instructions.md`. |
| 236 | + * Save `docs/instructions/copilot_testgen_java_instructions.md`. |
246 | 237 | 2. **Open Workspace Settings (JSON).** |
247 | 238 | 3. **Reference Instruction File:** Add or modify the relevant setting for test generation instructions (e.g., `github.copilot.tests.instructions` - check documentation for the exact key). |
248 | 239 | ```json |
249 | 240 | { |
250 | 241 | // ... other settings ... |
251 | 242 | "github.copilot.tests.instructions": [ // Hypothetical key, check actual setting name |
252 | 243 | { |
253 | | - "file": ".vscode/copilot_testgen_java_instructions.md" |
| 244 | + "file": "docs/instructions/copilot_testgen_java_instructions.md" |
254 | 245 | } |
255 | 246 | ] |
256 | 247 | // ... other settings ... |
257 | 248 | } |
258 | 249 | ``` |
259 | 250 | 4. Save `settings.json`. |
260 | | - 5. **Verification:** Perform the verification steps from the previous version of this exercise (using `/tests` command) and check if the generated tests adhere to the rules defined in your `.md` file. |
| 251 | + 5. **Verification:** Perform the verification steps from the previous version of this exercise (using `/tests` command) and check if the generated tests adhere to the rules defined in your `docs/instructions/copilot_testgen_java_instructions.md` file. |
261 | 252 |
|
262 | 253 | --- |
263 | 254 |
|
|
305 | 296 | * **Purpose:** To define instructions for an agent to implement the core game structure based on the specification. |
306 | 297 | * **Aim:** Create `implement_game_core_workflow.md` guiding the agent. |
307 | 298 | * **Steps:** |
308 | | - 1. Create `implement_game_core_workflow.md` in the workspace root or an `/instructions` folder. |
| 299 | + 1. Create `implement_game_core_workflow.md` in the workspace root or an `/instructions` folder (e.g., `docs/instructions/implement_game_core_workflow.md`). |
309 | 300 | 2. Add the following content: |
310 | 301 | ```markdown |
311 | 302 | # AI Agent Workflow: Implement Hangperson Core Logic |
|
345 | 336 | 1. Ensure `docs/specs/GameSpec.md` exists. |
346 | 337 | 2. In Copilot Chat, invoke the workflow: |
347 | 338 | ``` |
348 | | - # (select implement_game_core_workflow.md) /implement # (select docs/specs/GameSpec.md) |
| 339 | + # (select docs/instructions/implement_game_core_workflow.md) /implement # (select docs/specs/GameSpec.md) |
349 | 340 | ``` |
350 | | - *(Adjust invocation based on actual Copilot Agent capabilities)* |
| 341 | + *(Adjust invocation based on actual Copilot Agent capabilities and the location you saved the workflow file)* |
351 | 342 | 3. **Review Generated Code:** Examine the created files (`GameEngine.java`, `GameState.java`, `WordSource.java`). |
352 | 343 | * Does the structure match the plan? |
353 | | - * Does the error handling (if any generated yet) match the custom instructions defined in your `.vscode/*.md` files? |
| 344 | + * Does the error handling (if any generated yet) match the custom instructions defined in your `docs/instructions/*.md` files? |
354 | 345 | * Is the logic generally correct based on the spec? |
355 | 346 | 4. **Refine (Example):** |
356 | 347 | * Maybe the initial guess processing logic in `GameEngine` is too complex. Select that method. |
|
392 | 383 | ### Exercise 6.1: Refine Instructions or Prompts |
393 | 384 |
|
394 | 385 | * **Purpose:** To improve the guidance given to Copilot based on observed results. |
395 | | -* **Aim:** Modify the custom instructions (`.vscode/*.md` files referenced in `settings.json` or `.github/copilot-instructions.md`) or reusable prompts (`*.prompt.md`) to address any shortcomings noticed during implementation or testing. |
| 386 | +* **Aim:** Modify the custom instructions (`docs/instructions/*.md` files referenced in `settings.json` or `.github/copilot-instructions.md`) or reusable prompts (`*.prompt.md`) to address any shortcomings noticed during implementation or testing. |
396 | 387 | * **Steps:** |
397 | 388 | 1. Identify an area where Copilot's output didn't fully meet expectations (e.g., error handling wasn't robust enough, test naming was inconsistent despite instructions). |
398 | 389 | 2. Refine the relevant instruction file (`.md`) or prompt file (`.prompt.md`) to be more specific or clear. |
|
403 | 394 | * **Purpose:** To replace the hardcoded word list with logic to read from the provided `nouns`/`verbs` files. |
404 | 395 | * **Aim:** Use Copilot (Ask, Edits, Completion), guided by custom instructions for I/O error handling, to implement file reading in `WordSource.java`. |
405 | 396 | * **Steps:** |
406 | | - 1. Open `WordSource.java` (or the relevant file created by the agent). |
407 | | - 2. Use Copilot Chat or Edits mode: `# (select WordSource.java) /explain Modify this class to read words from text files named 'nouns.txt' and 'verbs.txt' located in the project root (or a specified resources directory). Load all words into a single list. Handle potential FileNotFoundException and IOException according to the project's error handling guidelines (use try-with-resources, log errors). Update the word selection method to use this list.` |
408 | | - 3. Review and refine the generated code, ensuring robust file handling. |
| 397 | + 1. *(Setup)* Ensure you have `nouns.txt` and `verbs.txt` files in your project root or a `src/main/resources` directory. |
| 398 | + 2. Open `WordSource.java` (or the relevant file created by the agent). |
| 399 | + 3. Use Copilot Chat or Edits mode: `# (select WordSource.java) /explain Modify this class to read words from text files named 'nouns.txt' and 'verbs.txt' located in the project root (or classpath resources if placed there). Load all words into a single list upon initialization. Handle potential FileNotFoundException and IOException according to the project's error handling guidelines (use try-with-resources, log errors). Update the word selection method to use this list.` |
| 400 | + 4. Review and refine the generated code, ensuring robust file handling. Consider where the files should ideally be placed (resources folder is common for classpath loading). |
409 | 401 |
|
410 | 402 | ### Exercise 6.3: Connect UI Loop |
411 | 403 |
|
412 | 404 | * **Purpose:** To integrate the core game logic with the main application loop for user interaction. |
413 | 405 | * **Aim:** Modify `App.java` to create instances of the game classes and run the main game loop, handling user input and displaying output. |
414 | 406 | * **Steps:** |
415 | 407 | 1. Open `App.java`. |
416 | | - 2. Use Copilot Chat/Edits/Completion: `# (select App.java) # (select GameEngine.java) /explain Modify the main method to: create a GameEngine instance, call its playGame method, and handle the overall application flow.` (You'll likely need more detailed prompts to handle reading user input from the console and displaying game state). |
| 408 | + 2. Use Copilot Chat/Edits/Completion: `# (select App.java) # (select GameEngine.java) /explain Modify the main method to: create a GameEngine instance, call its playGame method, and handle the overall application flow.` (You'll likely need more detailed prompts to handle reading user input from the console using `java.util.Scanner` and displaying game state). |
417 | 409 | 3. Focus on getting the basic loop working, relying on the methods already implemented in `GameEngine`, `GameState`, etc. |
418 | 410 |
|
419 | 411 | --- |
0 commit comments