wide-cli 0.5.1611261726 → 0.6.191126

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 (134) hide show
  1. package/data/osv-bundle.json +1 -1
  2. package/data/rules.json +1 -1
  3. package/dist/agent/index.d.ts +25 -3
  4. package/dist/agent/index.d.ts.map +1 -1
  5. package/dist/agent/index.js +117 -18
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/completion.js +5 -5
  8. package/dist/completion.js.map +1 -1
  9. package/dist/config/index.d.ts +4 -1
  10. package/dist/config/index.d.ts.map +1 -1
  11. package/dist/config/index.js +9 -2
  12. package/dist/config/index.js.map +1 -1
  13. package/dist/fix.d.ts +25 -0
  14. package/dist/fix.d.ts.map +1 -0
  15. package/dist/fix.js +197 -0
  16. package/dist/fix.js.map +1 -0
  17. package/dist/hook.d.ts +31 -0
  18. package/dist/hook.d.ts.map +1 -0
  19. package/dist/hook.js +152 -0
  20. package/dist/hook.js.map +1 -0
  21. package/dist/index.js +168 -5
  22. package/dist/index.js.map +1 -1
  23. package/dist/providers/antigravity.d.ts +46 -0
  24. package/dist/providers/antigravity.d.ts.map +1 -0
  25. package/dist/providers/antigravity.js +496 -0
  26. package/dist/providers/antigravity.js.map +1 -0
  27. package/dist/providers/claude-code.d.ts +60 -0
  28. package/dist/providers/claude-code.d.ts.map +1 -0
  29. package/dist/providers/claude-code.js +973 -0
  30. package/dist/providers/claude-code.js.map +1 -0
  31. package/dist/providers/codex.d.ts +52 -0
  32. package/dist/providers/codex.d.ts.map +1 -0
  33. package/dist/providers/codex.js +742 -0
  34. package/dist/providers/codex.js.map +1 -0
  35. package/dist/providers/index.d.ts.map +1 -1
  36. package/dist/providers/index.js +33 -1
  37. package/dist/providers/index.js.map +1 -1
  38. package/dist/repl/commands.d.ts.map +1 -1
  39. package/dist/repl/commands.js +53 -3
  40. package/dist/repl/commands.js.map +1 -1
  41. package/dist/repl/index.d.ts +3 -0
  42. package/dist/repl/index.d.ts.map +1 -1
  43. package/dist/repl/index.js +11 -6
  44. package/dist/repl/index.js.map +1 -1
  45. package/dist/repl/setup.d.ts.map +1 -1
  46. package/dist/repl/setup.js +16 -4
  47. package/dist/repl/setup.js.map +1 -1
  48. package/dist/security/crawler.d.ts +90 -0
  49. package/dist/security/crawler.d.ts.map +1 -0
  50. package/dist/security/crawler.js +622 -0
  51. package/dist/security/crawler.js.map +1 -0
  52. package/dist/security/fuzzer.d.ts +1 -0
  53. package/dist/security/fuzzer.d.ts.map +1 -1
  54. package/dist/security/fuzzer.js +25 -1
  55. package/dist/security/fuzzer.js.map +1 -1
  56. package/dist/security/inspect/evasion-decode.d.ts +41 -0
  57. package/dist/security/inspect/evasion-decode.d.ts.map +1 -0
  58. package/dist/security/inspect/evasion-decode.js +316 -0
  59. package/dist/security/inspect/evasion-decode.js.map +1 -0
  60. package/dist/security/inspect/http-conformance.d.ts +51 -0
  61. package/dist/security/inspect/http-conformance.d.ts.map +1 -0
  62. package/dist/security/inspect/http-conformance.js +389 -0
  63. package/dist/security/inspect/http-conformance.js.map +1 -0
  64. package/dist/security/inspect/lexical-sqli.d.ts +7 -0
  65. package/dist/security/inspect/lexical-sqli.d.ts.map +1 -0
  66. package/dist/security/inspect/lexical-sqli.js +986 -0
  67. package/dist/security/inspect/lexical-sqli.js.map +1 -0
  68. package/dist/security/inspect/lexical-xss.d.ts +10 -0
  69. package/dist/security/inspect/lexical-xss.d.ts.map +1 -0
  70. package/dist/security/inspect/lexical-xss.js +654 -0
  71. package/dist/security/inspect/lexical-xss.js.map +1 -0
  72. package/dist/security/inspect/libinjection-tables.d.ts +6 -0
  73. package/dist/security/inspect/libinjection-tables.d.ts.map +1 -0
  74. package/dist/security/inspect/libinjection-tables.js +6 -0
  75. package/dist/security/inspect/libinjection-tables.js.map +1 -0
  76. package/dist/security/inspect/safe-pattern.d.ts +62 -0
  77. package/dist/security/inspect/safe-pattern.d.ts.map +1 -0
  78. package/dist/security/inspect/safe-pattern.js +640 -0
  79. package/dist/security/inspect/safe-pattern.js.map +1 -0
  80. package/dist/security/inspect/score-policy.d.ts +82 -0
  81. package/dist/security/inspect/score-policy.d.ts.map +1 -0
  82. package/dist/security/inspect/score-policy.js +241 -0
  83. package/dist/security/inspect/score-policy.js.map +1 -0
  84. package/dist/security/inspect.d.ts +7 -0
  85. package/dist/security/inspect.d.ts.map +1 -0
  86. package/dist/security/inspect.js +7 -0
  87. package/dist/security/inspect.js.map +1 -0
  88. package/dist/security/loader.d.ts.map +1 -1
  89. package/dist/security/loader.js +12 -2
  90. package/dist/security/loader.js.map +1 -1
  91. package/dist/security/payloads.d.ts.map +1 -1
  92. package/dist/security/payloads.js +19 -0
  93. package/dist/security/payloads.js.map +1 -1
  94. package/dist/security/scanner.d.ts +2 -0
  95. package/dist/security/scanner.d.ts.map +1 -1
  96. package/dist/security/scanner.js +31 -26
  97. package/dist/security/scanner.js.map +1 -1
  98. package/dist/tools/article.d.ts +18 -0
  99. package/dist/tools/article.d.ts.map +1 -0
  100. package/dist/tools/article.js +193 -0
  101. package/dist/tools/article.js.map +1 -0
  102. package/dist/tools/browser.d.ts +8 -2
  103. package/dist/tools/browser.d.ts.map +1 -1
  104. package/dist/tools/browser.js +76 -10
  105. package/dist/tools/browser.js.map +1 -1
  106. package/dist/tools/docx.d.ts +11 -0
  107. package/dist/tools/docx.d.ts.map +1 -0
  108. package/dist/tools/docx.js +149 -0
  109. package/dist/tools/docx.js.map +1 -0
  110. package/dist/tools/fs.d.ts +2 -0
  111. package/dist/tools/fs.d.ts.map +1 -1
  112. package/dist/tools/fs.js +96 -7
  113. package/dist/tools/fs.js.map +1 -1
  114. package/dist/tools/http.d.ts.map +1 -1
  115. package/dist/tools/http.js +125 -48
  116. package/dist/tools/http.js.map +1 -1
  117. package/dist/tools/index.d.ts +21 -2
  118. package/dist/tools/index.d.ts.map +1 -1
  119. package/dist/tools/index.js +137 -14
  120. package/dist/tools/index.js.map +1 -1
  121. package/dist/tools/resilience.d.ts +78 -0
  122. package/dist/tools/resilience.d.ts.map +1 -0
  123. package/dist/tools/resilience.js +211 -0
  124. package/dist/tools/resilience.js.map +1 -0
  125. package/dist/tools/security.d.ts +2 -0
  126. package/dist/tools/security.d.ts.map +1 -1
  127. package/dist/tools/security.js +79 -1
  128. package/dist/tools/security.js.map +1 -1
  129. package/dist/tools/types.d.ts +4 -0
  130. package/dist/tools/types.d.ts.map +1 -1
  131. package/dist/ui/banner.d.ts.map +1 -1
  132. package/dist/ui/banner.js +2 -2
  133. package/dist/ui/banner.js.map +1 -1
  134. package/package.json +1 -1
