web3guard-cli 1.0.0 → 1.1.1

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 (3) hide show
  1. package/dist/api.js +8 -2
  2. package/dist/cli.js +71 -12
  3. package/package.json +1 -1
package/dist/api.js CHANGED
@@ -56,7 +56,13 @@ async function scanContract(filePath) {
56
56
  throw new Error(`File not found: ${absolutePath}`);
57
57
  }
58
58
  const sourceCode = fs.readFileSync(absolutePath, 'utf8');
59
- const ecosystem = absolutePath.endsWith('.sol') ? 'Solidity' : 'Rust';
59
+ let ecosystem = 'Rust';
60
+ if (absolutePath.endsWith('.sol'))
61
+ ecosystem = 'Solidity';
62
+ else if (absolutePath.endsWith('.move'))
63
+ ecosystem = 'Move';
64
+ else if (absolutePath.endsWith('.cairo'))
65
+ ecosystem = 'Cairo';
60
66
  const response = await client.post('/scan', {
61
67
  source_code: sourceCode,
62
68
  ecosystem: ecosystem,
@@ -79,7 +85,7 @@ function findContracts(dir) {
79
85
  }
80
86
  }
81
87
  else {
82
- if (filePath.endsWith('.rs') || filePath.endsWith('.sol')) {
88
+ if (filePath.endsWith('.rs') || filePath.endsWith('.sol') || filePath.endsWith('.move') || filePath.endsWith('.cairo')) {
83
89
  results.push(filePath);
84
90
  }
85
91
  }
package/dist/cli.js CHANGED
@@ -41,6 +41,8 @@ const commander_1 = require("commander");
41
41
  const chalk_1 = __importDefault(require("chalk"));
42
42
  const ora_1 = __importDefault(require("ora"));
43
43
  const fs = __importStar(require("fs"));
44
+ const path = __importStar(require("path"));
45
+ const child_process_1 = require("child_process");
44
46
  const api_1 = require("./api");
45
47
  const config_1 = require("./config");
46
48
  const program = new commander_1.Command();
@@ -49,27 +51,45 @@ program
49
51
  .description('CLI for Web3 Guard - Intelligent Multi-Chain Auditing & Security Oracle')
50
52
  .version('1.0.0');
51
53
  program
52
- .command('scan <path>')
54
+ .command('scan [path]')
53
55
  .description('Scan a local smart contract file or directory for vulnerabilities')
54
56
  .option('--json', 'Output result in JSON format')
55
57
  .option('--out <file>', 'Save output to a file (JSON format)')
58
+ .option('--staged', 'Scan only staged files in Git')
59
+ .option('--strict', 'Exit with code 1 if vulnerabilities are found')
56
60
  .action(async (scanPath, options) => {
57
61
  let filesToScan = [];
58
- try {
59
- const stat = fs.statSync(scanPath);
60
- if (stat.isDirectory()) {
61
- filesToScan = (0, api_1.findContracts)(scanPath);
62
+ if (options.staged) {
63
+ try {
64
+ const output = (0, child_process_1.execSync)('git diff --cached --name-only --diff-filter=ACM').toString();
65
+ filesToScan = output.split('\n').filter(f => f.endsWith('.rs') || f.endsWith('.sol') || f.endsWith('.move') || f.endsWith('.cairo')).map(f => f.trim()).filter(f => f.length > 0);
62
66
  }
63
- else {
64
- filesToScan = [scanPath];
67
+ catch (e) {
68
+ console.error(chalk_1.default.red('Error running git command. Are you in a git repository?'));
69
+ process.exit(1);
65
70
  }
66
71
  }
67
- catch (e) {
68
- console.error(chalk_1.default.red(`Error accessing path: ${e.message}`));
69
- return;
72
+ else {
73
+ if (!scanPath) {
74
+ console.error(chalk_1.default.red('Error: path is required if --staged is not used.'));
75
+ process.exit(1);
76
+ }
77
+ try {
78
+ const stat = fs.statSync(scanPath);
79
+ if (stat.isDirectory()) {
80
+ filesToScan = (0, api_1.findContracts)(scanPath);
81
+ }
82
+ else {
83
+ filesToScan = [scanPath];
84
+ }
85
+ }
86
+ catch (e) {
87
+ console.error(chalk_1.default.red(`Error accessing path: ${e.message}`));
88
+ return;
89
+ }
70
90
  }
71
91
  if (filesToScan.length === 0) {
72
- console.log(chalk_1.default.yellow('No .rs or .sol files found to scan.'));
92
+ console.log(chalk_1.default.yellow('No .rs, .sol, .move, or .cairo files found to scan.'));
73
93
  return;
74
94
  }
75
95
  let allResults = [];
@@ -102,7 +122,13 @@ program
102
122
  allResults.forEach(({ file, result, error }) => {
103
123
  console.log(`\n${chalk_1.default.cyan.bold(file)}:`);
104
124
  if (error) {
105
- console.log(chalk_1.default.red(`Error: ${error}`));
125
+ if (String(error).includes("429") || String(error).toLowerCase().includes("exhausted")) {
126
+ console.log(chalk_1.default.bgRed.white.bold(' ⏳ AI SCANNER RATE LIMITED '));
127
+ console.log(chalk_1.default.yellow('The backend is under heavy load. Exponential backoff retry limit reached. Please try again in a few seconds.'));
128
+ }
129
+ else {
130
+ console.log(chalk_1.default.red(`Error: ${error}`));
131
+ }
106
132
  return;
107
133
  }
108
134
  if (result.vulnerabilities && result.vulnerabilities.length > 0) {
@@ -126,6 +152,12 @@ program
126
152
  }
127
153
  });
128
154
  }
155
+ if (options.strict) {
156
+ const hasVulnerabilities = allResults.some(r => r.result && r.result.vulnerabilities && r.result.vulnerabilities.length > 0);
157
+ if (hasVulnerabilities) {
158
+ process.exit(1);
159
+ }
160
+ }
129
161
  });
130
162
  program
131
163
  .command('score <address>')
@@ -181,4 +213,31 @@ program
181
213
  console.log(chalk_1.default.yellow('Usage: web3guard config set api-url <url>'));
182
214
  }
183
215
  });
216
+ program
217
+ .command('init-hook')
218
+ .description('Initialize a Git pre-commit hook for Web3 Guard')
219
+ .action(() => {
220
+ const hookDir = path.join(process.cwd(), '.git', 'hooks');
221
+ const hookPath = path.join(hookDir, 'pre-commit');
222
+ if (!fs.existsSync(hookDir)) {
223
+ console.error(chalk_1.default.red('Error: .git/hooks directory not found. Are you in a Git repository?'));
224
+ process.exit(1);
225
+ }
226
+ const hookContent = `#!/bin/sh
227
+ echo "🛡️ Running Web3 Guard Pre-Commit Scan..."
228
+ npx web3guard-cli scan --staged --strict
229
+ if [ $? -ne 0 ]; then
230
+ echo "❌ Security vulnerabilities found! Commit rejected."
231
+ exit 1
232
+ fi
233
+ `;
234
+ try {
235
+ fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
236
+ console.log(chalk_1.default.green('✅ Successfully installed Web3 Guard pre-commit hook at .git/hooks/pre-commit'));
237
+ }
238
+ catch (e) {
239
+ console.error(chalk_1.default.red(`Error writing hook file: ${e.message}`));
240
+ process.exit(1);
241
+ }
242
+ });
184
243
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web3guard-cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Web3 Guard CLI and MCP Server",
5
5
  "main": "dist/index.js",
6
6
  "files": [