@hatem427/code-guard-ci 1.0.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.
- package/.husky/pre-commit +27 -0
- package/LICENSE +21 -0
- package/README.md +646 -0
- package/config/angular.config.ts +223 -0
- package/config/guidelines.config.ts +229 -0
- package/config/nextjs.config.ts +160 -0
- package/config/react.config.ts +330 -0
- package/dist/config/angular.config.d.ts +15 -0
- package/dist/config/angular.config.d.ts.map +1 -0
- package/dist/config/angular.config.js +187 -0
- package/dist/config/angular.config.js.map +1 -0
- package/dist/config/guidelines.config.d.ts +63 -0
- package/dist/config/guidelines.config.d.ts.map +1 -0
- package/dist/config/guidelines.config.js +167 -0
- package/dist/config/guidelines.config.js.map +1 -0
- package/dist/config/nextjs.config.d.ts +18 -0
- package/dist/config/nextjs.config.d.ts.map +1 -0
- package/dist/config/nextjs.config.js +133 -0
- package/dist/config/nextjs.config.js.map +1 -0
- package/dist/config/react.config.d.ts +15 -0
- package/dist/config/react.config.d.ts.map +1 -0
- package/dist/config/react.config.js +287 -0
- package/dist/config/react.config.js.map +1 -0
- package/dist/scripts/auto-fix.d.ts +16 -0
- package/dist/scripts/auto-fix.d.ts.map +1 -0
- package/dist/scripts/auto-fix.js +130 -0
- package/dist/scripts/auto-fix.js.map +1 -0
- package/dist/scripts/cli.d.ts +17 -0
- package/dist/scripts/cli.d.ts.map +1 -0
- package/dist/scripts/cli.js +255 -0
- package/dist/scripts/cli.js.map +1 -0
- package/dist/scripts/delete-bypass-logs.d.ts +17 -0
- package/dist/scripts/delete-bypass-logs.d.ts.map +1 -0
- package/dist/scripts/delete-bypass-logs.js +242 -0
- package/dist/scripts/delete-bypass-logs.js.map +1 -0
- package/dist/scripts/generate-doc.d.ts +18 -0
- package/dist/scripts/generate-doc.d.ts.map +1 -0
- package/dist/scripts/generate-doc.js +300 -0
- package/dist/scripts/generate-doc.js.map +1 -0
- package/dist/scripts/generate-pr-checklist.d.ts +20 -0
- package/dist/scripts/generate-pr-checklist.d.ts.map +1 -0
- package/dist/scripts/generate-pr-checklist.js +276 -0
- package/dist/scripts/generate-pr-checklist.js.map +1 -0
- package/dist/scripts/precommit-check.d.ts +23 -0
- package/dist/scripts/precommit-check.d.ts.map +1 -0
- package/dist/scripts/precommit-check.js +331 -0
- package/dist/scripts/precommit-check.js.map +1 -0
- package/dist/scripts/set-admin-password.d.ts +14 -0
- package/dist/scripts/set-admin-password.d.ts.map +1 -0
- package/dist/scripts/set-admin-password.js +116 -0
- package/dist/scripts/set-admin-password.js.map +1 -0
- package/dist/scripts/set-bypass-password.d.ts +11 -0
- package/dist/scripts/set-bypass-password.d.ts.map +1 -0
- package/dist/scripts/set-bypass-password.js +106 -0
- package/dist/scripts/set-bypass-password.js.map +1 -0
- package/dist/scripts/utils/auto-fixer.d.ts +28 -0
- package/dist/scripts/utils/auto-fixer.d.ts.map +1 -0
- package/dist/scripts/utils/auto-fixer.js +177 -0
- package/dist/scripts/utils/auto-fixer.js.map +1 -0
- package/dist/scripts/utils/bypass-manager.d.ts +101 -0
- package/dist/scripts/utils/bypass-manager.d.ts.map +1 -0
- package/dist/scripts/utils/bypass-manager.js +496 -0
- package/dist/scripts/utils/bypass-manager.js.map +1 -0
- package/dist/scripts/utils/code-analyzer.d.ts +34 -0
- package/dist/scripts/utils/code-analyzer.d.ts.map +1 -0
- package/dist/scripts/utils/code-analyzer.js +323 -0
- package/dist/scripts/utils/code-analyzer.js.map +1 -0
- package/dist/scripts/utils/file-checker.d.ts +93 -0
- package/dist/scripts/utils/file-checker.d.ts.map +1 -0
- package/dist/scripts/utils/file-checker.js +248 -0
- package/dist/scripts/utils/file-checker.js.map +1 -0
- package/dist/scripts/utils/logger.d.ts +26 -0
- package/dist/scripts/utils/logger.d.ts.map +1 -0
- package/dist/scripts/utils/logger.js +86 -0
- package/dist/scripts/utils/logger.js.map +1 -0
- package/dist/scripts/utils/project-detector.d.ts +34 -0
- package/dist/scripts/utils/project-detector.d.ts.map +1 -0
- package/dist/scripts/utils/project-detector.js +124 -0
- package/dist/scripts/utils/project-detector.js.map +1 -0
- package/dist/scripts/utils/rule-engine.d.ts +57 -0
- package/dist/scripts/utils/rule-engine.d.ts.map +1 -0
- package/dist/scripts/utils/rule-engine.js +158 -0
- package/dist/scripts/utils/rule-engine.js.map +1 -0
- package/dist/scripts/view-bypass-log.d.ts +13 -0
- package/dist/scripts/view-bypass-log.d.ts.map +1 -0
- package/dist/scripts/view-bypass-log.js +117 -0
- package/dist/scripts/view-bypass-log.js.map +1 -0
- package/package.json +74 -0
- package/scripts/auto-fix.ts +115 -0
- package/scripts/cli.ts +246 -0
- package/scripts/delete-bypass-logs.ts +253 -0
- package/scripts/generate-doc.ts +317 -0
- package/scripts/generate-pr-checklist.ts +285 -0
- package/scripts/precommit-check.ts +349 -0
- package/scripts/set-admin-password.ts +90 -0
- package/scripts/set-bypass-password.ts +80 -0
- package/scripts/utils/auto-fixer.ts +181 -0
- package/scripts/utils/bypass-manager.ts +566 -0
- package/scripts/utils/code-analyzer.ts +341 -0
- package/scripts/utils/file-checker.ts +253 -0
- package/scripts/utils/logger.ts +88 -0
- package/scripts/utils/project-detector.ts +115 -0
- package/scripts/utils/rule-engine.ts +186 -0
- package/scripts/view-bypass-log.ts +92 -0
- package/templates/feature-doc-api.md +101 -0
- package/templates/feature-doc-service.md +113 -0
- package/templates/feature-doc-ui.md +91 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* bypass-manager.ts — Bypass audit logging with authentication
|
|
5
|
+
* ============================================================================
|
|
6
|
+
*
|
|
7
|
+
* Tracks all bypass attempts with:
|
|
8
|
+
* - Author name (from git config)
|
|
9
|
+
* - Timestamp
|
|
10
|
+
* - Reason
|
|
11
|
+
* - Password verification
|
|
12
|
+
* - Commit hash
|
|
13
|
+
*
|
|
14
|
+
* Bypass log saved to: .code-guardian/bypass-log.json
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.verifyBypassPassword = verifyBypassPassword;
|
|
51
|
+
exports.setBypassPassword = setBypassPassword;
|
|
52
|
+
exports.verifyAdminPassword = verifyAdminPassword;
|
|
53
|
+
exports.setAdminPassword = setAdminPassword;
|
|
54
|
+
exports.recordBypass = recordBypass;
|
|
55
|
+
exports.updateBypassWithCommitHash = updateBypassWithCommitHash;
|
|
56
|
+
exports.getBypassesByAuthor = getBypassesByAuthor;
|
|
57
|
+
exports.getRecentBypasses = getRecentBypasses;
|
|
58
|
+
exports.deleteBypassEntries = deleteBypassEntries;
|
|
59
|
+
exports.getArchivedLogs = getArchivedLogs;
|
|
60
|
+
exports.generateBypassReport = generateBypassReport;
|
|
61
|
+
const fs = __importStar(require("fs"));
|
|
62
|
+
const path = __importStar(require("path"));
|
|
63
|
+
const child_process_1 = require("child_process");
|
|
64
|
+
const crypto = __importStar(require("crypto"));
|
|
65
|
+
// ── Configuration ───────────────────────────────────────────────────────────
|
|
66
|
+
const BYPASS_DIR = '.code-guardian';
|
|
67
|
+
const BYPASS_LOG_FILE = 'bypass-log.json';
|
|
68
|
+
const PASSWORD_FILE = 'bypass-password.hash';
|
|
69
|
+
const ADMIN_FILE = 'admin-credentials.hash';
|
|
70
|
+
const LOG_ARCHIVE_DIR = 'bypass-archive';
|
|
71
|
+
// Default password hash (password: "bypass123" - CHANGE THIS!)
|
|
72
|
+
const DEFAULT_PASSWORD_HASH = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'; // SHA-256 of "bypass123"
|
|
73
|
+
// Default admin password hash (password: "admin123" - CHANGE THIS IMMEDIATELY!)
|
|
74
|
+
const DEFAULT_ADMIN_PASSWORD_HASH = '240be518fabd2724ddb6f04eeb1da5967448d7e831c08c8fa822809f74c720a9'; // SHA-256 of "admin123"
|
|
75
|
+
// ── Password Management ─────────────────────────────────────────────────────
|
|
76
|
+
/**
|
|
77
|
+
* Hash a password using SHA-256
|
|
78
|
+
*/
|
|
79
|
+
function hashPassword(password) {
|
|
80
|
+
return crypto.createHash('sha256').update(password).digest('hex');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the stored password hash, or create default if not exists
|
|
84
|
+
*/
|
|
85
|
+
function getPasswordHash() {
|
|
86
|
+
const passwordPath = path.join(process.cwd(), BYPASS_DIR, PASSWORD_FILE);
|
|
87
|
+
if (!fs.existsSync(passwordPath)) {
|
|
88
|
+
// Create default password file
|
|
89
|
+
const dir = path.join(process.cwd(), BYPASS_DIR);
|
|
90
|
+
if (!fs.existsSync(dir)) {
|
|
91
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
fs.writeFileSync(passwordPath, DEFAULT_PASSWORD_HASH, 'utf-8');
|
|
94
|
+
console.warn('⚠️ Default bypass password created. Change it by running:');
|
|
95
|
+
console.warn(' npm run set-bypass-password');
|
|
96
|
+
return DEFAULT_PASSWORD_HASH;
|
|
97
|
+
}
|
|
98
|
+
return fs.readFileSync(passwordPath, 'utf-8').trim();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Verify a password against the stored hash
|
|
102
|
+
*/
|
|
103
|
+
function verifyBypassPassword(password) {
|
|
104
|
+
const storedHash = getPasswordHash();
|
|
105
|
+
const inputHash = hashPassword(password);
|
|
106
|
+
return inputHash === storedHash;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set a new bypass password
|
|
110
|
+
*/
|
|
111
|
+
function setBypassPassword(newPassword) {
|
|
112
|
+
const dir = path.join(process.cwd(), BYPASS_DIR);
|
|
113
|
+
if (!fs.existsSync(dir)) {
|
|
114
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
const passwordPath = path.join(dir, PASSWORD_FILE);
|
|
117
|
+
const hash = hashPassword(newPassword);
|
|
118
|
+
fs.writeFileSync(passwordPath, hash, 'utf-8');
|
|
119
|
+
console.log('✅ Bypass password updated successfully.');
|
|
120
|
+
console.log('⚠️ Keep this password secure and share only with authorized team members.');
|
|
121
|
+
}
|
|
122
|
+
// ── Admin Management ────────────────────────────────────────────────────────
|
|
123
|
+
/**
|
|
124
|
+
* Get the stored admin password hash, or create default if not exists
|
|
125
|
+
*/
|
|
126
|
+
function getAdminPasswordHash() {
|
|
127
|
+
const adminPath = path.join(process.cwd(), BYPASS_DIR, ADMIN_FILE);
|
|
128
|
+
if (!fs.existsSync(adminPath)) {
|
|
129
|
+
// Create default admin password file
|
|
130
|
+
const dir = path.join(process.cwd(), BYPASS_DIR);
|
|
131
|
+
if (!fs.existsSync(dir)) {
|
|
132
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
fs.writeFileSync(adminPath, DEFAULT_ADMIN_PASSWORD_HASH, 'utf-8');
|
|
135
|
+
console.warn('⚠️ Default admin password created. CHANGE IT IMMEDIATELY by running:');
|
|
136
|
+
console.warn(' npm run set-admin-password');
|
|
137
|
+
return DEFAULT_ADMIN_PASSWORD_HASH;
|
|
138
|
+
}
|
|
139
|
+
return fs.readFileSync(adminPath, 'utf-8').trim();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Verify admin password
|
|
143
|
+
*/
|
|
144
|
+
function verifyAdminPassword(password) {
|
|
145
|
+
const storedHash = getAdminPasswordHash();
|
|
146
|
+
const inputHash = hashPassword(password);
|
|
147
|
+
return inputHash === storedHash;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Set a new admin password
|
|
151
|
+
*/
|
|
152
|
+
function setAdminPassword(newPassword) {
|
|
153
|
+
const dir = path.join(process.cwd(), BYPASS_DIR);
|
|
154
|
+
if (!fs.existsSync(dir)) {
|
|
155
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
156
|
+
}
|
|
157
|
+
const adminPath = path.join(dir, ADMIN_FILE);
|
|
158
|
+
const hash = hashPassword(newPassword);
|
|
159
|
+
fs.writeFileSync(adminPath, hash, 'utf-8');
|
|
160
|
+
console.log('✅ Admin password updated successfully.');
|
|
161
|
+
console.log('🔐 Admin privileges: View and delete bypass logs');
|
|
162
|
+
console.log('⚠️ Keep this password highly secure!');
|
|
163
|
+
}
|
|
164
|
+
// ── Log Integrity ───────────────────────────────────────────────────────────
|
|
165
|
+
/**
|
|
166
|
+
* Calculate checksum for bypass log to detect tampering
|
|
167
|
+
*/
|
|
168
|
+
function calculateLogChecksum(log) {
|
|
169
|
+
// Create a stable string representation (excluding checksum itself)
|
|
170
|
+
const data = JSON.stringify({
|
|
171
|
+
entries: log.entries,
|
|
172
|
+
lastUpdated: log.lastUpdated,
|
|
173
|
+
});
|
|
174
|
+
return crypto.createHash('sha256').update(data).digest('hex');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Verify log integrity
|
|
178
|
+
*/
|
|
179
|
+
function verifyLogIntegrity(log) {
|
|
180
|
+
if (!log.checksum) {
|
|
181
|
+
// Legacy log without checksum - consider valid but warn
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
const expectedChecksum = calculateLogChecksum(log);
|
|
185
|
+
return expectedChecksum === log.checksum;
|
|
186
|
+
}
|
|
187
|
+
// ── Git Helpers ─────────────────────────────────────────────────────────────
|
|
188
|
+
function getGitAuthor() {
|
|
189
|
+
try {
|
|
190
|
+
const name = (0, child_process_1.execSync)('git config user.name', { encoding: 'utf-8' }).trim();
|
|
191
|
+
const email = (0, child_process_1.execSync)('git config user.email', { encoding: 'utf-8' }).trim();
|
|
192
|
+
return { name, email };
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return { name: 'Unknown', email: 'unknown@example.com' };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function getCurrentBranch() {
|
|
199
|
+
try {
|
|
200
|
+
return (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8' }).trim();
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return 'unknown';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function getStagedFiles() {
|
|
207
|
+
try {
|
|
208
|
+
const output = (0, child_process_1.execSync)('git diff --cached --name-only', { encoding: 'utf-8' }).trim();
|
|
209
|
+
return output ? output.split('\n') : [];
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// ── Bypass Log Management ───────────────────────────────────────────────────
|
|
216
|
+
/**
|
|
217
|
+
* Load the bypass log from disk
|
|
218
|
+
*/
|
|
219
|
+
function loadBypassLog() {
|
|
220
|
+
const logPath = path.join(process.cwd(), BYPASS_DIR, BYPASS_LOG_FILE);
|
|
221
|
+
if (!fs.existsSync(logPath)) {
|
|
222
|
+
return {
|
|
223
|
+
entries: [],
|
|
224
|
+
lastUpdated: new Date().toISOString(),
|
|
225
|
+
immutable: true,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const content = fs.readFileSync(logPath, 'utf-8');
|
|
230
|
+
const log = JSON.parse(content);
|
|
231
|
+
// Ensure immutable flag exists (for backward compatibility)
|
|
232
|
+
if (log.immutable === undefined) {
|
|
233
|
+
log.immutable = true;
|
|
234
|
+
}
|
|
235
|
+
// Verify integrity
|
|
236
|
+
if (!verifyLogIntegrity(log)) {
|
|
237
|
+
console.warn('⚠️ WARNING: Bypass log integrity check failed!');
|
|
238
|
+
console.warn(' The log may have been tampered with.');
|
|
239
|
+
console.warn(' Location: ' + logPath);
|
|
240
|
+
// Archive the potentially tampered log
|
|
241
|
+
archiveTamperedLog(log);
|
|
242
|
+
}
|
|
243
|
+
return log;
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
console.error('❌ Error loading bypass log:', err);
|
|
247
|
+
return {
|
|
248
|
+
entries: [],
|
|
249
|
+
lastUpdated: new Date().toISOString(),
|
|
250
|
+
immutable: true,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Save the bypass log to disk
|
|
256
|
+
*/
|
|
257
|
+
function saveBypassLog(log) {
|
|
258
|
+
const dir = path.join(process.cwd(), BYPASS_DIR);
|
|
259
|
+
if (!fs.existsSync(dir)) {
|
|
260
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
261
|
+
}
|
|
262
|
+
const logPath = path.join(dir, BYPASS_LOG_FILE);
|
|
263
|
+
log.lastUpdated = new Date().toISOString();
|
|
264
|
+
log.immutable = true; // Always mark as immutable
|
|
265
|
+
// Calculate and store checksum for integrity verification
|
|
266
|
+
log.checksum = calculateLogChecksum(log);
|
|
267
|
+
try {
|
|
268
|
+
// Temporarily make file writable if it exists and is read-only.
|
|
269
|
+
// This allows the log to remain effectively "read-only" to users while
|
|
270
|
+
// still letting Code Guardian append new entries.
|
|
271
|
+
if (fs.existsSync(logPath)) {
|
|
272
|
+
try {
|
|
273
|
+
fs.chmodSync(logPath, 0o644); // rw-r--r--
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// If chmod fails (e.g., filesystem does not support it), continue and
|
|
277
|
+
// rely on the write below to surface any real permission problems.
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Write the log file
|
|
281
|
+
fs.writeFileSync(logPath, JSON.stringify(log, null, 2), 'utf-8');
|
|
282
|
+
// After a successful write, set file permissions back to read-only
|
|
283
|
+
// (444 = r--r--r--) to discourage manual edits.
|
|
284
|
+
try {
|
|
285
|
+
fs.chmodSync(logPath, 0o444);
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
// Non-fatal: if we cannot change permissions, keep going.
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
// If we cannot write the log (for example, the file was made truly
|
|
293
|
+
// immutable with OS-level flags), do NOT block the bypass or commit.
|
|
294
|
+
// Instead, warn and continue so the hook stays usable.
|
|
295
|
+
console.warn('⚠️ Code Guardian: Failed to update bypass log file.');
|
|
296
|
+
console.warn(' Reason: ' + (err && err.message ? err.message : String(err)));
|
|
297
|
+
console.warn(' Tip: Ensure `.code-guardian/bypass-log.json` is writable by git user, '
|
|
298
|
+
+ 'or remove OS-level immutability flags if you want new bypasses to be recorded.');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Archive a potentially tampered log file
|
|
303
|
+
*/
|
|
304
|
+
function archiveTamperedLog(log) {
|
|
305
|
+
try {
|
|
306
|
+
const archiveDir = path.join(process.cwd(), BYPASS_DIR, LOG_ARCHIVE_DIR);
|
|
307
|
+
if (!fs.existsSync(archiveDir)) {
|
|
308
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
309
|
+
}
|
|
310
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
311
|
+
const archivePath = path.join(archiveDir, `tampered-log-${timestamp}.json`);
|
|
312
|
+
fs.writeFileSync(archivePath, JSON.stringify(log, null, 2), 'utf-8');
|
|
313
|
+
console.log(` Archived to: ${archivePath}`);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
console.error(' Failed to archive tampered log:', err);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Record a bypass attempt in the audit log
|
|
321
|
+
*/
|
|
322
|
+
function recordBypass(reason, commitMessage, method) {
|
|
323
|
+
const author = getGitAuthor();
|
|
324
|
+
const branch = getCurrentBranch();
|
|
325
|
+
const files = getStagedFiles();
|
|
326
|
+
const entry = {
|
|
327
|
+
id: crypto.randomUUID(),
|
|
328
|
+
author: author.name,
|
|
329
|
+
email: author.email,
|
|
330
|
+
timestamp: new Date().toISOString(),
|
|
331
|
+
reason,
|
|
332
|
+
commitMessage,
|
|
333
|
+
branch,
|
|
334
|
+
files,
|
|
335
|
+
method,
|
|
336
|
+
};
|
|
337
|
+
const log = loadBypassLog();
|
|
338
|
+
log.entries.push(entry);
|
|
339
|
+
saveBypassLog(log);
|
|
340
|
+
console.log('');
|
|
341
|
+
console.log('📝 Bypass recorded in audit log:');
|
|
342
|
+
console.log(` Author: ${author.name} <${author.email}>`);
|
|
343
|
+
console.log(` Reason: ${reason}`);
|
|
344
|
+
console.log(` Method: ${method}`);
|
|
345
|
+
console.log(` Files: ${files.length} file(s)`);
|
|
346
|
+
console.log('');
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Update a bypass entry with the commit hash after commit succeeds
|
|
350
|
+
*/
|
|
351
|
+
function updateBypassWithCommitHash(entryId, commitHash) {
|
|
352
|
+
const log = loadBypassLog();
|
|
353
|
+
const entry = log.entries.find((e) => e.id === entryId);
|
|
354
|
+
if (entry) {
|
|
355
|
+
entry.commitHash = commitHash;
|
|
356
|
+
saveBypassLog(log);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Get all bypass entries for a specific author
|
|
361
|
+
*/
|
|
362
|
+
function getBypassesByAuthor(authorEmail) {
|
|
363
|
+
const log = loadBypassLog();
|
|
364
|
+
return log.entries.filter((e) => e.email === authorEmail);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Get recent bypass entries (last N days)
|
|
368
|
+
*/
|
|
369
|
+
function getRecentBypasses(days = 30) {
|
|
370
|
+
const log = loadBypassLog();
|
|
371
|
+
const cutoff = new Date();
|
|
372
|
+
cutoff.setDate(cutoff.getDate() - days);
|
|
373
|
+
return log.entries.filter((e) => new Date(e.timestamp) >= cutoff);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Delete bypass entries (ADMIN ONLY)
|
|
377
|
+
* @param entryIds - Array of entry IDs to delete
|
|
378
|
+
* @param adminPassword - Admin password for verification
|
|
379
|
+
* @returns Success status and message
|
|
380
|
+
*/
|
|
381
|
+
function deleteBypassEntries(entryIds, adminPassword) {
|
|
382
|
+
// Verify admin password
|
|
383
|
+
if (!verifyAdminPassword(adminPassword)) {
|
|
384
|
+
return {
|
|
385
|
+
success: false,
|
|
386
|
+
message: '❌ Invalid admin password. Access denied.',
|
|
387
|
+
deletedCount: 0,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const logPath = path.join(process.cwd(), BYPASS_DIR, BYPASS_LOG_FILE);
|
|
391
|
+
// Remove read-only protection temporarily
|
|
392
|
+
try {
|
|
393
|
+
fs.chmodSync(logPath, 0o644);
|
|
394
|
+
}
|
|
395
|
+
catch (err) {
|
|
396
|
+
// Ignore if chmod fails
|
|
397
|
+
}
|
|
398
|
+
const log = loadBypassLog();
|
|
399
|
+
const initialCount = log.entries.length;
|
|
400
|
+
// Archive deleted entries before removal
|
|
401
|
+
const deletedEntries = log.entries.filter((e) => entryIds.includes(e.id));
|
|
402
|
+
if (deletedEntries.length > 0) {
|
|
403
|
+
archiveDeletedEntries(deletedEntries, adminPassword);
|
|
404
|
+
}
|
|
405
|
+
// Remove entries
|
|
406
|
+
log.entries = log.entries.filter((e) => !entryIds.includes(e.id));
|
|
407
|
+
const deletedCount = initialCount - log.entries.length;
|
|
408
|
+
if (deletedCount === 0) {
|
|
409
|
+
return {
|
|
410
|
+
success: false,
|
|
411
|
+
message: '⚠️ No matching entries found to delete.',
|
|
412
|
+
deletedCount: 0,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
// Save updated log
|
|
416
|
+
saveBypassLog(log);
|
|
417
|
+
return {
|
|
418
|
+
success: true,
|
|
419
|
+
message: `✅ Deleted ${deletedCount} bypass entry(ies) successfully.`,
|
|
420
|
+
deletedCount,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Archive deleted entries for audit trail
|
|
425
|
+
*/
|
|
426
|
+
function archiveDeletedEntries(entries, adminPassword) {
|
|
427
|
+
try {
|
|
428
|
+
const archiveDir = path.join(process.cwd(), BYPASS_DIR, LOG_ARCHIVE_DIR);
|
|
429
|
+
if (!fs.existsSync(archiveDir)) {
|
|
430
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
431
|
+
}
|
|
432
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
433
|
+
const archivePath = path.join(archiveDir, `deleted-entries-${timestamp}.json`);
|
|
434
|
+
const archiveData = {
|
|
435
|
+
deletedAt: new Date().toISOString(),
|
|
436
|
+
deletedBy: 'admin',
|
|
437
|
+
adminPasswordHash: hashPassword(adminPassword), // For audit purposes
|
|
438
|
+
entries,
|
|
439
|
+
};
|
|
440
|
+
fs.writeFileSync(archivePath, JSON.stringify(archiveData, null, 2), 'utf-8');
|
|
441
|
+
console.log(`📦 Deleted entries archived to: ${archivePath}`);
|
|
442
|
+
}
|
|
443
|
+
catch (err) {
|
|
444
|
+
console.error('⚠️ Warning: Failed to archive deleted entries:', err);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get all archived logs (deleted and tampered)
|
|
449
|
+
*/
|
|
450
|
+
function getArchivedLogs() {
|
|
451
|
+
const archiveDir = path.join(process.cwd(), BYPASS_DIR, LOG_ARCHIVE_DIR);
|
|
452
|
+
if (!fs.existsSync(archiveDir)) {
|
|
453
|
+
return { deleted: [], tampered: [] };
|
|
454
|
+
}
|
|
455
|
+
const files = fs.readdirSync(archiveDir);
|
|
456
|
+
return {
|
|
457
|
+
deleted: files.filter((f) => f.startsWith('deleted-entries-')),
|
|
458
|
+
tampered: files.filter((f) => f.startsWith('tampered-log-')),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Generate a bypass audit report
|
|
463
|
+
*/
|
|
464
|
+
function generateBypassReport() {
|
|
465
|
+
const log = loadBypassLog();
|
|
466
|
+
if (log.entries.length === 0) {
|
|
467
|
+
return '📊 Bypass Audit Report\n\nNo bypass entries found.';
|
|
468
|
+
}
|
|
469
|
+
let report = '📊 Bypass Audit Report\n';
|
|
470
|
+
report += '═'.repeat(60) + '\n\n';
|
|
471
|
+
report += `Total bypasses: ${log.entries.length}\n`;
|
|
472
|
+
report += `Last updated: ${log.lastUpdated}\n\n`;
|
|
473
|
+
// Group by author
|
|
474
|
+
const byAuthor = new Map();
|
|
475
|
+
for (const entry of log.entries) {
|
|
476
|
+
const key = `${entry.author} <${entry.email}>`;
|
|
477
|
+
const existing = byAuthor.get(key) || [];
|
|
478
|
+
existing.push(entry);
|
|
479
|
+
byAuthor.set(key, existing);
|
|
480
|
+
}
|
|
481
|
+
report += '📈 Bypasses by Author:\n';
|
|
482
|
+
report += '─'.repeat(60) + '\n';
|
|
483
|
+
for (const [author, entries] of byAuthor) {
|
|
484
|
+
report += `\n${author}: ${entries.length} bypass(es)\n`;
|
|
485
|
+
for (const entry of entries.slice(-5)) {
|
|
486
|
+
// Show last 5
|
|
487
|
+
const date = new Date(entry.timestamp).toLocaleString();
|
|
488
|
+
report += ` • ${date} - ${entry.reason}\n`;
|
|
489
|
+
report += ` Branch: ${entry.branch}, Files: ${entry.files.length}\n`;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
report += '\n' + '═'.repeat(60) + '\n';
|
|
493
|
+
report += `\nFull log: ${path.join(BYPASS_DIR, BYPASS_LOG_FILE)}\n`;
|
|
494
|
+
return report;
|
|
495
|
+
}
|
|
496
|
+
//# sourceMappingURL=bypass-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bypass-manager.js","sourceRoot":"","sources":["../../../scripts/utils/bypass-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FH,oDAIC;AAKD,8CAYC;AA6BD,kDAIC;AAKD,4CAaC;AAmLD,oCAgCC;AAKD,gEAQC;AAKD,kDAGC;AAKD,8CAMC;AAQD,kDAmDC;AAgCD,0CAaC;AAKD,oDAsCC;AAtiBD,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAyC;AACzC,+CAAiC;AAsCjC,+EAA+E;AAE/E,MAAM,UAAU,GAAG,gBAAgB,CAAC;AACpC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAC1C,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAC7C,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAC5C,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAEzC,+DAA+D;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AC;QACrB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,IAAI,0BAA0B,CAAC;IACrC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAChC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,MAAM,KAAK,OAAO,CAAC,MAAM,eAAe,CAAC;QAExD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,cAAc;YACd,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,cAAc,EAAE,CAAC;YACxD,MAAM,IAAI,OAAO,IAAI,MAAM,KAAK,CAAC,MAAM,IAAI,CAAC;YAC5C,MAAM,IAAI,eAAe,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,MAAM,IAAI,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACvC,MAAM,IAAI,eAAe,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,CAAC;IAEpE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* code-analyzer.ts — Automatic documentation from TypeScript/React code
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Analyzes TypeScript/React components and extracts:
|
|
7
|
+
* - Component props and their types
|
|
8
|
+
* - JSDoc comments
|
|
9
|
+
* - Default values
|
|
10
|
+
* - Event handlers
|
|
11
|
+
*/
|
|
12
|
+
export interface PropInfo {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
required: boolean;
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ComponentInfo {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
props: PropInfo[];
|
|
23
|
+
filePath: string;
|
|
24
|
+
isReactComponent: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Analyze a TypeScript/React component file
|
|
28
|
+
*/
|
|
29
|
+
export declare function analyzeComponent(filePath: string): ComponentInfo | null;
|
|
30
|
+
/**
|
|
31
|
+
* Search for component files in directory
|
|
32
|
+
*/
|
|
33
|
+
export declare function findComponentFile(componentName: string, searchDir?: string): string | null;
|
|
34
|
+
//# sourceMappingURL=code-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-analyzer.d.ts","sourceRoot":"","sources":["../../../scripts/utils/code-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CA8BvE;AAkPD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CA8BzG"}
|