package/dist/fix.js ADDED
@@ -0,0 +1,197 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { createInterface } from "node:readline";
4
+ import pc from "picocolors";
5
+ import { createOptionalProvider } from "./providers/index.js";
6
+ import { SecurityScanner } from "./security/scanner.js";
7
+ import { formatColoredDiffPreview } from "./ui/diff.js";
8
+ export function alignPatchIndentation(patch, originalSnippet) {
9
+ if (!patch || !originalSnippet)
10
+ return patch;
11
+ const indentMatch = originalSnippet.match(/^([ \t]+)/);
12
+ if (!indentMatch)
13
+ return patch;
14
+ const indent = indentMatch[1];
15
+ const lines = patch.split("\n");
16
+ if (lines.length > 0 && !lines[0].startsWith(" ") && !lines[0].startsWith("\t")) {
17
+ return lines.map((line) => (line.trim().length > 0 ? `${indent}${line}` : line)).join("\n");
18
+ }
19
+ return patch;
20
+ }
21
+ export function extractCodeFromFence(raw) {
22
+ const match = raw.match(/```(?:[a-zA-Z0-9_-]+)?\s*([\s\S]*?)```/);
23
+ if (match)
24
+ return match[1].trim();
25
+ return raw.trim();
26
+ }
27
+ export function createQuickFixSuppression(finding, originalLine) {
28
+ const ext = finding.file.split(".").pop()?.toLowerCase() || "";
29
+ const commentChar = ["py", "rb", "sh", "bash", "yaml", "yml", "dockerfile"].includes(ext) ? "#" : "//";
30
+ const indentMatch = originalLine.match(/^([ \t]*)/);
31
+ const indent = indentMatch ? indentMatch[1] : "";
32
+ const ruleId = finding.ruleId || finding.id;
33
+ return `${indent}${commentChar} wide-ignore ${ruleId}\n${originalLine}`;
34
+ }
35
+ async function promptUser(question) {
36
+ const rl = createInterface({
37
+ input: process.stdin,
38
+ output: process.stdout
39
+ });
40
+ return new Promise((resolvePrompt) => {
41
+ rl.question(question, (answer) => {
42
+ rl.close();
43
+ resolvePrompt(answer.trim().toLowerCase());
44
+ });
45
+ });
46
+ }
47
+ export async function runInteractiveFix(opts = {}) {
48
+ const cwd = opts.cwd || process.cwd();
49
+ const targetPath = opts.path || ".";
50
+ const scanner = new SecurityScanner(cwd, opts.rulesPath);
51
+ const filter = (opts.severity || "HIGH");
52
+ console.log(pc.cyan(`Scanning for fixable vulnerabilities in ${targetPath} (severity >= ${filter})...`));
53
+ const scanResult = await scanner.scanPath(targetPath, filter, { sca: false });
54
+ const codeFindings = scanResult.findings.filter((f) => f.source !== "sca" && f.line > 0);
55
+ if (codeFindings.length === 0) {
56
+ console.log(pc.green(`No fixable code vulnerabilities found at severity threshold ${filter}.`));
57
+ return { totalFindings: 0, fixed: 0, skipped: 0, filesModified: [] };
58
+ }
59
+ console.log(pc.bold(`Found ${codeFindings.length} vulnerability candidate(s) for interactive remediation.\n`));
60
+ let provider = null;
61
+ if (!opts.suppressOnly && (opts.ai || opts.provider || opts.model)) {
62
+ try {
63
+ provider = createOptionalProvider(opts.provider, opts.model);
64
+ }
65
+ catch { }
66
+ }
67
+ const byFile = new Map();
68
+ for (const f of codeFindings) {
69
+ const list = byFile.get(f.file) || [];
70
+ list.push(f);
71
+ byFile.set(f.file, list);
72
+ }
73
+ let autoApproveAll = Boolean(opts.yes);
74
+ let totalFixed = 0;
75
+ let totalSkipped = 0;
76
+ const modifiedFilesSet = new Set();
77
+ for (const [relFile, fileFindings] of byFile.entries()) {
78
+ const fullPath = resolve(cwd, relFile);
79
+ if (!existsSync(fullPath))
80
+ continue;
81
+ fileFindings.sort((a, b) => b.line - a.line);
82
+ for (const finding of fileFindings) {
83
+ let currentContent = "";
84
+ try {
85
+ currentContent = readFileSync(fullPath, "utf8");
86
+ }
87
+ catch {
88
+ continue;
89
+ }
90
+ const lines = currentContent.split("\n");
91
+ const lineIdx = finding.line - 1;
92
+ if (lineIdx < 0 || lineIdx >= lines.length) {
93
+ totalSkipped++;
94
+ continue;
95
+ }
96
+ const originalLine = lines[lineIdx];
97
+ const endLineIdx = finding.endLine && finding.endLine > finding.line ? finding.endLine - 1 : lineIdx;
98
+ const originalBlock = lines.slice(lineIdx, endLineIdx + 1).join("\n");
99
+ let replacementBlock = "";
100
+ let patchSource = "quick-fix";
101
+ if (provider && !opts.suppressOnly) {
102
+ try {
103
+ const windowStart = Math.max(0, lineIdx - 8);
104
+ const windowEnd = Math.min(lines.length, endLineIdx + 8);
105
+ const snippetWithContext = lines.slice(windowStart, windowEnd).join("\n");
106
+ const prompt = [
107
+ "You are an automated security remediation tool. Provide ONLY the corrected code replacement.",
108
+ `Vulnerability: ${finding.message} (${finding.ruleId || finding.id})`,
109
+ `Remediation suggestion: ${finding.remediation}`,
110
+ "Surrounding Context:",
111
+ snippetWithContext,
112
+ "Target vulnerable block to replace:",
113
+ originalBlock,
114
+ "Reply with ONLY the replacement code enclosed in a ```code fence. Do not explain."
115
+ ].join("\n\n");
116
+ const response = await provider.chatStream([{ role: "user", content: prompt }], [], () => { });
117
+ const rawText = response.content || "";
118
+ const extracted = extractCodeFromFence(rawText);
119
+ if (extracted && extracted !== originalBlock) {
120
+ replacementBlock = alignPatchIndentation(extracted, originalLine);
121
+ patchSource = "ai-remediation";
122
+ }
123
+ }
124
+ catch { }
125
+ }
126
+ if (!replacementBlock) {
127
+ replacementBlock = createQuickFixSuppression(finding, originalLine);
128
+ patchSource = "quick-fix suppression";
129
+ }
130
+ const patchedLines = [
131
+ ...lines.slice(0, lineIdx),
132
+ ...replacementBlock.split("\n"),
133
+ ...lines.slice(endLineIdx + 1)
134
+ ];
135
+ const patchedContent = patchedLines.join("\n");
136
+ if (patchedContent === currentContent) {
137
+ totalSkipped++;
138
+ continue;
139
+ }
140
+ const diffPreview = formatColoredDiffPreview(relFile, currentContent, patchedContent);
141
+ console.log(pc.bold(`\n--------------------------------------------------------------------------------\n` +
142
+ `${pc.cyan("[CANDIDATE]")} ${pc.bold(relFile)}:${finding.line} ` +
143
+ `[${finding.severity}] ${finding.message} (${patchSource})`));
144
+ console.log(diffPreview.preview);
145
+ let decision = "y";
146
+ if (!autoApproveAll) {
147
+ if (opts.askFn) {
148
+ decision = await opts.askFn(`Apply this patch? [y/n/a/q]: `);
149
+ }
150
+ else if (process.stdin.isTTY) {
151
+ const ans = await promptUser(pc.bold(pc.cyan(`Apply this fix to ${relFile}? [y]es / [n]o / [a]ll / [q]uit: `)));
152
+ decision = ans || "y";
153
+ }
154
+ else {
155
+ console.log(pc.yellow(`Non-interactive environment without --yes. Skipping fix.`));
156
+ decision = "n";
157
+ }
158
+ }
159
+ if (decision === "q" || decision === "quit") {
160
+ console.log(pc.yellow(`Aborted interactive fix session.`));
161
+ return {
162
+ totalFindings: codeFindings.length,
163
+ fixed: totalFixed,
164
+ skipped: totalSkipped,
165
+ filesModified: [...modifiedFilesSet]
166
+ };
167
+ }
168
+ if (decision === "a" || decision === "all") {
169
+ autoApproveAll = true;
170
+ decision = "y";
171
+ }
172
+ if (decision === "y" || decision === "yes") {
173
+ if (opts.dryRun) {
174
+ console.log(pc.yellow(`[DRY-RUN] Would apply patch to ${relFile}:${finding.line}`));
175
+ }
176
+ else {
177
+ writeFileSync(fullPath, patchedContent, "utf8");
178
+ console.log(pc.green(`[OK] Applied fix to ${relFile}:${finding.line}`));
179
+ modifiedFilesSet.add(relFile);
180
+ }
181
+ totalFixed++;
182
+ }
183
+ else {
184
+ console.log(pc.dim(`Skipped fix for ${relFile}:${finding.line}`));
185
+ totalSkipped++;
186
+ }
187
+ }
188
+ }
189
+ console.log(pc.bold(`\nWide Fix Complete: ${totalFixed} patch(es) applied, ${totalSkipped} skipped across ${modifiedFilesSet.size} modified file(s).\n`));
190
+ return {
191
+ totalFindings: codeFindings.length,
192
+ fixed: totalFixed,
193
+ skipped: totalSkipped,
194
+ filesModified: [...modifiedFilesSet]
195
+ };
196
+ }
197
+ //# sourceMappingURL=fix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix.js","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAgB,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAuBxD,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,eAAuB;IAC1E,IAAI,CAAC,KAAK,IAAI,CAAC,eAAe;QAAE,OAAO,KAAK,CAAC;IAC7C,MAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACvD,IAAI,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,I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B,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAClE,YAAY,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CACT,EAAE,CAAC,IAAI,CACL,wBAAwB,UAAU,uBAAuB,YAAY,mBAAmB,gBAAgB,CAAC,IAAI,sBAAsB,CACpI,CACF,CAAC;IAEF,OAAO;QACL,aAAa,EAAE,YAAY,CAAC,MAAM;QAClC,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,YAAY;QACrB,aAAa,EAAE,CAAC,GAAG,gBAAgB,CAAC;KACrC,CAAC;AACJ,CAAC"}
package/dist/hook.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { type Finding } from "./security/scanner.js";
2
+ export interface HookInstallOptions {
3
+ failOn?: string;
4
+ force?: boolean;
5
+ cwd?: string;
6
+ }
7
+ export interface HookUninstallOptions {
8
+ cwd?: string;
9
+ }
10
+ export interface HookRunOptions {
11
+ failOn?: string;
12
+ rulesPath?: string;
13
+ cwd?: string;
14
+ }
15
+ export declare function findGitDir(cwd?: string): string;
16
+ export declare function installPreCommitHook(opts?: HookInstallOptions): {
17
+ installed: boolean;
18
+ hookPath: string;
19
+ message: string;
20
+ };
21
+ export declare function uninstallPreCommitHook(opts?: HookUninstallOptions): {
22
+ uninstalled: boolean;
23
+ hookPath: string;
24
+ message: string;
25
+ };
26
+ export declare function runPreCommitHook(opts?: HookRunOptions): Promise<{
27
+ blocked: boolean;
28
+ findings: Finding[];
29
+ totalFilesScanned: number;
30
+ }>;
31
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AASD,wBAAgB,UAAU,CAAC,GAAG,SAAgB,GAAG,MAAM,CAgBtD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,GAAE,kBAAuB,GAAG;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CA0CA;AAED,wBAAgB,sBAAsB,CAAC,IAAI,GAAE,oBAAyB,GAAG;IACvE,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CA4BA;AAED,wBAAsB,gBAAgB,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CA+ED"}
package/dist/hook.js ADDED
@@ -0,0 +1,152 @@
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, chmodSync, mkdirSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import pc from "picocolors";
5
+ import { SecurityScanner } from "./security/scanner.js";
6
+ const SEVERITY_RANKS = {
7
+ CRITICAL: 4,
8
+ HIGH: 3,
9
+ MEDIUM: 2,
10
+ LOW: 1
11
+ };
12
+ export function findGitDir(cwd = process.cwd()) {
13
+ try {
14
+ const gitDirRaw = execSync("git rev-parse --git-dir", {
15
+ cwd,
16
+ encoding: "utf8",
17
+ stdio: ["ignore", "pipe", "ignore"]
18
+ }).trim();
19
+ if (gitDirRaw) {
20
+ return resolve(cwd, gitDirRaw);
21
+ }
22
+ }
23
+ catch { }
24
+ const fallback = resolve(cwd, ".git");
25
+ if (existsSync(fallback)) {
26
+ return fallback;
27
+ }
28
+ throw new Error(`Directory '${cwd}' is not inside a git repository.`);
29
+ }
30
+ export function installPreCommitHook(opts = {}) {
31
+ const cwd = opts.cwd || process.cwd();
32
+ const gitDir = findGitDir(cwd);
33
+ const hooksDir = resolve(gitDir, "hooks");
34
+ if (!existsSync(hooksDir)) {
35
+ mkdirSync(hooksDir, { recursive: true });
36
+ }
37
+ const hookPath = resolve(hooksDir, "pre-commit");
38
+ const failOn = (opts.failOn || "HIGH").toUpperCase();
39
+ if (existsSync(hookPath) && !opts.force) {
40
+ const existingContent = readFileSync(hookPath, "utf8");
41
+ if (!existingContent.includes("wide hook run")) {
42
+ return {
43
+ installed: false,
44
+ hookPath,
45
+ message: "A pre-commit hook already exists. Use --force to overwrite."
46
+ };
47
+ }
48
+ }
49
+ const script = [
50
+ "#!/usr/bin/env sh",
51
+ "if command -v wide >/dev/null 2>&1; then",
52
+ ` wide hook run --fail-on ${failOn}`,
53
+ " exit $?",
54
+ "elif command -v npx >/dev/null 2>&1; then",
55
+ ` npx wide hook run --fail-on ${failOn}`,
56
+ " exit $?",
57
+ "fi"
58
+ ].join("\n") + "\n";
59
+ writeFileSync(hookPath, script, "utf8");
60
+ try {
61
+ chmodSync(hookPath, 0o755);
62
+ }
63
+ catch { }
64
+ return {
65
+ installed: true,
66
+ hookPath,
67
+ message: `Pre-commit hook installed to ${hookPath} with severity threshold ${failOn}.`
68
+ };
69
+ }
70
+ export function uninstallPreCommitHook(opts = {}) {
71
+ const cwd = opts.cwd || process.cwd();
72
+ const gitDir = findGitDir(cwd);
73
+ const hookPath = resolve(gitDir, "hooks", "pre-commit");
74
+ if (!existsSync(hookPath)) {
75
+ return {
76
+ uninstalled: false,
77
+ hookPath,
78
+ message: "No pre-commit hook found."
79
+ };
80
+ }
81
+ const content = readFileSync(hookPath, "utf8");
82
+ if (!content.includes("wide hook run")) {
83
+ return {
84
+ uninstalled: false,
85
+ hookPath,
86
+ message: "Existing pre-commit hook was not created by Wide; left unchanged."
87
+ };
88
+ }
89
+ unlinkSync(hookPath);
90
+ return {
91
+ uninstalled: true,
92
+ hookPath,
93
+ message: `Removed pre-commit hook from ${hookPath}.`
94
+ };
95
+ }
96
+ export async function runPreCommitHook(opts = {}) {
97
+ const cwd = opts.cwd || process.cwd();
98
+ const failOn = (opts.failOn || "HIGH").toUpperCase();
99
+ const minRank = SEVERITY_RANKS[failOn] || 3;
100
+ let stagedRaw = "";
101
+ try {
102
+ stagedRaw = execSync("git diff --cached --name-only --diff-filter=ACMR", {
103
+ cwd,
104
+ encoding: "utf8",
105
+ stdio: ["ignore", "pipe", "ignore"]
106
+ }).trim();
107
+ }
108
+ catch (err) {
109
+ throw new Error(`Failed to list staged git changes: ${err.message}`);
110
+ }
111
+ const stagedFiles = stagedRaw
112
+ .split(/\r?\n/)
113
+ .map((f) => f.trim())
114
+ .filter((f) => f.length > 0);
115
+ if (stagedFiles.length === 0) {
116
+ console.log(pc.green("[OK] No staged files to check."));
117
+ return { blocked: false, findings: [], totalFilesScanned: 0 };
118
+ }
119
+ const existingFiles = stagedFiles.filter((f) => existsSync(resolve(cwd, f)));
120
+ if (existingFiles.length === 0) {
121
+ console.log(pc.green("[OK] No existing staged files to check."));
122
+ return { blocked: false, findings: [], totalFilesScanned: 0 };
123
+ }
124
+ const scanner = new SecurityScanner(cwd, opts.rulesPath);
125
+ const result = await scanner.scanFiles(existingFiles, "ALL");
126
+ const blockingFindings = result.findings.filter((f) => (SEVERITY_RANKS[f.severity] || 0) >= minRank);
127
+ if (blockingFindings.length > 0) {
128
+ console.log(pc.bold(pc.red(`\n[WIDE HOOK] Security check failed: ${blockingFindings.length} issue(s) at or above ${failOn} severity:`)));
129
+ for (const f of blockingFindings) {
130
+ const sevBadge = f.severity === "CRITICAL"
131
+ ? pc.bgRed(pc.white(` ${f.severity} `))
132
+ : pc.red(`[${f.severity}]`);
133
+ console.log(` ${sevBadge} ${pc.bold(f.file)}:${f.line} - ${f.message} (${pc.dim(f.id)})`);
134
+ if (f.snippet) {
135
+ console.log(` ${pc.dim(f.snippet.trim())}`);
136
+ }
137
+ }
138
+ console.log(pc.yellow("\nCommit blocked. Address the security vulnerabilities or suppress with '// wide-ignore <rule-id>' before committing.\n"));
139
+ return {
140
+ blocked: true,
141
+ findings: blockingFindings,
142
+ totalFilesScanned: result.totalFilesScanned
143
+ };
144
+ }
145
+ console.log(pc.green(`[OK] Wide pre-commit check passed (${result.totalFilesScanned} staged file(s) scanned, 0 blocking findings).`));
146
+ return {
147
+ blocked: false,
148
+ findings: result.findings,
149
+ totalFilesScanned: result.totalFilesScanned
150
+ };
151
+ }
152
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAgB,MAAM,uBAAuB,CAAC;AAkBtE,MAAM,cAAc,GAA2B;IAC7C,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;CACP,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IAC5C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,QAAQ,CAAC,yBAAyB,EAAE;YACpD,GAAG;YACH,QAAQ,EAAE,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AAC;gBACvC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;YAC3F,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CACT,EAAE,CAAC,MAAM,CACP,yHAAyH,CAC1H,CACF,CAAC;QACF,OAAO;YACL,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,gBAAgB;YAC1B,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;SAC5C,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,CACT,EAAE,CAAC,KAAK,CACN,sCAAsC,MAAM,CAAC,iBAAiB,gDAAgD,CAC/G,CACF,CAAC;IACF,OAAO;QACL,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;KAC5C,CAAC;AACJ,CAAC"}
package/dist/index.js CHANGED
@@ -64,15 +64,17 @@ const program = new Command();
64
64
  program
