@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,27 @@
|
|
|
1
|
+
export interface BoundedStream {
|
|
2
|
+
text: string;
|
|
3
|
+
totalBytes: number;
|
|
4
|
+
retainedBytes: number;
|
|
5
|
+
omittedBytes: number;
|
|
6
|
+
}
|
|
7
|
+
export interface BoundedProcessResult {
|
|
8
|
+
code: number | null;
|
|
9
|
+
signal: NodeJS.Signals | null;
|
|
10
|
+
stdout: BoundedStream;
|
|
11
|
+
stderr: BoundedStream;
|
|
12
|
+
timedOut: boolean;
|
|
13
|
+
aborted: boolean;
|
|
14
|
+
forced: boolean;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function runBoundedProcess(input: {
|
|
19
|
+
command: string;
|
|
20
|
+
args: string[];
|
|
21
|
+
cwd: string;
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
maxStdoutBytes: number;
|
|
25
|
+
maxStderrBytes: number;
|
|
26
|
+
killGraceMs?: number;
|
|
27
|
+
}): Promise<BoundedProcessResult>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
function collector(limit) {
|
|
4
|
+
const chunks = [];
|
|
5
|
+
let totalBytes = 0;
|
|
6
|
+
let retainedBytes = 0;
|
|
7
|
+
return {
|
|
8
|
+
add(chunk) {
|
|
9
|
+
totalBytes += chunk.length;
|
|
10
|
+
const remaining = limit - retainedBytes;
|
|
11
|
+
if (remaining > 0) {
|
|
12
|
+
const kept = chunk.subarray(0, remaining);
|
|
13
|
+
chunks.push(kept);
|
|
14
|
+
retainedBytes += kept.length;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
result() {
|
|
18
|
+
const decoder = new StringDecoder('utf8');
|
|
19
|
+
const text = chunks.map(chunk => decoder.write(chunk)).join('') + (totalBytes === retainedBytes ? decoder.end() : '');
|
|
20
|
+
return { text, totalBytes, retainedBytes, omittedBytes: totalBytes - retainedBytes };
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export async function runBoundedProcess(input) {
|
|
25
|
+
const startedAt = Date.now();
|
|
26
|
+
const stdout = collector(input.maxStdoutBytes);
|
|
27
|
+
const stderr = collector(input.maxStderrBytes);
|
|
28
|
+
if (input.signal?.aborted) {
|
|
29
|
+
return { code: null, signal: null, stdout: stdout.result(), stderr: stderr.result(), timedOut: false, aborted: true, forced: false, durationMs: 0 };
|
|
30
|
+
}
|
|
31
|
+
const detached = process.platform !== 'win32';
|
|
32
|
+
const child = spawn(input.command, input.args, { cwd: input.cwd, detached, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
33
|
+
let timedOut = false;
|
|
34
|
+
let aborted = false;
|
|
35
|
+
let forced = false;
|
|
36
|
+
let killTimer;
|
|
37
|
+
const killTree = (signal) => {
|
|
38
|
+
if (child.pid == null)
|
|
39
|
+
return;
|
|
40
|
+
if (process.platform === 'win32') {
|
|
41
|
+
if (signal === 'SIGKILL')
|
|
42
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore' }).unref();
|
|
43
|
+
else
|
|
44
|
+
child.kill('SIGTERM');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
try {
|
|
48
|
+
process.kill(-child.pid, signal);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
child.kill(signal);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const terminate = () => {
|
|
56
|
+
killTree('SIGTERM');
|
|
57
|
+
killTimer ??= setTimeout(() => { forced = true; killTree('SIGKILL'); }, input.killGraceMs ?? 500);
|
|
58
|
+
killTimer.unref?.();
|
|
59
|
+
};
|
|
60
|
+
const timeout = setTimeout(() => { timedOut = true; terminate(); }, input.timeoutMs);
|
|
61
|
+
const onAbort = () => { aborted = true; terminate(); };
|
|
62
|
+
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
63
|
+
child.stdout.on('data', (chunk) => stdout.add(chunk));
|
|
64
|
+
child.stderr.on('data', (chunk) => stderr.add(chunk));
|
|
65
|
+
return await new Promise(resolve => {
|
|
66
|
+
let settled = false;
|
|
67
|
+
const settle = (code, signal, error) => {
|
|
68
|
+
if (settled)
|
|
69
|
+
return;
|
|
70
|
+
settled = true;
|
|
71
|
+
clearTimeout(timeout);
|
|
72
|
+
if (killTimer)
|
|
73
|
+
clearTimeout(killTimer);
|
|
74
|
+
input.signal?.removeEventListener('abort', onAbort);
|
|
75
|
+
resolve({ code, signal, stdout: stdout.result(), stderr: stderr.result(), timedOut, aborted, forced, durationMs: Date.now() - startedAt, ...(error ? { error } : {}) });
|
|
76
|
+
};
|
|
77
|
+
child.once('error', error => settle(null, null, error.message));
|
|
78
|
+
child.once('close', (code, signal) => settle(code, signal));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -3,6 +3,9 @@ import path from 'node:path';
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { HAZE_DIR } from '../../config/paths.js';
|
|
5
5
|
import { prepareSessionEntryForWrite } from './sessionSlimming.js';
|
|
6
|
+
import { appendPrivateFile, ensurePrivateDir, tightenPrivateFile } from '../../config/privateStorage.js';
|
|
7
|
+
import { JSONL_LINE_BYTES } from '../limits/byteBudgets.js';
|
|
8
|
+
import { iterateBoundedUtf8Lines } from '../io/boundedRead.js';
|
|
6
9
|
const DEFAULT_SESSIONS_DIR = path.join(HAZE_DIR, 'sessions');
|
|
7
10
|
function cwdHash(cwd = process.cwd()) {
|
|
8
11
|
return crypto.createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 16);
|
|
@@ -20,12 +23,13 @@ export async function createSession(options = {}) {
|
|
|
20
23
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
21
24
|
const id = newSessionId();
|
|
22
25
|
const file = sessionFile(id, cwd, options.sessionsDir);
|
|
23
|
-
await
|
|
26
|
+
await ensurePrivateDir(path.dirname(file));
|
|
24
27
|
await appendSessionEntry({ id, file, cwd }, { type: 'header', id, cwd, createdAt: new Date().toISOString(), hazeVersion: options.hazeVersion });
|
|
25
28
|
return { id, file, cwd };
|
|
26
29
|
}
|
|
27
30
|
export async function latestSession(cwd = process.cwd(), sessionsDir = DEFAULT_SESSIONS_DIR) {
|
|
28
31
|
const dir = sessionDir(cwd, sessionsDir);
|
|
32
|
+
await ensurePrivateDir(dir);
|
|
29
33
|
const files = (await fs.readdir(dir).catch(() => []))
|
|
30
34
|
.filter(file => file.endsWith('.jsonl'))
|
|
31
35
|
.sort();
|
|
@@ -39,8 +43,36 @@ export async function appendSessionEntry(session, entry) {
|
|
|
39
43
|
const prepared = prepareSessionEntryForWrite(entry);
|
|
40
44
|
if (!prepared)
|
|
41
45
|
return;
|
|
42
|
-
await
|
|
43
|
-
|
|
46
|
+
await appendPrivateFile(session.file, `${JSON.stringify(prepared)}\n`);
|
|
47
|
+
}
|
|
48
|
+
const MAX_PARSE_ERRORS = 100;
|
|
49
|
+
async function scanSessionEntries(session, onEntry) {
|
|
50
|
+
await tightenPrivateFile(session.file);
|
|
51
|
+
const parseErrors = [];
|
|
52
|
+
let omittedErrors = 0;
|
|
53
|
+
const report = (message) => {
|
|
54
|
+
if (parseErrors.length < MAX_PARSE_ERRORS)
|
|
55
|
+
parseErrors.push(message);
|
|
56
|
+
else
|
|
57
|
+
omittedErrors++;
|
|
58
|
+
};
|
|
59
|
+
for await (const { line, lineNumber, oversized } of iterateBoundedUtf8Lines(session.file, JSONL_LINE_BYTES)) {
|
|
60
|
+
if (!line && !oversized)
|
|
61
|
+
continue;
|
|
62
|
+
if (oversized) {
|
|
63
|
+
report(`Line ${lineNumber}: exceeds ${JSONL_LINE_BYTES} byte limit`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
onEntry(JSON.parse(line));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
report(`Line ${lineNumber}: ${error instanceof Error ? error.message : String(error)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (omittedErrors > 0)
|
|
74
|
+
parseErrors.push(`${omittedErrors} additional parse errors omitted.`);
|
|
75
|
+
return parseErrors;
|
|
44
76
|
}
|
|
45
77
|
/**
|
|
46
78
|
* Read a session file and parse each non-empty line as a JSONL entry.
|
|
@@ -50,34 +82,25 @@ export async function appendSessionEntry(session, entry) {
|
|
|
50
82
|
* loss in debug mode instead of silently dropping messages.
|
|
51
83
|
*/
|
|
52
84
|
export async function readSessionEntries(session) {
|
|
53
|
-
const raw = await fs.readFile(session.file, 'utf8');
|
|
54
85
|
const entries = [];
|
|
55
|
-
const parseErrors =
|
|
56
|
-
// Number by true file position: a stray blank line (e.g. from corruption) must not shift
|
|
57
|
-
// the reported line number away from where the malformed line actually sits.
|
|
58
|
-
const lines = raw.split('\n');
|
|
59
|
-
for (let i = 0; i < lines.length; i++) {
|
|
60
|
-
const line = lines[i];
|
|
61
|
-
if (!line)
|
|
62
|
-
continue; // skip blank lines (e.g. the trailing newline)
|
|
63
|
-
try {
|
|
64
|
-
entries.push(JSON.parse(line));
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
parseErrors.push(`Line ${i + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
86
|
+
const parseErrors = await scanSessionEntries(session, entry => entries.push(entry));
|
|
70
87
|
return { entries, parseErrors };
|
|
71
88
|
}
|
|
72
89
|
export async function restoreConversation(session) {
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
90
|
+
let messages = [];
|
|
91
|
+
const parseErrors = await scanSessionEntries(session, entry => {
|
|
92
|
+
if (entry.type === 'conversation_snapshot')
|
|
93
|
+
messages = entry.messages;
|
|
94
|
+
});
|
|
95
|
+
return { messages, parseErrors };
|
|
76
96
|
}
|
|
77
97
|
export async function restoreWorkState(session) {
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
98
|
+
let state;
|
|
99
|
+
const parseErrors = await scanSessionEntries(session, entry => {
|
|
100
|
+
if (entry.type === 'work_state_snapshot')
|
|
101
|
+
state = entry.state;
|
|
102
|
+
});
|
|
103
|
+
return { state, parseErrors };
|
|
81
104
|
}
|
|
82
105
|
export function formatSession(session) {
|
|
83
106
|
return `${session.id} · ${session.file}`;
|
|
@@ -13,7 +13,7 @@ function toolSummary(output) {
|
|
|
13
13
|
return 'completed';
|
|
14
14
|
const o = output;
|
|
15
15
|
if (typeof o.totalMatches === 'number')
|
|
16
|
-
return o.totalMatches === 0 ? 'no matches' : `${o.totalMatches} matches`;
|
|
16
|
+
return o.totalMatches === 0 ? 'no matches' : `${o.matchCountIsLowerBound === true ? 'at least ' : ''}${o.totalMatches} matches`;
|
|
17
17
|
if (typeof o.code === 'number')
|
|
18
18
|
return `exit ${o.code}`;
|
|
19
19
|
if (o.ok === true)
|
package/dist/llm/client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createOpenAI } from '@ai-sdk/openai';
|
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
3
|
import { readSettings } from '../config/settings.js';
|
|
4
4
|
import { activeModel, resolveModelSelector } from '../config/providers.js';
|
|
5
|
+
import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js';
|
|
5
6
|
const HAZE_SITE_URL = 'https://denizokcu.github.io/haze/';
|
|
6
7
|
const HAZE_TITLE = 'Haze';
|
|
7
8
|
function isOpenRouter(providerName, baseURL) {
|
|
@@ -42,7 +43,9 @@ export async function modelWithConfig(session) {
|
|
|
42
43
|
if (!selection)
|
|
43
44
|
return undefined;
|
|
44
45
|
const baseURL = selection.provider.url;
|
|
45
|
-
const
|
|
46
|
+
const configuredKey = selection.provider.key ?? settings.apiKey;
|
|
47
|
+
assertCredentialedEndpointSecure(baseURL, configuredKey);
|
|
48
|
+
const apiKey = configuredKey ?? 'not-needed';
|
|
46
49
|
const name = selection.model;
|
|
47
50
|
const cacheSeed = session?.cwd ?? process.cwd();
|
|
48
51
|
const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
|