@denizokcu/haze 1.6.0 → 1.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 +23 -0
- package/README.md +7 -1
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -4
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +7 -0
- package/dist/cli/chat/wizard/providerHandlers.js +6 -2
- package/dist/cli/commands/chat.js +9 -0
- package/dist/cli/commands/formatters.d.ts +9 -0
- package/dist/cli/commands/formatters.js +19 -2
- package/dist/cli/commands/providerWizard.js +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +2 -2
- package/dist/cli/commands/streaming/attemptSetup.js +5 -3
- package/dist/cli/commands/streaming/goalSupervisor.js +2 -1
- package/dist/cli/commands/streaming/prepareStep.d.ts +12 -1
- package/dist/cli/commands/streaming/prepareStep.js +34 -11
- package/dist/cli/commands/streaming/streamLoop.d.ts +2 -0
- package/dist/cli/commands/streaming/streamLoop.js +10 -3
- package/dist/cli/commands/streaming/toolGroupRenderer.js +5 -2
- package/dist/cli/commands/streaming/turnRuntime.d.ts +1 -1
- package/dist/cli/commands/streaming/turnRuntime.js +8 -7
- package/dist/config/contextFiles.d.ts +26 -0
- package/dist/config/contextFiles.js +53 -5
- package/dist/config/hazeBuild.d.ts +43 -0
- package/dist/config/hazeBuild.js +92 -0
- package/dist/config/modelDiscovery.js +1 -1
- package/dist/config/providerPresets.d.ts +2 -0
- package/dist/config/providerPresets.js +5 -0
- package/dist/config/providers.js +1 -1
- package/dist/config/settings.d.ts +18 -1
- package/dist/config/settings.js +4 -1
- package/dist/core/agent/budgets.d.ts +11 -2
- package/dist/core/agent/budgets.js +13 -2
- package/dist/core/agent/compaction.d.ts +3 -1
- package/dist/core/agent/compaction.js +62 -8
- package/dist/core/agent/completionController.d.ts +7 -2
- package/dist/core/agent/completionController.js +10 -3
- package/dist/core/agent/contextBudget.d.ts +1 -2
- package/dist/core/agent/contextBudget.js +16 -3
- package/dist/core/agent/events.d.ts +1 -1
- package/dist/core/agent/toolOutputStore.d.ts +24 -1
- package/dist/core/agent/toolOutputStore.js +27 -6
- package/dist/core/agent/turnPolicy.d.ts +12 -2
- package/dist/core/agent/turnPolicy.js +27 -2
- package/dist/core/agent/workState.d.ts +6 -1
- package/dist/core/agent/workState.js +41 -5
- package/dist/core/attachments/imageAttachments.d.ts +4 -1
- package/dist/core/attachments/imageAttachments.js +7 -3
- package/dist/core/limits.d.ts +2 -0
- package/dist/core/limits.js +2 -0
- package/dist/core/log/llmLog.js +7 -2
- package/dist/core/process/backgroundRegistry.d.ts +9 -0
- package/dist/core/process/backgroundRegistry.js +12 -1
- package/dist/core/process/runBoundedProcess.d.ts +18 -0
- package/dist/core/process/runBoundedProcess.js +24 -1
- package/dist/core/providerContracts.d.ts +2 -0
- package/dist/core/safety/redaction.d.ts +18 -0
- package/dist/core/safety/redaction.js +50 -0
- package/dist/core/safety/secretPaths.js +54 -5
- package/dist/core/safety/untrustedEnvelopes.d.ts +22 -0
- package/dist/core/safety/untrustedEnvelopes.js +25 -0
- package/dist/core/safety/urlGuard.d.ts +5 -4
- package/dist/core/safety/urlGuard.js +12 -3
- package/dist/core/session/sessionSlimming.d.ts +3 -1
- package/dist/core/session/sessionSlimming.js +10 -1
- package/dist/core/session/sessionStore.d.ts +6 -0
- package/dist/core/session/sessionStore.js +1 -1
- package/dist/core/subagent/contracts.d.ts +3 -0
- package/dist/core/subagent/executionProfiles.js +1 -0
- package/dist/llm/client.d.ts +4 -1
- package/dist/llm/client.js +52 -16
- package/dist/llm/hazeBuild.d.ts +9 -0
- package/dist/llm/hazeBuild.js +35 -0
- package/dist/llm/hazeTools.d.ts +144 -128
- package/dist/llm/lsp/workspaceEdit.d.ts +1 -1
- package/dist/llm/mcp.js +53 -1
- package/dist/llm/requestContext.js +18 -7
- package/dist/llm/subagentRunner.d.ts +9 -0
- package/dist/llm/subagentRunner.js +52 -15
- package/dist/llm/systemPrompt.d.ts +0 -2
- package/dist/llm/systemPrompt.js +10 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/fetchTool.js +7 -3
- package/dist/llm/tools/fileTools.d.ts +128 -128
- package/dist/llm/tools/fileTools.js +8 -1
- package/dist/llm/tools/gitIgnore.d.ts +7 -0
- package/dist/llm/tools/gitIgnore.js +21 -8
- package/dist/llm/tools/outputCap.d.ts +5 -2
- package/dist/llm/tools/outputCap.js +5 -3
- package/dist/llm/tools/readRecovery.js +4 -0
- package/dist/llm/tools/replaceInFiles.d.ts +1 -1
- package/dist/llm/tools/shellTool.d.ts +16 -0
- package/dist/llm/tools/shellTool.js +12 -3
- package/dist/llm/tools/toolContext.d.ts +2 -2
- package/dist/llm/tools/toolContext.js +4 -4
- package/dist/llm/tools/workspaceFile.d.ts +5 -4
- package/dist/llm/tools/workspaceFile.js +213 -4
- package/dist/skills/SkillRegistry.js +10 -1
- package/dist/skills/skillTools.js +19 -1
- package/dist/skills/types.d.ts +5 -0
- package/dist/ui/codeHighlight.js +6 -1
- package/dist/ui/components/MarkdownText.js +7 -1
- package/dist/ui/components/StreamingMarkdownText.js +6 -1
- package/dist/ui/terminalSanitize.d.ts +23 -0
- package/dist/ui/terminalSanitize.js +122 -0
- package/package.json +13 -15
|
@@ -23,18 +23,42 @@ import path from 'node:path';
|
|
|
23
23
|
* keep working (they are excluded from grep traversal, which cannot
|
|
24
24
|
* re-include them without whitelisting the whole search).
|
|
25
25
|
*/
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Whole directories under the user's home that tools must never touch. Browser
|
|
28
|
+
* profile directories hold cookie/password stores; `.claude`/`.codex` hold
|
|
29
|
+
* OAuth credentials of other agent CLIs; `.snowsql`/`.oci`/`.netlify`/`.travis`
|
|
30
|
+
* hold provider tokens (R2-HZ-5).
|
|
31
|
+
*/
|
|
32
|
+
const PROTECTED_HOME_DIRS = [
|
|
33
|
+
'.ssh', '.gnupg', '.aws', '.azure', '.kube', '.gcloud', '.config/gcloud', '.config/gh',
|
|
34
|
+
'.claude', '.codex', '.snowsql', '.config/snowflake', '.oci', '.netlify', '.travis',
|
|
35
|
+
// Browser profile stores (cookies, logins) — macOS and Linux locations.
|
|
36
|
+
'library/application support/google/chrome', 'library/application support/chromium',
|
|
37
|
+
'library/application support/microsoft edge', 'library/application support/firefox',
|
|
38
|
+
'library/application support/arc',
|
|
39
|
+
'.mozilla/firefox', '.config/google-chrome', '.config/chromium',
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Home-relative directory prefixes with `*` wildcards (one wildcard per path
|
|
43
|
+
* segment, not crossing `/`): Flatpak browser profiles live under
|
|
44
|
+
* `.var/app/<app-id>/config/chromium`-style paths.
|
|
45
|
+
*/
|
|
46
|
+
const PROTECTED_HOME_DIR_PATTERNS = ['.var/app/*/config/chromium'];
|
|
28
47
|
/** Shell/REPL history basenames, protected anywhere on disk (not only home). */
|
|
29
48
|
const SHELL_HISTORY_BASENAMES = [
|
|
30
49
|
'.bash_history', '.zsh_history', '.sh_history', '.ksh_history', '.lesshst',
|
|
31
50
|
'.mysql_history', '.psql_history', '.python_history', '.node_repl_history',
|
|
32
51
|
'.sqlite_history', '.rediscli_history', 'fish_history',
|
|
33
52
|
];
|
|
34
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Exact files under the user's home that tools must never touch. Includes the
|
|
55
|
+
* CLI's own credential-bearing settings files — the two files only, so
|
|
56
|
+
* `~/.haze/sessions` and `~/.haze/logs` stay tool-accessible (R2-HZ-5).
|
|
57
|
+
*/
|
|
35
58
|
const PROTECTED_HOME_FILES = [
|
|
36
59
|
'.netrc', '.npmrc', '.pypirc', '.vault-token', '.git-credentials',
|
|
37
60
|
'.gem/credentials', '.docker/config.json', '.local/share/fish/fish_history',
|
|
61
|
+
'.pgpass', '.my.cnf', '.msmtprc', '.haze/settings.json', '.haze/auth.json',
|
|
38
62
|
...SHELL_HISTORY_BASENAMES,
|
|
39
63
|
];
|
|
40
64
|
/** Basenames protected in any directory, workspace included. */
|
|
@@ -42,10 +66,20 @@ const PROTECTED_BASENAMES = new Set([
|
|
|
42
66
|
...SHELL_HISTORY_BASENAMES,
|
|
43
67
|
'secrets.json', 'secrets.yaml', 'secrets.yml', 'secrets.toml',
|
|
44
68
|
]);
|
|
69
|
+
/**
|
|
70
|
+
* Glob-style basename patterns protected in any directory: cloud
|
|
71
|
+
* service-account key files whose names carry a project prefix, so a fixed
|
|
72
|
+
* basename list cannot cover them.
|
|
73
|
+
*/
|
|
74
|
+
const PROTECTED_BASENAME_PATTERNS = [
|
|
75
|
+
'*-service-account*.json',
|
|
76
|
+
'firebase-adminsdk-*.json',
|
|
77
|
+
];
|
|
78
|
+
const PROTECTED_BASENAME_MATCHERS = PROTECTED_BASENAME_PATTERNS.map(pattern => new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^/]*')}$`, 'i'));
|
|
45
79
|
/** OpenSSH private-key stems; `<stem>.pub` public keys stay readable. */
|
|
46
80
|
const SSH_KEY_STEMS = ['id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519'];
|
|
47
81
|
/** Extensions that conventionally carry private-key material. */
|
|
48
|
-
const PROTECTED_EXTENSIONS = ['.pem', '.key'];
|
|
82
|
+
const PROTECTED_EXTENSIONS = ['.pem', '.key', '.ppk', '.p12', '.pfx'];
|
|
49
83
|
/** Suffixes after `.env`/`.envrc` that conventionally hold placeholders, not secrets. */
|
|
50
84
|
const ENV_DOC_SUFFIXES = new Set(['example', 'sample', 'template']);
|
|
51
85
|
const ENV_STEMS = ['.env', '.envrc'];
|
|
@@ -62,6 +96,14 @@ function isProtectedEnvName(basename) {
|
|
|
62
96
|
function isProtectedSshKeyName(basename) {
|
|
63
97
|
return SSH_KEY_STEMS.some(stem => basename === stem || (basename.startsWith(`${stem}.`) && basename !== `${stem}.pub`));
|
|
64
98
|
}
|
|
99
|
+
/** Whether a lowercased home-relative directory path matches a `*`-wildcard pattern (one wildcard per segment). */
|
|
100
|
+
function matchesHomeDirPattern(pattern, joined) {
|
|
101
|
+
const patternSegments = pattern.split('/');
|
|
102
|
+
const candidateSegments = joined.split('/');
|
|
103
|
+
if (patternSegments.length !== candidateSegments.length)
|
|
104
|
+
return false;
|
|
105
|
+
return patternSegments.every((segment, index) => segment === '*' ? candidateSegments[index] !== '' : segment === candidateSegments[index]);
|
|
106
|
+
}
|
|
65
107
|
/**
|
|
66
108
|
* Whether a path points at (or inside) a protected secret file or credential
|
|
67
109
|
* store. Checked against both lexical names and real paths by callers so
|
|
@@ -76,6 +118,8 @@ export function isProtectedSecretPath(candidatePath, homeDir = os.homedir()) {
|
|
|
76
118
|
const basename = path.basename(absolute).toLowerCase();
|
|
77
119
|
if (PROTECTED_BASENAMES.has(basename))
|
|
78
120
|
return true;
|
|
121
|
+
if (PROTECTED_BASENAME_MATCHERS.some(matcher => matcher.test(basename)))
|
|
122
|
+
return true;
|
|
79
123
|
if (isProtectedEnvName(basename))
|
|
80
124
|
return true;
|
|
81
125
|
if (isProtectedSshKeyName(basename))
|
|
@@ -87,7 +131,10 @@ export function isProtectedSecretPath(candidatePath, homeDir = os.homedir()) {
|
|
|
87
131
|
if (insideHome) {
|
|
88
132
|
const segments = relativeToHome.split(path.sep).map(segment => segment.toLowerCase());
|
|
89
133
|
for (let depth = 1; depth <= segments.length; depth++) {
|
|
90
|
-
|
|
134
|
+
const joined = segments.slice(0, depth).join('/');
|
|
135
|
+
if (PROTECTED_HOME_DIRS.includes(joined))
|
|
136
|
+
return true;
|
|
137
|
+
if (PROTECTED_HOME_DIR_PATTERNS.some(pattern => matchesHomeDirPattern(pattern, joined)))
|
|
91
138
|
return true;
|
|
92
139
|
}
|
|
93
140
|
if (PROTECTED_HOME_FILES.includes(segments.join('/')))
|
|
@@ -112,7 +159,9 @@ export function secretSearchExcludeGlobs() {
|
|
|
112
159
|
...SSH_KEY_STEMS.map(stem => `!${stem}*`),
|
|
113
160
|
...PROTECTED_EXTENSIONS.map(extension => `!*${extension}`),
|
|
114
161
|
...[...PROTECTED_BASENAMES].map(name => `!${name}`),
|
|
162
|
+
...PROTECTED_BASENAME_PATTERNS.map(pattern => `!${pattern}`),
|
|
115
163
|
...PROTECTED_HOME_DIRS.flatMap(directory => [`!**/${directory}`, `!**/${directory}/**`]),
|
|
164
|
+
...PROTECTED_HOME_DIR_PATTERNS.flatMap(pattern => [`!**/${pattern}`, `!**/${pattern}/**`]),
|
|
116
165
|
...PROTECTED_HOME_FILES.map(file => `!**/${file}`),
|
|
117
166
|
])];
|
|
118
167
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared closing-tag escaper for untrusted-content envelopes (R2-HZ-11).
|
|
3
|
+
*
|
|
4
|
+
* Every producer that interpolates untrusted text inside a labeled container
|
|
5
|
+
* (`<web_content>`, `<mcp_result>`, `<project_instructions>`,
|
|
6
|
+
* `<project_context>`, `<haze_compaction>`) must neutralize forged closers in
|
|
7
|
+
* the payload: a closing tag inside the content would end the envelope early
|
|
8
|
+
* in the model's perception and promote the trailing payload to a
|
|
9
|
+
* higher-trust position. The match is variant-tolerant (case differences,
|
|
10
|
+
* whitespace inside the tag, a newline before `>`) because lenient XML
|
|
11
|
+
* readers — and models — accept those spellings as closers too; exact-match
|
|
12
|
+
* `replaceAll` replacements pass them through unescaped.
|
|
13
|
+
*
|
|
14
|
+
* One helper for all envelope producers: no ad-hoc per-site escapes.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Escape every envelope-closing-tag variant in `content` so the payload
|
|
18
|
+
* cannot forge an envelope boundary. The escape breaks the tag open (`<\/`)
|
|
19
|
+
* while leaving the visible text recognizable; envelope parsers that reverse
|
|
20
|
+
* the exact form keep working because the producer's own closer is intact.
|
|
21
|
+
*/
|
|
22
|
+
export declare function escapeEnvelopeClosers(content: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared closing-tag escaper for untrusted-content envelopes (R2-HZ-11).
|
|
3
|
+
*
|
|
4
|
+
* Every producer that interpolates untrusted text inside a labeled container
|
|
5
|
+
* (`<web_content>`, `<mcp_result>`, `<project_instructions>`,
|
|
6
|
+
* `<project_context>`, `<haze_compaction>`) must neutralize forged closers in
|
|
7
|
+
* the payload: a closing tag inside the content would end the envelope early
|
|
8
|
+
* in the model's perception and promote the trailing payload to a
|
|
9
|
+
* higher-trust position. The match is variant-tolerant (case differences,
|
|
10
|
+
* whitespace inside the tag, a newline before `>`) because lenient XML
|
|
11
|
+
* readers — and models — accept those spellings as closers too; exact-match
|
|
12
|
+
* `replaceAll` replacements pass them through unescaped.
|
|
13
|
+
*
|
|
14
|
+
* One helper for all envelope producers: no ad-hoc per-site escapes.
|
|
15
|
+
*/
|
|
16
|
+
const ENVELOPE_CLOSER = /<\/\s*(web_content|mcp_result|project_instructions|project_context|haze_compaction)\s*>/gi;
|
|
17
|
+
/**
|
|
18
|
+
* Escape every envelope-closing-tag variant in `content` so the payload
|
|
19
|
+
* cannot forge an envelope boundary. The escape breaks the tag open (`<\/`)
|
|
20
|
+
* while leaving the visible text recognizable; envelope parsers that reverse
|
|
21
|
+
* the exact form keep working because the producer's own closer is intact.
|
|
22
|
+
*/
|
|
23
|
+
export function escapeEnvelopeClosers(content) {
|
|
24
|
+
return content.replace(ENVELOPE_CLOSER, closer => closer.replace('</', '<\\/'));
|
|
25
|
+
}
|
|
@@ -15,7 +15,7 @@ export type UrlValidation = {
|
|
|
15
15
|
resolvedAddresses?: string[];
|
|
16
16
|
} | {
|
|
17
17
|
ok: false;
|
|
18
|
-
reasonCode: 'invalid_url' | 'blocked_scheme' | 'blocked_host' | 'blocked_address';
|
|
18
|
+
reasonCode: 'invalid_url' | 'blocked_scheme' | 'blocked_host' | 'blocked_address' | 'blocked_port';
|
|
19
19
|
reason: string;
|
|
20
20
|
};
|
|
21
21
|
export type DnsLookupFn = (hostname: string) => Promise<string[]>;
|
|
@@ -28,9 +28,10 @@ export declare function isBlockedIp(ip: string): boolean;
|
|
|
28
28
|
/**
|
|
29
29
|
* Validate a URL for outbound fetching.
|
|
30
30
|
*
|
|
31
|
-
* Checks scheme allowlist, blocks well-known dangerous hostnames,
|
|
32
|
-
* literal private/loopback/link-local
|
|
33
|
-
* resolves it to reject names that point
|
|
31
|
+
* Checks scheme allowlist, blocks well-known dangerous hostnames, allows only
|
|
32
|
+
* the default web ports (80/443), blocks literal private/loopback/link-local
|
|
33
|
+
* IPs, and (if the host is a DNS name) resolves it to reject names that point
|
|
34
|
+
* at private/loopback/link-local IPs.
|
|
34
35
|
*
|
|
35
36
|
* `lookup` is injectable for deterministic offline tests.
|
|
36
37
|
*/
|
|
@@ -149,9 +149,10 @@ const defaultLookup = async (hostname) => {
|
|
|
149
149
|
/**
|
|
150
150
|
* Validate a URL for outbound fetching.
|
|
151
151
|
*
|
|
152
|
-
* Checks scheme allowlist, blocks well-known dangerous hostnames,
|
|
153
|
-
* literal private/loopback/link-local
|
|
154
|
-
* resolves it to reject names that point
|
|
152
|
+
* Checks scheme allowlist, blocks well-known dangerous hostnames, allows only
|
|
153
|
+
* the default web ports (80/443), blocks literal private/loopback/link-local
|
|
154
|
+
* IPs, and (if the host is a DNS name) resolves it to reject names that point
|
|
155
|
+
* at private/loopback/link-local IPs.
|
|
155
156
|
*
|
|
156
157
|
* `lookup` is injectable for deterministic offline tests.
|
|
157
158
|
*/
|
|
@@ -178,6 +179,14 @@ export async function validateUrl(input, options) {
|
|
|
178
179
|
if (!host) {
|
|
179
180
|
return { ok: false, reasonCode: 'blocked_host', reason: 'URL has no hostname.' };
|
|
180
181
|
}
|
|
182
|
+
// Port policy: without one, the fetch tool becomes a scanner for databases
|
|
183
|
+
// and admin panels on public hosts (Redis/memcached-style services). Only
|
|
184
|
+
// the default web ports are fetchable; `url.port` is '' when the URL omits
|
|
185
|
+
// the port or spells out the scheme's default.
|
|
186
|
+
const port = url.port;
|
|
187
|
+
if (port !== '' && port !== '80' && port !== '443') {
|
|
188
|
+
return { ok: false, reasonCode: 'blocked_port', reason: `Port '${port}' is not allowed; only default web ports (80, 443) are permitted.` };
|
|
189
|
+
}
|
|
181
190
|
// If the host is a literal IP, check ranges directly (no DNS needed).
|
|
182
191
|
// No resolvedAddresses: literal IPs carry no DNS-rebinding surface, so the
|
|
183
192
|
// caller can connect to the URL as-is without pinning.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
2
|
import type { SessionEntry } from './sessionStore.js';
|
|
3
3
|
export declare function repairRestoredConversation(messages: ModelMessage[]): ModelMessage[];
|
|
4
|
-
export declare function prepareSessionEntryForWrite(entry: SessionEntry
|
|
4
|
+
export declare function prepareSessionEntryForWrite(entry: SessionEntry, options?: {
|
|
5
|
+
redactSecrets?: boolean;
|
|
6
|
+
}): SessionEntry | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SESSION_INLINE_VALUE_BYTES as INLINE_VALUE_BYTES, SESSION_LARGE_STRING_CHARS as LARGE_STRING_CHARS, SESSION_PREVIEW_CHARS as PREVIEW_CHARS } from '../limits.js';
|
|
2
2
|
import { imageFilePartBytes, isImageFilePart } from '../attachments/imageAttachments.js';
|
|
3
|
+
import { redactUnknown } from '../safety/redaction.js';
|
|
3
4
|
import { formatBytes } from '../../utils/format.js';
|
|
4
5
|
function jsonByteLength(value) {
|
|
5
6
|
try {
|
|
@@ -128,7 +129,15 @@ function slimToolStartInput(input) {
|
|
|
128
129
|
}
|
|
129
130
|
/** Goal-ledger request text bound; the exact bytes live in conversation snapshots, the ledger needs a resumable copy (P1). */
|
|
130
131
|
const GOAL_LEDGER_REQUEST_CHARS = 1024;
|
|
131
|
-
export function prepareSessionEntryForWrite(entry) {
|
|
132
|
+
export function prepareSessionEntryForWrite(entry, options = {}) {
|
|
133
|
+
const prepared = slimSessionEntry(entry);
|
|
134
|
+
if (prepared === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
// Opt-in secret-shape redaction (HZ-9): applied after slimming so it covers
|
|
137
|
+
// every persisted entry type, including snapshots and event payloads.
|
|
138
|
+
return options.redactSecrets === true ? redactUnknown(prepared) : prepared;
|
|
139
|
+
}
|
|
140
|
+
function slimSessionEntry(entry) {
|
|
132
141
|
if (entry.type === 'event') {
|
|
133
142
|
if (entry.name === 'message_update')
|
|
134
143
|
return undefined;
|
|
@@ -113,6 +113,12 @@ export interface HazeSession {
|
|
|
113
113
|
sessionsDir: string;
|
|
114
114
|
/** New sessions stay memory-only until they contain a resumable message. */
|
|
115
115
|
deferredWrite?: DeferredSessionWrite;
|
|
116
|
+
/**
|
|
117
|
+
* Opt-in secret-shape redaction for this session's writes (HZ-9), set from
|
|
118
|
+
* the `redactSessionSecrets` setting when the session object is created or
|
|
119
|
+
* resumed; default (absent/false) persists entries verbatim.
|
|
120
|
+
*/
|
|
121
|
+
redactSecrets?: boolean;
|
|
116
122
|
}
|
|
117
123
|
export declare function createSession(options?: {
|
|
118
124
|
cwd?: string;
|
|
@@ -86,7 +86,7 @@ function entryMakesSessionResumable(entry) {
|
|
|
86
86
|
}
|
|
87
87
|
export async function appendSessionEntry(session, entry) {
|
|
88
88
|
const file = validatedSessionFile(session);
|
|
89
|
-
const prepared = prepareSessionEntryForWrite(entry);
|
|
89
|
+
const prepared = prepareSessionEntryForWrite(entry, { redactSecrets: session.redactSecrets === true });
|
|
90
90
|
if (!prepared)
|
|
91
91
|
return;
|
|
92
92
|
const deferred = session.deferredWrite;
|
|
@@ -70,6 +70,9 @@ export interface SubagentExecutionResult {
|
|
|
70
70
|
error?: string;
|
|
71
71
|
}
|
|
72
72
|
export interface WorkerRuntime {
|
|
73
|
+
contextWindowTokens?: number;
|
|
74
|
+
maxOutputTokens?: number;
|
|
75
|
+
nativeMaxConcurrency?: number;
|
|
73
76
|
model: LanguageModel;
|
|
74
77
|
selector: string;
|
|
75
78
|
providerName: string;
|
|
@@ -17,6 +17,7 @@ export const COMPATIBILITY_PROFILE = {
|
|
|
17
17
|
deadlineMs: SUBAGENT_DEFAULT_DEADLINE_MS, maxRetries: 2,
|
|
18
18
|
};
|
|
19
19
|
export const BUILT_IN_SUBAGENT_PROFILES = {
|
|
20
|
+
'haze-build': { ...COMPATIBILITY_PROFILE, name: 'haze-build', maxConcurrency: 2, maxInputTokens: 48_000, maxOutputTokens: 6_144, maxRetries: 0 },
|
|
20
21
|
'local-safe': { ...COMPATIBILITY_PROFILE, name: 'local-safe', maxConcurrency: 1, maxSteps: 32, maxToolCalls: 24, maxOutputTokens: 4_096, maxInputTokens: 40_000, maxRetries: 0 },
|
|
21
22
|
'local-throughput': { ...COMPATIBILITY_PROFILE, name: 'local-throughput', maxConcurrency: 2, maxSteps: 40, maxToolCalls: 32, maxOutputTokens: 6_144, maxInputTokens: 48_000, maxRetries: 0 },
|
|
22
23
|
'cloud-balanced': { ...COMPATIBILITY_PROFILE, name: 'cloud-balanced', maxConcurrency: 3, deadlineMs: 360_000 },
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HazeBuildManifest } from '../config/hazeBuild.js';
|
|
1
2
|
import { readSettings, type HazeProviderSettings } from '../config/settings.js';
|
|
2
3
|
import type { ProviderCapabilities, ProviderRequestOptions } from '../core/providerContracts.js';
|
|
3
4
|
import type { WorkerRuntime } from '../core/subagent/contracts.js';
|
|
@@ -24,7 +25,9 @@ export interface ModelRuntimeConfig {
|
|
|
24
25
|
*/
|
|
25
26
|
contextWindowTokens: number;
|
|
26
27
|
/** Where contextWindowTokens came from: per-model settings, the curated model catalog, a user-set fallback, or the built-in default. */
|
|
27
|
-
contextWindowSource: 'settings' | 'catalog' | 'user-fallback' | 'default-fallback';
|
|
28
|
+
contextWindowSource: 'settings' | 'catalog' | 'user-fallback' | 'default-fallback' | 'deployment';
|
|
29
|
+
deployment?: HazeBuildManifest;
|
|
30
|
+
warnings?: string[];
|
|
28
31
|
/** Optional output-token limit metadata for request budgeting (RH-005). */
|
|
29
32
|
maxOutputTokens?: number;
|
|
30
33
|
}
|
package/dist/llm/client.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
3
|
+
import { discoverHazeBuildManifest } from '../config/hazeBuild.js';
|
|
4
|
+
import { createHazeBuildModel } from './hazeBuild.js';
|
|
2
5
|
import crypto from 'node:crypto';
|
|
3
6
|
import { readSettings } from '../config/settings.js';
|
|
4
7
|
import { catalogLimitsFor } from '../config/modelCatalog.js';
|
|
@@ -7,7 +10,7 @@ import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js'
|
|
|
7
10
|
import { effectiveRequestedReasoning, isStoredReasoning, reasoningCallSetting, resolveAttemptReasoning, resolveReasoningPolicy } from '../core/agent/reasoningPolicy.js';
|
|
8
11
|
import { FALLBACK_CONTEXT_WINDOW_TOKENS, FALLBACK_LOCAL_CONTEXT_TOKENS } from '../core/agent/contextBudget.js';
|
|
9
12
|
import { createChatGptCodexFetch } from './openaiCodex.js';
|
|
10
|
-
const HAZE_SITE_URL = 'https://
|
|
13
|
+
const HAZE_SITE_URL = 'https://github.com/DenizOkcu/haze';
|
|
11
14
|
const HAZE_TITLE = 'Haze';
|
|
12
15
|
// The SDK requires a non-empty apiKey even though the OAuth fetch adapter
|
|
13
16
|
// replaces authentication. Generate a non-credential sentinel at runtime so
|
|
@@ -24,8 +27,12 @@ function openRouterHeaders(providerName, baseURL) {
|
|
|
24
27
|
'X-Title': HAZE_TITLE,
|
|
25
28
|
};
|
|
26
29
|
}
|
|
30
|
+
/** True when the endpoint is OpenAI's own API, not a gateway/local server speaking the compatible subset. */
|
|
31
|
+
function isDirectOpenAi(providerName, baseURL, providerKind) {
|
|
32
|
+
return providerKind !== 'chatgpt-codex' && (providerName === 'openai' || /api\.openai\.com/i.test(baseURL));
|
|
33
|
+
}
|
|
27
34
|
function capabilities(providerName, baseURL, providerKind, explicit) {
|
|
28
|
-
const directOpenAI =
|
|
35
|
+
const directOpenAI = isDirectOpenAi(providerName, baseURL, providerKind);
|
|
29
36
|
const openRouter = isOpenRouter(providerName, baseURL);
|
|
30
37
|
// Reasoning-effort support is explicit-first: a user override wins either
|
|
31
38
|
// way. Otherwise loopback/local inference servers (LM Studio, Ollama,
|
|
@@ -33,15 +40,16 @@ function capabilities(providerName, baseURL, providerKind, explicit) {
|
|
|
33
40
|
// unsupported levels — even `none` — to `on` (LM Studio), inverting the
|
|
34
41
|
// request, and subagent workers rely on `none` meaning off. Hosted
|
|
35
42
|
// OpenAI-compatible endpoints keep the SDK pass-through (`true`).
|
|
36
|
-
const supportsReasoningEffort = explicit?.reasoningEffort ?? !isLocalProviderUrl(baseURL);
|
|
43
|
+
const supportsReasoningEffort = explicit?.reasoningEffort ?? (providerKind === 'haze-build' || !isLocalProviderUrl(baseURL));
|
|
37
44
|
return {
|
|
38
|
-
reportsCacheUsage: directOpenAI || openRouter,
|
|
45
|
+
reportsCacheUsage: providerKind === 'haze-build' || directOpenAI || openRouter,
|
|
39
46
|
supportsPromptCacheKey: directOpenAI,
|
|
40
47
|
supportsExtendedCacheRetention: false,
|
|
41
48
|
supportsStickySessionId: openRouter,
|
|
42
49
|
supportsServerCompaction: false,
|
|
43
50
|
supportsTextVerbosity: directOpenAI,
|
|
44
51
|
supportsReasoningEffort,
|
|
52
|
+
...(providerKind === 'haze-build' ? { supportsBinaryThinking: true } : {}),
|
|
45
53
|
};
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
@@ -70,7 +78,7 @@ export function isLocalProviderUrl(url) {
|
|
|
70
78
|
return false;
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
|
-
function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessionReasoningByModel) {
|
|
81
|
+
function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessionReasoningByModel, deployment) {
|
|
74
82
|
const baseURL = selection.provider.url;
|
|
75
83
|
const providerKind = selection.provider.kind;
|
|
76
84
|
const configuredKey = providerKind === 'chatgpt-codex' ? undefined : selection.provider.key ?? settings.apiKey;
|
|
@@ -94,10 +102,25 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
94
102
|
globalSetting: isStoredReasoning(settings.reasoning) ? settings.reasoning : undefined,
|
|
95
103
|
});
|
|
96
104
|
const requestedReasoning = effectiveRequestedReasoning(storedReasoning);
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
?
|
|
100
|
-
:
|
|
105
|
+
const resolvedPolicy = reasoningPolicyForModel(name, requestedReasoning, caps);
|
|
106
|
+
const reasoningPolicy = deployment && resolvedPolicy.effective !== 'disabled'
|
|
107
|
+
? { ...resolvedPolicy, reason: `haze.build binary thinking ${requestedReasoning === 'none' ? 'off' : 'on'}; effort levels do not imply different compute budgets` }
|
|
108
|
+
: resolvedPolicy;
|
|
109
|
+
// Transport split mirrors the wire reality: OpenAI's own endpoints and the
|
|
110
|
+
// codex OAuth kind ride @ai-sdk/openai (Responses access, `prompt_cache_key`,
|
|
111
|
+
// catalog effort remapping); every other endpoint — gateways, local servers,
|
|
112
|
+
// custom proxies — speaks the compatible subset and rides
|
|
113
|
+
// @ai-sdk/openai-compatible. `includeUsage` is mandatory there: the openai
|
|
114
|
+
// package always streams `include_usage` and context estimation depends on
|
|
115
|
+
// provider usage. Reasoning levels pass through verbatim (no catalog remap).
|
|
116
|
+
const headers = openRouterHeaders(selection.provider.name, baseURL);
|
|
117
|
+
const model = deployment
|
|
118
|
+
? createHazeBuildModel({ baseURL, apiKey, manifest: deployment })
|
|
119
|
+
: providerKind === 'chatgpt-codex'
|
|
120
|
+
? createOpenAI({ apiKey: OAUTH_SDK_SENTINEL, baseURL, fetch: createChatGptCodexFetch(selection.provider.name) }).responses(name)
|
|
121
|
+
: isDirectOpenAi(selection.provider.name, baseURL, providerKind)
|
|
122
|
+
? createOpenAI({ apiKey, baseURL, headers }).chat(name)
|
|
123
|
+
: createOpenAICompatible({ name: selection.provider.name, baseURL, apiKey, headers, includeUsage: true }).chatModel(name);
|
|
101
124
|
const limits = modelLimitsFor(selection.provider, name);
|
|
102
125
|
// Class-aware fallback so unknown local models (server-configured window,
|
|
103
126
|
// silent truncation) stay conservative while unknown hosted models get the
|
|
@@ -118,7 +141,7 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
118
141
|
: userFallback !== undefined ? 'user-fallback' : 'default-fallback';
|
|
119
142
|
const maxOutputTokens = limits.maxOutputTokens ?? catalog?.maxOutputTokens;
|
|
120
143
|
return {
|
|
121
|
-
model
|
|
144
|
+
model,
|
|
122
145
|
selector,
|
|
123
146
|
config: {
|
|
124
147
|
providerName: selection.provider.name,
|
|
@@ -128,9 +151,14 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
128
151
|
cacheKey,
|
|
129
152
|
capabilities: caps,
|
|
130
153
|
reasoningPolicy,
|
|
131
|
-
contextWindowTokens: limits.contextWindowTokens ?? catalog?.contextWindowTokens ?? fallbackTokens,
|
|
132
|
-
contextWindowSource,
|
|
133
|
-
...(
|
|
154
|
+
contextWindowTokens: deployment ? Math.min(limits.contextWindowTokens ?? deployment.contextWindowTokens, deployment.contextWindowTokens) : limits.contextWindowTokens ?? catalog?.contextWindowTokens ?? fallbackTokens,
|
|
155
|
+
contextWindowSource: deployment ? 'deployment' : contextWindowSource,
|
|
156
|
+
...(deployment ? { deployment, maxOutputTokens: Math.min(limits.maxOutputTokens ?? deployment.maxOutputTokens, deployment.maxOutputTokens),
|
|
157
|
+
warnings: [
|
|
158
|
+
...(limits.contextWindowTokens !== undefined && limits.contextWindowTokens !== deployment.contextWindowTokens ? ['Configured context differs from the current haze.build deployment; using the smaller safe limit.'] : []),
|
|
159
|
+
...(limits.maxOutputTokens !== undefined && limits.maxOutputTokens !== deployment.maxOutputTokens ? ['Configured output tokens differ from the current haze.build deployment; using the smaller safe limit.'] : []),
|
|
160
|
+
] }
|
|
161
|
+
: maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
134
162
|
},
|
|
135
163
|
};
|
|
136
164
|
}
|
|
@@ -159,7 +187,12 @@ export async function modelWithConfig(session, settings) {
|
|
|
159
187
|
}
|
|
160
188
|
else
|
|
161
189
|
selection = activeModel(resolvedSettings);
|
|
162
|
-
|
|
190
|
+
if (!selection)
|
|
191
|
+
return undefined;
|
|
192
|
+
const deployment = selection.provider.kind === 'haze-build' ? await discoverHazeBuildManifest(selection.provider) : undefined;
|
|
193
|
+
if (deployment && selection.model !== deployment.model)
|
|
194
|
+
throw new Error(`haze.build currently serves ${deployment.model}; choose it explicitly via /model.`);
|
|
195
|
+
return runtimeForSelection(resolvedSettings, selection, session?.cwd, session?.reasoningOverride, session?.reasoningByModel, deployment);
|
|
163
196
|
}
|
|
164
197
|
export async function resolveWorkerRuntime(input) {
|
|
165
198
|
const requested = input.selector?.trim();
|
|
@@ -168,9 +201,12 @@ export async function resolveWorkerRuntime(input) {
|
|
|
168
201
|
const resolved = resolveModelSelector(input.settings, requested);
|
|
169
202
|
if (resolved.status !== 'found')
|
|
170
203
|
return { status: resolved.status, message: resolved.status === 'ambiguous' ? `Worker model ${requested} is ambiguous; use provider:model.` : `Worker model ${requested} is not configured. Configure it via /provider or remove subagents.workerModel.` };
|
|
171
|
-
|
|
204
|
+
const deployment = resolved.provider.kind === 'haze-build' ? await discoverHazeBuildManifest(resolved.provider) : undefined;
|
|
205
|
+
if (deployment && resolved.model !== deployment.model)
|
|
206
|
+
return { status: 'missing', message: `haze.build currently serves ${deployment.model}.` };
|
|
207
|
+
selected = runtimeForSelection(input.settings, { provider: resolved.provider, model: resolved.model }, input.cwd, undefined, undefined, deployment);
|
|
172
208
|
}
|
|
173
|
-
return { status: 'found', runtime: { model: selected.model, selector: selected.selector, providerName: selected.config.providerName, capabilities: selected.config.capabilities, requestOptions: providerRequestSettings(selected.config) } };
|
|
209
|
+
return { status: 'found', runtime: { model: selected.model, selector: selected.selector, providerName: selected.config.providerName, capabilities: selected.config.capabilities, requestOptions: providerRequestSettings(selected.config), contextWindowTokens: selected.config.contextWindowTokens, maxOutputTokens: selected.config.maxOutputTokens, ...(selected.config.deployment ? { nativeMaxConcurrency: Math.min(2, selected.config.deployment.activeSequences) } : {}) } };
|
|
174
210
|
}
|
|
175
211
|
export function providerRequestSettings(config) {
|
|
176
212
|
// Top-level AI SDK `reasoning` setting; the key is omitted entirely when the
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
import type { HazeBuildManifest } from '../config/hazeBuild.js';
|
|
3
|
+
/** Native vLLM contract; the maintained compatible adapter preserves reasoning both ways. */
|
|
4
|
+
export declare function createHazeBuildModel(input: {
|
|
5
|
+
baseURL: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
manifest: HazeBuildManifest;
|
|
8
|
+
fetchImpl?: typeof fetch;
|
|
9
|
+
}): LanguageModel;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js';
|
|
3
|
+
/** Native vLLM contract; the maintained compatible adapter preserves reasoning both ways. */
|
|
4
|
+
export function createHazeBuildModel(input) {
|
|
5
|
+
const fetchImpl = input.fetchImpl ?? fetch;
|
|
6
|
+
const provider = createOpenAICompatible({
|
|
7
|
+
name: 'hazeBuild', baseURL: input.baseURL, apiKey: input.apiKey, includeUsage: true,
|
|
8
|
+
fetch: async (url, init) => {
|
|
9
|
+
assertCredentialedEndpointSecure(String(url), input.apiKey);
|
|
10
|
+
// Credentials and repository prompts stay on the explicitly configured origin.
|
|
11
|
+
return fetchImpl(url, { ...init, redirect: 'error' });
|
|
12
|
+
},
|
|
13
|
+
transformRequestBody: (body) => {
|
|
14
|
+
const effort = body.reasoning_effort;
|
|
15
|
+
const enabled = typeof effort === 'string' ? effort !== 'none' : undefined;
|
|
16
|
+
// The client owns native sampling (the server override is only a fallback
|
|
17
|
+
// for ad-hoc checks) and stays mode-aware: the pinned model recommends
|
|
18
|
+
// 0.6/0.95 for thinking and 0.7/0.8 without it. Unset thinking means the
|
|
19
|
+
// template default (on), so it keeps the thinking samplers.
|
|
20
|
+
const samplers = enabled === false ? { temperature: 0.7, top_p: 0.8 } : { temperature: 0.6, top_p: 0.95 };
|
|
21
|
+
const transformed = { ...body,
|
|
22
|
+
temperature: body.temperature ?? samplers.temperature,
|
|
23
|
+
top_p: body.top_p ?? samplers.top_p,
|
|
24
|
+
top_k: body.top_k ?? 20, presence_penalty: body.presence_penalty ?? 0,
|
|
25
|
+
repetition_penalty: body.repetition_penalty ?? 1,
|
|
26
|
+
chat_template_kwargs: { preserve_thinking: input.manifest.capabilities.preserveThinking,
|
|
27
|
+
...(enabled === undefined ? {} : { enable_thinking: enabled }) },
|
|
28
|
+
};
|
|
29
|
+
// Qwen supports a binary switch, not distinct OpenAI compute-effort levels.
|
|
30
|
+
delete transformed.reasoning_effort;
|
|
31
|
+
return transformed;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return provider.chatModel(input.manifest.model);
|
|
35
|
+
}
|