65
65
  .name("wide")
66
66
  .description("Terminal-first autonomous AI coding and security agent for the Wide ecosystem")
67
- .version("0.5.1611261726")
67
+ .version("0.6.191126")
68
68
  .option("-d, --debug", "Enable structured debug diagnostics to stderr")
69
69
  .option("-v, --verbose", "Enable verbose diagnostic logging")
70
70
  .argument("[prompt...]", "Optional initial prompt for the agent")
71
71
  .option("-p, --print", "Run a single prompt non-interactively and exit")
72
72
  .option("-c, --continue", "Resume the most recent saved interactive session")
73
73
  .option("-r, --resume [sessionId]", "Resume a saved interactive session by ID")
74
- .option("--provider <provider>", "LLM provider to use (gemini, ollama, claude, deepseek, openai)")
74
+ .option("--provider <provider>", "LLM provider to use (gemini, ollama, claude, claude-code, antigravity, codex, deepseek, openai)")
75
75
  .option("-m, --model <model>", "Model name to use")
76
+ .option("--mode <mode>", "Tool mode to use (full, code, security)")
77
+ .option("--no-browser", "Disable interactive browser_* tools")
76
78
  .option("-y, --yes", "Auto-approve all file edits and non-destructive command executions")
77
79
  .hook("preAction", () => {
78
80
  const rootOpts = program.opts();
@@ -94,6 +96,16 @@ program
94
96
  if (ws.rules.length > 0) {
95
97
  console.log(pc.dim(`Loaded ${ws.rules.length} workspace rule(s) from .wide/rules`));
96
98
  }
99
+ if (options.mode !== undefined) {
100
+ const normalizedMode = String(options.mode).trim().toLowerCase();
101
+ if (normalizedMode !== "full" && normalizedMode !== "code" && normalizedMode !== "security") {
102
+ console.error(pc.red(`Error: Invalid --mode '${options.mode}'. Choose one of: full, code, security.`));
103
+ process.exit(1);
104
+ }
105
+ options.mode = normalizedMode;
106
+ }
107
+ const cliToolMode = options.mode;
108
+ const cliAllowBrowser = options.browser === false ? false : undefined;
97
109
  const nonInteractive = Boolean(options.print || pipedData);
98
110
  if (nonInteractive) {
99
111
  if (!userPrompt) {
@@ -108,7 +120,10 @@ program
108
120
  import("./tools/index.js"),
109
121
  ]);
110
122
  const provider = createProvider(options.provider, options.model);
111
- const agent = new Agent(process.cwd(), provider);
123
+ const agent = new Agent(process.cwd(), provider, {
124
+ toolMode: cliToolMode,
125
+ allowBrowser: cliAllowBrowser,
126
+ });
112
127
  if (options.continue) {
113
128
  const latest = loadLatestSession();
114
129
  if (latest)
@@ -123,7 +138,9 @@ program
123
138
  autoApproveWrite: options.yes ? true : undefined,
124
139
  autoApproveRun: options.yes ? true : undefined,
125
140
  });
126
- await executeTool("browser_close", {}, { workingDirectory: process.cwd() });
141
+ if (agent.getAllowBrowser()) {
142
+ await executeTool("browser_close", {}, { workingDirectory: process.cwd() });
143
+ }
127
144
  }
