wide-cli 0.0.0-stage → 0.5.161126

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 (184) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +81 -2
  3. package/bin/wide.js +17 -0
  4. package/dist/agent/context.d.ts +7 -0
  5. package/dist/agent/context.d.ts.map +1 -0
  6. package/dist/agent/context.js +42 -0
  7. package/dist/agent/context.js.map +1 -0
  8. package/dist/agent/index.d.ts +45 -0
  9. package/dist/agent/index.d.ts.map +1 -0
  10. package/dist/agent/index.js +272 -0
  11. package/dist/agent/index.js.map +1 -0
  12. package/dist/completion.d.ts +13 -0
  13. package/dist/completion.d.ts.map +1 -0
  14. package/dist/completion.js +170 -0
  15. package/dist/completion.js.map +1 -0
  16. package/dist/config/index.d.ts +32 -0
  17. package/dist/config/index.d.ts.map +1 -0
  18. package/dist/config/index.js +94 -0
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/config/logger.d.ts +4 -0
  21. package/dist/config/logger.d.ts.map +1 -0
  22. package/dist/config/logger.js +13 -0
  23. package/dist/config/logger.js.map +1 -0
  24. package/dist/config/workspace.d.ts +7 -0
  25. package/dist/config/workspace.d.ts.map +1 -0
  26. package/dist/config/workspace.js +31 -0
  27. package/dist/config/workspace.js.map +1 -0
  28. package/dist/decision/index.d.ts +113 -0
  29. package/dist/decision/index.d.ts.map +1 -0
  30. package/dist/decision/index.js +487 -0
  31. package/dist/decision/index.js.map +1 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +332 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/providers/claude.d.ts +10 -0
  37. package/dist/providers/claude.d.ts.map +1 -0
  38. package/dist/providers/claude.js +163 -0
  39. package/dist/providers/claude.js.map +1 -0
  40. package/dist/providers/gemini.d.ts +10 -0
  41. package/dist/providers/gemini.d.ts.map +1 -0
  42. package/dist/providers/gemini.js +145 -0
  43. package/dist/providers/gemini.js.map +1 -0
  44. package/dist/providers/index.d.ts +10 -0
  45. package/dist/providers/index.d.ts.map +1 -0
  46. package/dist/providers/index.js +63 -0
  47. package/dist/providers/index.js.map +1 -0
  48. package/dist/providers/ollama.d.ts +15 -0
  49. package/dist/providers/ollama.d.ts.map +1 -0
  50. package/dist/providers/ollama.js +169 -0
  51. package/dist/providers/ollama.js.map +1 -0
  52. package/dist/providers/openai.d.ts +11 -0
  53. package/dist/providers/openai.d.ts.map +1 -0
  54. package/dist/providers/openai.js +158 -0
  55. package/dist/providers/openai.js.map +1 -0
  56. package/dist/providers/retry.d.ts +7 -0
  57. package/dist/providers/retry.d.ts.map +1 -0
  58. package/dist/providers/retry.js +72 -0
  59. package/dist/providers/retry.js.map +1 -0
  60. package/dist/providers/types.d.ts +23 -0
  61. package/dist/providers/types.d.ts.map +1 -0
  62. package/dist/providers/types.js +2 -0
  63. package/dist/providers/types.js.map +1 -0
  64. package/dist/repl/commands.d.ts +18 -0
  65. package/dist/repl/commands.d.ts.map +1 -0
  66. package/dist/repl/commands.js +351 -0
  67. package/dist/repl/commands.js.map +1 -0
  68. package/dist/repl/history.d.ts +3 -0
  69. package/dist/repl/history.d.ts.map +1 -0
  70. package/dist/repl/history.js +57 -0
  71. package/dist/repl/history.js.map +1 -0
  72. package/dist/repl/index.d.ts +10 -0
  73. package/dist/repl/index.d.ts.map +1 -0
  74. package/dist/repl/index.js +345 -0
  75. package/dist/repl/index.js.map +1 -0
  76. package/dist/repl/mentions.d.ts +8 -0
  77. package/dist/repl/mentions.d.ts.map +1 -0
  78. package/dist/repl/mentions.js +100 -0
  79. package/dist/repl/mentions.js.map +1 -0
  80. package/dist/repl/sessions.d.ts +21 -0
  81. package/dist/repl/sessions.d.ts.map +1 -0
  82. package/dist/repl/sessions.js +117 -0
  83. package/dist/repl/sessions.js.map +1 -0
  84. package/dist/repl/setup.d.ts +4 -0
  85. package/dist/repl/setup.d.ts.map +1 -0
  86. package/dist/repl/setup.js +73 -0
  87. package/dist/repl/setup.js.map +1 -0
  88. package/dist/security/fuzzer.d.ts +30 -0
  89. package/dist/security/fuzzer.d.ts.map +1 -0
  90. package/dist/security/fuzzer.js +180 -0
  91. package/dist/security/fuzzer.js.map +1 -0
  92. package/dist/security/loader.d.ts +31 -0
  93. package/dist/security/loader.d.ts.map +1 -0
  94. package/dist/security/loader.js +366 -0
  95. package/dist/security/loader.js.map +1 -0
  96. package/dist/security/payloads.d.ts +9 -0
  97. package/dist/security/payloads.d.ts.map +1 -0
  98. package/dist/security/payloads.js +88 -0
  99. package/dist/security/payloads.js.map +1 -0
  100. package/dist/security/rules.d.ts +16 -0
  101. package/dist/security/rules.d.ts.map +1 -0
  102. package/dist/security/rules.js +381 -0
  103. package/dist/security/rules.js.map +1 -0
  104. package/dist/security/sca.d.ts +39 -0
  105. package/dist/security/sca.d.ts.map +1 -0
  106. package/dist/security/sca.js +464 -0
  107. package/dist/security/sca.js.map +1 -0
  108. package/dist/security/scanner.d.ts +47 -0
  109. package/dist/security/scanner.d.ts.map +1 -0
  110. package/dist/security/scanner.js +353 -0
  111. package/dist/security/scanner.js.map +1 -0
  112. package/dist/security/secrets.d.ts +5 -0
  113. package/dist/security/secrets.d.ts.map +1 -0
  114. package/dist/security/secrets.js +109 -0
  115. package/dist/security/secrets.js.map +1 -0
  116. package/dist/security/taint.d.ts +14 -0
  117. package/dist/security/taint.d.ts.map +1 -0
  118. package/dist/security/taint.js +517 -0
  119. package/dist/security/taint.js.map +1 -0
  120. package/dist/tools/browser.d.ts +110 -0
  121. package/dist/tools/browser.d.ts.map +1 -0
  122. package/dist/tools/browser.js +2105 -0
  123. package/dist/tools/browser.js.map +1 -0
  124. package/dist/tools/db.d.ts +106 -0
  125. package/dist/tools/db.d.ts.map +1 -0
  126. package/dist/tools/db.js +1526 -0
  127. package/dist/tools/db.js.map +1 -0
  128. package/dist/tools/fs.d.ts +5 -0
  129. package/dist/tools/fs.d.ts.map +1 -0
  130. package/dist/tools/fs.js +165 -0
  131. package/dist/tools/fs.js.map +1 -0
  132. package/dist/tools/git.d.ts +3 -0
  133. package/dist/tools/git.d.ts.map +1 -0
  134. package/dist/tools/git.js +50 -0
  135. package/dist/tools/git.js.map +1 -0
  136. package/dist/tools/http.d.ts +3 -0
  137. package/dist/tools/http.d.ts.map +1 -0
  138. package/dist/tools/http.js +74 -0
  139. package/dist/tools/http.js.map +1 -0
  140. package/dist/tools/index.d.ts +5 -0
  141. package/dist/tools/index.d.ts.map +1 -0
  142. package/dist/tools/index.js +72 -0
  143. package/dist/tools/index.js.map +1 -0
  144. package/dist/tools/risk.d.ts +9 -0
  145. package/dist/tools/risk.d.ts.map +1 -0
  146. package/dist/tools/risk.js +156 -0
  147. package/dist/tools/risk.js.map +1 -0
  148. package/dist/tools/search.d.ts +4 -0
  149. package/dist/tools/search.d.ts.map +1 -0
  150. package/dist/tools/search.js +133 -0
  151. package/dist/tools/search.js.map +1 -0
  152. package/dist/tools/security.d.ts +5 -0
  153. package/dist/tools/security.d.ts.map +1 -0
  154. package/dist/tools/security.js +147 -0
  155. package/dist/tools/security.js.map +1 -0
  156. package/dist/tools/shell.d.ts +10 -0
  157. package/dist/tools/shell.d.ts.map +1 -0
  158. package/dist/tools/shell.js +189 -0
  159. package/dist/tools/shell.js.map +1 -0
  160. package/dist/tools/types.d.ts +45 -0
  161. package/dist/tools/types.d.ts.map +1 -0
  162. package/dist/tools/types.js +2 -0
  163. package/dist/tools/types.js.map +1 -0
  164. package/dist/ui/banner.d.ts +24 -0
  165. package/dist/ui/banner.d.ts.map +1 -0
  166. package/dist/ui/banner.js +394 -0
  167. package/dist/ui/banner.js.map +1 -0
  168. package/dist/ui/colors.d.ts +18 -0
  169. package/dist/ui/colors.d.ts.map +1 -0
  170. package/dist/ui/colors.js +19 -0
  171. package/dist/ui/colors.js.map +1 -0
  172. package/dist/ui/diff.d.ts +14 -0
  173. package/dist/ui/diff.d.ts.map +1 -0
  174. package/dist/ui/diff.js +55 -0
  175. package/dist/ui/diff.js.map +1 -0
  176. package/dist/ui/markdown.d.ts +2 -0
  177. package/dist/ui/markdown.d.ts.map +1 -0
  178. package/dist/ui/markdown.js +32 -0
  179. package/dist/ui/markdown.js.map +1 -0
  180. package/dist/ui/spinner.d.ts +14 -0
  181. package/dist/ui/spinner.d.ts.map +1 -0
  182. package/dist/ui/spinner.js +59 -0
  183. package/dist/ui/spinner.js.map +1 -0
  184. package/package.json +61 -4
