@denizokcu/haze 0.8.0 → 0.9.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 +11 -1
- package/README.md +15 -13
- package/dist/cli/chat/sessionRecorder.d.ts +3 -0
- package/dist/cli/chat/sessionRecorder.js +23 -8
- package/dist/cli/commands/chat.js +90 -104
- package/dist/cli/commands/commands.d.ts +1 -1
- package/dist/cli/commands/commands.js +1 -1
- package/dist/cli/commands/formatters.js +3 -3
- package/dist/cli/commands/logsCommand.js +7 -21
- package/dist/cli/commands/mcpWizard.js +24 -2
- package/dist/cli/commands/providerWizard.js +18 -5
- package/dist/cli/commands/runCommand.js +7 -15
- package/dist/cli/commands/settingsSummary.js +3 -1
- package/dist/cli/commands/streaming/turnOutcome.d.ts +10 -0
- package/dist/cli/commands/streaming/turnOutcome.js +13 -0
- package/dist/cli/commands/streaming.js +66 -29
- package/dist/cli/commands/wizardPrompts.js +1 -1
- package/dist/cli/commands/wizardSuggestions.js +2 -1
- package/dist/cli/commands/wizardTransition.d.ts +33 -0
- package/dist/cli/commands/wizardTransition.js +44 -0
- package/dist/config/contextFiles.js +6 -3
- package/dist/config/endpointSecurity.d.ts +2 -0
- package/dist/config/endpointSecurity.js +28 -0
- package/dist/config/inputHistory.js +4 -2
- package/dist/config/privateStorage.d.ts +6 -0
- package/dist/config/privateStorage.js +61 -0
- package/dist/config/settings.js +4 -4
- package/dist/config/updateCheck.js +4 -2
- package/dist/core/agent/toolOutputStore.d.ts +3 -0
- package/dist/core/agent/toolOutputStore.js +32 -11
- package/dist/core/goal/completionPolicy.d.ts +0 -28
- package/dist/core/goal/completionPolicy.js +0 -88
- package/dist/core/io/boundedRead.d.ts +15 -0
- package/dist/core/io/boundedRead.js +97 -0
- package/dist/core/limits/byteBudgets.d.ts +13 -0
- package/dist/core/limits/byteBudgets.js +13 -0
- package/dist/core/log/llmLog.d.ts +10 -0
- package/dist/core/log/llmLog.js +59 -13
- package/dist/core/persistence/orderedFileWriter.d.ts +11 -0
- package/dist/core/persistence/orderedFileWriter.js +29 -0
- package/dist/core/process/runBoundedProcess.d.ts +27 -0
- package/dist/core/process/runBoundedProcess.js +80 -0
- package/dist/core/session/sessionStore.js +48 -25
- package/dist/core/subagent/subagentRunner.js +1 -1
- package/dist/llm/client.js +4 -1
- package/dist/llm/hazeTools.d.ts +410 -16
- package/dist/llm/hazeTools.js +36 -32
- package/dist/llm/lsp.d.ts +21 -3
- package/dist/llm/lsp.js +55 -13
- package/dist/llm/lspTools.d.ts +96 -48
- package/dist/llm/mcp.d.ts +1 -1
- package/dist/llm/mcp.js +65 -16
- package/dist/llm/requestContext.d.ts +1 -0
- package/dist/llm/requestContext.js +6 -3
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/bashTool.d.ts +368 -16
- package/dist/llm/tools/bashTool.js +19 -57
- package/dist/llm/tools/grepRunner.d.ts +15 -0
- package/dist/llm/tools/grepRunner.js +85 -0
- package/dist/skills/SkillLoader.js +17 -5
- package/dist/skills/SkillRegistry.js +19 -6
- package/dist/skills/types.d.ts +5 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +9 -4
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
import { GREP_STREAM_BYTES, PROCESS_STDERR_BYTES, TEXT_LINE_BYTES } from '../../core/limits/byteBudgets.js';
|
|
4
|
+
export async function runRipgrepBounded(input) {
|
|
5
|
+
if (input.signal?.aborted)
|
|
6
|
+
return { stdout: '', stderr: '', code: null, capped: false, timedOut: false, aborted: true };
|
|
7
|
+
const child = spawn(input.executable, input.args, { cwd: input.cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
8
|
+
const decoder = new StringDecoder('utf8');
|
|
9
|
+
const stderrDecoder = new StringDecoder('utf8');
|
|
10
|
+
let pending = '';
|
|
11
|
+
const lines = [];
|
|
12
|
+
let stderr = '';
|
|
13
|
+
let retainedBytes = 0;
|
|
14
|
+
let stderrBytes = 0;
|
|
15
|
+
let matches = 0;
|
|
16
|
+
let capped = false;
|
|
17
|
+
let timedOut = false;
|
|
18
|
+
let aborted = false;
|
|
19
|
+
let protocolError;
|
|
20
|
+
let forceTimer;
|
|
21
|
+
const stop = () => {
|
|
22
|
+
if (!child.killed)
|
|
23
|
+
child.kill('SIGTERM');
|
|
24
|
+
forceTimer ??= setTimeout(() => child.kill('SIGKILL'), 500);
|
|
25
|
+
forceTimer.unref?.();
|
|
26
|
+
};
|
|
27
|
+
const timer = setTimeout(() => { timedOut = true; stop(); }, input.timeoutMs ?? 30_000);
|
|
28
|
+
const abort = () => { aborted = true; stop(); };
|
|
29
|
+
input.signal?.addEventListener('abort', abort, { once: true });
|
|
30
|
+
child.stdout.on('data', (chunk) => {
|
|
31
|
+
pending += decoder.write(chunk);
|
|
32
|
+
if (Buffer.byteLength(pending, 'utf8') > TEXT_LINE_BYTES) {
|
|
33
|
+
protocolError = `ripgrep JSON line exceeds ${TEXT_LINE_BYTES} bytes`;
|
|
34
|
+
stop();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const parts = pending.split('\n');
|
|
38
|
+
pending = parts.pop() ?? '';
|
|
39
|
+
for (const line of parts) {
|
|
40
|
+
if (capped)
|
|
41
|
+
continue;
|
|
42
|
+
const lineBytes = Buffer.byteLength(line, 'utf8') + 1;
|
|
43
|
+
if (retainedBytes + lineBytes > GREP_STREAM_BYTES) {
|
|
44
|
+
capped = true;
|
|
45
|
+
stop();
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
lines.push(line);
|
|
49
|
+
retainedBytes += lineBytes;
|
|
50
|
+
try {
|
|
51
|
+
if (JSON.parse(line).type === 'match')
|
|
52
|
+
matches++;
|
|
53
|
+
}
|
|
54
|
+
catch { /* parser reports malformed data later */ }
|
|
55
|
+
if (matches > input.maxMatches) {
|
|
56
|
+
capped = true;
|
|
57
|
+
stop();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
child.stderr.on('data', (chunk) => {
|
|
62
|
+
const remaining = PROCESS_STDERR_BYTES - stderrBytes;
|
|
63
|
+
if (remaining <= 0)
|
|
64
|
+
return;
|
|
65
|
+
const kept = chunk.subarray(0, remaining);
|
|
66
|
+
stderrBytes += kept.length;
|
|
67
|
+
stderr += stderrDecoder.write(kept);
|
|
68
|
+
});
|
|
69
|
+
return await new Promise((resolve, reject) => {
|
|
70
|
+
child.once('error', reject);
|
|
71
|
+
child.once('close', code => {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
if (forceTimer)
|
|
74
|
+
clearTimeout(forceTimer);
|
|
75
|
+
input.signal?.removeEventListener('abort', abort);
|
|
76
|
+
const tail = pending + decoder.end();
|
|
77
|
+
if (tail && !capped)
|
|
78
|
+
lines.push(tail);
|
|
79
|
+
stderr += stderrDecoder.end();
|
|
80
|
+
if (protocolError)
|
|
81
|
+
stderr = `${stderr}${stderr ? '\n' : ''}${protocolError}`;
|
|
82
|
+
resolve({ stdout: lines.join('\n'), stderr, code, capped, timedOut, aborted });
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import YAML from 'yaml';
|
|
4
|
+
import { assertRealPathInsideRoot } from '../utils/path.js';
|
|
5
|
+
import { SKILL_MARKDOWN_BYTES } from '../core/limits/byteBudgets.js';
|
|
6
|
+
import { readUtf8Prefix } from '../core/io/boundedRead.js';
|
|
4
7
|
const MAX_REFERENCE_BYTES = 50_000;
|
|
5
8
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
6
9
|
const MARKDOWN_LINK_RE = /\[[^\]]*\]\(([^)]+)\)/g;
|
|
@@ -49,20 +52,29 @@ async function loadReference(dir, referencePath) {
|
|
|
49
52
|
const relative = path.relative(dir, absolutePath);
|
|
50
53
|
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
51
54
|
throw new Error(`Skill reference escapes skill directory: ${referencePath}`);
|
|
52
|
-
const
|
|
55
|
+
const realPath = await assertRealPathInsideRoot(dir, absolutePath, referencePath, 'skill directory');
|
|
56
|
+
const stat = await fs.stat(realPath);
|
|
53
57
|
if (!stat.isFile())
|
|
54
58
|
throw new Error(`Skill reference is not a file: ${referencePath}`);
|
|
55
|
-
|
|
59
|
+
const prefix = await readUtf8Prefix(realPath, MAX_REFERENCE_BYTES);
|
|
60
|
+
if (prefix.truncated)
|
|
56
61
|
throw new Error(`Skill reference is too large: ${referencePath}`);
|
|
57
|
-
return { path: referencePath, absolutePath, content:
|
|
62
|
+
return { path: referencePath, absolutePath: realPath, content: prefix.content };
|
|
58
63
|
}
|
|
59
64
|
export async function loadSkill(dir, source = 'global') {
|
|
60
65
|
const skillPath = path.join(dir, 'SKILL.md');
|
|
61
66
|
if (!(await fs.pathExists(skillPath)))
|
|
62
67
|
return null;
|
|
63
|
-
const
|
|
68
|
+
const realSkillPath = await assertRealPathInsideRoot(dir, skillPath, 'SKILL.md', 'skill directory');
|
|
69
|
+
const stat = await fs.stat(realSkillPath);
|
|
70
|
+
if (!stat.isFile())
|
|
71
|
+
throw new Error('SKILL.md is not a file');
|
|
72
|
+
const prefix = await readUtf8Prefix(realSkillPath, SKILL_MARKDOWN_BYTES);
|
|
73
|
+
if (prefix.truncated)
|
|
74
|
+
throw new Error(`SKILL.md exceeds ${SKILL_MARKDOWN_BYTES} byte limit`);
|
|
75
|
+
const content = prefix.content;
|
|
64
76
|
const { frontmatter, body } = parseSkillMarkdown(content);
|
|
65
77
|
const references = await Promise.all(referencedPaths(body).map(ref => loadReference(dir, ref)));
|
|
66
|
-
return { dir, path:
|
|
78
|
+
return { dir, path: realSkillPath, name: frontmatter.name, description: frontmatter.description, body, references, source };
|
|
67
79
|
}
|
|
68
80
|
export const internals = { parseSkillMarkdown, referencedPaths };
|
|
@@ -2,16 +2,29 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { GLOBAL_SKILLS_DIR } from '../config/paths.js';
|
|
4
4
|
import { loadSkill } from './SkillLoader.js';
|
|
5
|
+
import { assertRealPathInsideRoot } from '../utils/path.js';
|
|
5
6
|
export async function loadSkillRegistry() {
|
|
6
7
|
const skills = new Map();
|
|
8
|
+
const errors = [];
|
|
7
9
|
await fs.ensureDir(GLOBAL_SKILLS_DIR);
|
|
8
|
-
for (const name of await fs.readdir(GLOBAL_SKILLS_DIR)) {
|
|
10
|
+
for (const name of (await fs.readdir(GLOBAL_SKILLS_DIR)).sort()) {
|
|
9
11
|
const dir = path.join(GLOBAL_SKILLS_DIR, name);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
try {
|
|
13
|
+
await assertRealPathInsideRoot(GLOBAL_SKILLS_DIR, dir, name, 'skills root');
|
|
14
|
+
if (!(await fs.stat(dir)).isDirectory())
|
|
15
|
+
continue;
|
|
16
|
+
const skill = await loadSkill(dir, 'global');
|
|
17
|
+
if (!skill)
|
|
18
|
+
continue;
|
|
19
|
+
if (skills.has(skill.name)) {
|
|
20
|
+
errors.push({ directory: name, message: `duplicate skill name "${skill.name}"; first valid skill wins` });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
14
23
|
skills.set(skill.name, skill);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
errors.push({ directory: name, message: error instanceof Error ? error.message : String(error) });
|
|
27
|
+
}
|
|
15
28
|
}
|
|
16
|
-
return { skills };
|
|
29
|
+
return { skills, errors };
|
|
17
30
|
}
|
package/dist/skills/types.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface LoadedSkill {
|
|
|
16
16
|
references: LoadedSkillReference[];
|
|
17
17
|
source: 'global';
|
|
18
18
|
}
|
|
19
|
+
export interface SkillRegistryError {
|
|
20
|
+
directory: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
19
23
|
export interface SkillRegistry {
|
|
20
24
|
skills: Map<string, LoadedSkill>;
|
|
25
|
+
errors: SkillRegistryError[];
|
|
21
26
|
}
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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 assertPathInsideRoot(root: string, candidate: string, inputPath: string, label?: string): void;
|
|
5
|
+
export declare function assertRealPathInsideRoot(root: string, candidate: string, inputPath?: string, label?: string): Promise<string>;
|
|
4
6
|
export declare function assertRealPathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
|
|
5
7
|
export declare function assertWritablePathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
|
package/dist/utils/path.js
CHANGED
|
@@ -15,18 +15,23 @@ export function resolveWorkspacePath(inputPath) {
|
|
|
15
15
|
export function workspaceRelativePath(absolutePath) {
|
|
16
16
|
return path.relative(workspaceRoot(), absolutePath) || '.';
|
|
17
17
|
}
|
|
18
|
-
function assertPathInsideRoot(root, candidate, inputPath) {
|
|
18
|
+
export function assertPathInsideRoot(root, candidate, inputPath, label = 'workspace') {
|
|
19
19
|
const relative = path.relative(root, candidate);
|
|
20
20
|
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
21
|
-
throw new Error(`Path is outside the
|
|
21
|
+
throw new Error(`Path is outside the ${label}: ${inputPath}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export async function assertRealPathInsideRoot(root, candidate, inputPath = candidate, label = 'root') {
|
|
25
|
+
const [realRoot, realCandidate] = await Promise.all([fs.realpath(root), fs.realpath(candidate)]);
|
|
26
|
+
assertPathInsideRoot(realRoot, realCandidate, inputPath, label);
|
|
27
|
+
return realCandidate;
|
|
28
|
+
}
|
|
24
29
|
export async function assertRealPathInsideWorkspace(absolutePath, inputPath = absolutePath) {
|
|
25
30
|
const [realRoot, realPath] = await Promise.all([
|
|
26
31
|
fs.realpath(workspaceRoot()),
|
|
27
32
|
fs.realpath(absolutePath),
|
|
28
33
|
]);
|
|
29
|
-
assertPathInsideRoot(realRoot, realPath, inputPath);
|
|
34
|
+
assertPathInsideRoot(realRoot, realPath, inputPath, 'workspace');
|
|
30
35
|
}
|
|
31
36
|
async function nearestExistingPath(absolutePath) {
|
|
32
37
|
let current = absolutePath;
|
|
@@ -52,5 +57,5 @@ export async function assertWritablePathInsideWorkspace(absolutePath, inputPath
|
|
|
52
57
|
nearestExistingPath(absolutePath),
|
|
53
58
|
]);
|
|
54
59
|
const realExisting = await fs.realpath(existing);
|
|
55
|
-
assertPathInsideRoot(realRoot, realExisting, inputPath);
|
|
60
|
+
assertPathInsideRoot(realRoot, realExisting, inputPath, 'workspace');
|
|
56
61
|
}
|