128
145
  catch (err) {
129
146
  console.error(`${pc.red("Error:")} ${err.message}`);
@@ -139,6 +156,8 @@ program
139
156
  overrideProvider: options.provider,
140
157
  overrideModel: options.model,
141
158
  autoApproveAll: Boolean(options.yes),
159
+ toolMode: cliToolMode,
160
+ allowBrowser: cliAllowBrowser,
142
161
  });
143
162
  });
144
163
  program
@@ -161,6 +180,38 @@ program
161
180
  }, { workingDirectory: process.cwd() });
162
181
  console.log(res.output);
163
182
  });
183
+ program
184
+ .command("fix [path]")
185
+ .description("Interactively review and apply security patches or quick-fix suppressions")
186
+ .option("-s, --severity <level>", "Minimum severity to fix (CRITICAL, HIGH, MEDIUM, LOW, ALL)", "HIGH")
187
+ .option("-r, --rules <path>", "Path to custom rules.json file")
188
+ .option("-y, --yes", "Auto-apply all proposed patches without interactive confirmation")
189
+ .option("--dry-run", "Preview proposed diffs without writing modifications to disk")
190
+ .option("--suppress", "Only generate quick-fix suppressions (wide-ignore directives)")
191
+ .option("--ai", "Use AI LLM provider to synthesize intelligent code remediation patches")
192
+ .option("--provider <provider>", "LLM provider override (gemini, ollama, claude, claude-code, antigravity, codex, deepseek, openai)")
193
+ .option("-m, --model <model>", "Model name override")
194
+ .action(async (targetPath = ".", opts) => {
195
+ try {
196
+ const { runInteractiveFix } = await import("./fix.js");
197
+ await runInteractiveFix({
198
+ path: targetPath,
199
+ severity: opts.severity,
200
+ rulesPath: opts.rules,
201
+ yes: Boolean(opts.yes),
202
+ dryRun: Boolean(opts.dryRun),
203
+ suppressOnly: Boolean(opts.suppress),
204
+ ai: Boolean(opts.ai),
205
+ provider: opts.provider,
206
+ model: opts.model,
207
+ cwd: process.cwd()
208
+ });
209
+ }
210
+ catch (err) {
211
+ console.error(pc.red(`Fix failed: ${err.message}`));
212
+ process.exit(1);
213
+ }
214
+ });
164
215
  program
