wide-cli 0.0.0-stage → 0.3.101126
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/.github/workflows/ci.yml +29 -0
- package/LICENSE +674 -0
- package/README.md +80 -2
- package/assets/logo.png +0 -0
- package/assets/wide-logo.png +0 -0
- package/bin/wide.js +17 -0
- package/dist/agent/context.d.ts +7 -0
- package/dist/agent/context.d.ts.map +1 -0
- package/dist/agent/context.js +38 -0
- package/dist/agent/context.js.map +1 -0
- package/dist/agent/index.d.ts +16 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +138 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/config/index.d.ts +29 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +66 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/workspace.d.ts +7 -0
- package/dist/config/workspace.d.ts.map +1 -0
- package/dist/config/workspace.js +31 -0
- package/dist/config/workspace.js.map +1 -0
- package/dist/decision/index.d.ts +113 -0
- package/dist/decision/index.d.ts.map +1 -0
- package/dist/decision/index.js +485 -0
- package/dist/decision/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +167 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/claude.d.ts +10 -0
- package/dist/providers/claude.d.ts.map +1 -0
- package/dist/providers/claude.js +147 -0
- package/dist/providers/claude.js.map +1 -0
- package/dist/providers/gemini.d.ts +10 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +129 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +44 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/ollama.d.ts +10 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +94 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +11 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +142 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +22 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/repl/index.d.ts +2 -0
- package/dist/repl/index.d.ts.map +1 -0
- package/dist/repl/index.js +94 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/security/fuzzer.d.ts +20 -0
- package/dist/security/fuzzer.d.ts.map +1 -0
- package/dist/security/fuzzer.js +109 -0
- package/dist/security/fuzzer.js.map +1 -0
- package/dist/security/loader.d.ts +17 -0
- package/dist/security/loader.d.ts.map +1 -0
- package/dist/security/loader.js +126 -0
- package/dist/security/loader.js.map +1 -0
- package/dist/security/payloads.d.ts +9 -0
- package/dist/security/payloads.d.ts.map +1 -0
- package/dist/security/payloads.js +88 -0
- package/dist/security/payloads.js.map +1 -0
- package/dist/security/rules.d.ts +14 -0
- package/dist/security/rules.d.ts.map +1 -0
- package/dist/security/rules.js +288 -0
- package/dist/security/rules.js.map +1 -0
- package/dist/security/scanner.d.ts +29 -0
- package/dist/security/scanner.d.ts.map +1 -0
- package/dist/security/scanner.js +136 -0
- package/dist/security/scanner.js.map +1 -0
- package/dist/tools/browser.d.ts +47 -0
- package/dist/tools/browser.d.ts.map +1 -0
- package/dist/tools/browser.js +441 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/fs.d.ts +5 -0
- package/dist/tools/fs.d.ts.map +1 -0
- package/dist/tools/fs.js +131 -0
- package/dist/tools/fs.js.map +1 -0
- package/dist/tools/git.d.ts +3 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +50 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/http.d.ts +3 -0
- package/dist/tools/http.d.ts.map +1 -0
- package/dist/tools/http.js +69 -0
- package/dist/tools/http.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +50 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search.d.ts +4 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +109 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/security.d.ts +5 -0
- package/dist/tools/security.d.ts.map +1 -0
- package/dist/tools/security.js +129 -0
- package/dist/tools/security.js.map +1 -0
- package/dist/tools/shell.d.ts +3 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +50 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/types.d.ts +33 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/ui/banner.d.ts +2 -0
- package/dist/ui/banner.d.ts.map +1 -0
- package/dist/ui/banner.js +14 -0
- package/dist/ui/banner.js.map +1 -0
- package/dist/ui/colors.d.ts +18 -0
- package/dist/ui/colors.d.ts.map +1 -0
- package/dist/ui/colors.js +19 -0
- package/dist/ui/colors.js.map +1 -0
- package/dist/ui/diff.d.ts +2 -0
- package/dist/ui/diff.d.ts.map +1 -0
- package/dist/ui/diff.js +26 -0
- package/dist/ui/diff.js.map +1 -0
- package/dist/ui/markdown.d.ts +2 -0
- package/dist/ui/markdown.d.ts.map +1 -0
- package/dist/ui/markdown.js +32 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/spinner.d.ts +12 -0
- package/dist/ui/spinner.d.ts.map +1 -0
- package/dist/ui/spinner.js +46 -0
- package/dist/ui/spinner.js.map +1 -0
- package/package.json +50 -4
- package/src/agent/context.ts +44 -0
- package/src/agent/index.ts +166 -0
- package/src/config/index.ts +88 -0
- package/src/config/workspace.ts +39 -0
- package/src/decision/index.ts +528 -0
- package/src/index.ts +180 -0
- package/src/providers/claude.ts +163 -0
- package/src/providers/gemini.ts +147 -0
- package/src/providers/index.ts +52 -0
- package/src/providers/ollama.ts +108 -0
- package/src/providers/openai.ts +159 -0
- package/src/providers/types.ts +29 -0
- package/src/repl/index.ts +100 -0
- package/src/security/fuzzer.ts +140 -0
- package/src/security/loader.ts +129 -0
- package/src/security/payloads.ts +95 -0
- package/src/security/rules.ts +300 -0
- package/src/security/scanner.ts +180 -0
- package/src/tools/browser.ts +528 -0
- package/src/tools/fs.ts +143 -0
- package/src/tools/git.ts +51 -0
- package/src/tools/http.ts +77 -0
- package/src/tools/index.ts +64 -0
- package/src/tools/search.ts +109 -0
- package/src/tools/security.ts +140 -0
- package/src/tools/shell.ts +56 -0
- package/src/tools/types.ts +33 -0
- package/src/ui/banner.ts +17 -0
- package/src/ui/colors.ts +19 -0
- package/src/ui/diff.ts +24 -0
- package/src/ui/markdown.ts +34 -0
- package/src/ui/spinner.ts +53 -0
- package/tests/browser.test.mjs +71 -0
- package/tests/decision.test.mjs +68 -0
- package/tests/loader.test.mjs +24 -0
- package/tests/suite.test.mjs +61 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const colors: {
|
|
2
|
+
primary: import("picocolors/types.js").Formatter;
|
|
3
|
+
primaryBold: (t: string) => string;
|
|
4
|
+
accent: import("picocolors/types.js").Formatter;
|
|
5
|
+
accentBold: (t: string) => string;
|
|
6
|
+
success: import("picocolors/types.js").Formatter;
|
|
7
|
+
successBold: (t: string) => string;
|
|
8
|
+
warning: import("picocolors/types.js").Formatter;
|
|
9
|
+
warningBold: (t: string) => string;
|
|
10
|
+
error: import("picocolors/types.js").Formatter;
|
|
11
|
+
errorBold: (t: string) => string;
|
|
12
|
+
muted: import("picocolors/types.js").Formatter;
|
|
13
|
+
bold: import("picocolors/types.js").Formatter;
|
|
14
|
+
dim: import("picocolors/types.js").Formatter;
|
|
15
|
+
inverse: import("picocolors/types.js").Formatter;
|
|
16
|
+
underline: import("picocolors/types.js").Formatter;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/ui/colors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;qBAEA,MAAM;;oBAEP,MAAM;;qBAEL,MAAM;;qBAEN,MAAM;;mBAER,MAAM;;;;;;CAMtB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
export const colors = {
|
|
3
|
+
primary: pc.cyan,
|
|
4
|
+
primaryBold: (t) => pc.bold(pc.cyan(t)),
|
|
5
|
+
accent: pc.magenta,
|
|
6
|
+
accentBold: (t) => pc.bold(pc.magenta(t)),
|
|
7
|
+
success: pc.green,
|
|
8
|
+
successBold: (t) => pc.bold(pc.green(t)),
|
|
9
|
+
warning: pc.yellow,
|
|
10
|
+
warningBold: (t) => pc.bold(pc.yellow(t)),
|
|
11
|
+
error: pc.red,
|
|
12
|
+
errorBold: (t) => pc.bold(pc.red(t)),
|
|
13
|
+
muted: pc.gray,
|
|
14
|
+
bold: pc.bold,
|
|
15
|
+
dim: pc.dim,
|
|
16
|
+
inverse: pc.inverse,
|
|
17
|
+
underline: pc.underline,
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/ui/colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO,EAAE,EAAE,CAAC,IAAI;IAChB,WAAW,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,EAAE,EAAE,CAAC,OAAO;IAClB,UAAU,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,EAAE,CAAC,KAAK;IACjB,WAAW,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,EAAE,EAAE,CAAC,MAAM;IAClB,WAAW,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,EAAE,EAAE,CAAC,GAAG;IACb,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5C,KAAK,EAAE,EAAE,CAAC,IAAI;IACd,IAAI,EAAE,EAAE,CAAC,IAAI;IACb,GAAG,EAAE,EAAE,CAAC,GAAG;IACX,OAAO,EAAE,EAAE,CAAC,OAAO;IACnB,SAAS,EAAE,EAAE,CAAC,SAAS;CACxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/ui/diff.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAoB1F"}
|
package/dist/ui/diff.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createPatch } from "diff";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
export function formatUnifiedDiff(filePath, oldStr, newStr) {
|
|
4
|
+
const patch = createPatch(filePath, oldStr, newStr, "original", "modified", { context: 3 });
|
|
5
|
+
const lines = patch.split("\n");
|
|
6
|
+
const coloredLines = [];
|
|
7
|
+
for (const line of lines) {
|
|
8
|
+
if (line.startsWith("---") || line.startsWith("+++")) {
|
|
9
|
+
coloredLines.push(pc.bold(pc.gray(line)));
|
|
10
|
+
}
|
|
11
|
+
else if (line.startsWith("@@")) {
|
|
12
|
+
coloredLines.push(pc.cyan(line));
|
|
13
|
+
}
|
|
14
|
+
else if (line.startsWith("+")) {
|
|
15
|
+
coloredLines.push(pc.green(line));
|
|
16
|
+
}
|
|
17
|
+
else if (line.startsWith("-")) {
|
|
18
|
+
coloredLines.push(pc.red(line));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
coloredLines.push(pc.gray(line));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return coloredLines.join("\n");
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/ui/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,MAAc,EAAE,MAAc;IAChF,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5F,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/ui/markdown.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA+B3D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
export function formatTerminalMarkdown(text) {
|
|
3
|
+
if (!text)
|
|
4
|
+
return "";
|
|
5
|
+
const lines = text.split("\n");
|
|
6
|
+
const formatted = [];
|
|
7
|
+
let inCodeBlock = false;
|
|
8
|
+
for (const line of lines) {
|
|
9
|
+
if (line.startsWith("```")) {
|
|
10
|
+
inCodeBlock = !inCodeBlock;
|
|
11
|
+
formatted.push(pc.gray(line));
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (inCodeBlock) {
|
|
15
|
+
formatted.push(pc.green(line));
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (line.startsWith("# ")) {
|
|
19
|
+
formatted.push(pc.bold(pc.cyan(line)));
|
|
20
|
+
}
|
|
21
|
+
else if (line.startsWith("## ") || line.startsWith("### ")) {
|
|
22
|
+
formatted.push(pc.bold(pc.white(line)));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
let l = line.replace(/`([^`]+)`/g, (_, code) => pc.yellow(code));
|
|
26
|
+
l = l.replace(/\*\*([^*]+)\*\*/g, (_, bold) => pc.bold(bold));
|
|
27
|
+
formatted.push(l);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return formatted.join("\n");
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/ui/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,WAAW,GAAG,CAAC,WAAW,CAAC;YAC3B,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9B,SAAS;QACX,CAAC;QAED,IAAI,WAAW,EAAE,CAAC;YAChB,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/B,SAAS;QACX,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7D,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACjE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9D,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class Spinner {
|
|
2
|
+
private timer;
|
|
3
|
+
private currentFrame;
|
|
4
|
+
private message;
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
start(message?: string): this;
|
|
7
|
+
update(message: string): this;
|
|
8
|
+
stop(clear?: boolean): void;
|
|
9
|
+
succeed(message: string): void;
|
|
10
|
+
fail(message: string): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=spinner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../src/ui/spinner.ts"],"names":[],"mappings":"AAIA,qBAAa,OAAO;IAClB,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,SAAgB;IAI5B,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAc7B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK7B,IAAI,CAAC,KAAK,UAAO,GAAG,IAAI;IAWxB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK9B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAInC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
const SPINNER_FRAMES = ["-", "\\", "|", "/"];
|
|
3
|
+
export class Spinner {
|
|
4
|
+
timer = null;
|
|
5
|
+
currentFrame = 0;
|
|
6
|
+
message;
|
|
7
|
+
constructor(message = "Thinking...") {
|
|
8
|
+
this.message = message;
|
|
9
|
+
}
|
|
10
|
+
start(message) {
|
|
11
|
+
if (message)
|
|
12
|
+
this.message = message;
|
|
13
|
+
if (this.timer)
|
|
14
|
+
return this;
|
|
15
|
+
process.stdout.write("\x1B[?25l");
|
|
16
|
+
this.timer = setInterval(() => {
|
|
17
|
+
const frame = SPINNER_FRAMES[this.currentFrame % SPINNER_FRAMES.length];
|
|
18
|
+
process.stdout.write(`\r${pc.cyan(frame)} ${pc.dim(this.message)} `);
|
|
19
|
+
this.currentFrame++;
|
|
20
|
+
}, 80);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
update(message) {
|
|
24
|
+
this.message = message;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
stop(clear = true) {
|
|
28
|
+
if (this.timer) {
|
|
29
|
+
clearInterval(this.timer);
|
|
30
|
+
this.timer = null;
|
|
31
|
+
}
|
|
32
|
+
if (clear) {
|
|
33
|
+
process.stdout.write("\r\x1B[K");
|
|
34
|
+
}
|
|
35
|
+
process.stdout.write("\x1B[?25h");
|
|
36
|
+
}
|
|
37
|
+
succeed(message) {
|
|
38
|
+
this.stop(true);
|
|
39
|
+
console.log(`${pc.green("[OK]")} ${message}`);
|
|
40
|
+
}
|
|
41
|
+
fail(message) {
|
|
42
|
+
this.stop(true);
|
|
43
|
+
console.log(`${pc.red("[FAIL]")} ${message}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=spinner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../src/ui/spinner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE7C,MAAM,OAAO,OAAO;IACV,KAAK,GAA0B,IAAI,CAAC;IACpC,YAAY,GAAG,CAAC,CAAC;IACjB,OAAO,CAAS;IAExB,YAAY,OAAO,GAAG,aAAa;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAgB;QAC3B,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACpC,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAE5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC5B,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACrE,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,OAAe;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,IAAI,CAAC,KAAK,GAAG,IAAI;QACtB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IAEM,OAAO,CAAC,OAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAChD,CAAC;IAEM,IAAI,CAAC,OAAe;QACzB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAChD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wide-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.101126",
|
|
4
|
+
"description": "Terminal-first autonomous AI coding & security agent for the Wide ecosystem",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"wide": "bin/wide.js"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"dev": "tsc && node dist/index.js",
|
|
14
|
+
"start": "node bin/wide.js",
|
|
15
|
+
"test": "node tests/suite.test.mjs",
|
|
16
|
+
"lint": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"wide",
|
|
20
|
+
"wide-cli",
|
|
21
|
+
"ai-agent",
|
|
22
|
+
"devsecops",
|
|
23
|
+
"appsec",
|
|
24
|
+
"terminal",
|
|
25
|
+
"cli",
|
|
26
|
+
"security-scanner"
|
|
27
|
+
],
|
|
28
|
+
"author": "sl4de <sl4de0day@github>",
|
|
29
|
+
"license": "GPL-3.0-or-later",
|
|
30
|
+
"homepage": "https://github.com/sl4de0day/wide-cli",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/sl4de0day/wide-cli.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/sl4de0day/wide-cli/issues"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"commander": "^13.1.0",
|
|
40
|
+
"diff": "^7.0.0",
|
|
41
|
+
"fast-glob": "^3.3.3",
|
|
42
|
+
"picocolors": "^1.1.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/diff": "^7.0.2",
|
|
46
|
+
"@types/node": "^22.13.0",
|
|
47
|
+
"typescript": "^5.7.3"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ChatMessage } from "../providers/types.js";
|
|
2
|
+
|
|
3
|
+
export class ContextManager {
|
|
4
|
+
private maxCharacters: number;
|
|
5
|
+
|
|
6
|
+
constructor(maxCharacters = 40000) {
|
|
7
|
+
this.maxCharacters = maxCharacters;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public compactMessages(messages: ChatMessage[]): ChatMessage[] {
|
|
11
|
+
const totalChars = messages.reduce((sum, m) => sum + (m.content ? m.content.length : 0), 0);
|
|
12
|
+
if (totalChars <= this.maxCharacters && messages.length <= 20) {
|
|
13
|
+
return messages;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const systemMsg = messages[0];
|
|
17
|
+
const initialUserMsg = messages.find((m, i) => i > 0 && m.role === "user");
|
|
18
|
+
const recentMessages = messages.slice(-10);
|
|
19
|
+
|
|
20
|
+
const compacted: ChatMessage[] = [];
|
|
21
|
+
if (systemMsg) compacted.push(systemMsg);
|
|
22
|
+
if (initialUserMsg && !recentMessages.includes(initialUserMsg)) {
|
|
23
|
+
compacted.push(initialUserMsg);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
compacted.push({
|
|
27
|
+
role: "system",
|
|
28
|
+
content: "[Context Compaction] Earlier tool interactions were summarized to preserve context window limits. Continue with current objective."
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
for (const msg of recentMessages) {
|
|
32
|
+
if (msg.role === "tool" && msg.content.length > 2000) {
|
|
33
|
+
compacted.push({
|
|
34
|
+
...msg,
|
|
35
|
+
content: msg.content.slice(0, 2000) + "\n... [Output compacted]"
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
compacted.push(msg);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return compacted;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { configManager } from "../config/index.js";
|
|
3
|
+
import { createProvider, type ChatMessage, type LLMProvider } from "../providers/index.js";
|
|
4
|
+
import { executeTool, getToolDefinitions } from "../tools/index.js";
|
|
5
|
+
import { Spinner } from "../ui/spinner.js";
|
|
6
|
+
import { ContextManager } from "./context.js";
|
|
7
|
+
import { CommitmentGate } from "../decision/index.js";
|
|
8
|
+
import { RuleLoader } from "../security/loader.js";
|
|
9
|
+
import { type SecurityRule } from "../security/rules.js";
|
|
10
|
+
|
|
11
|
+
const SYSTEM_PROMPT = `You are Wide CLI, a security-first autonomous AI coding and web penetration testing agent.
|
|
12
|
+
You operate directly in the user's terminal workspace.
|
|
13
|
+
|
|
14
|
+
Your capabilities:
|
|
15
|
+
- Read, write, and edit code files autonomously.
|
|
16
|
+
- Run terminal commands to test, build, or verify projects.
|
|
17
|
+
- Run Wide's native SAST engine (run_security_scan) across 20+ vulnerability classes (SQLi, XSS, SSRF, Command Injection, XXE, Deserialization, Hardcoded Secrets, IDOR, Path Traversal, CORS, CSRF, ReDoS) with deep taint heuristics.
|
|
18
|
+
- Send HTTP requests (send_http_request) to test web endpoints, probe API security, or verify fixes.
|
|
19
|
+
- Fuzz web endpoints (fuzz_endpoint) with automated injection vectors to verify live vulnerabilities.
|
|
20
|
+
- Generate targeted offensive security payloads (generate_payloads) for penetration testing and verification.
|
|
21
|
+
- Autonomously navigate, interact with, click, fill forms, and extract content in a background headless browser using browser tools (browser_navigate, browser_click, browser_type, browser_extract, browser_screenshot, browser_close).
|
|
22
|
+
- Keep your answers concise, practical, and action-oriented. Do not produce boilerplate pleasantries.
|
|
23
|
+
- Always inspect relevant files before modifying them.
|
|
24
|
+
- When fixing security vulnerabilities, provide clean, secure, production-grade solutions.`;
|
|
25
|
+
|
|
26
|
+
export class Agent {
|
|
27
|
+
private messages: ChatMessage[] = [];
|
|
28
|
+
private provider: LLMProvider;
|
|
29
|
+
private workingDirectory: string;
|
|
30
|
+
private contextManager: ContextManager;
|
|
31
|
+
private agentRules: SecurityRule[] = [];
|
|
32
|
+
|
|
33
|
+
constructor(workingDirectory = process.cwd(), provider?: LLMProvider) {
|
|
34
|
+
this.workingDirectory = workingDirectory;
|
|
35
|
+
this.provider = provider || createProvider();
|
|
36
|
+
this.contextManager = new ContextManager();
|
|
37
|
+
this.agentRules = RuleLoader.loadAgentRules(undefined, workingDirectory);
|
|
38
|
+
this.messages.push({
|
|
39
|
+
role: "system",
|
|
40
|
+
content: SYSTEM_PROMPT
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getAgentRules(): SecurityRule[] {
|
|
45
|
+
return this.agentRules;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public reloadAgentRules(): SecurityRule[] {
|
|
49
|
+
this.agentRules = RuleLoader.loadAgentRules(undefined, this.workingDirectory);
|
|
50
|
+
return this.agentRules;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public setProvider(provider: LLMProvider): void {
|
|
54
|
+
this.provider = provider;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public clearHistory(): void {
|
|
58
|
+
this.messages = [{
|
|
59
|
+
role: "system",
|
|
60
|
+
content: SYSTEM_PROMPT
|
|
61
|
+
}];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async runPrompt(userPrompt: string): Promise<string> {
|
|
65
|
+
const cfg = configManager.get();
|
|
66
|
+
this.messages.push({
|
|
67
|
+
role: "user",
|
|
68
|
+
content: userPrompt
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const tools = getToolDefinitions();
|
|
72
|
+
const spinner = new Spinner("Wide thinking...");
|
|
73
|
+
const gate = new CommitmentGate(32, 0.0);
|
|
74
|
+
const callCounts = new Map<string, number>();
|
|
75
|
+
let iteration = 0;
|
|
76
|
+
let finalAssistantText = "";
|
|
77
|
+
|
|
78
|
+
while (iteration < cfg.maxIterations) {
|
|
79
|
+
iteration++;
|
|
80
|
+
this.messages = this.contextManager.compactMessages(this.messages);
|
|
81
|
+
|
|
82
|
+
spinner.start("Wide thinking...");
|
|
83
|
+
|
|
84
|
+
let streamedText = "";
|
|
85
|
+
let response;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
response = await this.provider.chatStream(
|
|
89
|
+
this.messages,
|
|
90
|
+
tools,
|
|
91
|
+
(chunk) => {
|
|
92
|
+
if (!streamedText) {
|
|
93
|
+
spinner.stop(true);
|
|
94
|
+
}
|
|
95
|
+
streamedText += chunk;
|
|
96
|
+
process.stdout.write(chunk);
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
} catch (err: any) {
|
|
100
|
+
spinner.fail(err.message);
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (streamedText && !streamedText.endsWith("\n")) {
|
|
105
|
+
process.stdout.write("\n");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
finalAssistantText = response.content;
|
|
109
|
+
|
|
110
|
+
this.messages.push({
|
|
111
|
+
role: "assistant",
|
|
112
|
+
content: response.content,
|
|
113
|
+
toolCalls: response.toolCalls
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (!response.toolCalls || response.toolCalls.length === 0) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (const tc of response.toolCalls) {
|
|
121
|
+
console.log(`\n${pc.cyan("[TOOL]")} ${pc.bold(tc.name)} ${pc.dim(JSON.stringify(tc.arguments))}`);
|
|
122
|
+
|
|
123
|
+
const sig = `${tc.name}:${JSON.stringify(tc.arguments)}`;
|
|
124
|
+
const count = (callCounts.get(sig) || 0) + 1;
|
|
125
|
+
callCounts.set(sig, count);
|
|
126
|
+
|
|
127
|
+
if (count > 3) {
|
|
128
|
+
spinner.fail(`${tc.name} suppressed by DecisionCore CommitmentGate (repeated call threshold exceeded)`);
|
|
129
|
+
this.messages.push({
|
|
130
|
+
role: "tool",
|
|
131
|
+
name: tc.name,
|
|
132
|
+
toolCallId: tc.id,
|
|
133
|
+
content: "ERROR: DecisionCore CommitmentGate suppressed duplicate tool execution. Please synthesize your findings and answer or select an alternative tool."
|
|
134
|
+
});
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
spinner.start(`Executing ${tc.name}...`);
|
|
139
|
+
|
|
140
|
+
const result = await executeTool(tc.name, tc.arguments, {
|
|
141
|
+
workingDirectory: this.workingDirectory,
|
|
142
|
+
autoApproveRead: cfg.autoApproveRead,
|
|
143
|
+
autoApproveWrite: cfg.autoApproveWrite,
|
|
144
|
+
autoApproveRun: cfg.autoApproveRun
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (result.success) {
|
|
148
|
+
spinner.succeed(`${tc.name} succeeded`);
|
|
149
|
+
} else {
|
|
150
|
+
spinner.fail(`${tc.name} failed: ${result.error}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const toolOutput = result.success ? result.output : `ERROR: ${result.error}`;
|
|
154
|
+
|
|
155
|
+
this.messages.push({
|
|
156
|
+
role: "tool",
|
|
157
|
+
name: tc.name,
|
|
158
|
+
toolCallId: tc.id,
|
|
159
|
+
content: toolOutput
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return finalAssistantText;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
export interface WideConfig {
|
|
6
|
+
provider: "gemini" | "ollama" | "claude" | "deepseek" | "openai";
|
|
7
|
+
model: string;
|
|
8
|
+
apiKeys: {
|
|
9
|
+
gemini?: string;
|
|
10
|
+
claude?: string;
|
|
11
|
+
deepseek?: string;
|
|
12
|
+
openai?: string;
|
|
13
|
+
};
|
|
14
|
+
ollamaBaseUrl: string;
|
|
15
|
+
autoApproveRead: boolean;
|
|
16
|
+
autoApproveWrite: boolean;
|
|
17
|
+
autoApproveRun: boolean;
|
|
18
|
+
maxIterations: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DEFAULT_CONFIG: WideConfig = {
|
|
22
|
+
provider: "gemini",
|
|
23
|
+
model: "gemini-2.5-flash",
|
|
24
|
+
apiKeys: {},
|
|
25
|
+
ollamaBaseUrl: "http://localhost:11434",
|
|
26
|
+
autoApproveRead: true,
|
|
27
|
+
autoApproveWrite: false,
|
|
28
|
+
autoApproveRun: false,
|
|
29
|
+
maxIterations: 25,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export class ConfigManager {
|
|
33
|
+
private configDir: string;
|
|
34
|
+
private configPath: string;
|
|
35
|
+
private config: WideConfig;
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
this.configDir = join(homedir(), ".wide");
|
|
39
|
+
this.configPath = join(this.configDir, "config.json");
|
|
40
|
+
this.config = this.load();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public get(): WideConfig {
|
|
44
|
+
return { ...this.config };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public set<K extends keyof WideConfig>(key: K, value: WideConfig[K]): void {
|
|
48
|
+
this.config[key] = value;
|
|
49
|
+
this.save();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public setApiKey(provider: keyof WideConfig["apiKeys"], key: string): void {
|
|
53
|
+
if (!this.config.apiKeys) this.config.apiKeys = {};
|
|
54
|
+
this.config.apiKeys[provider] = key;
|
|
55
|
+
this.save();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public getApiKey(provider: keyof WideConfig["apiKeys"]): string | undefined {
|
|
59
|
+
return process.env[`WIDE_${provider.toUpperCase()}_API_KEY`] ||
|
|
60
|
+
process.env[`${provider.toUpperCase()}_API_KEY`] ||
|
|
61
|
+
this.config.apiKeys?.[provider];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private load(): WideConfig {
|
|
65
|
+
try {
|
|
66
|
+
if (existsSync(this.configPath)) {
|
|
67
|
+
const raw = readFileSync(this.configPath, "utf8");
|
|
68
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(raw) };
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
return { ...DEFAULT_CONFIG };
|
|
72
|
+
}
|
|
73
|
+
return { ...DEFAULT_CONFIG };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private save(): void {
|
|
77
|
+
try {
|
|
78
|
+
if (!existsSync(this.configDir)) {
|
|
79
|
+
mkdirSync(this.configDir, { recursive: true });
|
|
80
|
+
}
|
|
81
|
+
writeFileSync(this.configPath, JSON.stringify(this.config, null, 2), "utf8");
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error("Failed to save config:", err);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const configManager = new ConfigManager();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export interface WorkspaceConfig {
|
|
5
|
+
rules: string[];
|
|
6
|
+
ignoredPatterns: string[];
|
|
7
|
+
isWideRepo: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function loadWorkspaceConfig(dir = process.cwd()): WorkspaceConfig {
|
|
11
|
+
const rulesPath = join(dir, ".wide", "rules");
|
|
12
|
+
const ignorePath = join(dir, ".wideignore");
|
|
13
|
+
const repoMarker = join(dir, ".widerepo");
|
|
14
|
+
|
|
15
|
+
const rules: string[] = [];
|
|
16
|
+
const ignoredPatterns: string[] = [];
|
|
17
|
+
|
|
18
|
+
if (existsSync(rulesPath)) {
|
|
19
|
+
try {
|
|
20
|
+
const content = readFileSync(rulesPath, "utf8");
|
|
21
|
+
rules.push(...content.split("\n").map(l => l.trim()).filter(Boolean));
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (existsSync(ignorePath)) {
|
|
27
|
+
try {
|
|
28
|
+
const content = readFileSync(ignorePath, "utf8");
|
|
29
|
+
ignoredPatterns.push(...content.split("\n").map(l => l.trim()).filter(Boolean));
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
rules,
|
|
36
|
+
ignoredPatterns,
|
|
37
|
+
isWideRepo: existsSync(repoMarker)
|
|
38
|
+
};
|
|
39
|
+
}
|