@denizokcu/haze 0.6.0 → 0.7.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 +19 -0
- package/README.md +59 -12
- package/dist/cli/chat/TaskBar.d.ts +9 -0
- package/dist/cli/chat/TaskBar.js +40 -0
- package/dist/cli/chat/chatMetrics.d.ts +11 -0
- package/dist/cli/chat/chatMetrics.js +50 -0
- package/dist/cli/chat/inputSuggestions.d.ts +16 -0
- package/dist/cli/chat/inputSuggestions.js +55 -0
- package/dist/cli/chat/messages.d.ts +9 -0
- package/dist/cli/chat/messages.js +76 -0
- package/dist/cli/chat/sessionRecorder.d.ts +12 -0
- package/dist/cli/chat/sessionRecorder.js +21 -0
- package/dist/cli/chat/startupInfo.d.ts +4 -0
- package/dist/cli/chat/startupInfo.js +53 -0
- package/dist/cli/chat/turnState.d.ts +5 -0
- package/dist/cli/chat/turnState.js +20 -0
- package/dist/cli/commands/chat.d.ts +0 -1
- package/dist/cli/commands/chat.js +293 -894
- package/dist/cli/commands/chatModes.d.ts +8 -0
- package/dist/cli/commands/chatModes.js +44 -0
- package/dist/cli/commands/commandHelp.d.ts +6 -0
- package/dist/cli/commands/commandHelp.js +25 -0
- package/dist/cli/commands/commands.d.ts +1 -1
- package/dist/cli/commands/commands.js +41 -267
- package/dist/cli/commands/formatters.js +12 -4
- package/dist/cli/commands/initCommand.d.ts +2 -0
- package/dist/cli/commands/initCommand.js +19 -0
- package/dist/cli/commands/logsCommand.d.ts +2 -0
- package/dist/cli/commands/logsCommand.js +63 -0
- package/dist/cli/commands/lspWizard.d.ts +14 -0
- package/dist/cli/commands/lspWizard.js +44 -0
- package/dist/cli/commands/mcpWizard.d.ts +15 -0
- package/dist/cli/commands/mcpWizard.js +69 -0
- package/dist/cli/commands/modelCommand.d.ts +2 -0
- package/dist/cli/commands/modelCommand.js +36 -0
- package/dist/cli/commands/providerWizard.d.ts +30 -0
- package/dist/cli/commands/providerWizard.js +114 -0
- package/dist/cli/commands/runCommand.d.ts +16 -0
- package/dist/cli/commands/runCommand.js +170 -0
- package/dist/cli/commands/settingsSummary.d.ts +3 -0
- package/dist/cli/commands/settingsSummary.js +40 -0
- package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
- package/dist/cli/commands/skillConfirmRemove.js +19 -0
- package/dist/cli/commands/skillCreation.d.ts +12 -0
- package/dist/cli/commands/skillCreation.js +14 -0
- package/dist/cli/commands/skillWizard.d.ts +15 -0
- package/dist/cli/commands/skillWizard.js +38 -0
- package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
- package/dist/cli/commands/streaming/assistantText.js +115 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
- package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
- package/dist/cli/commands/streaming/toolResultState.js +25 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
- package/dist/cli/commands/streaming/turnRuntime.js +86 -0
- package/dist/cli/commands/streaming.d.ts +9 -25
- package/dist/cli/commands/streaming.js +82 -347
- package/dist/cli/commands/wizardActions.d.ts +40 -0
- package/dist/cli/commands/wizardActions.js +40 -0
- package/dist/cli/commands/wizardInput.d.ts +4 -0
- package/dist/cli/commands/wizardInput.js +19 -0
- package/dist/cli/commands/wizardPrompts.d.ts +22 -0
- package/dist/cli/commands/wizardPrompts.js +52 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
- package/dist/cli/commands/wizardSuggestions.js +139 -0
- package/dist/cli/index.js +62 -4
- package/dist/config/contextFiles.d.ts +8 -1
- package/dist/config/contextFiles.js +25 -12
- package/dist/config/lspSettings.js +3 -6
- package/dist/config/mcpSettings.js +5 -5
- package/dist/config/providers.js +4 -4
- package/dist/config/skillSettings.js +4 -3
- package/dist/core/agent/budgets.d.ts +6 -0
- package/dist/core/agent/budgets.js +6 -0
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +0 -7
- package/dist/core/agent/requestAssembly.js +27 -5
- package/dist/core/agent/toolOutputStore.js +5 -4
- package/dist/core/agent/toolResults.d.ts +31 -0
- package/dist/core/agent/toolResults.js +42 -0
- package/dist/core/agent/turnPolicy.d.ts +8 -0
- package/dist/core/agent/turnPolicy.js +23 -0
- package/dist/core/agent/workState.d.ts +18 -5
- package/dist/core/agent/workState.js +39 -20
- package/dist/core/bashOutput/reducers/content.d.ts +1 -0
- package/dist/core/bashOutput/reducers/content.js +1 -1
- package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
- package/dist/core/bashOutput/reducers/gh.js +77 -0
- package/dist/core/bashOutput/registry.js +8 -0
- package/dist/core/goal/sessionGoal.d.ts +6 -30
- package/dist/core/goal/sessionGoal.js +3 -68
- package/dist/core/safety/bashClassifier.js +30 -0
- package/dist/core/safety/urlGuard.d.ts +1 -0
- package/dist/core/safety/urlGuard.js +6 -1
- package/dist/core/session/sessionSlimming.d.ts +5 -0
- package/dist/core/session/sessionSlimming.js +78 -0
- package/dist/core/session/sessionStore.d.ts +23 -3
- package/dist/core/session/sessionStore.js +30 -10
- package/dist/core/subagent/subagentRunner.d.ts +11 -1
- package/dist/core/subagent/subagentRunner.js +1 -0
- package/dist/llm/capabilities.d.ts +12 -0
- package/dist/llm/capabilities.js +10 -0
- package/dist/llm/client.d.ts +1 -0
- package/dist/llm/client.js +11 -2
- package/dist/llm/hazeTools.d.ts +31 -32
- package/dist/llm/hazeTools.js +40 -567
- package/dist/llm/lsp.d.ts +46 -1
- package/dist/llm/lsp.js +9 -9
- package/dist/llm/lspTools.d.ts +2 -20
- package/dist/llm/mcp.js +9 -0
- package/dist/llm/requestContext.js +7 -22
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +1 -1
- package/dist/llm/tools/bashTool.d.ts +5 -0
- package/dist/llm/tools/bashTool.js +81 -0
- package/dist/llm/tools/editMatch.d.ts +55 -0
- package/dist/llm/tools/editMatch.js +99 -0
- package/dist/llm/tools/failures.d.ts +36 -0
- package/dist/llm/tools/failures.js +38 -0
- package/dist/llm/tools/fetchTool.d.ts +65 -0
- package/dist/llm/tools/fetchTool.js +45 -0
- package/dist/llm/tools/fileToolShared.d.ts +10 -0
- package/dist/llm/tools/fileToolShared.js +43 -0
- package/dist/llm/tools/grepParse.d.ts +13 -0
- package/dist/llm/tools/grepParse.js +67 -0
- package/dist/llm/tools/outputCap.d.ts +53 -0
- package/dist/llm/tools/outputCap.js +67 -0
- package/dist/llm/tools/storedOutputTool.d.ts +10 -0
- package/dist/llm/tools/storedOutputTool.js +17 -0
- package/dist/llm/tools/taskTool.d.ts +28 -0
- package/dist/llm/tools/taskTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +69 -0
- package/dist/llm/tools/toolContext.js +187 -0
- package/dist/llm/tools/workspaceFile.d.ts +33 -0
- package/dist/llm/tools/workspaceFile.js +27 -0
- package/dist/llm/webFetch.d.ts +13 -1
- package/dist/llm/webFetch.js +91 -7
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +1 -1
- package/dist/ui/components/TextInput.js +1 -99
- package/dist/ui/inputBuffer.d.ts +28 -0
- package/dist/ui/inputBuffer.js +99 -0
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/collections.js +9 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +40 -0
- package/package.json +1 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { assertRealPathInsideWorkspace, assertWritablePathInsideWorkspace, resolveWorkspacePath } from '../../utils/path.js';
|
|
2
|
+
import { assertNotIgnored } from './fileToolShared.js';
|
|
3
|
+
import { discoverScopedContext, scopedContextMutationStop } from './toolContext.js';
|
|
4
|
+
export async function prepareWorkspaceExisting(filePath) {
|
|
5
|
+
const absolutePath = resolveWorkspacePath(filePath);
|
|
6
|
+
await assertRealPathInsideWorkspace(absolutePath, filePath);
|
|
7
|
+
return absolutePath;
|
|
8
|
+
}
|
|
9
|
+
export async function prepareWorkspaceRead(filePath, allowIgnored) {
|
|
10
|
+
const absolutePath = resolveWorkspacePath(filePath);
|
|
11
|
+
await assertNotIgnored(absolutePath, filePath, allowIgnored);
|
|
12
|
+
await assertRealPathInsideWorkspace(absolutePath, filePath);
|
|
13
|
+
return absolutePath;
|
|
14
|
+
}
|
|
15
|
+
export async function prepareWorkspaceMutation(toolName, filePath, allowIgnored, context) {
|
|
16
|
+
const absolutePath = await prepareWorkspaceRead(filePath, allowIgnored);
|
|
17
|
+
const scopedContext = await discoverScopedContext(filePath, context);
|
|
18
|
+
const scopedStop = scopedContextMutationStop(toolName, filePath, scopedContext);
|
|
19
|
+
return { absolutePath, scopedContext, scopedStop };
|
|
20
|
+
}
|
|
21
|
+
export async function prepareWorkspaceWritePath(toolName, filePath, allowIgnored, context) {
|
|
22
|
+
const absolutePath = resolveWorkspacePath(filePath);
|
|
23
|
+
await assertNotIgnored(absolutePath, filePath, allowIgnored);
|
|
24
|
+
const scopedContext = await discoverScopedContext(filePath, context);
|
|
25
|
+
const scopedStop = scopedContextMutationStop(toolName, filePath, scopedContext);
|
|
26
|
+
return { absolutePath, scopedContext, scopedStop, assertExistingInsideWorkspace: async () => await assertRealPathInsideWorkspace(absolutePath, filePath), assertWritableInsideWorkspace: async () => await assertWritablePathInsideWorkspace(absolutePath, filePath) };
|
|
27
|
+
}
|
package/dist/llm/webFetch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type UrlValidation } from '../core/safety/urlGuard.js';
|
|
1
|
+
import { type UrlValidation, type DnsLookupFn } from '../core/safety/urlGuard.js';
|
|
2
2
|
/**
|
|
3
3
|
* Bounded HTTP fetch + content extraction for the `fetch` tool.
|
|
4
4
|
*
|
|
@@ -19,7 +19,18 @@ export interface FetchOptions {
|
|
|
19
19
|
maxRedirects?: number;
|
|
20
20
|
signal?: AbortSignal;
|
|
21
21
|
format?: 'auto' | 'text';
|
|
22
|
+
/** @internal custom DNS resolver forwarded to validateUrl (testing seam). */
|
|
23
|
+
lookup?: DnsLookupFn;
|
|
24
|
+
/** @internal transport override (testing seam); defaults to pinnedFetch. */
|
|
25
|
+
fetcher?: PinnedFetcher;
|
|
22
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Transport signature: fetch `url`, pinning the TCP connection to `pinnedIp`
|
|
29
|
+
* when set (hostname URL whose DNS was already resolved and validated by the
|
|
30
|
+
* caller). When `pinnedIp` is undefined (literal-IP URL), the transport falls
|
|
31
|
+
* back to the global fetch — no DNS-rebinding surface exists for a literal IP.
|
|
32
|
+
*/
|
|
33
|
+
export type PinnedFetcher = (url: URL, pinnedIp: string | undefined, init: RequestInit) => Promise<Response>;
|
|
23
34
|
export interface FetchResult {
|
|
24
35
|
url: string;
|
|
25
36
|
status: number;
|
|
@@ -47,6 +58,7 @@ export declare function extractContent(html: string, url: string): Promise<{
|
|
|
47
58
|
content: string;
|
|
48
59
|
title?: string;
|
|
49
60
|
}>;
|
|
61
|
+
export declare function pinnedFetch(url: URL, pinnedIp: string | undefined, init: RequestInit): Promise<Response>;
|
|
50
62
|
/**
|
|
51
63
|
* Fetch a public http(s) URL and return readable content.
|
|
52
64
|
*
|
package/dist/llm/webFetch.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import https from 'node:https';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
1
4
|
import { validateUrl } from '../core/safety/urlGuard.js';
|
|
2
5
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
3
6
|
const DEFAULT_MAX_BYTES = 2_000_000;
|
|
@@ -121,6 +124,80 @@ async function readBodyCapped(response, maxBytes, abortController) {
|
|
|
121
124
|
}
|
|
122
125
|
return { text, bytes: Math.min(received, maxBytes), truncated };
|
|
123
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Perform an HTTP(S) request with the TCP connection pinned to `pinnedIp`.
|
|
129
|
+
*
|
|
130
|
+
* This closes the DNS-rebinding TOCTOU: `validateUrl` resolved the hostname and
|
|
131
|
+
* verified every address is public, but the global `fetch` would re-resolve the
|
|
132
|
+
* hostname at connect time — an attacker-controlled DNS server can return a
|
|
133
|
+
* public IP for the validation lookup and a private/internal IP for the connect
|
|
134
|
+
* lookup. By connecting directly to the already-validated IP (`hostname:
|
|
135
|
+
* pinnedIp`) while keeping the original `Host` header and TLS `servername`
|
|
136
|
+
* (`url.hostname`), the connection target is fixed to what we validated, with no
|
|
137
|
+
* second DNS lookup. TLS certificate verification still runs against the original
|
|
138
|
+
* hostname via `servername`, so pinning does not weaken identity checks.
|
|
139
|
+
*
|
|
140
|
+
* Literal-IP URLs carry no DNS-rebinding surface (`pinnedIp` is undefined), so
|
|
141
|
+
* they fall through to the global `fetch` — which also keeps the test mocks that
|
|
142
|
+
* stub `globalThis.fetch` working for that path.
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Coerce a RequestInit headers value into a plain string record. Keeps the
|
|
146
|
+
* transport defensive against `Headers`/tuple/array inputs instead of blindly
|
|
147
|
+
* casting (the fetch tool only ever passes a plain object, but be safe).
|
|
148
|
+
*/
|
|
149
|
+
function normalizeHeaders(input) {
|
|
150
|
+
if (!input)
|
|
151
|
+
return {};
|
|
152
|
+
if (Array.isArray(input)) {
|
|
153
|
+
const out = {};
|
|
154
|
+
for (const pair of input) {
|
|
155
|
+
if (Array.isArray(pair) && pair.length === 2)
|
|
156
|
+
out[String(pair[0])] = String(pair[1]);
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
if (input instanceof Headers) {
|
|
161
|
+
const out = {};
|
|
162
|
+
input.forEach((value, key) => {
|
|
163
|
+
out[key] = value;
|
|
164
|
+
});
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
return { ...input };
|
|
168
|
+
}
|
|
169
|
+
export async function pinnedFetch(url, pinnedIp, init) {
|
|
170
|
+
if (!pinnedIp)
|
|
171
|
+
return globalThis.fetch(url, init);
|
|
172
|
+
const isTls = url.protocol === 'https:';
|
|
173
|
+
const port = url.port ? Number(url.port) : (isTls ? 443 : 80);
|
|
174
|
+
const path = url.pathname + url.search;
|
|
175
|
+
const headers = normalizeHeaders(init.headers);
|
|
176
|
+
// Preserve the original host in the request line; node would otherwise send
|
|
177
|
+
// the pinned IP as the Host header.
|
|
178
|
+
headers.host = url.host;
|
|
179
|
+
const lib = isTls ? https : http;
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
const req = lib.request({
|
|
182
|
+
method: init.method ?? 'GET',
|
|
183
|
+
hostname: pinnedIp,
|
|
184
|
+
port,
|
|
185
|
+
path,
|
|
186
|
+
headers,
|
|
187
|
+
...(isTls ? { servername: url.hostname, rejectUnauthorized: true } : {}),
|
|
188
|
+
signal: init.signal,
|
|
189
|
+
}, (res) => {
|
|
190
|
+
const body = Readable.toWeb(res);
|
|
191
|
+
resolve(new Response(body, {
|
|
192
|
+
status: res.statusCode ?? 200,
|
|
193
|
+
statusText: res.statusMessage ?? '',
|
|
194
|
+
headers: res.headers,
|
|
195
|
+
}));
|
|
196
|
+
});
|
|
197
|
+
req.on('error', reject);
|
|
198
|
+
req.end();
|
|
199
|
+
});
|
|
200
|
+
}
|
|
124
201
|
/**
|
|
125
202
|
* Fetch a public http(s) URL and return readable content.
|
|
126
203
|
*
|
|
@@ -132,10 +209,16 @@ export async function fetchUrlContent(input, opts) {
|
|
|
132
209
|
const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
133
210
|
const maxBytes = opts?.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
134
211
|
const maxRedirects = opts?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
135
|
-
const
|
|
212
|
+
const fetcher = opts?.fetcher ?? pinnedFetch;
|
|
213
|
+
const validateOpts = opts?.lookup ? { lookup: opts.lookup } : undefined;
|
|
214
|
+
const initial = await validateUrl(input, validateOpts);
|
|
136
215
|
if (!initial.ok)
|
|
137
216
|
throw new BlockedUrlError(initial);
|
|
138
217
|
let currentUrl = initial.url;
|
|
218
|
+
// Pin the connection to the address we just validated — the validated IP
|
|
219
|
+
// flows from validateUrl straight into the transport, with no second DNS
|
|
220
|
+
// lookup in between (that gap was the rebinding window).
|
|
221
|
+
let currentPinnedIp = initial.resolvedAddresses?.[0];
|
|
139
222
|
let response;
|
|
140
223
|
const visited = [];
|
|
141
224
|
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
@@ -150,7 +233,7 @@ export async function fetchUrlContent(input, opts) {
|
|
|
150
233
|
}
|
|
151
234
|
const combined = AbortSignal.any([timeoutSignal, abortController.signal]);
|
|
152
235
|
try {
|
|
153
|
-
response = await
|
|
236
|
+
response = await fetcher(currentUrl, currentPinnedIp, {
|
|
154
237
|
redirect: 'manual',
|
|
155
238
|
signal: combined,
|
|
156
239
|
headers: { accept: 'text/html,application/xhtml+xml,application/json,text/plain;q=0.5,*/*;q=0.1', 'user-agent': USER_AGENT },
|
|
@@ -189,7 +272,7 @@ export async function fetchUrlContent(input, opts) {
|
|
|
189
272
|
if (nextUrl.protocol !== 'http:' && nextUrl.protocol !== 'https:') {
|
|
190
273
|
throw new BlockedUrlError({ ok: false, reasonCode: 'blocked_scheme', reason: `Redirect to non-http(s) scheme '${nextUrl.protocol}' is blocked.` });
|
|
191
274
|
}
|
|
192
|
-
const redirectValidation = await validateUrl(nextUrl.href);
|
|
275
|
+
const redirectValidation = await validateUrl(nextUrl.href, validateOpts);
|
|
193
276
|
if (!redirectValidation.ok)
|
|
194
277
|
throw new BlockedUrlError(redirectValidation);
|
|
195
278
|
if (visited.includes(nextUrl.href)) {
|
|
@@ -197,16 +280,17 @@ export async function fetchUrlContent(input, opts) {
|
|
|
197
280
|
}
|
|
198
281
|
visited.push(currentUrl.href);
|
|
199
282
|
currentUrl = nextUrl;
|
|
283
|
+
currentPinnedIp = redirectValidation.resolvedAddresses?.[0];
|
|
200
284
|
continue;
|
|
201
285
|
}
|
|
202
286
|
break;
|
|
203
287
|
}
|
|
204
288
|
if (!response)
|
|
205
289
|
throw new Error(`No response fetching ${input}`);
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
290
|
+
// No post-fetch re-validation: every hop (including the final response) was
|
|
291
|
+
// validated and connection-pinned at fetch time. Re-resolving the final URL
|
|
292
|
+
// here would only reopen a rebinding race against a connection that already
|
|
293
|
+
// used a safe, pinned IP.
|
|
210
294
|
const abortController = new AbortController();
|
|
211
295
|
const onAbort = () => abortController.abort();
|
|
212
296
|
if (opts?.signal) {
|
|
@@ -26,6 +26,7 @@ declare function withSkillName(content: string, name: string): string;
|
|
|
26
26
|
declare function normalizeSkillDescription(description: string): string;
|
|
27
27
|
declare function withSkillDescription(content: string, description: string): string;
|
|
28
28
|
declare function parseGeneratedSkill(text: string, description: string): GeneratedSkill;
|
|
29
|
+
declare function assertSafeGeneratedFile(filePath: string): string;
|
|
29
30
|
export declare function createSkill(input: CreateSkillInput): Promise<{
|
|
30
31
|
name: string;
|
|
31
32
|
dir: string;
|
|
@@ -41,5 +42,7 @@ export declare const internals: {
|
|
|
41
42
|
withSkillDescription: typeof withSkillDescription;
|
|
42
43
|
normalizeSkillDescription: typeof normalizeSkillDescription;
|
|
43
44
|
toSkillDirName: typeof toSkillDirName;
|
|
45
|
+
slug: typeof slug;
|
|
46
|
+
assertSafeGeneratedFile: typeof assertSafeGeneratedFile;
|
|
44
47
|
};
|
|
45
48
|
export {};
|
|
@@ -273,4 +273,4 @@ export async function createSkill(input) {
|
|
|
273
273
|
}
|
|
274
274
|
return { name: finalName, dir, file: skillFile };
|
|
275
275
|
}
|
|
276
|
-
export const internals = { SKILL_CREATOR_SKILL, STANDARD_SKILL_REQUIREMENTS, parseGeneratedSkill, fallbackSkill, withStandardRequirements, withSkillName, withSkillDescription, normalizeSkillDescription, toSkillDirName };
|
|
276
|
+
export const internals = { SKILL_CREATOR_SKILL, STANDARD_SKILL_REQUIREMENTS, parseGeneratedSkill, fallbackSkill, withStandardRequirements, withSkillName, withSkillDescription, normalizeSkillDescription, toSkillDirName, slug, assertSafeGeneratedFile };
|
|
@@ -2,106 +2,8 @@ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Box, Text, useInput } from 'ink';
|
|
4
4
|
import { theme } from '../theme.js';
|
|
5
|
+
import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
|
|
5
6
|
const COMPACT_PASTE_MIN_LINES = 4;
|
|
6
|
-
function normalizeLineEndings(text) {
|
|
7
|
-
return text.replace(/\r\n|\r/g, '\n');
|
|
8
|
-
}
|
|
9
|
-
function lineCount(text) {
|
|
10
|
-
return normalizeLineEndings(text).split('\n').length;
|
|
11
|
-
}
|
|
12
|
-
function pastePlaceholder(block) {
|
|
13
|
-
return `[paste #${block.id} +${block.lineCount} lines]`;
|
|
14
|
-
}
|
|
15
|
-
function updatePasteBlocksForReplacement(blocks, start, end, insertedLength) {
|
|
16
|
-
const delta = insertedLength - (end - start);
|
|
17
|
-
return blocks.flatMap(block => {
|
|
18
|
-
const replacesInsideBlock = start < block.end && end > block.start;
|
|
19
|
-
const insertsInsideBlock = start === end && start > block.start && start < block.end;
|
|
20
|
-
if (replacesInsideBlock || insertsInsideBlock)
|
|
21
|
-
return [];
|
|
22
|
-
if (block.start >= end)
|
|
23
|
-
return [{ ...block, start: block.start + delta, end: block.end + delta }];
|
|
24
|
-
return [block];
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function displayCursorForValueCursor(blocks, valueCursor) {
|
|
28
|
-
let displayCursor = valueCursor;
|
|
29
|
-
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
30
|
-
const placeholderLength = pastePlaceholder(block).length;
|
|
31
|
-
const compactedLength = block.end - block.start - placeholderLength;
|
|
32
|
-
if (valueCursor <= block.start)
|
|
33
|
-
break;
|
|
34
|
-
if (valueCursor < block.end)
|
|
35
|
-
return block.start + placeholderLength;
|
|
36
|
-
displayCursor -= compactedLength;
|
|
37
|
-
}
|
|
38
|
-
return displayCursor;
|
|
39
|
-
}
|
|
40
|
-
function compactPasteBlocksForDisplay(value, blocks) {
|
|
41
|
-
if (blocks.length === 0)
|
|
42
|
-
return value;
|
|
43
|
-
let displayValue = '';
|
|
44
|
-
let offset = 0;
|
|
45
|
-
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
46
|
-
displayValue += value.slice(offset, block.start);
|
|
47
|
-
displayValue += pastePlaceholder(block);
|
|
48
|
-
offset = block.end;
|
|
49
|
-
}
|
|
50
|
-
displayValue += value.slice(offset);
|
|
51
|
-
return displayValue;
|
|
52
|
-
}
|
|
53
|
-
function valueCursorForDisplayCursor(blocks, displayCursor) {
|
|
54
|
-
let valueCursor = displayCursor;
|
|
55
|
-
let displayOffset = 0;
|
|
56
|
-
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
57
|
-
const placeholderLength = pastePlaceholder(block).length;
|
|
58
|
-
const displayStart = block.start - displayOffset;
|
|
59
|
-
const displayEnd = displayStart + placeholderLength;
|
|
60
|
-
if (displayCursor <= displayStart)
|
|
61
|
-
break;
|
|
62
|
-
if (displayCursor <= displayEnd)
|
|
63
|
-
return block.end;
|
|
64
|
-
const compactedLength = block.end - block.start - placeholderLength;
|
|
65
|
-
valueCursor += compactedLength;
|
|
66
|
-
displayOffset += compactedLength;
|
|
67
|
-
}
|
|
68
|
-
return valueCursor;
|
|
69
|
-
}
|
|
70
|
-
function wrapDisplayValue(displayValue, width) {
|
|
71
|
-
const wrapWidth = Math.max(1, width);
|
|
72
|
-
const lines = [];
|
|
73
|
-
let start = 0;
|
|
74
|
-
let text = '';
|
|
75
|
-
for (let index = 0; index < displayValue.length; index += 1) {
|
|
76
|
-
const char = displayValue[index];
|
|
77
|
-
if (char === '\n') {
|
|
78
|
-
lines.push({ text, start, end: index });
|
|
79
|
-
start = index + 1;
|
|
80
|
-
text = '';
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (text.length >= wrapWidth) {
|
|
84
|
-
lines.push({ text, start, end: index });
|
|
85
|
-
start = index;
|
|
86
|
-
text = '';
|
|
87
|
-
}
|
|
88
|
-
text += char;
|
|
89
|
-
}
|
|
90
|
-
lines.push({ text, start, end: displayValue.length });
|
|
91
|
-
return lines;
|
|
92
|
-
}
|
|
93
|
-
function cursorPosition(lines, displayCursor) {
|
|
94
|
-
const foundIndex = lines.findIndex((line, index) => {
|
|
95
|
-
const isLast = index === lines.length - 1;
|
|
96
|
-
if (line.start === line.end)
|
|
97
|
-
return displayCursor === line.start;
|
|
98
|
-
const nextLineStartsAfterNewline = lines[index + 1]?.start === line.end + 1;
|
|
99
|
-
return displayCursor >= line.start && (displayCursor < line.end || (nextLineStartsAfterNewline && displayCursor === line.end) || (isLast && displayCursor <= line.end));
|
|
100
|
-
});
|
|
101
|
-
const lineIndex = Math.max(0, foundIndex);
|
|
102
|
-
const line = lines[lineIndex] ?? lines[0] ?? { start: 0, end: 0 };
|
|
103
|
-
return { lineIndex, column: Math.max(0, Math.min(displayCursor - line.start, line.end - line.start)) };
|
|
104
|
-
}
|
|
105
7
|
export function TextInput({ placeholder, disabled, mask, historyItems = [], recordHistory = true, suggestions = [], suggestionMode = 'slash', submitOnEmpty = false, width = 80, onHistoryAdd, onCancel, onEscape, onToggleTasks, onSubmit }) {
|
|
106
8
|
const [value, setValue] = useState('');
|
|
107
9
|
const [cursor, setCursor] = useState(0);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type PasteBlock = {
|
|
2
|
+
id: number;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
lineCount: number;
|
|
6
|
+
};
|
|
7
|
+
export type WrappedLine = {
|
|
8
|
+
text: string;
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function normalizeLineEndings(text: string): string;
|
|
13
|
+
export declare function lineCount(text: string): number;
|
|
14
|
+
export declare function pastePlaceholder(block: PasteBlock): string;
|
|
15
|
+
export declare function updatePasteBlocksForReplacement(blocks: PasteBlock[], start: number, end: number, insertedLength: number): {
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
id: number;
|
|
19
|
+
lineCount: number;
|
|
20
|
+
}[];
|
|
21
|
+
export declare function displayCursorForValueCursor(blocks: PasteBlock[], valueCursor: number): number;
|
|
22
|
+
export declare function compactPasteBlocksForDisplay(value: string, blocks: PasteBlock[]): string;
|
|
23
|
+
export declare function valueCursorForDisplayCursor(blocks: PasteBlock[], displayCursor: number): number;
|
|
24
|
+
export declare function wrapDisplayValue(displayValue: string, width: number): WrappedLine[];
|
|
25
|
+
export declare function cursorPosition(lines: WrappedLine[], displayCursor: number): {
|
|
26
|
+
lineIndex: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export function normalizeLineEndings(text) {
|
|
2
|
+
return text.replace(/\r\n|\r/g, '\n');
|
|
3
|
+
}
|
|
4
|
+
export function lineCount(text) {
|
|
5
|
+
return normalizeLineEndings(text).split('\n').length;
|
|
6
|
+
}
|
|
7
|
+
export function pastePlaceholder(block) {
|
|
8
|
+
return `[paste #${block.id} +${block.lineCount} lines]`;
|
|
9
|
+
}
|
|
10
|
+
export function updatePasteBlocksForReplacement(blocks, start, end, insertedLength) {
|
|
11
|
+
const delta = insertedLength - (end - start);
|
|
12
|
+
return blocks.flatMap(block => {
|
|
13
|
+
const replacesInsideBlock = start < block.end && end > block.start;
|
|
14
|
+
const insertsInsideBlock = start === end && start > block.start && start < block.end;
|
|
15
|
+
if (replacesInsideBlock || insertsInsideBlock)
|
|
16
|
+
return [];
|
|
17
|
+
if (block.start >= end)
|
|
18
|
+
return [{ ...block, start: block.start + delta, end: block.end + delta }];
|
|
19
|
+
return [block];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function displayCursorForValueCursor(blocks, valueCursor) {
|
|
23
|
+
let displayCursor = valueCursor;
|
|
24
|
+
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
25
|
+
const placeholderLength = pastePlaceholder(block).length;
|
|
26
|
+
const compactedLength = block.end - block.start - placeholderLength;
|
|
27
|
+
if (valueCursor <= block.start)
|
|
28
|
+
break;
|
|
29
|
+
if (valueCursor < block.end)
|
|
30
|
+
return block.start + placeholderLength;
|
|
31
|
+
displayCursor -= compactedLength;
|
|
32
|
+
}
|
|
33
|
+
return displayCursor;
|
|
34
|
+
}
|
|
35
|
+
export function compactPasteBlocksForDisplay(value, blocks) {
|
|
36
|
+
if (blocks.length === 0)
|
|
37
|
+
return value;
|
|
38
|
+
let displayValue = '';
|
|
39
|
+
let offset = 0;
|
|
40
|
+
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
41
|
+
displayValue += value.slice(offset, block.start);
|
|
42
|
+
displayValue += pastePlaceholder(block);
|
|
43
|
+
offset = block.end;
|
|
44
|
+
}
|
|
45
|
+
displayValue += value.slice(offset);
|
|
46
|
+
return displayValue;
|
|
47
|
+
}
|
|
48
|
+
export function valueCursorForDisplayCursor(blocks, displayCursor) {
|
|
49
|
+
let valueCursor = displayCursor;
|
|
50
|
+
let displayOffset = 0;
|
|
51
|
+
for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
|
|
52
|
+
const placeholderLength = pastePlaceholder(block).length;
|
|
53
|
+
const displayStart = block.start - displayOffset;
|
|
54
|
+
const displayEnd = displayStart + placeholderLength;
|
|
55
|
+
if (displayCursor <= displayStart)
|
|
56
|
+
break;
|
|
57
|
+
if (displayCursor <= displayEnd)
|
|
58
|
+
return block.end;
|
|
59
|
+
const compactedLength = block.end - block.start - placeholderLength;
|
|
60
|
+
valueCursor += compactedLength;
|
|
61
|
+
displayOffset += compactedLength;
|
|
62
|
+
}
|
|
63
|
+
return valueCursor;
|
|
64
|
+
}
|
|
65
|
+
export function wrapDisplayValue(displayValue, width) {
|
|
66
|
+
const wrapWidth = Math.max(1, width);
|
|
67
|
+
const lines = [];
|
|
68
|
+
let start = 0;
|
|
69
|
+
let text = '';
|
|
70
|
+
for (let index = 0; index < displayValue.length; index += 1) {
|
|
71
|
+
const char = displayValue[index];
|
|
72
|
+
if (char === '\n') {
|
|
73
|
+
lines.push({ text, start, end: index });
|
|
74
|
+
start = index + 1;
|
|
75
|
+
text = '';
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (text.length >= wrapWidth) {
|
|
79
|
+
lines.push({ text, start, end: index });
|
|
80
|
+
start = index;
|
|
81
|
+
text = '';
|
|
82
|
+
}
|
|
83
|
+
text += char;
|
|
84
|
+
}
|
|
85
|
+
lines.push({ text, start, end: displayValue.length });
|
|
86
|
+
return lines;
|
|
87
|
+
}
|
|
88
|
+
export function cursorPosition(lines, displayCursor) {
|
|
89
|
+
const foundIndex = lines.findIndex((line, index) => {
|
|
90
|
+
const isLast = index === lines.length - 1;
|
|
91
|
+
if (line.start === line.end)
|
|
92
|
+
return displayCursor === line.start;
|
|
93
|
+
const nextLineStartsAfterNewline = lines[index + 1]?.start === line.end + 1;
|
|
94
|
+
return displayCursor >= line.start && (displayCursor < line.end || (nextLineStartsAfterNewline && displayCursor === line.end) || (isLast && displayCursor <= line.end));
|
|
95
|
+
});
|
|
96
|
+
const lineIndex = Math.max(0, foundIndex);
|
|
97
|
+
const line = lines[lineIndex] ?? lines[0] ?? { start: 0, end: 0 };
|
|
98
|
+
return { lineIndex, column: Math.max(0, Math.min(displayCursor - line.start, line.end - line.start)) };
|
|
99
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type NamedItem = {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export declare function findByName<T extends NamedItem>(items: readonly T[], name: string): T | undefined;
|
|
5
|
+
export declare function removeByName<T extends NamedItem>(items: readonly T[], name: string): T[];
|
|
6
|
+
export declare function upsertByName<T extends NamedItem>(items: readonly T[], item: T): T[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function findByName(items, name) {
|
|
2
|
+
return items.find(item => item.name === name);
|
|
3
|
+
}
|
|
4
|
+
export function removeByName(items, name) {
|
|
5
|
+
return items.filter(item => item.name !== name);
|
|
6
|
+
}
|
|
7
|
+
export function upsertByName(items, item) {
|
|
8
|
+
return [...removeByName(items, item.name), item];
|
|
9
|
+
}
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare function workspaceRoot(): string;
|
|
2
2
|
export declare function resolveWorkspacePath(inputPath: string): string;
|
|
3
3
|
export declare function workspaceRelativePath(absolutePath: string): string;
|
|
4
|
+
export declare function assertRealPathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
|
|
5
|
+
export declare function assertWritablePathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
|
package/dist/utils/path.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
export function workspaceRoot() {
|
|
3
4
|
return process.cwd();
|
|
@@ -14,3 +15,42 @@ export function resolveWorkspacePath(inputPath) {
|
|
|
14
15
|
export function workspaceRelativePath(absolutePath) {
|
|
15
16
|
return path.relative(workspaceRoot(), absolutePath) || '.';
|
|
16
17
|
}
|
|
18
|
+
function assertPathInsideRoot(root, candidate, inputPath) {
|
|
19
|
+
const relative = path.relative(root, candidate);
|
|
20
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
21
|
+
throw new Error(`Path is outside the workspace: ${inputPath}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function assertRealPathInsideWorkspace(absolutePath, inputPath = absolutePath) {
|
|
25
|
+
const [realRoot, realPath] = await Promise.all([
|
|
26
|
+
fs.realpath(workspaceRoot()),
|
|
27
|
+
fs.realpath(absolutePath),
|
|
28
|
+
]);
|
|
29
|
+
assertPathInsideRoot(realRoot, realPath, inputPath);
|
|
30
|
+
}
|
|
31
|
+
async function nearestExistingPath(absolutePath) {
|
|
32
|
+
let current = absolutePath;
|
|
33
|
+
while (true) {
|
|
34
|
+
try {
|
|
35
|
+
await fs.access(current);
|
|
36
|
+
return current;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
|
|
40
|
+
if (code !== 'ENOENT')
|
|
41
|
+
throw error;
|
|
42
|
+
const parent = path.dirname(current);
|
|
43
|
+
if (parent === current)
|
|
44
|
+
throw error;
|
|
45
|
+
current = parent;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function assertWritablePathInsideWorkspace(absolutePath, inputPath = absolutePath) {
|
|
50
|
+
const [realRoot, existing] = await Promise.all([
|
|
51
|
+
fs.realpath(workspaceRoot()),
|
|
52
|
+
nearestExistingPath(absolutePath),
|
|
53
|
+
]);
|
|
54
|
+
const realExisting = await fs.realpath(existing);
|
|
55
|
+
assertPathInsideRoot(realRoot, realExisting, inputPath);
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denizokcu/haze",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A pragmatic agentic CLI for building apps from the terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@ai-sdk/mcp": "^1.0.52",
|
|
48
48
|
"@ai-sdk/openai": "3.0.73",
|
|
49
|
-
"@inquirer/prompts": "8.5.2",
|
|
50
49
|
"@vscode/ripgrep": "1.18.0",
|
|
51
50
|
"ai": "6.0.208",
|
|
52
51
|
"cli-highlight": "2.1.11",
|