165
216
  .command("update")
166
217
  .alias("upgrade")
@@ -172,7 +223,7 @@ program
172
223
  const ruleResult = await RuleLoader.updateRules();
173
224
  console.log(pc.green(`Synchronized ${ruleResult.count} security rules to ${ruleResult.path}`));
174
225
  console.log(pc.cyan("Checking for Wide CLI updates..."));
175
- const currentVersion = "0.5151126";
226
+ const currentVersion = "0.6.191126";
176
227
  const res = await fetch("https://api.github.com/repos/sl4de0day/wide-cli/releases/latest", {
177
228
  headers: { "User-Agent": "Wide-CLI", Accept: "application/vnd.github+json" },
178
229
  signal: AbortSignal.timeout(10000)
@@ -248,6 +299,49 @@ program
248
299
  const res = await executeTool("fuzz_endpoint", { url, param, payloadType: type, method: opts.method }, { workingDirectory: process.cwd() });
249
300
  console.log(res.output);
250
301
  });
302
+ program
303
+ .command("crawl <url>")
304
+ .description("Crawl a web target with SSRF protection, PathTrie normalization, SimHash dedup, and passive audits")
305
+ .option("-d, --depth <n>", "Crawl depth limit", "3")
306
+ .option("-m, --max-pages <n>", "Maximum pages to crawl", "80")
307
+ .option("-s, --scope <mode>", "Scope mode (rdn, fqdn, dn)", "rdn")
308
+ .option("--allow-private", "Allow private/loopback addresses")
309
+ .option("--tls-profile <profile>", "TLS/browser profile (none, chrome, firefox, safari)", "none")
310
+ .action(async (url, opts) => {
311
+ const { executeTool } = await import("./tools/index.js");
312
+ const res = await executeTool("crawl_target", {
313
+ url,
314
+ maxDepth: Number(opts.depth) || 3,
315
+ maxPages: Number(opts.maxPages) || 80,
316
+ fieldScope: opts.scope || "rdn",
317
+ allowPrivate: Boolean(opts.allowPrivate),
318
+ tlsProfile: opts.tlsProfile || "none"
319
+ }, { workingDirectory: process.cwd() });
320
+ if (!res.success && res.error) {
321
+ console.error(res.error);
322
+ process.exitCode = 1;
323
+ return;
324
+ }
325
+ console.log(res.output);
326
+ });
327
+ program
328
+ .command("inspect <url>")
329
+ .description("Inspect an HTTP request/wire frame for RFC 9112 smuggling, evasion decoding, lexical SQLi/XSS, and scored policy")
330
+ .option("-X, --method <method>", "HTTP method", "GET")
331
+ .option("-b, --body <body>", "Request body")
332
+ .option("--raw <wire>", "Raw HTTP/1.x wire request")
333
+ .option("--learn", "Generate dated exception drafts")
334
+ .action(async (url, opts) => {
335
+ const { executeTool } = await import("./tools/index.js");
336
+ const res = await executeTool("inspect_http_message", {
337
+ url,
338
+ method: opts.method,
339
+ body: opts.body,
340
+ rawRequest: opts.raw,
341
+ learning: Boolean(opts.learn),
342
+ }, { workingDirectory: process.cwd() });
343
+ console.log(res.output);
344
+ });
251
345
  const configCmd = program
