@nerviq/cli 1.17.2 → 1.18.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.
@@ -1,197 +1,218 @@
1
- /**
2
- * Copilot project context.
3
- *
4
- * Extends the shared ProjectContext with Copilot-specific file lookups,
5
- * 3-surface detection (VS Code, cloud agent, CLI), instruction parsing,
6
- * and per-surface config resolution.
7
- */
8
-
9
- const fs = require('fs');
10
- const path = require('path');
11
- const { ProjectContext } = require('../context');
12
- const { tryParseJson, extractFrontmatter, getValueByPath } = require('./config-parser');
13
-
14
- function listFiles(fullPath, filter) {
15
- try {
16
- const entries = fs.readdirSync(fullPath).filter(f => !f.startsWith('.'));
17
- return filter ? entries.filter(filter) : entries;
18
- } catch {
19
- return [];
20
- }
21
- }
22
-
23
- class CopilotProjectContext extends ProjectContext {
24
-
25
- // ─── Instructions ─────────────────────────────────────────────────────
26
-
27
- /**
28
- * .github/copilot-instructions.md — repo-wide instructions for all surfaces.
29
- */
30
- copilotInstructionsContent() {
31
- return this.fileContent('.github/copilot-instructions.md');
32
- }
33
-
34
- /**
35
- * .github/instructions/*.instructions.md — path-scoped instructions.
36
- * Returns array of { name, path, frontmatter, body, applyTo }.
37
- */
38
- scopedInstructions() {
39
- const dir = path.join(this.dir, '.github', 'instructions');
40
- const files = listFiles(dir, f => f.endsWith('.instructions.md'));
41
- return files.map(f => {
42
- const relPath = `.github/instructions/${f}`;
43
- const content = this.fileContent(relPath);
44
- if (!content) return null;
45
- const parsed = extractFrontmatter(content);
46
- return {
47
- name: f.replace('.instructions.md', ''),
48
- path: relPath,
49
- frontmatter: parsed.frontmatter,
50
- body: parsed.body,
51
- applyTo: parsed.frontmatter ? parsed.frontmatter.applyTo : null,
52
- };
53
- }).filter(Boolean);
54
- }
55
-
56
- /**
57
- * .github/prompts/*.prompt.md — reusable prompt templates.
58
- * Returns array of { name, path, frontmatter, body }.
59
- */
60
- promptFiles() {
61
- const dir = path.join(this.dir, '.github', 'prompts');
62
- const files = listFiles(dir, f => f.endsWith('.prompt.md'));
63
- return files.map(f => {
64
- const relPath = `.github/prompts/${f}`;
65
- const content = this.fileContent(relPath);
66
- if (!content) return null;
67
- const parsed = extractFrontmatter(content);
68
- return {
69
- name: f.replace('.prompt.md', ''),
70
- path: relPath,
71
- frontmatter: parsed.frontmatter,
72
- body: parsed.body,
73
- };
74
- }).filter(Boolean);
75
- }
76
-
77
- // ─── VS Code settings ─────────────────────────────────────────────────
78
-
79
- /**
80
- * .vscode/settings.json parsed — full VS Code settings (Copilot-relevant keys).
81
- */
82
- vscodeSettings() {
83
- const content = this.fileContent('.vscode/settings.json');
84
- if (!content) {
85
- return { ok: false, data: null, error: 'missing .vscode/settings.json', source: '.vscode/settings.json' };
86
- }
87
- const parsed = tryParseJson(content);
88
- return { ...parsed, source: '.vscode/settings.json' };
89
- }
90
-
91
- /**
92
- * Get a specific Copilot-related setting from .vscode/settings.json.
93
- */
94
- copilotSetting(dottedKey) {
95
- const result = this.vscodeSettings();
96
- if (!result.ok) return undefined;
97
- return getValueByPath(result.data, dottedKey);
98
- }
99
-
100
- // ─── Cloud agent config ───────────────────────────────────────────────
101
-
102
- /**
103
- * copilot-setup-steps.yml cloud agent environment setup.
104
- */
105
- cloudAgentConfig() {
106
- return this.fileContent('.github/workflows/copilot-setup-steps.yml') ||
107
- this.fileContent('copilot-setup-steps.yml');
108
- }
109
-
110
- // ─── MCP config ───────────────────────────────────────────────────────
111
-
112
- /**
113
- * .vscode/mcp.json — VS Code MCP server configuration.
114
- * Note: Copilot MCP uses .vscode/mcp.json (separate from settings.json mcpServers).
115
- */
116
- mcpConfig() {
117
- const content = this.fileContent('.vscode/mcp.json');
118
- if (!content) {
119
- return { ok: false, data: null, error: 'missing .vscode/mcp.json', source: '.vscode/mcp.json' };
120
- }
121
- const parsed = tryParseJson(content);
122
- return { ...parsed, source: '.vscode/mcp.json' };
123
- }
124
-
125
- /**
126
- * MCP servers from .vscode/mcp.json.
127
- */
128
- mcpServers() {
129
- const result = this.mcpConfig();
130
- if (!result.ok || !result.data) return {};
131
- return result.data.servers || result.data.mcpServers || {};
132
- }
133
-
134
- // ─── Content exclusions ───────────────────────────────────────────────
135
-
136
- /**
137
- * Content exclusion patterns from .vscode/settings.json or org-level markers.
138
- * Returns array of glob patterns, or null if not configured.
139
- */
140
- contentExclusions() {
141
- const settings = this.vscodeSettings();
142
- if (!settings.ok) return null;
143
-
144
- // Check multiple possible config keys for content exclusions
145
- const exclusions = getValueByPath(settings.data, 'github.copilot.advanced.contentExclusion') ||
146
- getValueByPath(settings.data, 'github.copilot.contentExclusion') ||
147
- null;
148
-
149
- return exclusions;
150
- }
151
-
152
- // ─── Workflow files ───────────────────────────────────────────────────
153
-
154
- workflowFiles() {
155
- const dir = path.join(this.dir, '.github', 'workflows');
156
- return listFiles(dir, f => f.endsWith('.yml') || f.endsWith('.yaml'))
157
- .map(f => `.github/workflows/${f}`);
158
- }
159
-
160
- // ─── Surface detection ────────────────────────────────────────────────
161
-
162
- /**
163
- * Detect which Copilot surfaces are configured.
164
- */
165
- detectSurfaces() {
166
- const vscode = Boolean(
167
- this.fileContent('.vscode/settings.json') ||
168
- this.fileContent('.vscode/mcp.json')
169
- );
170
- const cloudAgent = Boolean(this.cloudAgentConfig());
171
- const cli = false; // CLI detection is local-only; can't detect from repo files
172
-
173
- return { vscode, cloudAgent, cli };
174
- }
175
-
176
- // ─── Static detection ─────────────────────────────────────────────────
177
-
178
- static isCopilotRepo(dir) {
179
- try {
180
- return fs.existsSync(path.join(dir, '.github', 'copilot-instructions.md')) ||
181
- fs.existsSync(path.join(dir, '.vscode', 'mcp.json')) ||
182
- fs.existsSync(path.join(dir, '.github', 'instructions'));
183
- } catch {
184
- return false;
185
- }
186
- }
187
-
188
- // ─── Stack detection (reuse shared) ───────────────────────────────────
189
-
190
- detectStacks(STACKS) {
191
- return super.detectStacks(STACKS);
192
- }
193
- }
194
-
195
- module.exports = {
196
- CopilotProjectContext,
197
- };
1
+ /**
2
+ * Copilot project context.
3
+ *
4
+ * Extends the shared ProjectContext with Copilot-specific file lookups,
5
+ * 3-surface detection (VS Code, cloud agent, CLI), instruction parsing,
6
+ * and per-surface config resolution.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { ProjectContext } = require('../context');
12
+ const { tryParseJson, extractFrontmatter, getValueByPath } = require('./config-parser');
13
+
14
+ function listFiles(fullPath, filter) {
15
+ try {
16
+ const entries = fs.readdirSync(fullPath).filter(f => !f.startsWith('.'));
17
+ return filter ? entries.filter(filter) : entries;
18
+ } catch {
19
+ return [];
20
+ }
21
+ }
22
+
23
+ class CopilotProjectContext extends ProjectContext {
24
+
25
+ // ─── Instructions ─────────────────────────────────────────────────────
26
+
27
+ /**
28
+ * .github/copilot-instructions.md — repo-wide instructions for all surfaces.
29
+ *
30
+ * Copilot CLI also ingests root-level AGENTS.md and CLAUDE.md automatically
31
+ * (see GitHub Copilot CLI docs — "custom instructions"). When the canonical
32
+ * file is missing, fall back to these alternate cross-platform instruction
33
+ * files so repos that standardize on AGENTS.md/CLAUDE.md (a common pattern
34
+ * in the Rust/Python ecosystems) are not penalized as having no instructions.
35
+ */
36
+ copilotInstructionsContent() {
37
+ return this.fileContent('.github/copilot-instructions.md') ||
38
+ this.fileContent('AGENTS.md') ||
39
+ this.fileContent('CLAUDE.md');
40
+ }
41
+
42
+ /**
43
+ * Returns true if the repo has any instruction surface recognised by
44
+ * Copilot (native or cross-platform via CLI auto-ingestion).
45
+ */
46
+ hasAnyInstructionsSurface() {
47
+ return Boolean(
48
+ this.fileContent('.github/copilot-instructions.md') ||
49
+ this.fileContent('AGENTS.md') ||
50
+ this.fileContent('CLAUDE.md')
51
+ );
52
+ }
53
+
54
+ /**
55
+ * .github/instructions/*.instructions.md — path-scoped instructions.
56
+ * Returns array of { name, path, frontmatter, body, applyTo }.
57
+ */
58
+ scopedInstructions() {
59
+ const dir = path.join(this.dir, '.github', 'instructions');
60
+ const files = listFiles(dir, f => f.endsWith('.instructions.md'));
61
+ return files.map(f => {
62
+ const relPath = `.github/instructions/${f}`;
63
+ const content = this.fileContent(relPath);
64
+ if (!content) return null;
65
+ const parsed = extractFrontmatter(content);
66
+ return {
67
+ name: f.replace('.instructions.md', ''),
68
+ path: relPath,
69
+ frontmatter: parsed.frontmatter,
70
+ body: parsed.body,
71
+ applyTo: parsed.frontmatter ? parsed.frontmatter.applyTo : null,
72
+ };
73
+ }).filter(Boolean);
74
+ }
75
+
76
+ /**
77
+ * .github/prompts/*.prompt.md reusable prompt templates.
78
+ * Returns array of { name, path, frontmatter, body }.
79
+ */
80
+ promptFiles() {
81
+ const dir = path.join(this.dir, '.github', 'prompts');
82
+ const files = listFiles(dir, f => f.endsWith('.prompt.md'));
83
+ return files.map(f => {
84
+ const relPath = `.github/prompts/${f}`;
85
+ const content = this.fileContent(relPath);
86
+ if (!content) return null;
87
+ const parsed = extractFrontmatter(content);
88
+ return {
89
+ name: f.replace('.prompt.md', ''),
90
+ path: relPath,
91
+ frontmatter: parsed.frontmatter,
92
+ body: parsed.body,
93
+ };
94
+ }).filter(Boolean);
95
+ }
96
+
97
+ // ─── VS Code settings ─────────────────────────────────────────────────
98
+
99
+ /**
100
+ * .vscode/settings.json parsed full VS Code settings (Copilot-relevant keys).
101
+ */
102
+ vscodeSettings() {
103
+ const content = this.fileContent('.vscode/settings.json');
104
+ if (!content) {
105
+ return { ok: false, data: null, error: 'missing .vscode/settings.json', source: '.vscode/settings.json' };
106
+ }
107
+ const parsed = tryParseJson(content);
108
+ return { ...parsed, source: '.vscode/settings.json' };
109
+ }
110
+
111
+ /**
112
+ * Get a specific Copilot-related setting from .vscode/settings.json.
113
+ */
114
+ copilotSetting(dottedKey) {
115
+ const result = this.vscodeSettings();
116
+ if (!result.ok) return undefined;
117
+ return getValueByPath(result.data, dottedKey);
118
+ }
119
+
120
+ // ─── Cloud agent config ───────────────────────────────────────────────
121
+
122
+ /**
123
+ * copilot-setup-steps.yml — cloud agent environment setup.
124
+ */
125
+ cloudAgentConfig() {
126
+ return this.fileContent('.github/workflows/copilot-setup-steps.yml') ||
127
+ this.fileContent('copilot-setup-steps.yml');
128
+ }
129
+
130
+ // ─── MCP config ───────────────────────────────────────────────────────
131
+
132
+ /**
133
+ * .vscode/mcp.json — VS Code MCP server configuration.
134
+ * Note: Copilot MCP uses .vscode/mcp.json (separate from settings.json mcpServers).
135
+ */
136
+ mcpConfig() {
137
+ const content = this.fileContent('.vscode/mcp.json');
138
+ if (!content) {
139
+ return { ok: false, data: null, error: 'missing .vscode/mcp.json', source: '.vscode/mcp.json' };
140
+ }
141
+ const parsed = tryParseJson(content);
142
+ return { ...parsed, source: '.vscode/mcp.json' };
143
+ }
144
+
145
+ /**
146
+ * MCP servers from .vscode/mcp.json.
147
+ */
148
+ mcpServers() {
149
+ const result = this.mcpConfig();
150
+ if (!result.ok || !result.data) return {};
151
+ return result.data.servers || result.data.mcpServers || {};
152
+ }
153
+
154
+ // ─── Content exclusions ───────────────────────────────────────────────
155
+
156
+ /**
157
+ * Content exclusion patterns from .vscode/settings.json or org-level markers.
158
+ * Returns array of glob patterns, or null if not configured.
159
+ */
160
+ contentExclusions() {
161
+ const settings = this.vscodeSettings();
162
+ if (!settings.ok) return null;
163
+
164
+ // Check multiple possible config keys for content exclusions
165
+ const exclusions = getValueByPath(settings.data, 'github.copilot.advanced.contentExclusion') ||
166
+ getValueByPath(settings.data, 'github.copilot.contentExclusion') ||
167
+ null;
168
+
169
+ return exclusions;
170
+ }
171
+
172
+ // ─── Workflow files ───────────────────────────────────────────────────
173
+
174
+ workflowFiles() {
175
+ const dir = path.join(this.dir, '.github', 'workflows');
176
+ return listFiles(dir, f => f.endsWith('.yml') || f.endsWith('.yaml'))
177
+ .map(f => `.github/workflows/${f}`);
178
+ }
179
+
180
+ // ─── Surface detection ────────────────────────────────────────────────
181
+
182
+ /**
183
+ * Detect which Copilot surfaces are configured.
184
+ */
185
+ detectSurfaces() {
186
+ const vscode = Boolean(
187
+ this.fileContent('.vscode/settings.json') ||
188
+ this.fileContent('.vscode/mcp.json')
189
+ );
190
+ const cloudAgent = Boolean(this.cloudAgentConfig());
191
+ const cli = false; // CLI detection is local-only; can't detect from repo files
192
+
193
+ return { vscode, cloudAgent, cli };
194
+ }
195
+
196
+ // ─── Static detection ─────────────────────────────────────────────────
197
+
198
+ static isCopilotRepo(dir) {
199
+ try {
200
+ return fs.existsSync(path.join(dir, '.github', 'copilot-instructions.md')) ||
201
+ fs.existsSync(path.join(dir, '.vscode', 'mcp.json')) ||
202
+ fs.existsSync(path.join(dir, '.github', 'instructions')) ||
203
+ fs.existsSync(path.join(dir, '.github', 'prompts'));
204
+ } catch {
205
+ return false;
206
+ }
207
+ }
208
+
209
+ // ─── Stack detection (reuse shared) ───────────────────────────────────
210
+
211
+ detectStacks(STACKS) {
212
+ return super.detectStacks(STACKS);
213
+ }
214
+ }
215
+
216
+ module.exports = {
217
+ CopilotProjectContext,
218
+ };