@@ -0,0 +1,189 @@
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ import pc from "picocolors";
3
+ import { assessShellRisk } from "./risk.js";
4
+ const INTERACTIVE_PROMPT_TAIL = /(confirm|continue|proceed|overwrite|password|passphrase|enter\s+.*:|\[[yn]\/[yn]\]|\(yes\/no\)|:\s*$|\?\s*$)/i;
5
+ function terminateProcessTree(pid) {
6
+ if (!pid)
7
+ return;
8
+ if (process.platform === "win32") {
9
+ try {
10
+ spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
11
+ return;
12
+ }
13
+ catch {
14
+ }
15
+ }
16
+ try {
17
+ process.kill(-pid, "SIGTERM");
18
+ }
19
+ catch {
20
+ try {
21
+ process.kill(pid, "SIGKILL");
22
+ }
23
+ catch {
24
+ }
25
+ }
26
+ }
27
+ export async function runShellProcess(command, workingDirectory, options = {}) {
28
+ const timeoutMs = Math.max(500, options.timeoutMs || 30000);
29
+ if (options.signal?.aborted) {
30
+ return { success: false, output: "", error: "Command aborted.", exitCode: 130 };
31
+ }
32
+ return new Promise((resolvePromise) => {
33
+ const child = spawn(command, {
34
+ cwd: workingDirectory,
35
+ shell: true,
36
+ detached: process.platform !== "win32",
37
+ windowsHide: true,
38
+ stdio: ["pipe", "pipe", "pipe"],
39
+ });
40
+ try {
41
+ child.stdin?.end();
42
+ }
43
+ catch {
44
+ }
45
+ let stdout = "";
46
+ let stderr = "";
47
+ let settled = false;
48
+ let timedOut = false;
49
+ let interactiveStall = false;
50
+ let aborted = false;
51
+ const finish = (code) => {
52
+ if (settled)
53
+ return;
54
+ settled = true;
55
+ clearTimeout(hardTimer);
56
+ if (idleTimer)
57
+ clearTimeout(idleTimer);
58
+ options.signal?.removeEventListener("abort", onAbort);
59
+ let out = stdout;
60
+ let err = stderr;
61
+ if (out.length > 8000)
62
+ out = out.slice(0, 8000) + "\n... [Output truncated]";
63
+ if (err.length > 4000)
64
+ err = err.slice(0, 4000) + "\n... [Stderr truncated]";
65
+ const finalCode = aborted ? 130 : (interactiveStall || timedOut ? 124 : code);
66
+ const statusNote = aborted
67
+ ? "Command aborted by user (Ctrl+C)."
68
+ : interactiveStall
69
+ ? "Command aborted after interactive prompt idle wait (non-interactive shell)."
70
+ : timedOut
71
+ ? `Command timed out after ${timeoutMs}ms.`
72
+ : "";
73
+ const parts = [
74
+ out ? `Stdout:\n${out.trimEnd()}` : "",
75
+ err ? `Stderr:\n${err.trimEnd()}` : "",
76
+ statusNote,
77
+ `Exit Code: ${finalCode}`,
78
+ ].filter(Boolean);
79
+ resolvePromise({
80
+ success: finalCode === 0,
81
+ output: parts.join("\n\n"),
82
+ error: finalCode === 0 ? undefined : statusNote || `Command exited with code ${finalCode}`,
83
+ exitCode: finalCode,
84
+ });
85
+ };
86
+ let idleTimer = null;
87
+ const resetIdleCheck = () => {
88
+ if (idleTimer)
89
+ clearTimeout(idleTimer);
90
+ idleTimer = setTimeout(() => {
91
+ const tail = (stdout + "\n" + stderr).slice(-300).trimEnd();
92
+ if (tail && INTERACTIVE_PROMPT_TAIL.test(tail)) {
93
+ interactiveStall = true;
94
+ terminateProcessTree(child.pid);
95
+ finish(124);
96
+ }
97
+ }, 5000);
98
+ idleTimer.unref?.();
99
+ };
100
+ const hardTimer = setTimeout(() => {
101
+ timedOut = true;
102
+ terminateProcessTree(child.pid);
103
+ finish(124);
104
+ }, timeoutMs);
105
+ hardTimer.unref?.();
106
+ const onAbort = () => {
107
+ aborted = true;
108
+ terminateProcessTree(child.pid);
109
+ finish(130);
110
+ };
111
+ options.signal?.addEventListener("abort", onAbort, { once: true });
112
+ child.stdout?.on("data", (chunk) => {
113
+ const text = chunk.toString("utf8");
114
+ if (stdout.length < 32768)
115
+ stdout += text;
116
+ if (options.streamToStdout)
117
+ process.stdout.write(text);
118
+ resetIdleCheck();
119
+ });
120
+ child.stderr?.on("data", (chunk) => {
121
+ const text = chunk.toString("utf8");
122
+ if (stderr.length < 16384)
123
+ stderr += text;
124
+ if (options.streamToStdout)
125
+ process.stderr.write(text);
126
+ resetIdleCheck();
127
+ });
128
+ child.on("error", (err) => {
129
+ stderr += err.message;
130
+ finish(1);
131
+ });
132
+ child.on("close", (code) => {
133
+ finish(typeof code === "number" ? code : 0);
134
+ });
135
+ });
136
+ }
137
+ export const runCommandTool = {
138
+ definition: {
139
+ name: "run_command",
140
+ description: "Execute a shell command in the project directory and return stdout/stderr.",
141
+ parameters: {
142
+ type: "object",
143
+ properties: {
144
+ command: { type: "string", description: "The shell command line to execute." },
145
+ timeoutMs: { type: "number", description: "Optional timeout in milliseconds (default: 30000)." }
146
+ },
147
+ required: ["command"]
148
+ }
149
+ },
150
+ async execute(params, context) {
151
+ const cmd = String(params.command || "").trim();
152
+ if (!cmd) {
153
+ return { success: false, output: "", error: "run_command requires a non-empty command." };
154
+ }
155
+ const risk = assessShellRisk(cmd);
156
+ const sessionAutoAllowed = !risk.destructive && context.sessionApprovedTools?.has("run_command");
157
+ const needsApproval = risk.destructive ? Boolean(context.requestApproval || !context.autoApproveRun) : (!context.autoApproveRun && !sessionAutoAllowed);
158
+ if (needsApproval) {
159
+ if (!context.requestApproval) {
160
+ return {
161
+ success: false,
162
+ output: "",
163
+ error: risk.destructive
164
+ ? `Blocked destructive command (${risk.reason}). Interactive approval required.`
165
+ : "Command rejected: run_command requires approval (run interactively or pass --yes)."
166
+ };
167
+ }
168
+ const decision = await context.requestApproval({
169
+ tool: "run_command",
170
+ title: risk.destructive ? `Destructive command blocked for confirmation (${risk.reason})` : "Allow shell command execution?",
171
+ detail: cmd,
172
+ preview: `${pc.dim("$")} ${pc.bold(cmd)}`,
173
+ destructive: risk.destructive,
174
+ sessionKey: risk.destructive ? undefined : "run_command",
175
+ });
176
+ if (decision === "deny") {
177
+ return { success: false, output: "", error: "Command execution declined by user." };
178
+ }
179
+ if (decision === "always" && !risk.destructive) {
180
+ context.sessionApprovedTools?.add("run_command");
181
+ }
182
+ }
183
+ return runShellProcess(cmd, context.workingDirectory, {
184
+ timeoutMs: params.timeoutMs || 30000,
185
+ signal: context.signal,
186
+ });
187
+ }
188
+ };
189
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/tools/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG5C,MAAM,uBAAuB,GAAG,+GAA+G,CAAC;AAEhJ,SAAS,oBAAoB,CAAC,GAAuB;IACnD,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,SAAS,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YACjG,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;QACT,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;QACT,CA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AM,QAAQ,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC;gBAC7C,IAAI,EAAE,aAAa;gBACnB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,iDAAiD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,gCAAgC;gBAC5H,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACzC,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa;aACzD,CAAC,CAAC;YACH,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACxB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,qCAAqC,EAAE,CAAC;YACtF,CAAC;YACD,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC/C,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,gBAAgB,EAAE;YACpD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,KAAK;YACpC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,45 @@
1
+ export type ApprovalDecision = "once" | "always" | "deny";
2
+ export interface ApprovalRequest {
3
+ tool: string;
4
+ title: string;
5
+ detail: string;
6
+ preview?: string;
7
+ destructive?: boolean;
8
+ sessionKey?: string;
9
+ }
10
+ export interface ToolDefinition {
11
+ name: string;
12
+ description: string;
13
+ parameters: {
14
+ type: "object";
15
+ properties: Record<string, {
16
+ type: string;
17
+ description: string;
18
+ enum?: string[];
19
+ items?: {
20
+ type: string;
21
+ };
22
+ }>;
23
+ required: string[];
24
+ };
25
+ }
26
+ export interface ToolExecutionContext {
27
+ workingDirectory: string;
28
+ autoApproveRead?: boolean;
29
+ autoApproveWrite?: boolean;
30
+ autoApproveRun?: boolean;
31
+ signal?: AbortSignal;
32
+ sessionApprovedTools?: Set<string>;
33
+ requestApproval?: (request: ApprovalRequest) => Promise<ApprovalDecision>;
34
+ }
35
+ export interface ToolResult {
36
+ success: boolean;
37
+ output: string;
38
+ error?: string;
39
+ truncated?: boolean;
40
+ }
41
+ export interface Tool {
42
+ definition: ToolDefinition;
43
+ execute(params: Record<string, any>, context: ToolExecutionContext): Promise<ToolResult>;
44
+ }
45
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;YACzB,IAAI,EAAE,MAAM,CAAC;YACb,WAAW,EAAE,MAAM,CAAC;YACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;YAChB,KAAK,CAAC,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC;SAC1B,CAAC,CAAC;QACH,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC3E;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1F"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ export type ColorMode = "truecolor" | "ansi256" | "none";
2
+ export interface RgbaImage {
3
+ width: number;
4
+ height: number;
5
+ data: Uint8Array;
6
+ }
7
+ export interface Pixel {
8
+ r: number;
9
+ g: number;
10
+ b: number;
11
+ a: number;
12
+ }
13
+ export interface LogoRenderOptions {
14
+ cols?: number;
15
+ pixelRows?: number;
16
+ logoPath?: string;
17
+ colorMode?: ColorMode;
18
+ }
19
+ export declare function decodePngRgba(buffer: Buffer): RgbaImage | null;
20
+ export declare function detectColorDepth(explicit?: ColorMode): ColorMode;
21
+ export declare function renderLogoLines(options?: LogoRenderOptions): string[];
22
+ export declare function formatBannerLines(version?: string, options?: LogoRenderOptions): string[];
23
+ export declare function printBanner(version?: string): void;
24
+ //# sourceMappingURL=banner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../../src/ui/banner.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAyCD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAsH9D;AAwCD,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAoChE;AAwDD,wBAAgB,eAAe,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,CAuDzE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,SAAc,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,CAmClG;AAED,wBAAgB,WAAW,CAAC,OAAO,SAAc,QAMhD"}
@@ -0,0 +1,394 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { inflateSync } from "node:zlib";
5
+ import pc from "picocolors";
6
+ const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
7
+ let cachedImagePath = null;
8
+ let cachedImageData = null;
9
+ function resolveLogoPath(explicitPath) {
10
+ if (explicitPath) {
11
+ return existsSync(explicitPath) ? explicitPath : null;
12
+ }
13
+ const here = dirname(fileURLToPath(import.meta.url));
14
+ const candidates = [
15
+ join(here, "..", "..", "assets", "logo.png"),
16
+ join(here, "..", "..", "assets", "wide-logo.png"),
17
+ join(process.cwd(), "assets", "logo.png"),
18
+ ];
19
+ for (const candidate of candidates) {
20
+ if (existsSync(candidate)) {
21
+ return candidate;
22
+ }
23
+ }
24
+ return null;
25
+ }
26
+ function paethPredictor(a, b, c) {
27
+ const p = a + b - c;
28
+ const pa = Math.abs(p - a);
29
+ const pb = Math.abs(p - b);
30
+ const pcDiff = Math.abs(p - c);
31
+ if (pa <= pb && pa <= pcDiff)
32
+ return a;
33
+ return pb <= pcDiff ? b : c;
34
+ }
35
+ function channelsForColorType(colorType) {
36
+ if (colorType === 6)
37
+ return 4;
38
+ if (colorType === 2)
39
+ return 3;
40
+ if (colorType === 4)
41
+ return 2;
42
+ if (colorType === 0 || colorType === 3)
43
+ return 1;
44
+ return 0;
45
+ }
46
+ export function decodePngRgba(buffer) {
47
+ if (buffer.length < 33 || !buffer.subarray(0, 8).equals(PNG_SIGNATURE)) {
48
+ return null;
49
+ }
50
+ let offset = 8;
51
+ let width = 0;
52
+ let height = 0;
53
+ let bitDepth = 0;
54
+ let colorType = 0;
55
+ let interlace = 0;
56
+ let palette = null;
57
+ let trns = null;
58
+ const idatChunks = [];
59
+ while (offset + 12 <= buffer.length) {
60
+ const length = buffer.readUInt32BE(offset);
61
+ const type = buffer.subarray(offset + 4, offset + 8).toString("ascii");
62
+ const dataStart = offset + 8;
63
+ const dataEnd = dataStart + length;
64
+ if (dataEnd + 4 > buffer.length)
65
+ return null;
66
+ const chunkData = buffer.subarray(dataStart, dataEnd);
67
+ if (type === "IHDR") {
68
+ if (length < 13)
69
+ return null;
70
+ width = chunkData.readUInt32BE(0);
71
+ height = chunkData.readUInt32BE(4);
72
+ bitDepth = chunkData[8];
73
+ colorType = chunkData[9];
74
+ interlace = chunkData[12];
75
+ }
76
+ else if (type === "PLTE") {
77
+ palette = chunkData;
78
+ }
79
+ else if (type === "tRNS") {
80
+ trns = chunkData;
81
+ }
82
+ else if (type === "IDAT") {
83
+ idatChunks.push(chunkData);
84
+ }
85
+ else if (type === "IEND") {
86
+ break;
87
+ }
88
+ offset = dataEnd + 4;
89
+ }
90
+ if (width <= 0 || height <= 0 || bitDepth !== 8 || interlace !== 0 || idatChunks.length === 0) {
91
+ return null;
92
+ }
93
+ const bpp = channelsForColorType(colorType);
94
+ if (bpp === 0)
95
+ return null;
96
+ let raw;
97
+ try {
98
+ raw = inflateSync(Buffer.concat(idatChunks));
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ const stride = width * bpp;
104
+ if (raw.length < height * (stride + 1))
105
+ return null;
106
+ const pixels = new Uint8Array(height * stride);
107
+ for (let y = 0; y < height; y++) {
108
+ const filter = raw[y * (stride + 1)];
109
+ const rowIn = y * (stride + 1) + 1;
110
+ const rowOut = y * stride;
111
+ const prevOut = (y - 1) * stride;
112
+ for (let x = 0; x < stride; x++) {
113
+ const value = raw[rowIn + x];
114
+ const a = x >= bpp ? pixels[rowOut + x - bpp] : 0;
115
+ const b = y > 0 ? pixels[prevOut + x] : 0;
116
+ const c = x >= bpp && y > 0 ? pixels[prevOut + x - bpp] : 0;
117
+ let decoded = value;
118
+ if (filter === 1)
119
+ decoded = (value + a) & 255;
120
+ else if (filter === 2)
121
+ decoded = (value + b) & 255;
122
+ else if (filter === 3)
123
+ decoded = (value + ((a + b) >> 1)) & 255;
124
+ else if (filter === 4)
125
+ decoded = (value + paethPredictor(a, b, c)) & 255;
126
+ else if (filter !== 0)
127
+ return null;
128
+ pixels[rowOut + x] = decoded;
129
+ }
130
+ }
131
+ if (colorType === 6) {
132
+ return { width, height, data: pixels };
133
+ }
134
+ const rgba = new Uint8Array(width * height * 4);
135
+ for (let i = 0; i < width * height; i++) {
136
+ const out = i * 4;
137
+ if (colorType === 2) {
138
+ const src = i * 3;
139
+ rgba[out] = pixels[src];
140
+ rgba[out + 1] = pixels[src + 1];
141
+ rgba[out + 2] = pixels[src + 2];
142
+ rgba[out + 3] = 255;
143
+ }
144
+ else if (colorType === 4) {
145
+ const src = i * 2;
146
+ rgba[out] = pixels[src];
147
+ rgba[out + 1] = pixels[src];
148
+ rgba[out + 2] = pixels[src];
149
+ rgba[out + 3] = pixels[src + 1];
150
+ }
151
+ else if (colorType === 0) {
152
+ const v = pixels[i];
153
+ rgba[out] = v;
154
+ rgba[out + 1] = v;
155
+ rgba[out + 2] = v;
156
+ rgba[out + 3] = 255;
157
+ }
158
+ else if (colorType === 3 && palette) {
159
+ const idx = pixels[i];
160
+ const pIdx = idx * 3;
161
+ if (pIdx + 2 < palette.length) {
162
+ rgba[out] = palette[pIdx];
163
+ rgba[out + 1] = palette[pIdx + 1];
164
+ rgba[out + 2] = palette[pIdx + 2];
165
+ }
166
+ rgba[out + 3] = trns && idx < trns.length ? trns[idx] : 255;
167
+ }
168
+ }
169
+ return { width, height, data: rgba };
170
+ }
171
+ function fallbackBitmap() {
172
+ const empty = { r: 0, g: 0, b: 0, a: 0 };
173
+ const white = { r: 255, g: 255, b: 255, a: 255 };
174
+ const blue = { r: 94, g: 129, b: 172, a: 255 };
175
+ const grid = [
176
+ empty, white, empty,
177
+ blue, white, white,
178
+ blue, blue, empty,
179
+ ];
180
+ const data = new Uint8Array(grid.length * 4);
181
+ for (let i = 0; i < grid.length; i++) {
182
+ data[i * 4] = grid[i].r;
183
+ data[i * 4 + 1] = grid[i].g;
184
+ data[i * 4 + 2] = grid[i].b;
185
+ data[i * 4 + 3] = grid[i].a;
186
+ }
187
+ return { width: 3, height: 3, data };
188
+ }
189
+ function loadLogoImage(explicitPath) {
190
+ const resolved = resolveLogoPath(explicitPath);
191
+ if (resolved) {
192
+ if (cachedImagePath === resolved && cachedImageData) {
193
+ return cachedImageData;
194
+ }
195
+ try {
196
+ const decoded = decodePngRgba(readFileSync(resolved));
197
+ if (decoded) {
198
+ cachedImagePath = resolved;
199
+ cachedImageData = decoded;
200
+ return decoded;
201
+ }
202
+ }
203
+ catch {
204
+ }
205
+ }
206
+ return fallbackBitmap();
207
+ }
208
+ export function detectColorDepth(explicit) {
209
+ if (explicit)
210
+ return explicit;
211
+ if (process.env.NO_COLOR !== undefined ||
212
+ process.env.NODE_DISABLE_COLORS !== undefined ||
213
+ process.argv.includes("--no-color")) {
214
+ return "none";
215
+ }
216
+ const forceColor = process.env.FORCE_COLOR;
217
+ if (forceColor === "0")
218
+ return "none";
219
+ if (!process.stdout.isTTY && !forceColor) {
220
+ return "truecolor";
221
+ }
222
+ const colorTerm = (process.env.COLORTERM || "").toLowerCase();
223
+ const termProgram = process.env.TERM_PROGRAM || "";
224
+ const term = (process.env.TERM || "").toLowerCase();
225
+ if (colorTerm === "truecolor" ||
226
+ colorTerm === "24bit" ||
227
+ Boolean(process.env.WT_SESSION) ||
228
+ (process.platform === "win32" && termProgram !== "Apple_Terminal") ||
229
+ term.includes("24bit") ||
230
+ term.includes("truecolor") ||
231
+ term.includes("kitty") ||
232
+ term.includes("alacritty") ||
233
+ term.includes("wezterm") ||
234
+ termProgram === "vscode" ||
235
+ termProgram === "iTerm.app" ||
236
+ termProgram === "WezTerm" ||
237
+ termProgram === "Ghostty" ||
238
+ termProgram === "Hyper") {
239
+ return "truecolor";
240
+ }
241
+ return "ansi256";
242
+ }
243
+ function rgbToAnsi256(r, g, b) {
244
+ if (r === g && g === b) {
245
+ if (r < 8)
246
+ return 16;
247
+ if (r > 248)
248
+ return 231;
249
+ return Math.round(((r - 8) / 247) * 24) + 232;
250
+ }
251
+ const ri = Math.round((r / 255) * 5);
252
+ const gi = Math.round((g / 255) * 5);
253
+ const bi = Math.round((b / 255) * 5);
254
+ return 16 + 36 * ri + 6 * gi + bi;
255
+ }
256
+ function fgEscape(p, mode) {
257
+ if (mode === "truecolor")
258
+ return `\x1b[38;2;${p.r};${p.g};${p.b}m`;
259
+ if (mode === "ansi256")
260
+ return `\x1b[38;5;${rgbToAnsi256(p.r, p.g, p.b)}m`;
261
+ return "";
262
+ }
263
+ function bgEscape(p, mode) {
264
+ if (mode === "truecolor")
265
+ return `\x1b[48;2;${p.r};${p.g};${p.b}m`;
266
+ if (mode === "ansi256")
267
+ return `\x1b[48;5;${rgbToAnsi256(p.r, p.g, p.b)}m`;
268
+ return "";
269
+ }
270
+ function samplePixel(image, gx, gy, cols, pixelRows) {
271
+ const x = Math.min(image.width - 1, Math.max(0, Math.floor(((gx + 0.5) / cols) * image.width)));
272
+ const y = Math.min(image.height - 1, Math.max(0, Math.floor(((gy + 0.5) / pixelRows) * image.height)));
273
+ const idx = (y * image.width + x) * 4;
274
+ return {
275
+ r: image.data[idx],
276
+ g: image.data[idx + 1],
277
+ b: image.data[idx + 2],
278
+ a: image.data[idx + 3],
279
+ };
280
+ }
281
+ function sameColor(a, b) {
282
+ return Math.abs(a.r - b.r) <= 4 && Math.abs(a.g - b.g) <= 4 && Math.abs(a.b - b.b) <= 4;
283
+ }
284
+ function isOpaque(p) {
285
+ return p.a >= 128;
286
+ }
287
+ function monochromeGlyph(top, bot) {
288
+ const topOn = isOpaque(top);
289
+ const botOn = isOpaque(bot);
290
+ if (!topOn && !botOn)
291
+ return " ";
292
+ if (topOn && !botOn)
293
+ return "▀";
294
+ if (!topOn && botOn)
295
+ return "▄";
296
+ const luma = (top.r + top.g + top.b + bot.r + bot.g + bot.b) / 6;
297
+ return luma >= 190 ? "█" : "▓";
298
+ }
299
+ export function renderLogoLines(options = {}) {
300
+ const image = loadLogoImage(options.logoPath);
301
+ const cols = Math.max(6, options.cols ?? 12);
302
+ const rawRows = options.pixelRows ?? Math.max(4, Math.round((cols * image.height) / image.width));
303
+ const pixelRows = rawRows % 2 === 0 ? rawRows : rawRows + 1;
304
+ const mode = detectColorDepth(options.colorMode);
305
+ const lines = [];
306
+ for (let gy = 0; gy < pixelRows; gy += 2) {
307
+ let row = "";
308
+ let activeStyle = "";
309
+ for (let gx = 0; gx < cols; gx++) {
310
+ const top = samplePixel(image, gx, gy, cols, pixelRows);
311
+ const bot = samplePixel(image, gx, gy + 1, cols, pixelRows);
312
+ if (mode === "none") {
313
+ row += monochromeGlyph(top, bot);
314
+ continue;
315
+ }
316
+ const topOn = isOpaque(top);
317
+ const botOn = isOpaque(bot);
318
+ let style = "";
319
+ let ch = " ";
320
+ if (topOn && botOn) {
321
+ if (sameColor(top, bot)) {
322
+ style = fgEscape(top, mode);
323
+ ch = "█";
324
+ }
325
+ else {
326
+ style = fgEscape(top, mode) + bgEscape(bot, mode);
327
+ ch = "▀";
328
+ }
329
+ }
330
+ else if (topOn) {
331
+ style = fgEscape(top, mode);
332
+ ch = "▀";
333
+ }
334
+ else if (botOn) {
335
+ style = fgEscape(bot, mode);
336
+ ch = "▄";
337
+ }
338
+ if (style !== activeStyle) {
339
+ if (activeStyle)
340
+ row += "\x1b[0m";
341
+ if (style)
342
+ row += style;
343
+ activeStyle = style;
344
+ }
345
+ row += ch;
346
+ }
347
+ if (activeStyle)
348
+ row += "\x1b[0m";
349
+ lines.push(row);
350
+ }
351
+ return lines;
352
+ }
353
+ export function formatBannerLines(version = "0.5151126", options = {}) {
354
+ const logoLines = renderLogoLines(options);
355
+ const nordAccent = (text) => {
356
+ const mode = detectColorDepth(options.colorMode);
357
+ if (mode === "truecolor")
358
+ return `\x1b[38;2;94;129;172m${text}\x1b[0m`;
359
+ if (mode === "ansi256")
360
+ return `\x1b[38;5;67m${text}\x1b[0m`;
361
+ return text;
362
+ };
363
+ const titleLine = `${pc.bold(pc.white("Wide"))} ${pc.dim(`v${version}`)}`;
364
+ const subtitleLine = pc.gray("Security-First Autonomous AI Agent");
365
+ const hintLine = `${pc.dim("Type")} ${nordAccent("/help")} ${pc.dim("for commands or")} ${nordAccent("exit")} ${pc.dim("to quit.")}`;
366
+ const columns = process.stdout.columns || 80;
367
+ const sideBySide = columns >= 68 && logoLines.length >= 5;
368
+ if (!sideBySide) {
369
+ return [
370
+ ...logoLines.map((line) => ` ${line}`),
371
+ "",
372
+ ` ${titleLine}`,
373
+ ` ${subtitleLine}`,
374
+ ` ${hintLine}`,
375
+ ];
376
+ }
377
+ const infoMap = new Map([
378
+ [1, titleLine],
379
+ [2, subtitleLine],
380
+ [4, hintLine],
381
+ ]);
382
+ return logoLines.map((line, index) => {
383
+ const info = infoMap.get(index);
384
+ return info ? ` ${line} ${info}` : ` ${line}`;
385
+ });
386
+ }
387
+ export function printBanner(version = "0.5151126") {
388
+ console.log("");
389
+ for (const line of formatBannerLines(version)) {
390
+ console.log(line);
391
+ }
392
+ console.log("");
393
+ }
394
+ //# sourceMappingURL=banner.js.map