252
346
  .command("config")
253
347
  .description("Manage Wide CLI configuration and API keys");
@@ -328,5 +422,74 @@ completionCmd
328
422
  process.exit(1);
329
423
  }
330
424
  });
425
+ const hookCmd = program
426
+ .command("hook")
427
+ .description("Manage and execute Git pre-commit security hooks");
428
+ hookCmd
429
+ .command("install")
430
+ .description("Install Wide pre-commit security hook in the current Git repository")
431
+ .option("--fail-on <severity>", "Minimum severity to block commit (CRITICAL, HIGH, MEDIUM, LOW)", "HIGH")
432
+ .option("-f, --force", "Overwrite existing pre-commit hook")
433
+ .action(async (opts) => {
434
+ try {
435
+ const { installPreCommitHook } = await import("./hook.js");
436
+ const res = installPreCommitHook({
437
+ failOn: opts.failOn,
438
+ force: Boolean(opts.force),
439
+ cwd: process.cwd()
440
+ });
441
+ if (res.installed) {
442
+ console.log(pc.green(`[OK] Pre-commit hook installed to ${res.hookPath}`));
443
+ }
444
+ else {
445
+ console.log(pc.cyan(`[OK] ${res.message}`));
446
+ }
447
+ }
448
+ catch (err) {
449
+ console.error(pc.red(`Failed to install hook: ${err.message}`));
450
+ process.exit(1);
451
+ }
452
+ });
453
+ hookCmd
454
+ .command("uninstall")
455
+ .description("Uninstall Wide pre-commit security hook from the current Git repository")
456
+ .action(async () => {
457
+ try {
458
+ const { uninstallPreCommitHook } = await import("./hook.js");
459
+ const res = uninstallPreCommitHook({ cwd: process.cwd() });
460
+ if (res.uninstalled) {
461
+ console.log(pc.green(`[OK] Pre-commit hook removed from ${res.hookPath}`));
462
+ }
463
+ else {
464
+ console.log(pc.yellow(`[WARN] ${res.message}`));
465
+ }
466
+ }
467
+ catch (err) {
468
+ console.error(pc.red(`Failed to uninstall hook: ${err.message}`));
469
+ process.exit(1);
470
+ }
471
+ });
472
+ hookCmd
473
+ .command("run")
474
+ .description("Run security check against staged Git changes")
475
+ .option("--fail-on <severity>", "Minimum severity to block commit (CRITICAL, HIGH, MEDIUM, LOW)", "HIGH")
476
+ .option("-r, --rules <path>", "Path to custom rules.json file")
477
+ .action(async (opts) => {
478
+ try {
479
+ const { runPreCommitHook } = await import("./hook.js");
480
+ const res = await runPreCommitHook({
481
+ failOn: opts.failOn,
482
+ rulesPath: opts.rules,
483
+ cwd: process.cwd()
484
+ });
485
+ if (res.blocked) {
486
+ process.exit(1);
487
+ }
488
+ }
489
+ catch (err) {
490
+ console.error(pc.red(`Hook execution failed: ${err.message}`));
491
+ process.exit(1);
492
+ }
493
+ });
331
494
  await program.parseAsync(process.argv);
332
495
  //# sourceMappingURL=index.js.map