everything-claude-code 1.4.3

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +739 -0
  3. package/README.zh-CN.md +523 -0
  4. package/crates/ecc-kernel/Cargo.lock +160 -0
  5. package/crates/ecc-kernel/Cargo.toml +15 -0
  6. package/crates/ecc-kernel/src/main.rs +710 -0
  7. package/docs/ecc.md +117 -0
  8. package/package.json +45 -0
  9. package/packs/blueprint.json +8 -0
  10. package/packs/forge.json +16 -0
  11. package/packs/instinct.json +16 -0
  12. package/packs/orchestra.json +15 -0
  13. package/packs/proof.json +8 -0
  14. package/packs/sentinel.json +8 -0
  15. package/prompts/ecc/patch.md +25 -0
  16. package/prompts/ecc/plan.md +28 -0
  17. package/schemas/ecc.apply.schema.json +35 -0
  18. package/schemas/ecc.config.schema.json +37 -0
  19. package/schemas/ecc.lock.schema.json +34 -0
  20. package/schemas/ecc.patch.schema.json +25 -0
  21. package/schemas/ecc.plan.schema.json +32 -0
  22. package/schemas/ecc.run.schema.json +67 -0
  23. package/schemas/ecc.verify.schema.json +27 -0
  24. package/schemas/hooks.schema.json +81 -0
  25. package/schemas/package-manager.schema.json +17 -0
  26. package/schemas/plugin.schema.json +13 -0
  27. package/scripts/ecc/catalog.js +82 -0
  28. package/scripts/ecc/config.js +43 -0
  29. package/scripts/ecc/diff.js +113 -0
  30. package/scripts/ecc/exec.js +121 -0
  31. package/scripts/ecc/fixtures/basic/patches/impl-core.diff +8 -0
  32. package/scripts/ecc/fixtures/basic/patches/tests.diff +8 -0
  33. package/scripts/ecc/fixtures/basic/plan.json +23 -0
  34. package/scripts/ecc/fixtures/unauthorized/patches/impl-core.diff +8 -0
  35. package/scripts/ecc/fixtures/unauthorized/plan.json +15 -0
  36. package/scripts/ecc/git.js +139 -0
  37. package/scripts/ecc/id.js +37 -0
  38. package/scripts/ecc/install-kernel.js +344 -0
  39. package/scripts/ecc/json-extract.js +301 -0
  40. package/scripts/ecc/json.js +26 -0
  41. package/scripts/ecc/kernel.js +144 -0
  42. package/scripts/ecc/lock.js +36 -0
  43. package/scripts/ecc/paths.js +28 -0
  44. package/scripts/ecc/plan.js +57 -0
  45. package/scripts/ecc/project.js +37 -0
  46. package/scripts/ecc/providers/codex.js +168 -0
  47. package/scripts/ecc/providers/index.js +23 -0
  48. package/scripts/ecc/providers/mock.js +49 -0
  49. package/scripts/ecc/report.js +127 -0
  50. package/scripts/ecc/run.js +105 -0
  51. package/scripts/ecc/validate.js +325 -0
  52. package/scripts/ecc/verify.js +125 -0
  53. package/scripts/ecc.js +532 -0
  54. package/scripts/lib/package-manager.js +390 -0
  55. package/scripts/lib/session-aliases.js +432 -0
  56. package/scripts/lib/session-manager.js +396 -0
  57. package/scripts/lib/utils.js +426 -0
