Skip to content

Commit 5edd65c

Browse files
committed
chore: improve copilot instructions
1 parent ec17278 commit 5edd65c

1 file changed

Lines changed: 134 additions & 69 deletions

File tree

.github/copilot-instructions.md

Lines changed: 134 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
# GitHub Copilot Instructions for Node Module Template
22

3+
## Related Templates (Choose the Right Template First)
4+
5+
This repository is a **GitHub Template Repo** for Node.js libraries. Before proceeding, confirm this is the right template for the project.
6+
7+
Consider these alternatives depending on your project type:
8+
9+
| If you are building… | Pick this template | Typical outcomes |
10+
|---|---|---|
11+
| Command-line tools, generators, build tooling | [`node-cli-template`](https://github.com/voxpelli/node-cli-template) | CLI apps, terminal workflows |
12+
| Web APIs, GraphQL services, workers/daemons | [`node-app-template`](https://github.com/voxpelli/node-app-template) | Long-running services |
13+
| Reusable libraries and shared utilities | [`node-module-template`](https://github.com/voxpelli/node-module-template) | npm modules, framework utilities |
14+
15+
Default agent behavior: when intent is ambiguous in this repo, proceed in **library mode** and ask clarifying questions only if strong CLI/service signals appear.
16+
17+
## Copilot Fast Path (Read First)
18+
19+
Use this file to optimize for safe, high-quality, low-friction contributions in this Node.js module template.
20+
21+
- Build for a **library package**, not a CLI or long-running app.
22+
- Use **ESM only** (`import` / `export`) and follow neostandard style.
23+
- Write JavaScript with **clear JSDoc types** so declarations can be generated and type-checked.
24+
- Keep `index.js` minimal and focused on re-exports from `lib/`.
25+
- Start with **local repository context first** (existing code + tests), then use MCP tools when external/current guidance is needed.
26+
- Validate before finishing: run checks/tests (`npm test` or equivalent scoped checks).
27+
- When behavior, scope, or risk is unclear, ask clarifying questions early instead of guessing.
28+
29+
## Priority Rules: MUST, SHOULD, ASK FIRST, NEVER
30+
31+
If rules conflict, follow `MUST` over `SHOULD`. If uncertainty remains, use `ask_questions` before making risky changes.
32+
33+
### MUST
34+
35+
- Use ESM syntax only; do not introduce CommonJS.
36+
- Keep changes minimal, targeted, and consistent with existing file structure and style.
37+
- Add or update tests when behavior changes.
38+
- Validate changes with lint/type/test checks before finalizing.
39+
- Prefer local patterns first; use MCP research for unknown APIs, external docs, and non-obvious decisions.
40+
41+
### SHOULD
42+
43+
- Prefer built-in Node.js APIs and avoid unnecessary dependencies.
44+
- Keep functions small, explicit, and documented with JSDoc.
45+
- Ask multiple focused MCP questions (2–4) rather than one broad question for unfamiliar domains.
46+
- Explain non-obvious implementation choices briefly in comments or PR notes.
47+
48+
### ASK FIRST
49+
50+
- Adding or replacing runtime dependencies.
51+
- Changing public API shape, exported names, or package entry points.
52+
- Large refactors, file moves, or renames beyond the immediate task.
53+
- Disabling checks, removing tests, or altering CI-related behavior.
54+
55+
### NEVER
56+
57+
- Mix module systems (`require` / `module.exports` in runtime code).
58+
- Bypass failing checks silently or claim validation that was not run.
59+
- Commit auto-generated declaration artifacts that repository policy says not to commit.
60+
- Guess requirements when clarification can be obtained quickly.
61+
362
## Overview
463

564
This repository is a **template for creating Node.js library modules** - packages that provide reusable functionality to other projects. It implements best practices for modern Node.js module development with TypeScript types in JavaScript, ESM modules, and comprehensive testing.
@@ -11,78 +70,84 @@ Use this template when creating:
1170
- **Shared code modules** used across multiple projects
1271
- **Packages with no CLI or server components**
1372

14-
### Related Templates
73+
### Project Snapshot (Architecture + Workflow)
1574

16-
Consider these alternatives depending on your project type:
75+
- `index.js` re-exports from `lib/main.js`; keep entrypoint surface minimal.
76+
- `lib/main.js` contains runtime implementation; `test/*.spec.js` validates behavior.
77+
- `index.d.ts` and `lib/*-types.d.ts` define the type surface.
78+
- Validation contract: run local checks/tests before commit, then rely on CI for lint + tests + TypeScript verification.
1779

18-
```mermaid
19-
graph TD
20-
A[What are you building?] --> B{Has CLI?}
21-
A --> C{Is it a service/API?}
22-
A --> D{Is it a library?}
23-
24-
B -->|Yes| E[node-cli-template]
25-
C -->|Yes| F[node-app-template]
26-
D -->|Yes| G[node-module-template]
27-
28-
E --> H[Command-line tools<br/>CLI applications<br/>Build tools]
29-
F --> I[Web servers<br/>REST APIs<br/>Background services]
30-
G --> J[npm libraries<br/>Shared utilities<br/>Frameworks]
31-
32-
style G fill:#90EE90
33-
style E fill:#FFB6C1
34-
style F fill:#87CEEB
35-
```
80+
---
3681

37-
**Use [node-cli-template](https://github.com/voxpelli/node-cli-template) when:**
38-
- Building command-line tools or CLI applications
39-
- Creating build tools or generators
40-
- Need to execute commands from the terminal
41-
42-
**Use [node-app-template](https://github.com/voxpelli/node-app-template) when:**
43-
- Building web servers, REST APIs, or GraphQL services
44-
- Creating background workers or daemons
45-
- Need long-running processes or services
46-
47-
### Project Architecture
48-
49-
```mermaid
50-
graph LR
51-
A[index.js] -->|exports| B[lib/main.js]
52-
B --> C[Implementation]
53-
D[index.d.ts] -->|types| C
54-
E[test/*.spec.js] -->|validates| C
55-
56-
F[TypeScript] -->|generates| D
57-
G[ESLint] -->|validates| C
58-
H[Mocha+Chai] -->|runs| E
59-
60-
style A fill:#FFE4B5
61-
style D fill:#E0BBE4
62-
style E fill:#B4E7CE
63-
```
82+
## MCP-Assisted Research Workflow for Copilot
6483

65-
### Development Workflow
66-
67-
```mermaid
68-
sequenceDiagram
69-
participant Dev as Developer
70-
participant Git as Git Hooks
71-
participant CI as GitHub Actions
72-
73-
Dev->>Dev: Make code changes
74-
Dev->>Dev: npm test (local)
75-
Dev->>Git: git commit
76-
Git->>Git: Run husky hooks
77-
Git->>Dev: ✓ Hooks passed
78-
Dev->>CI: git push
79-
CI->>CI: Run lint workflow
80-
CI->>CI: Run test workflow
81-
CI->>CI: Run TypeScript checks
82-
CI->>Dev: ✓ All checks passed
83-
```
84+
Use MCP tools proactively to improve implementation quality and speed, especially when working with unfamiliar dependencies, protocols, or external systems.
8485

85-
---
86+
### Working Pattern (Strong Advisory)
87+
88+
1. **Start local first**
89+
- Read relevant files and tests in this repository first.
90+
- Confirm existing patterns before introducing new approaches.
91+
92+
2. **Use MCP for uncertainty or external knowledge**
93+
- If the task depends on current docs, ecosystem practices, or repository-specific behavior not obvious from local code, default to MCP research before coding.
94+
- Ask multiple targeted questions (typically 2–4) instead of one broad question.
95+
96+
3. **Clarify ambiguities before implementation**
97+
- If requirements, scope, or expected behavior are unclear, use `ask_questions` early rather than guessing.
98+
99+
4. **Apply and verify**
100+
- Convert findings into concrete code and tests.
101+
- Validate with linting, type checks, and test runs.
102+
103+
### Tool Selection by Trigger
104+
105+
| Trigger | Prefer | Example Outcome | Provider |
106+
|------|------|-----------------|
107+
| Need current external facts or docs | `tavily_search` | Find authoritative and up-to-date references | Tavily MCP server |
108+
| Need structured content from a specific URL | `tavily_extract` | Pull relevant sections from docs/pages for implementation details | Tavily MCP server |
109+
| Need repository-specific architectural or usage guidance | `ask_question` | Get targeted answers grounded in a repository's docs/wiki | DeepWiki MCP server |
110+
| Requirements or assumptions are ambiguous | `askQuestion` | Resolve uncertainty before making code changes | VSCode built in tool |
111+
112+
### Example MCP Usage Scenarios
113+
114+
| Scenario | Use this tool (or sequence) | Example prompt | What to do with result |
115+
|---|---|---|---|
116+
| Integrating a new library and you need current best practices | `tavily_search` | "Latest best practices for validating unknown JSON in Node.js ESM libraries" | Use results to select a validation approach and reflect it in code + tests |
117+
| You already have official docs URL and need implementation details | `tavily_extract` | "Extract sections on authentication middleware options and error handling" | Translate extracted sections into concrete function signatures and edge-case tests |
118+
| You need repository-specific guidance before using a dependency | `ask_question` | "In owner/repo, which helpers are recommended for nested object access and type guards?" | Prefer repository-recommended utilities over custom ad hoc implementations |
119+
| Acceptance criteria are unclear before coding | `askQuestion` | "Should invalid input throw, return null, or return Result-style errors?" | Lock behavior expectations first, then implement to that contract |
120+
121+
### Question Quality Guidelines
122+
123+
Prefer specific, implementation-oriented questions.
124+
125+
- Better: "What are the recommended patterns for validating unknown JSON payloads in X?"
126+
- Better: "What utility functions does X provide for nested object access, and when should each be used?"
127+
- Better: "What are the safe type-guard patterns for Y in modern Node.js ESM projects?"
128+
- Avoid: "How do I use X?"
129+
130+
### Suggested Research Cadence
131+
132+
When integrating a new dependency or protocol:
133+
134+
1. Ask 2–4 targeted questions with `mcp_deepwiki_ask_question` (or equivalent source-aware MCP tools).
135+
2. Use `mcp_tavily_tavily_search` to validate recency and cross-check guidance.
136+
3. Use `mcp_tavily_tavily_extract` for exact sections from canonical docs.
137+
4. Implement with the discovered patterns, then verify through tests and checks.
138+
139+
### Anti-Patterns to Avoid
140+
141+
1. ❌ Skipping research when implementing unfamiliar APIs or protocols
142+
2. ❌ Asking one broad question and coding from partial answers
143+
3. ❌ Proceeding with unclear requirements instead of using `ask_questions`
144+
4. ❌ Treating stale assumptions as facts without checking current documentation
145+
146+
### Tool Availability and Fallbacks
147+
148+
- Default to the MCP tools above when available in the execution environment.
149+
- If a named MCP tool is unavailable, use the closest equivalent available tool path and continue with the same workflow.
150+
- Keep behavior consistent: local context first, then targeted external research, then implementation and verification.
86151

87152
## Coding Guidelines for GitHub Copilot
88153

@@ -137,9 +202,9 @@ sequenceDiagram
137202
```javascript
138203
import { describe, it } from 'mocha';
139204
import chai from 'chai';
140-
205+
141206
const { expect } = chai;
142-
207+
143208
describe('something()', () => {
144209
it('should return true', async () => {
145210
const result = await something('test');

0 commit comments

Comments
 (0)