@denizokcu/haze 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +31 -29
- package/dist/cli/commands/chat.js +106 -48
- package/dist/cli/commands/commands.js +15 -1
- package/dist/cli/commands/streaming.d.ts +4 -0
- package/dist/cli/commands/streaming.js +242 -111
- package/dist/config/contextFiles.d.ts +6 -0
- package/dist/config/contextFiles.js +47 -16
- package/dist/config/providers.d.ts +2 -5
- package/dist/config/providers.js +16 -12
- package/dist/core/agent/requestAssembly.js +12 -1
- package/dist/core/agent/toolOutputStore.d.ts +6 -1
- package/dist/core/agent/toolOutputStore.js +33 -1
- package/dist/core/bashOutput/ansi.d.ts +1 -0
- package/dist/core/bashOutput/ansi.js +7 -0
- package/dist/core/bashOutput/command.d.ts +2 -0
- package/dist/core/bashOutput/command.js +62 -0
- package/dist/core/bashOutput/lineFilter.d.ts +25 -0
- package/dist/core/bashOutput/lineFilter.js +62 -0
- package/dist/core/bashOutput/reducers/content.d.ts +3 -0
- package/dist/core/bashOutput/reducers/content.js +134 -0
- package/dist/core/bashOutput/reducers/git.d.ts +1 -0
- package/dist/core/bashOutput/reducers/git.js +147 -0
- package/dist/core/bashOutput/reducers/search.d.ts +7 -0
- package/dist/core/bashOutput/reducers/search.js +76 -0
- package/dist/core/bashOutput/reducers/validation.d.ts +2 -0
- package/dist/core/bashOutput/reducers/validation.js +41 -0
- package/dist/core/bashOutput/registry.d.ts +4 -0
- package/dist/core/bashOutput/registry.js +126 -0
- package/dist/core/bashOutput/types.d.ts +46 -0
- package/dist/core/bashOutput/types.js +1 -0
- package/dist/core/goal/completionPolicy.d.ts +1 -0
- package/dist/core/goal/completionPolicy.js +4 -0
- package/dist/core/safety/urlGuard.d.ts +37 -0
- package/dist/core/safety/urlGuard.js +206 -0
- package/dist/core/subagent/subagentRunner.d.ts +1 -1
- package/dist/core/subagent/subagentRunner.js +2 -2
- package/dist/core/toolOutput/reduction.d.ts +25 -0
- package/dist/core/toolOutput/reduction.js +23 -0
- package/dist/llm/client.d.ts +2 -2
- package/dist/llm/client.js +6 -4
- package/dist/llm/hazeTools.d.ts +133 -16
- package/dist/llm/hazeTools.js +205 -31
- package/dist/llm/initPrompt.js +2 -1
- package/dist/llm/systemPrompt.js +3 -1
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/webFetch.d.ts +57 -0
- package/dist/llm/webFetch.js +270 -0
- package/dist/ui/components/MarkdownText.d.ts +2 -0
- package/dist/ui/components/MarkdownText.js +116 -3
- package/package.json +17 -10
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { validateUrl } from '../core/safety/urlGuard.js';
|
|
2
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
3
|
+
const DEFAULT_MAX_BYTES = 2_000_000;
|
|
4
|
+
const DEFAULT_MAX_REDIRECTS = 5;
|
|
5
|
+
const USER_AGENT = 'Haze/0.5 (+https://github.com/DenizOkcu/haze)';
|
|
6
|
+
/** Error thrown when a URL is rejected by the SSRF guard. */
|
|
7
|
+
export class BlockedUrlError extends Error {
|
|
8
|
+
reasonCode;
|
|
9
|
+
validation;
|
|
10
|
+
constructor(validation) {
|
|
11
|
+
const reason = !validation.ok ? validation.reason : 'URL blocked';
|
|
12
|
+
super(reason);
|
|
13
|
+
this.name = 'BlockedUrlError';
|
|
14
|
+
this.reasonCode = 'blocked_url';
|
|
15
|
+
this.validation = validation;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Minimal fallback HTML→text when defuddle fails on malformed input. */
|
|
19
|
+
function fallbackStripTags(html) {
|
|
20
|
+
return html
|
|
21
|
+
.replace(/<script[\s\S]*?<\/script>/gi, '')
|
|
22
|
+
.replace(/<style[\s\S]*?<\/style>/gi, '')
|
|
23
|
+
.replace(/<nav[\s\S]*?<\/nav>/gi, '')
|
|
24
|
+
.replace(/<header[\s\S]*?<\/header>/gi, '')
|
|
25
|
+
.replace(/<footer[\s\S]*?<\/footer>/gi, '')
|
|
26
|
+
.replace(/<[^>]+>/g, '')
|
|
27
|
+
.replace(/ /g, ' ')
|
|
28
|
+
.replace(/&/g, '&')
|
|
29
|
+
.replace(/</g, '<')
|
|
30
|
+
.replace(/>/g, '>')
|
|
31
|
+
.replace(/"/g, '"')
|
|
32
|
+
.replace(/'/g, "'")
|
|
33
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
34
|
+
.trim();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extract readable content from an HTML string. Returns markdown via defuddle
|
|
38
|
+
* when possible, falling back to a tag strip. Also surfaces the page title so
|
|
39
|
+
* the tool can prefix the content.
|
|
40
|
+
*/
|
|
41
|
+
export async function extractContent(html, url) {
|
|
42
|
+
try {
|
|
43
|
+
const { Defuddle } = await import('defuddle/node');
|
|
44
|
+
const result = await Defuddle(html, url, { markdown: true, useAsync: false });
|
|
45
|
+
const content = typeof result.content === 'string' && result.content.trim().length > 0
|
|
46
|
+
? result.content
|
|
47
|
+
: fallbackStripTags(html);
|
|
48
|
+
const title = typeof result.title === 'string' && result.title.trim().length > 0 ? result.title.trim() : undefined;
|
|
49
|
+
return { content, title };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { content: fallbackStripTags(html) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function prettyJson(raw) {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(JSON.parse(raw), null, 2);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function classifyContentType(contentType) {
|
|
64
|
+
const ct = contentType.toLowerCase();
|
|
65
|
+
if (ct.includes('json') || ct.includes('+json'))
|
|
66
|
+
return 'json';
|
|
67
|
+
if (ct.includes('html') || ct.includes('xhtml'))
|
|
68
|
+
return 'html';
|
|
69
|
+
return 'text';
|
|
70
|
+
}
|
|
71
|
+
async function readBodyCapped(response, maxBytes, abortController) {
|
|
72
|
+
const body = response.body;
|
|
73
|
+
if (body == null || typeof body.getReader !== 'function') {
|
|
74
|
+
// No streamable body; read as text once and cap.
|
|
75
|
+
const text = await response.text();
|
|
76
|
+
const bytes = Buffer.byteLength(text, 'utf8');
|
|
77
|
+
if (bytes > maxBytes) {
|
|
78
|
+
return { text: text.slice(0, maxBytes), bytes: maxBytes, truncated: true };
|
|
79
|
+
}
|
|
80
|
+
return { text, bytes, truncated: false };
|
|
81
|
+
}
|
|
82
|
+
const reader = body.getReader();
|
|
83
|
+
const decoder = new TextDecoder('utf-8');
|
|
84
|
+
let text = '';
|
|
85
|
+
let received = 0;
|
|
86
|
+
let truncated = false;
|
|
87
|
+
try {
|
|
88
|
+
// Stream with a byte counter; stop and mark truncated once the ceiling is hit.
|
|
89
|
+
while (true) {
|
|
90
|
+
const { done, value } = await reader.read();
|
|
91
|
+
if (done)
|
|
92
|
+
break;
|
|
93
|
+
const chunkBytes = value.byteLength;
|
|
94
|
+
received += chunkBytes;
|
|
95
|
+
if (received > maxBytes) {
|
|
96
|
+
const already = received - chunkBytes;
|
|
97
|
+
const remaining = Math.max(0, maxBytes - already);
|
|
98
|
+
if (remaining > 0)
|
|
99
|
+
text += decoder.decode(value.slice(0, remaining), { stream: true });
|
|
100
|
+
text += decoder.decode();
|
|
101
|
+
truncated = true;
|
|
102
|
+
try {
|
|
103
|
+
reader.cancel();
|
|
104
|
+
}
|
|
105
|
+
catch { /* ignore */ }
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
text += decoder.decode(value, { stream: true });
|
|
109
|
+
}
|
|
110
|
+
if (!truncated)
|
|
111
|
+
text += decoder.decode();
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
try {
|
|
115
|
+
reader.releaseLock();
|
|
116
|
+
}
|
|
117
|
+
catch { /* ignore */ }
|
|
118
|
+
// If we hit the cap, abort the fetch to free the underlying connection.
|
|
119
|
+
if (truncated && !abortController.signal.aborted)
|
|
120
|
+
abortController.abort();
|
|
121
|
+
}
|
|
122
|
+
return { text, bytes: Math.min(received, maxBytes), truncated };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Fetch a public http(s) URL and return readable content.
|
|
126
|
+
*
|
|
127
|
+
* Non-2xx responses are still returned (with status text in the content) so the
|
|
128
|
+
* model can see e.g. a 404 message; only network errors, aborts, and SSRF
|
|
129
|
+
* rejections throw.
|
|
130
|
+
*/
|
|
131
|
+
export async function fetchUrlContent(input, opts) {
|
|
132
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
133
|
+
const maxBytes = opts?.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
134
|
+
const maxRedirects = opts?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
135
|
+
const initial = await validateUrl(input);
|
|
136
|
+
if (!initial.ok)
|
|
137
|
+
throw new BlockedUrlError(initial);
|
|
138
|
+
let currentUrl = initial.url;
|
|
139
|
+
let response;
|
|
140
|
+
const visited = [];
|
|
141
|
+
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
142
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
143
|
+
const abortController = new AbortController();
|
|
144
|
+
const onAbort = () => abortController.abort();
|
|
145
|
+
if (opts?.signal) {
|
|
146
|
+
if (opts.signal.aborted)
|
|
147
|
+
abortController.abort();
|
|
148
|
+
else
|
|
149
|
+
opts.signal.addEventListener('abort', onAbort, { once: true });
|
|
150
|
+
}
|
|
151
|
+
const combined = AbortSignal.any([timeoutSignal, abortController.signal]);
|
|
152
|
+
try {
|
|
153
|
+
response = await fetch(currentUrl, {
|
|
154
|
+
redirect: 'manual',
|
|
155
|
+
signal: combined,
|
|
156
|
+
headers: { accept: 'text/html,application/xhtml+xml,application/json,text/plain;q=0.5,*/*;q=0.1', 'user-agent': USER_AGENT },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (opts?.signal)
|
|
161
|
+
opts.signal.removeEventListener('abort', onAbort);
|
|
162
|
+
if (abortController.signal.aborted && !timeoutSignal.aborted) {
|
|
163
|
+
// Aborted by caller or size cap; surface a clear error.
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
if (opts?.signal)
|
|
170
|
+
opts.signal.removeEventListener('abort', onAbort);
|
|
171
|
+
}
|
|
172
|
+
// Follow redirects ourselves, re-validating each Location (closes the
|
|
173
|
+
// redirect-to-internal-IP hole).
|
|
174
|
+
const status = response.status;
|
|
175
|
+
if (status >= 300 && status < 400) {
|
|
176
|
+
const location = response.headers.get('location');
|
|
177
|
+
if (!location)
|
|
178
|
+
break;
|
|
179
|
+
if (hop >= maxRedirects) {
|
|
180
|
+
throw new Error(`Too many redirects (>${maxRedirects}) fetching ${input}`);
|
|
181
|
+
}
|
|
182
|
+
let nextUrl;
|
|
183
|
+
try {
|
|
184
|
+
nextUrl = new URL(location, currentUrl);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
throw new Error(`Invalid redirect Location '${location}'`);
|
|
188
|
+
}
|
|
189
|
+
if (nextUrl.protocol !== 'http:' && nextUrl.protocol !== 'https:') {
|
|
190
|
+
throw new BlockedUrlError({ ok: false, reasonCode: 'blocked_scheme', reason: `Redirect to non-http(s) scheme '${nextUrl.protocol}' is blocked.` });
|
|
191
|
+
}
|
|
192
|
+
const redirectValidation = await validateUrl(nextUrl.href);
|
|
193
|
+
if (!redirectValidation.ok)
|
|
194
|
+
throw new BlockedUrlError(redirectValidation);
|
|
195
|
+
if (visited.includes(nextUrl.href)) {
|
|
196
|
+
throw new Error(`Redirect loop detected fetching ${input}`);
|
|
197
|
+
}
|
|
198
|
+
visited.push(currentUrl.href);
|
|
199
|
+
currentUrl = nextUrl;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (!response)
|
|
205
|
+
throw new Error(`No response fetching ${input}`);
|
|
206
|
+
// Belt-and-suspenders: re-validate the final URL after redirects.
|
|
207
|
+
const finalValidation = await validateUrl(currentUrl.href);
|
|
208
|
+
if (!finalValidation.ok)
|
|
209
|
+
throw new BlockedUrlError(finalValidation);
|
|
210
|
+
const abortController = new AbortController();
|
|
211
|
+
const onAbort = () => abortController.abort();
|
|
212
|
+
if (opts?.signal) {
|
|
213
|
+
if (opts.signal.aborted)
|
|
214
|
+
abortController.abort();
|
|
215
|
+
else
|
|
216
|
+
opts.signal.addEventListener('abort', onAbort, { once: true });
|
|
217
|
+
}
|
|
218
|
+
let bodyResult;
|
|
219
|
+
try {
|
|
220
|
+
bodyResult = await readBodyCapped(response, maxBytes, abortController);
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
if (opts?.signal)
|
|
224
|
+
opts.signal.removeEventListener('abort', onAbort);
|
|
225
|
+
}
|
|
226
|
+
const contentType = response.headers.get('content-type') ?? 'application/octet-stream';
|
|
227
|
+
const kind = classifyContentType(contentType);
|
|
228
|
+
let content = bodyResult.text;
|
|
229
|
+
let extractionMethod;
|
|
230
|
+
if (response.ok || response.status === 304) {
|
|
231
|
+
if (opts?.format === 'text') {
|
|
232
|
+
extractionMethod = 'text';
|
|
233
|
+
}
|
|
234
|
+
else if (kind === 'json') {
|
|
235
|
+
const pretty = prettyJson(bodyResult.text);
|
|
236
|
+
if (pretty !== undefined) {
|
|
237
|
+
content = pretty;
|
|
238
|
+
extractionMethod = 'json';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
extractionMethod = 'text';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (kind === 'html') {
|
|
245
|
+
const extracted = await extractContent(bodyResult.text, currentUrl.href);
|
|
246
|
+
const titlePrefix = extracted.title ? `# ${extracted.title}\n\n` : '';
|
|
247
|
+
content = `${titlePrefix}${extracted.content}`;
|
|
248
|
+
extractionMethod = 'markdown';
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
extractionMethod = 'text';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const statusText = response.statusText || `HTTP ${response.status}`;
|
|
256
|
+
content = `[${response.status} ${statusText}] ${bodyResult.text}`.trim();
|
|
257
|
+
extractionMethod = 'text';
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
url: currentUrl.href,
|
|
261
|
+
status: response.status,
|
|
262
|
+
statusText: response.statusText,
|
|
263
|
+
contentType,
|
|
264
|
+
bytes: bodyResult.bytes,
|
|
265
|
+
redirected: currentUrl.href !== initial.url.href,
|
|
266
|
+
content,
|
|
267
|
+
extractionMethod,
|
|
268
|
+
truncated: bodyResult.truncated,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -14,7 +14,7 @@ function MarkdownBlock({ token, width }) {
|
|
|
14
14
|
switch (token.type) {
|
|
15
15
|
case 'heading': {
|
|
16
16
|
const heading = token;
|
|
17
|
-
return _jsx(
|
|
17
|
+
return _jsx(HeadingBlock, { heading: heading, width: width });
|
|
18
18
|
}
|
|
19
19
|
case 'paragraph': {
|
|
20
20
|
const paragraph = token;
|
|
@@ -42,12 +42,28 @@ function MarkdownBlock({ token, width }) {
|
|
|
42
42
|
}
|
|
43
43
|
case 'table': {
|
|
44
44
|
const table = token;
|
|
45
|
-
|
|
45
|
+
const lines = renderMarkdownTable(table, width);
|
|
46
|
+
return _jsx(Box, { flexDirection: "column", marginBottom: 1, children: lines.map((line, index) => _jsx(TableLine, { line: line }, index)) });
|
|
46
47
|
}
|
|
47
48
|
default:
|
|
48
49
|
return _jsx(Text, { children: 'raw' in token ? String(token.raw) : '' });
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
function HeadingBlock({ heading, width }) {
|
|
53
|
+
const title = stripInline(heading.text).trim();
|
|
54
|
+
if (heading.depth === 1)
|
|
55
|
+
return _jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, children: [_jsx(Text, { color: theme.purple, bold: true, children: title.toUpperCase() }), _jsx(Text, { color: theme.deepPurple, children: '─'.repeat(Math.min(width, Math.max(12, visibleLength(title)))) })] });
|
|
56
|
+
if (heading.depth === 2)
|
|
57
|
+
return _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { color: theme.purple, bold: true, children: title }) });
|
|
58
|
+
return _jsx(Box, { marginTop: heading.depth <= 3 ? 1 : 0, children: _jsx(Text, { color: theme.violet, bold: true, children: title }) });
|
|
59
|
+
}
|
|
60
|
+
function TableLine({ line }) {
|
|
61
|
+
if (isTableBorder(line))
|
|
62
|
+
return _jsx(Text, { color: theme.deepPurple, children: line });
|
|
63
|
+
return _jsx(Text, { children: [...line].map((char, index) => char === '│'
|
|
64
|
+
? _jsx(Text, { color: theme.deepPurple, children: char }, index)
|
|
65
|
+
: _jsx(Text, { children: char }, index)) });
|
|
66
|
+
}
|
|
51
67
|
function CodeBlock({ code, language, width }) {
|
|
52
68
|
let rendered;
|
|
53
69
|
try {
|
|
@@ -94,6 +110,100 @@ function tokenizeInline(text) {
|
|
|
94
110
|
out.push({ kind: 'text', text: text.slice(last) });
|
|
95
111
|
return out;
|
|
96
112
|
}
|
|
113
|
+
export function renderMarkdownTable(table, maxWidth) {
|
|
114
|
+
const rows = [table.header, ...table.rows].map(row => row.map(cell => normalizeTableCell(cell.text)));
|
|
115
|
+
const columnCount = Math.max(table.header.length, ...table.rows.map(row => row.length), 0);
|
|
116
|
+
const widths = tableColumnWidths(rows, columnCount, maxWidth);
|
|
117
|
+
const aligns = Array.from({ length: columnCount }, (_, column) => table.align[column] ?? null);
|
|
118
|
+
const border = (left, separator, right) => `${left}${widths.map(width => '─'.repeat(width + 2)).join(separator)}${right}`;
|
|
119
|
+
const rowLines = (row, isHeader = false) => {
|
|
120
|
+
const wrappedCells = widths.map((width, column) => wrapTableCell(row[column] ?? '', width));
|
|
121
|
+
const height = Math.max(1, ...wrappedCells.map(cell => cell.length));
|
|
122
|
+
return Array.from({ length: height }, (_, line) => `│${widths.map((width, column) => {
|
|
123
|
+
const align = isHeader ? null : aligns[column];
|
|
124
|
+
return ` ${alignCell(wrappedCells[column]?.[line] ?? '', width, align)} `;
|
|
125
|
+
}).join('│')}│`);
|
|
126
|
+
};
|
|
127
|
+
return [
|
|
128
|
+
border('┌', '┬', '┐'),
|
|
129
|
+
...rowLines(rows[0] ?? [], true),
|
|
130
|
+
border('├', '┼', '┤'),
|
|
131
|
+
...rows.slice(1).flatMap(row => rowLines(row)),
|
|
132
|
+
border('└', '┴', '┘'),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
function tableColumnWidths(rows, columnCount, maxWidth) {
|
|
136
|
+
const naturalWidths = Array.from({ length: columnCount }, (_, column) => Math.max(3, ...rows.map(row => visibleLength(row[column] ?? ''))));
|
|
137
|
+
if (!maxWidth)
|
|
138
|
+
return naturalWidths;
|
|
139
|
+
const contentBudget = Math.max(columnCount, maxWidth - (columnCount * 3 + 1));
|
|
140
|
+
if (naturalWidths.reduce((sum, width) => sum + width, 0) <= contentBudget)
|
|
141
|
+
return naturalWidths;
|
|
142
|
+
const minWidths = naturalWidths.map(width => Math.min(3, width));
|
|
143
|
+
const widths = [...naturalWidths];
|
|
144
|
+
while (widths.reduce((sum, width) => sum + width, 0) > contentBudget) {
|
|
145
|
+
let widest = -1;
|
|
146
|
+
for (let index = 0; index < widths.length; index++) {
|
|
147
|
+
if (widths[index] > minWidths[index] && (widest === -1 || widths[index] > widths[widest]))
|
|
148
|
+
widest = index;
|
|
149
|
+
}
|
|
150
|
+
if (widest === -1)
|
|
151
|
+
break;
|
|
152
|
+
widths[widest]--;
|
|
153
|
+
}
|
|
154
|
+
return widths;
|
|
155
|
+
}
|
|
156
|
+
function wrapTableCell(text, width) {
|
|
157
|
+
if (!text)
|
|
158
|
+
return [''];
|
|
159
|
+
const lines = [];
|
|
160
|
+
let current = '';
|
|
161
|
+
const flush = () => {
|
|
162
|
+
lines.push(current);
|
|
163
|
+
current = '';
|
|
164
|
+
};
|
|
165
|
+
for (const word of text.split(/\s+/)) {
|
|
166
|
+
if (!word)
|
|
167
|
+
continue;
|
|
168
|
+
if (!current && visibleLength(word) > width) {
|
|
169
|
+
for (let index = 0; index < word.length; index += width)
|
|
170
|
+
lines.push(word.slice(index, index + width));
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const next = current ? `${current} ${word}` : word;
|
|
174
|
+
if (visibleLength(next) <= width)
|
|
175
|
+
current = next;
|
|
176
|
+
else {
|
|
177
|
+
flush();
|
|
178
|
+
if (visibleLength(word) > width) {
|
|
179
|
+
for (let index = 0; index < word.length; index += width)
|
|
180
|
+
lines.push(word.slice(index, index + width));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
current = word;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (current || lines.length === 0)
|
|
188
|
+
lines.push(current);
|
|
189
|
+
return lines;
|
|
190
|
+
}
|
|
191
|
+
function isTableBorder(line) {
|
|
192
|
+
return line.startsWith('┌') || line.startsWith('├') || line.startsWith('└');
|
|
193
|
+
}
|
|
194
|
+
function normalizeTableCell(text) {
|
|
195
|
+
return stripInline(text).replace(/\s+/g, ' ').trim();
|
|
196
|
+
}
|
|
197
|
+
function alignCell(value, width, align) {
|
|
198
|
+
const padding = Math.max(0, width - visibleLength(value));
|
|
199
|
+
if (align === 'right')
|
|
200
|
+
return `${' '.repeat(padding)}${value}`;
|
|
201
|
+
if (align === 'center') {
|
|
202
|
+
const left = Math.floor(padding / 2);
|
|
203
|
+
return `${' '.repeat(left)}${value}${' '.repeat(padding - left)}`;
|
|
204
|
+
}
|
|
205
|
+
return `${value}${' '.repeat(padding)}`;
|
|
206
|
+
}
|
|
97
207
|
function stripInline(text) {
|
|
98
208
|
return text
|
|
99
209
|
.replace(/`([^`]+)`/g, '$1')
|
|
@@ -102,7 +212,10 @@ function stripInline(text) {
|
|
|
102
212
|
.replace(/~~([^~]+)~~/g, '$1')
|
|
103
213
|
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
|
|
104
214
|
}
|
|
215
|
+
function visibleLength(value) {
|
|
216
|
+
return stripAnsi(value).length;
|
|
217
|
+
}
|
|
105
218
|
function padAnsi(value, width) {
|
|
106
|
-
const visible =
|
|
219
|
+
const visible = visibleLength(value);
|
|
107
220
|
return visible >= width ? value : value + ' '.repeat(width - visible);
|
|
108
221
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denizokcu/haze",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A pragmatic agentic CLI for building apps from the terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,30 +44,37 @@
|
|
|
44
44
|
"prepublishOnly": "npm run typecheck && npm run build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ai-sdk/openai": "3.0.
|
|
47
|
+
"@ai-sdk/openai": "3.0.73",
|
|
48
48
|
"@inquirer/prompts": "8.5.2",
|
|
49
49
|
"@vscode/ripgrep": "1.18.0",
|
|
50
|
-
"ai": "6.0.
|
|
50
|
+
"ai": "6.0.208",
|
|
51
51
|
"cli-highlight": "2.1.11",
|
|
52
52
|
"commander": "15.0.0",
|
|
53
|
+
"defuddle": "^0.19.0",
|
|
53
54
|
"fs-extra": "11.3.5",
|
|
54
|
-
"ink": "7.0
|
|
55
|
+
"ink": "7.1.0",
|
|
55
56
|
"ink-spinner": "5.0.0",
|
|
56
|
-
"
|
|
57
|
+
"linkedom": "^0.18.12",
|
|
58
|
+
"marked": "18.0.5",
|
|
57
59
|
"react": "19.2.7",
|
|
58
60
|
"strip-ansi": "7.2.0",
|
|
61
|
+
"turndown": "^7.2.4",
|
|
59
62
|
"yaml": "2.9.0",
|
|
60
63
|
"zod": "4.4.3"
|
|
61
64
|
},
|
|
62
65
|
"devDependencies": {
|
|
63
66
|
"@eslint/js": "^10.0.1",
|
|
64
67
|
"@types/fs-extra": "11.0.4",
|
|
65
|
-
"@types/node": "
|
|
66
|
-
"@types/react": "19.2.
|
|
67
|
-
"eslint": "^10.
|
|
68
|
+
"@types/node": "26.0.0",
|
|
69
|
+
"@types/react": "19.2.17",
|
|
70
|
+
"eslint": "^10.5.0",
|
|
68
71
|
"tsx": "4.22.4",
|
|
69
72
|
"typescript": "6.0.3",
|
|
70
|
-
"typescript-eslint": "^8.
|
|
71
|
-
"vitest": "^4.1.
|
|
73
|
+
"typescript-eslint": "^8.61.1",
|
|
74
|
+
"vitest": "^4.1.9"
|
|
75
|
+
},
|
|
76
|
+
"allowScripts": {
|
|
77
|
+
"esbuild@0.28.1": true,
|
|
78
|
+
"fsevents@2.3.3": true
|
|
72
79
|
}
|
|
73
80
|
}
|