@fyow/copilot-everything 1.0.0 → 1.0.2
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/package.json +2 -1
- package/scripts/hooks/evaluate-session.js +78 -0
- package/scripts/hooks/post-tool-use.ps1 +55 -0
- package/scripts/hooks/post-tool-use.sh +68 -0
- package/scripts/hooks/pre-compact.js +48 -0
- package/scripts/hooks/session-end.js +82 -0
- package/scripts/hooks/session-start.js +61 -0
- package/scripts/hooks/suggest-compact.js +60 -0
- package/scripts/lib/package-manager.js +390 -0
- package/scripts/lib/utils.js +368 -0
- package/scripts/migrate-to-copilot.js +247 -0
- package/scripts/setup-package-manager.js +206 -0
- package/src/commands/init.js +11 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform utility functions for Claude Code hooks and scripts
|
|
3
|
+
* Works on Windows, macOS, and Linux
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
const { execSync, spawnSync } = require('child_process');
|
|
10
|
+
|
|
11
|
+
// Platform detection
|
|
12
|
+
const isWindows = process.platform === 'win32';
|
|
13
|
+
const isMacOS = process.platform === 'darwin';
|
|
14
|
+
const isLinux = process.platform === 'linux';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the user's home directory (cross-platform)
|
|
18
|
+
*/
|
|
19
|
+
function getHomeDir() {
|
|
20
|
+
return os.homedir();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get the Claude config directory
|
|
25
|
+
*/
|
|
26
|
+
function getClaudeDir() {
|
|
27
|
+
return path.join(getHomeDir(), '.claude');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the sessions directory
|
|
32
|
+
*/
|
|
33
|
+
function getSessionsDir() {
|
|
34
|
+
return path.join(getClaudeDir(), 'sessions');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the learned skills directory
|
|
39
|
+
*/
|
|
40
|
+
function getLearnedSkillsDir() {
|
|
41
|
+
return path.join(getClaudeDir(), 'skills', 'learned');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the temp directory (cross-platform)
|
|
46
|
+
*/
|
|
47
|
+
function getTempDir() {
|
|
48
|
+
return os.tmpdir();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Ensure a directory exists (create if not)
|
|
53
|
+
*/
|
|
54
|
+
function ensureDir(dirPath) {
|
|
55
|
+
if (!fs.existsSync(dirPath)) {
|
|
56
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
return dirPath;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get current date in YYYY-MM-DD format
|
|
63
|
+
*/
|
|
64
|
+
function getDateString() {
|
|
65
|
+
const now = new Date();
|
|
66
|
+
const year = now.getFullYear();
|
|
67
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
68
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
69
|
+
return `${year}-${month}-${day}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get current time in HH:MM format
|
|
74
|
+
*/
|
|
75
|
+
function getTimeString() {
|
|
76
|
+
const now = new Date();
|
|
77
|
+
const hours = String(now.getHours()).padStart(2, '0');
|
|
78
|
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
79
|
+
return `${hours}:${minutes}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get current datetime in YYYY-MM-DD HH:MM:SS format
|
|
84
|
+
*/
|
|
85
|
+
function getDateTimeString() {
|
|
86
|
+
const now = new Date();
|
|
87
|
+
const year = now.getFullYear();
|
|
88
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
89
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
90
|
+
const hours = String(now.getHours()).padStart(2, '0');
|
|
91
|
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
92
|
+
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
93
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Find files matching a pattern in a directory (cross-platform alternative to find)
|
|
98
|
+
* @param {string} dir - Directory to search
|
|
99
|
+
* @param {string} pattern - File pattern (e.g., "*.tmp", "*.md")
|
|
100
|
+
* @param {object} options - Options { maxAge: days, recursive: boolean }
|
|
101
|
+
*/
|
|
102
|
+
function findFiles(dir, pattern, options = {}) {
|
|
103
|
+
const { maxAge = null, recursive = false } = options;
|
|
104
|
+
const results = [];
|
|
105
|
+
|
|
106
|
+
if (!fs.existsSync(dir)) {
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const regexPattern = pattern
|
|
111
|
+
.replace(/\./g, '\\.')
|
|
112
|
+
.replace(/\*/g, '.*')
|
|
113
|
+
.replace(/\?/g, '.');
|
|
114
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
115
|
+
|
|
116
|
+
function searchDir(currentDir) {
|
|
117
|
+
try {
|
|
118
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
119
|
+
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
122
|
+
|
|
123
|
+
if (entry.isFile() && regex.test(entry.name)) {
|
|
124
|
+
if (maxAge !== null) {
|
|
125
|
+
const stats = fs.statSync(fullPath);
|
|
126
|
+
const ageInDays = (Date.now() - stats.mtimeMs) / (1000 * 60 * 60 * 24);
|
|
127
|
+
if (ageInDays <= maxAge) {
|
|
128
|
+
results.push({ path: fullPath, mtime: stats.mtimeMs });
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
const stats = fs.statSync(fullPath);
|
|
132
|
+
results.push({ path: fullPath, mtime: stats.mtimeMs });
|
|
133
|
+
}
|
|
134
|
+
} else if (entry.isDirectory() && recursive) {
|
|
135
|
+
searchDir(fullPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
// Ignore permission errors
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
searchDir(dir);
|
|
144
|
+
|
|
145
|
+
// Sort by modification time (newest first)
|
|
146
|
+
results.sort((a, b) => b.mtime - a.mtime);
|
|
147
|
+
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Read JSON from stdin (for hook input)
|
|
153
|
+
*/
|
|
154
|
+
async function readStdinJson() {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
let data = '';
|
|
157
|
+
|
|
158
|
+
process.stdin.setEncoding('utf8');
|
|
159
|
+
process.stdin.on('data', chunk => {
|
|
160
|
+
data += chunk;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
process.stdin.on('end', () => {
|
|
164
|
+
try {
|
|
165
|
+
if (data.trim()) {
|
|
166
|
+
resolve(JSON.parse(data));
|
|
167
|
+
} else {
|
|
168
|
+
resolve({});
|
|
169
|
+
}
|
|
170
|
+
} catch (err) {
|
|
171
|
+
reject(err);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
process.stdin.on('error', reject);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Log to stderr (visible to user in Claude Code)
|
|
181
|
+
*/
|
|
182
|
+
function log(message) {
|
|
183
|
+
console.error(message);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Output to stdout (returned to Claude)
|
|
188
|
+
*/
|
|
189
|
+
function output(data) {
|
|
190
|
+
if (typeof data === 'object') {
|
|
191
|
+
console.log(JSON.stringify(data));
|
|
192
|
+
} else {
|
|
193
|
+
console.log(data);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Read a text file safely
|
|
199
|
+
*/
|
|
200
|
+
function readFile(filePath) {
|
|
201
|
+
try {
|
|
202
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
203
|
+
} catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Write a text file
|
|
210
|
+
*/
|
|
211
|
+
function writeFile(filePath, content) {
|
|
212
|
+
ensureDir(path.dirname(filePath));
|
|
213
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Append to a text file
|
|
218
|
+
*/
|
|
219
|
+
function appendFile(filePath, content) {
|
|
220
|
+
ensureDir(path.dirname(filePath));
|
|
221
|
+
fs.appendFileSync(filePath, content, 'utf8');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Check if a command exists in PATH
|
|
226
|
+
*/
|
|
227
|
+
function commandExists(cmd) {
|
|
228
|
+
try {
|
|
229
|
+
if (isWindows) {
|
|
230
|
+
execSync(`where ${cmd}`, { stdio: 'pipe' });
|
|
231
|
+
} else {
|
|
232
|
+
execSync(`which ${cmd}`, { stdio: 'pipe' });
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Run a command and return output
|
|
242
|
+
*/
|
|
243
|
+
function runCommand(cmd, options = {}) {
|
|
244
|
+
try {
|
|
245
|
+
const result = execSync(cmd, {
|
|
246
|
+
encoding: 'utf8',
|
|
247
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
248
|
+
...options
|
|
249
|
+
});
|
|
250
|
+
return { success: true, output: result.trim() };
|
|
251
|
+
} catch (err) {
|
|
252
|
+
return { success: false, output: err.stderr || err.message };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Check if current directory is a git repository
|
|
258
|
+
*/
|
|
259
|
+
function isGitRepo() {
|
|
260
|
+
return runCommand('git rev-parse --git-dir').success;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Get git modified files
|
|
265
|
+
*/
|
|
266
|
+
function getGitModifiedFiles(patterns = []) {
|
|
267
|
+
if (!isGitRepo()) return [];
|
|
268
|
+
|
|
269
|
+
const result = runCommand('git diff --name-only HEAD');
|
|
270
|
+
if (!result.success) return [];
|
|
271
|
+
|
|
272
|
+
let files = result.output.split('\n').filter(Boolean);
|
|
273
|
+
|
|
274
|
+
if (patterns.length > 0) {
|
|
275
|
+
files = files.filter(file => {
|
|
276
|
+
return patterns.some(pattern => {
|
|
277
|
+
const regex = new RegExp(pattern);
|
|
278
|
+
return regex.test(file);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return files;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Replace text in a file (cross-platform sed alternative)
|
|
288
|
+
*/
|
|
289
|
+
function replaceInFile(filePath, search, replace) {
|
|
290
|
+
const content = readFile(filePath);
|
|
291
|
+
if (content === null) return false;
|
|
292
|
+
|
|
293
|
+
const newContent = content.replace(search, replace);
|
|
294
|
+
writeFile(filePath, newContent);
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Count occurrences of a pattern in a file
|
|
300
|
+
*/
|
|
301
|
+
function countInFile(filePath, pattern) {
|
|
302
|
+
const content = readFile(filePath);
|
|
303
|
+
if (content === null) return 0;
|
|
304
|
+
|
|
305
|
+
const regex = pattern instanceof RegExp ? pattern : new RegExp(pattern, 'g');
|
|
306
|
+
const matches = content.match(regex);
|
|
307
|
+
return matches ? matches.length : 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Search for pattern in file and return matching lines with line numbers
|
|
312
|
+
*/
|
|
313
|
+
function grepFile(filePath, pattern) {
|
|
314
|
+
const content = readFile(filePath);
|
|
315
|
+
if (content === null) return [];
|
|
316
|
+
|
|
317
|
+
const regex = pattern instanceof RegExp ? pattern : new RegExp(pattern);
|
|
318
|
+
const lines = content.split('\n');
|
|
319
|
+
const results = [];
|
|
320
|
+
|
|
321
|
+
lines.forEach((line, index) => {
|
|
322
|
+
if (regex.test(line)) {
|
|
323
|
+
results.push({ lineNumber: index + 1, content: line });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return results;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
module.exports = {
|
|
331
|
+
// Platform info
|
|
332
|
+
isWindows,
|
|
333
|
+
isMacOS,
|
|
334
|
+
isLinux,
|
|
335
|
+
|
|
336
|
+
// Directories
|
|
337
|
+
getHomeDir,
|
|
338
|
+
getClaudeDir,
|
|
339
|
+
getSessionsDir,
|
|
340
|
+
getLearnedSkillsDir,
|
|
341
|
+
getTempDir,
|
|
342
|
+
ensureDir,
|
|
343
|
+
|
|
344
|
+
// Date/Time
|
|
345
|
+
getDateString,
|
|
346
|
+
getTimeString,
|
|
347
|
+
getDateTimeString,
|
|
348
|
+
|
|
349
|
+
// File operations
|
|
350
|
+
findFiles,
|
|
351
|
+
readFile,
|
|
352
|
+
writeFile,
|
|
353
|
+
appendFile,
|
|
354
|
+
replaceInFile,
|
|
355
|
+
countInFile,
|
|
356
|
+
grepFile,
|
|
357
|
+
|
|
358
|
+
// Hook I/O
|
|
359
|
+
readStdinJson,
|
|
360
|
+
log,
|
|
361
|
+
output,
|
|
362
|
+
|
|
363
|
+
// System
|
|
364
|
+
commandExists,
|
|
365
|
+
runCommand,
|
|
366
|
+
isGitRepo,
|
|
367
|
+
getGitModifiedFiles
|
|
368
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Migration script to convert Claude Code configs to Copilot CLI format
|
|
5
|
+
*
|
|
6
|
+
* Usage: node scripts/migrate-to-copilot.js [--dry-run]
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs')
|
|
10
|
+
const path = require('path')
|
|
11
|
+
|
|
12
|
+
const DRY_RUN = process.argv.includes('--dry-run')
|
|
13
|
+
|
|
14
|
+
// Tool name mappings from Claude Code to Copilot CLI
|
|
15
|
+
const TOOL_MAPPINGS = {
|
|
16
|
+
'Read': 'read',
|
|
17
|
+
'Write': 'edit',
|
|
18
|
+
'Edit': 'edit',
|
|
19
|
+
'Bash': 'shell',
|
|
20
|
+
'Grep': 'search',
|
|
21
|
+
'Glob': 'search',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Model mappings
|
|
25
|
+
const MODEL_MAPPINGS = {
|
|
26
|
+
'opus': 'claude-opus-4-5',
|
|
27
|
+
'sonnet': 'claude-sonnet-4-5',
|
|
28
|
+
'haiku': 'claude-haiku-4-5',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function log(message) {
|
|
32
|
+
console.log(`[migrate] ${message}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ensureDir(dirPath) {
|
|
36
|
+
if (!fs.existsSync(dirPath)) {
|
|
37
|
+
if (!DRY_RUN) {
|
|
38
|
+
fs.mkdirSync(dirPath, { recursive: true })
|
|
39
|
+
}
|
|
40
|
+
log(`Created directory: ${dirPath}`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readMarkdownWithFrontmatter(filePath) {
|
|
45
|
+
const content = fs.readFileSync(filePath, 'utf8')
|
|
46
|
+
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/)
|
|
47
|
+
|
|
48
|
+
if (!match) {
|
|
49
|
+
return { frontmatter: {}, body: content }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const frontmatterLines = match[1].split('\n')
|
|
53
|
+
const frontmatter = {}
|
|
54
|
+
|
|
55
|
+
for (const line of frontmatterLines) {
|
|
56
|
+
const colonIndex = line.indexOf(':')
|
|
57
|
+
if (colonIndex > 0) {
|
|
58
|
+
const key = line.slice(0, colonIndex).trim()
|
|
59
|
+
const value = line.slice(colonIndex + 1).trim()
|
|
60
|
+
frontmatter[key] = value
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { frontmatter, body: match[2] }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function convertTools(toolsString) {
|
|
68
|
+
if (!toolsString) return undefined
|
|
69
|
+
|
|
70
|
+
const tools = toolsString.split(',').map(t => t.trim())
|
|
71
|
+
const converted = tools.map(t => TOOL_MAPPINGS[t] || t.toLowerCase())
|
|
72
|
+
|
|
73
|
+
// Remove duplicates
|
|
74
|
+
return [...new Set(converted)]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function convertAgent(sourcePath, destPath) {
|
|
78
|
+
const { frontmatter, body } = readMarkdownWithFrontmatter(sourcePath)
|
|
79
|
+
|
|
80
|
+
const newFrontmatter = {
|
|
81
|
+
name: frontmatter.name,
|
|
82
|
+
description: frontmatter.description,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Convert tools
|
|
86
|
+
const tools = convertTools(frontmatter.tools)
|
|
87
|
+
if (tools && tools.length > 0) {
|
|
88
|
+
newFrontmatter.tools = JSON.stringify(tools)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Build new content
|
|
92
|
+
let newContent = '---\n'
|
|
93
|
+
newContent += `name: ${newFrontmatter.name}\n`
|
|
94
|
+
newContent += `description: ${newFrontmatter.description}\n`
|
|
95
|
+
if (tools) {
|
|
96
|
+
newContent += `tools: ${JSON.stringify(tools)}\n`
|
|
97
|
+
}
|
|
98
|
+
newContent += '---\n\n'
|
|
99
|
+
newContent += body
|
|
100
|
+
|
|
101
|
+
if (!DRY_RUN) {
|
|
102
|
+
ensureDir(path.dirname(destPath))
|
|
103
|
+
fs.writeFileSync(destPath, newContent)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
log(`Converted agent: ${path.basename(sourcePath)} → ${path.basename(destPath)}`)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function convertRule(sourcePath, destPath, applyTo = '**') {
|
|
110
|
+
const content = fs.readFileSync(sourcePath, 'utf8')
|
|
111
|
+
|
|
112
|
+
// Add frontmatter with applyTo
|
|
113
|
+
let newContent = '---\n'
|
|
114
|
+
newContent += `applyTo: "${applyTo}"\n`
|
|
115
|
+
newContent += '---\n\n'
|
|
116
|
+
newContent += content
|
|
117
|
+
|
|
118
|
+
if (!DRY_RUN) {
|
|
119
|
+
ensureDir(path.dirname(destPath))
|
|
120
|
+
fs.writeFileSync(destPath, newContent)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
log(`Converted rule: ${path.basename(sourcePath)} → ${path.basename(destPath)}`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function convertHooks(sourcePath, destPath) {
|
|
127
|
+
const content = JSON.parse(fs.readFileSync(sourcePath, 'utf8'))
|
|
128
|
+
|
|
129
|
+
const newHooks = {
|
|
130
|
+
version: 1,
|
|
131
|
+
hooks: {}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Map hook types
|
|
135
|
+
const hookTypeMap = {
|
|
136
|
+
'PreToolUse': 'preToolUse',
|
|
137
|
+
'PostToolUse': 'postToolUse',
|
|
138
|
+
'SessionStart': 'sessionStart',
|
|
139
|
+
'SessionEnd': 'sessionEnd',
|
|
140
|
+
'Stop': 'sessionEnd',
|
|
141
|
+
'PreCompact': 'preToolUse',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
for (const [oldType, hooks] of Object.entries(content.hooks || {})) {
|
|
145
|
+
const newType = hookTypeMap[oldType]
|
|
146
|
+
if (!newType) continue
|
|
147
|
+
|
|
148
|
+
if (!newHooks.hooks[newType]) {
|
|
149
|
+
newHooks.hooks[newType] = []
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const hook of hooks) {
|
|
153
|
+
// Extract command from hook
|
|
154
|
+
let command = ''
|
|
155
|
+
if (hook.hooks && hook.hooks[0]) {
|
|
156
|
+
command = hook.hooks[0].command
|
|
157
|
+
} else if (hook.command) {
|
|
158
|
+
command = hook.command
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!command) continue
|
|
162
|
+
|
|
163
|
+
newHooks.hooks[newType].push({
|
|
164
|
+
type: 'command',
|
|
165
|
+
bash: command,
|
|
166
|
+
powershell: command,
|
|
167
|
+
cwd: '.',
|
|
168
|
+
timeoutSec: 30
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!DRY_RUN) {
|
|
174
|
+
ensureDir(path.dirname(destPath))
|
|
175
|
+
fs.writeFileSync(destPath, JSON.stringify(newHooks, null, 2))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
log(`Converted hooks: ${path.basename(sourcePath)} → ${path.basename(destPath)}`)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function main() {
|
|
182
|
+
const projectRoot = path.resolve(__dirname, '..')
|
|
183
|
+
|
|
184
|
+
log('Starting migration to Copilot CLI format...')
|
|
185
|
+
if (DRY_RUN) {
|
|
186
|
+
log('DRY RUN - no files will be modified')
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Create directories
|
|
190
|
+
ensureDir(path.join(projectRoot, '.github', 'agents'))
|
|
191
|
+
ensureDir(path.join(projectRoot, '.github', 'skills'))
|
|
192
|
+
ensureDir(path.join(projectRoot, '.github', 'instructions'))
|
|
193
|
+
ensureDir(path.join(projectRoot, '.github', 'hooks'))
|
|
194
|
+
ensureDir(path.join(projectRoot, 'copilot'))
|
|
195
|
+
|
|
196
|
+
// Convert agents
|
|
197
|
+
const agentsDir = path.join(projectRoot, 'agents')
|
|
198
|
+
if (fs.existsSync(agentsDir)) {
|
|
199
|
+
for (const file of fs.readdirSync(agentsDir)) {
|
|
200
|
+
if (file.endsWith('.md')) {
|
|
201
|
+
const name = file.replace('.md', '')
|
|
202
|
+
convertAgent(
|
|
203
|
+
path.join(agentsDir, file),
|
|
204
|
+
path.join(projectRoot, '.github', 'agents', `${name}.agent.md`)
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Convert rules to instructions
|
|
211
|
+
const rulesDir = path.join(projectRoot, 'rules')
|
|
212
|
+
const rulePatterns = {
|
|
213
|
+
'security.md': '**/*.ts,**/*.tsx,**/*.js,**/*.jsx',
|
|
214
|
+
'coding-style.md': '**/*.ts,**/*.tsx,**/*.js,**/*.jsx',
|
|
215
|
+
'testing.md': '**/*.test.ts,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx',
|
|
216
|
+
'git-workflow.md': '**',
|
|
217
|
+
'performance.md': '**',
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (fs.existsSync(rulesDir)) {
|
|
221
|
+
for (const file of fs.readdirSync(rulesDir)) {
|
|
222
|
+
if (file.endsWith('.md')) {
|
|
223
|
+
const name = file.replace('.md', '')
|
|
224
|
+
const applyTo = rulePatterns[file] || '**'
|
|
225
|
+
convertRule(
|
|
226
|
+
path.join(rulesDir, file),
|
|
227
|
+
path.join(projectRoot, '.github', 'instructions', `${name}.instructions.md`),
|
|
228
|
+
applyTo
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Note: Skills are already compatible format, just need to be copied
|
|
235
|
+
log('Skills are already in compatible format (.github/skills/*/SKILL.md)')
|
|
236
|
+
|
|
237
|
+
log('')
|
|
238
|
+
log('Migration complete!')
|
|
239
|
+
log('')
|
|
240
|
+
log('Next steps:')
|
|
241
|
+
log('1. Review generated files in .github/')
|
|
242
|
+
log('2. Copy copilot/mcp-config.json to ~/.copilot/')
|
|
243
|
+
log('3. Test with: copilot')
|
|
244
|
+
log('4. Use /agent to see available agents')
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
main()
|