@@ -0,0 +1,426 @@
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 session aliases file path
39
+ */
40
+ function getAliasesPath() {
41
+ return path.join(getClaudeDir(), 'session-aliases.json');
42
+ }
43
+
44
+ /**
45
+ * Get the learned skills directory
46
+ */
47
+ function getLearnedSkillsDir() {
48
+ return path.join(getClaudeDir(), 'skills', 'learned');
49
+ }
50
+
51
+ /**
52
+ * Get the temp directory (cross-platform)
53
+ */
54
+ function getTempDir() {
55
+ return os.tmpdir();
56
+ }
57
+
58
+ /**
59
+ * Ensure a directory exists (create if not)
60
+ */
61
+ function ensureDir(dirPath) {
62
+ if (!fs.existsSync(dirPath)) {
63
+ fs.mkdirSync(dirPath, { recursive: true });
64
+ }
65
+ return dirPath;
66
+ }
67
+
68
+ /**
69
+ * Get current date in YYYY-MM-DD format
70
+ */
71
+ function getDateString() {
72
+ const now = new Date();
73
+ const year = now.getFullYear();
74
+ const month = String(now.getMonth() + 1).padStart(2, '0');
75
+ const day = String(now.getDate()).padStart(2, '0');
76
+ return `${year}-${month}-${day}`;
77
+ }
78
+
79
+ /**
80
+ * Get current time in HH:MM format
81
+ */
82
+ function getTimeString() {
83
+ const now = new Date();
84
+ const hours = String(now.getHours()).padStart(2, '0');
85
+ const minutes = String(now.getMinutes()).padStart(2, '0');
86
+ return `${hours}:${minutes}`;
87
+ }
88
+
89
+ /**
90
+ * Get the git repository name
91
+ */
92
+ function getGitRepoName() {
93
+ const result = runCommand('git rev-parse --show-toplevel');
94
+ if (!result.success) return null;
95
+ return path.basename(result.output);
96
+ }
97
+
98
+ /**
99
+ * Get project name from git repo or current directory
100
+ */
101
+ function getProjectName() {
102
+ const repoName = getGitRepoName();
103
+ if (repoName) return repoName;
104
+ return path.basename(process.cwd()) || null;
105
+ }
106
+
107
+ /**
108
+ * Get short session ID from CLAUDE_SESSION_ID environment variable
109
+ * Returns last 8 characters, falls back to project name then 'default'
110
+ */
111
+ function getSessionIdShort(fallback = 'default') {
112
+ const sessionId = process.env.CLAUDE_SESSION_ID;
113
+ if (sessionId && sessionId.length > 0) {
114
+ return sessionId.slice(-8);
115
+ }
116
+ return getProjectName() || fallback;
117
+ }
118
+
119
+ /**
120
+ * Get current datetime in YYYY-MM-DD HH:MM:SS format
121
+ */
122
+ function getDateTimeString() {
123
+ const now = new Date();
124
+ const year = now.getFullYear();
125
+ const month = String(now.getMonth() + 1).padStart(2, '0');
126
+ const day = String(now.getDate()).padStart(2, '0');
127
+ const hours = String(now.getHours()).padStart(2, '0');
128
+ const minutes = String(now.getMinutes()).padStart(2, '0');
129
+ const seconds = String(now.getSeconds()).padStart(2, '0');
130
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
131
+ }
132
+
133
+ /**
134
+ * Find files matching a pattern in a directory (cross-platform alternative to find)
135
+ * @param {string} dir - Directory to search
136
+ * @param {string} pattern - File pattern (e.g., "*.tmp", "*.md")
137
+ * @param {object} options - Options { maxAge: days, recursive: boolean }
138
+ */
139
+ function findFiles(dir, pattern, options = {}) {
140
+ const { maxAge = null, recursive = false } = options;
141
+ const results = [];
142
+
143
+ if (!fs.existsSync(dir)) {
144
+ return results;
145
+ }
146
+
147
+ const regexPattern = pattern
148
+ .replace(/\./g, '\\.')
149
+ .replace(/\*/g, '.*')
150
+ .replace(/\?/g, '.');
151
+ const regex = new RegExp(`^${regexPattern}$`);
152
+
153
+ function searchDir(currentDir) {
154
+ try {
155
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
156
+
157
+ for (const entry of entries) {
158
+ const fullPath = path.join(currentDir, entry.name);
159
+
160
+ if (entry.isFile() && regex.test(entry.name)) {
161
+ if (maxAge !== null) {
162
+ const stats = fs.statSync(fullPath);
163
+ const ageInDays = (Date.now() - stats.mtimeMs) / (1000 * 60 * 60 * 24);
164
+ if (ageInDays <= maxAge) {
165
+ results.push({ path: fullPath, mtime: stats.mtimeMs });
166
+ }
167
+ } else {
168
+ const stats = fs.statSync(fullPath);
169
+ results.push({ path: fullPath, mtime: stats.mtimeMs });
170
+ }
171
+ } else if (entry.isDirectory() && recursive) {
172
+ searchDir(fullPath);
173
+ }
174
+ }
175
+ } catch (_err) {
176
+ // Ignore permission errors
177
+ }
178
+ }
179
+
180
+ searchDir(dir);
181
+
182
+ // Sort by modification time (newest first)
183
+ results.sort((a, b) => b.mtime - a.mtime);
184
+
185
+ return results;
186
+ }
187
+
188
+ /**
189
+ * Read JSON from stdin (for hook input)
190
+ */
191
+ async function readStdinJson() {
192
+ return new Promise((resolve, reject) => {
193
+ let data = '';
194
+
195
+ process.stdin.setEncoding('utf8');
196
+ process.stdin.on('data', chunk => {
197
+ data += chunk;
198
+ });
199
+
200
+ process.stdin.on('end', () => {
201
+ try {
202
+ if (data.trim()) {
203
+ resolve(JSON.parse(data));
204
+ } else {
205
+ resolve({});
206
+ }
207
+ } catch (err) {
208
+ reject(err);
209
+ }
210
+ });
211
+
212
+ process.stdin.on('error', reject);
213
+ });
214
+ }
215
+
216
+ /**
217
+ * Log to stderr (visible to user in Claude Code)
218
+ */
219
+ function log(message) {
220
+ console.error(message);
221
+ }
222
+
223
+ /**
224
+ * Output to stdout (returned to Claude)
225
+ */
226
+ function output(data) {
227
+ if (typeof data === 'object') {
228
+ console.log(JSON.stringify(data));
229
+ } else {
230
+ console.log(data);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Read a text file safely
236
+ */
237
+ function readFile(filePath) {
238
+ try {
239
+ return fs.readFileSync(filePath, 'utf8');
240
+ } catch {
241
+ return null;
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Write a text file
247
+ */
248
+ function writeFile(filePath, content) {
249
+ ensureDir(path.dirname(filePath));
250
+ fs.writeFileSync(filePath, content, 'utf8');
251
+ }
252
+
253
+ /**
254
+ * Append to a text file
255
+ */
256
+ function appendFile(filePath, content) {
257
+ ensureDir(path.dirname(filePath));
258
+ fs.appendFileSync(filePath, content, 'utf8');
259
+ }
260
+
261
+ /**
262
+ * Check if a command exists in PATH
263
+ * Uses execFileSync to prevent command injection
264
+ */
265
+ function commandExists(cmd) {
266
+ // Validate command name - only allow alphanumeric, dash, underscore, dot
267
+ if (!/^[a-zA-Z0-9_.-]+$/.test(cmd)) {
268
+ return false;
269
+ }
270
+
271
+ try {
272
+ if (isWindows) {
273
+ // Use spawnSync to avoid shell interpolation
274
+ const result = spawnSync('where', [cmd], { stdio: 'pipe' });
275
+ return result.status === 0;
276
+ } else {
277
+ const result = spawnSync('which', [cmd], { stdio: 'pipe' });
278
+ return result.status === 0;
279
+ }
280
+ } catch {
281
+ return false;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Run a command and return output
287
+ *
288
+ * SECURITY NOTE: This function executes shell commands. Only use with
289
+ * trusted, hardcoded commands. Never pass user-controlled input directly.
290
+ * For user input, use spawnSync with argument arrays instead.
291
+ *
292
+ * @param {string} cmd - Command to execute (should be trusted/hardcoded)
293
+ * @param {object} options - execSync options
294
+ */
295
+ function runCommand(cmd, options = {}) {
296
+ try {
297
+ const result = execSync(cmd, {
298
+ encoding: 'utf8',
299
+ stdio: ['pipe', 'pipe', 'pipe'],
300
+ ...options
301
+ });
302
+ return { success: true, output: result.trim() };
303
+ } catch (err) {
304
+ return { success: false, output: err.stderr || err.message };
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Check if current directory is a git repository
310
+ */
311
+ function isGitRepo() {
312
+ return runCommand('git rev-parse --git-dir').success;
313
+ }
314
+
315
+ /**
316
+ * Get git modified files
317
+ */
318
+ function getGitModifiedFiles(patterns = []) {
319
+ if (!isGitRepo()) return [];
320
+
321
+ const result = runCommand('git diff --name-only HEAD');
322
+ if (!result.success) return [];
323
+
324
+ let files = result.output.split('\n').filter(Boolean);
325
+
326
+ if (patterns.length > 0) {
327
+ files = files.filter(file => {
328
+ return patterns.some(pattern => {
329
+ const regex = new RegExp(pattern);
330
+ return regex.test(file);
331
+ });
332
+ });
333
+ }
334
+
335
+ return files;
336
+ }
337
+
338
+ /**
339
+ * Replace text in a file (cross-platform sed alternative)
340
+ */
341
+ function replaceInFile(filePath, search, replace) {
342
+ const content = readFile(filePath);
343
+ if (content === null) return false;
344
+
345
+ const newContent = content.replace(search, replace);
346
+ writeFile(filePath, newContent);
347
+ return true;
348
+ }
349
+
350
+ /**
351
+ * Count occurrences of a pattern in a file
352
+ */
353
+ function countInFile(filePath, pattern) {
354
+ const content = readFile(filePath);
355
+ if (content === null) return 0;
356
+
357
+ const regex = pattern instanceof RegExp ? pattern : new RegExp(pattern, 'g');
358
+ const matches = content.match(regex);
359
+ return matches ? matches.length : 0;
360
+ }
361
+
362
+ /**
363
+ * Search for pattern in file and return matching lines with line numbers
364
+ */
365
+ function grepFile(filePath, pattern) {
366
+ const content = readFile(filePath);
367
+ if (content === null) return [];
368
+
369
+ const regex = pattern instanceof RegExp ? pattern : new RegExp(pattern);
370
+ const lines = content.split('\n');
371
+ const results = [];
372
+
373
+ lines.forEach((line, index) => {
374
+ if (regex.test(line)) {
375
+ results.push({ lineNumber: index + 1, content: line });
376
+ }
377
+ });
378
+
379
+ return results;
380
+ }
381
+
382
+ module.exports = {
383
+ // Platform info
384
+ isWindows,
385
+ isMacOS,
386
+ isLinux,
387
+
388
+ // Directories
389
+ getHomeDir,
390
+ getClaudeDir,
391
+ getSessionsDir,
392
+ getAliasesPath,
393
+ getLearnedSkillsDir,
394
+ getTempDir,
395
+ ensureDir,
396
+
397
+ // Date/Time
398
+ getDateString,
399
+ getTimeString,
400
+ getDateTimeString,
401
+
402
+ // Session/Project
403
+ getSessionIdShort,
404
+ getGitRepoName,
405
+ getProjectName,
406
+
407
+ // File operations
408
+ findFiles,
409
+ readFile,
410
+ writeFile,
411
+ appendFile,
412
+ replaceInFile,
413
+ countInFile,
414
+ grepFile,
415
+
416
+ // Hook I/O
417
+ readStdinJson,
418
+ log,
419
+ output,
420
+
421
+ // System
422
+ commandExists,
423
+ runCommand,
424
+ isGitRepo,
425
+ getGitModifiedFiles
426
+ };