@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.7.0 - 2026-06-29
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **`--output stream-json` for print mode.** `haze -p "…" --output stream-json` streams the run as newline-delimited JSON: public progress events (`turn_start`, `message_start`/`message_update`/`message_end`, `tool_start`/`tool_end`, `retry`, `context_overflow`, `turn_end`, each with an ISO-8601 `at` timestamp) are written to stdout as they happen, and the final line is the same `{type,status,result,usage}` envelope as `--output json`. Tool events omit raw inputs/outputs so captured stdout stays suitable for harness and CI logs. Previously print mode stayed silent until the end and emitted only that single envelope, so harnesses driving Haze headlessly had no live progress and could not run stdout-based stagnation/loop detection on a silent-but-alive run. Every line is standalone valid JSON (pipeable through `jq -c .`). `text` and `json` outputs are unchanged.
|
|
10
|
+
- **Startup context visibility.** The interactive startup message now lists the context files sent with the system prompt, making it easier to verify whether global `CLAUDE.md`/`AGENTS.md` and workspace instructions were loaded.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **CLI print mode.** `haze -p "prompt"` runs a single non-interactive turn and prints the result, with optional `--model provider:name` override (per-run, no settings write) and `--output json` structured output. Reads the prompt from stdin when piped. The exit code and JSON `status` are driven by the agent's authoritative terminal state (`complete`/`aborted`/`failed`) rather than by parsing the reply, so CI gating on the exit code is reliable. A bad or ambiguous `--model` selector reports a precise error and exits non-zero, `--debug` writes a JSONL log under `~/.haze/logs/`, and the `--output json` `usage` object is pinned to a documented set of fields.
|
|
15
|
+
- **Scoped context refresh during turns.** Nested `CLAUDE.md`/`AGENTS.md` files discovered by file tools are injected into the next model step, tracked by signature, and reread when they change. Concurrent scoped-context discovery is serialized so unchanged instruction files are read once while still surfacing newly changed guidance.
|
|
16
|
+
- **Smaller durable session files.** Session persistence now drops streaming `message_update` events and slims large tool outputs/errors in persisted `tool_end` events and `conversation_snapshot` tool results to previews plus byte counts. Sessions remain resumable while avoiding runaway JSONL growth from repeated streamed text or large file reads.
|
|
17
|
+
|
|
18
|
+
### Security
|
|
19
|
+
|
|
20
|
+
- **Closed a DNS-rebinding TOCTOU in the `fetch` tool.** `urlGuard.validateUrl` resolved a hostname and confirmed every address was public, but the subsequent global `fetch` re-resolved the hostname at connect time, so an attacker-controlled DNS server could answer validation with a public IP and connect with an internal/cloud-metadata IP — fully bypassing the SSRF guard that exists precisely to stop that. `fetchUrlContent` now pins each connection (and each redirect hop) to the already-validated IP via a small stdlib transport that preserves the original `Host` header and TLS `servername`/cert verification, with no second DNS lookup between validation and connect. The post-fetch re-validation was removed as it re-resolved DNS against an already-pinned connection and only reopened the race. Literal-IP URLs keep using the global `fetch` (no rebinding surface).
|
|
21
|
+
|
|
3
22
|
## 0.6.0 - 2026-06-21
|
|
4
23
|
|
|
5
24
|
### Added
|
package/README.md
CHANGED
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
A minimal LLM harness for your terminal.
|
|
4
4
|
|
|
5
|
-
## What's new in 0.
|
|
5
|
+
## What's new in 0.7.0
|
|
6
6
|
|
|
7
|
-
Haze 0.
|
|
7
|
+
Haze 0.7.0 focuses on headless observability, safer web fetches, more reliable scoped project instructions, and durable sessions that stay small enough to keep.
|
|
8
8
|
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **Context breakdown.** `/context` shows estimated system-prompt, project-context, tool (including MCP), and message tokens for the current request.
|
|
15
|
-
- **Startup update check.** Haze quietly surfaces a newer published version when one exists.
|
|
9
|
+
- **Live print-mode JSON streams.** `haze -p "…" --output stream-json` emits newline-delimited progress events (`turn_start`, message events, tool events, retries, context overflow, `turn_end`) as they happen, then finishes with the same result envelope as `--output json`. Tool event payloads omit raw inputs/outputs so CI logs stay safe and compact.
|
|
10
|
+
- **Pinned-connection `fetch` safety.** Public URL fetching now pins each request and redirect hop to the IP address that passed validation, preserving the original `Host`/TLS server name and closing a DNS-rebinding race between URL validation and connection.
|
|
11
|
+
- **Scoped instructions refresh during a turn.** When file tools discover nested `CLAUDE.md`/`AGENTS.md`, Haze injects those instructions into the next model step, tracks file signatures, and rereads changed scoped guidance instead of assuming the first version stays valid forever.
|
|
12
|
+
- **Smaller durable sessions.** Session JSONL no longer persists every streaming `message_update`, and large tool outputs in persisted events/snapshots are replaced with previews plus size metadata. Resume remains useful while `~/.haze/sessions` avoids runaway growth.
|
|
13
|
+
- **Startup context visibility.** The opening system message now lists which context files were sent with the system prompt, making global/project instruction loading easier to verify.
|
|
16
14
|
|
|
17
15
|
Previous releases:
|
|
18
16
|
|
|
17
|
+
- **0.6.0** — AI SDK-native ToolLoopAgent core, optional LSP semantic navigation, MCP server support, unified config pickers, cleaner transcripts, `/context`, and startup update checks.
|
|
19
18
|
- **0.5.0** — `fetch` tool for public URLs (Markdown/JSON/text, SSRF-protected), removed all provider env vars (config via `/provider`/`/model`/`/settings`), debug-only LLM logs, command-aware output reduction, Markdown rendering in the CLI, scoped nested context files, and auto-clearing completed tasks.
|
|
20
19
|
- **0.4.0** — 3-step skill wizard, language-agnostic skill intent extraction, model-managed tasks, leaner command surface, docs site additions.
|
|
21
20
|
- **0.3.0** — Docs site redesign, task bar moves above the activity spinner, tasks auto-clear between sessions.
|
|
@@ -205,6 +204,52 @@ haze --continue # resume the latest saved session for this workspace
|
|
|
205
204
|
haze --no-session # run without durable session storage
|
|
206
205
|
```
|
|
207
206
|
|
|
207
|
+
Non-interactive / print mode:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
haze -p "refactor utils.ts to remove the unused export"
|
|
211
|
+
haze -p "summarize this repo" --model openai:gpt-4o-mini
|
|
212
|
+
haze -p "list the top 3 bugs in src/api.ts" --output json
|
|
213
|
+
haze -p "audit src/auth.ts" --output stream-json # live NDJSON events, then the result envelope
|
|
214
|
+
echo "what does this project do?" | haze
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`-p` / `--prompt` runs a single agentic turn (with the full tool set and guardrails) and prints the final assistant text. `--model` overrides the active model for that one run without changing `~/.haze/settings.json` — accepts a bare model name or `provider:name`. The selected model must already be registered under a provider's `models` (add it once via `/provider`); an unknown or ambiguous selector exits non-zero with a precise error on stderr. When `-p` is omitted and stdin is piped, the prompt is read from stdin. A one-shot run never starts or resumes a durable session; `--continue` is ignored in this mode. Headless runs do **not** auto-compact on context overflow, so very large CI prompts may fail rather than recover — keep prompts within the model's window. Add `--debug` to also write a detailed JSONL log under `~/.haze/logs/`. `--output` selects how the run is reported: `text` (default), `json` (a single final envelope), or `stream-json` (a live NDJSON event stream ending in that envelope) — see below.
|
|
218
|
+
|
|
219
|
+
`--output json` prints a single-line envelope instead of plain text:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"type": "result",
|
|
224
|
+
"status": "complete", // "complete" (exit 0) | "aborted" | "failed" (both exit non-zero)
|
|
225
|
+
"result": "the final assistant text",
|
|
226
|
+
"usage": {
|
|
227
|
+
"inputTokens": 0,
|
|
228
|
+
"outputTokens": 0,
|
|
229
|
+
"cacheReadTokens": 0,
|
|
230
|
+
"cacheWriteTokens": 0,
|
|
231
|
+
"reasoningTokens": 0
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The `status` field is authoritative (driven by the agent's terminal state, not by parsing `result`), and the exit code mirrors it: `0` only for `complete`. A `complete` run with an empty `result` means the model produced no visible text — distinct from a `failed` run.
|
|
237
|
+
|
|
238
|
+
`--output stream-json` streams the run as it happens instead of staying silent until the end. Each public progress event is written to stdout as one newline-delimited JSON object (NDJSON), and the **last** line is the exact same `{ type: "result", status, result, usage }` envelope as `--output json` — so a consumer can render live progress and still parse the final line identically:
|
|
239
|
+
|
|
240
|
+
```jsonc
|
|
241
|
+
{"type":"turn_start","request":"audit src/auth.ts","at":"2026-06-27T22:00:00.000Z"}
|
|
242
|
+
{"type":"message_start","id":"a1","role":"assistant","at":"..."}
|
|
243
|
+
{"type":"message_update","id":"a1","text":"Reading the auth module…","at":"..."}
|
|
244
|
+
{"type":"tool_start","id":"t1","name":"readFile","at":"..."}
|
|
245
|
+
{"type":"tool_end","id":"t1","name":"readFile","success":true,"durationMs":12,"at":"..."}
|
|
246
|
+
{"type":"message_end","id":"a1","text":"Here are the findings…","at":"..."}
|
|
247
|
+
{"type":"turn_end","request":"audit src/auth.ts","status":"complete","at":"..."}
|
|
248
|
+
{"type":"result","status":"complete","result":"Here are the findings…","usage":{"inputTokens":0,"outputTokens":0,"cacheReadTokens":0,"cacheWriteTokens":0,"reasoningTokens":0}}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Every line is standalone valid JSON, so the stream pipes cleanly through `jq -c .`. The event types are `turn_start`, `message_start` / `message_update` / `message_end`, `tool_start` / `tool_end`, `retry`, `context_overflow`, and `turn_end`; each carries an ISO-8601 `at` timestamp. Tool events intentionally omit raw tool inputs and outputs because stdout is often captured by CI/harness logs; use `--debug` when detailed local JSONL logs are needed. This mode is intended for harnesses driving Haze autonomously: the incremental, ever-changing output lets a supervisor show live progress and run stdout-based stagnation/loop detection, while the trailing `result` envelope remains the single source of truth for status, text, and usage. `text` and `json` outputs are unchanged.
|
|
252
|
+
|
|
208
253
|
By default, Haze does **not** write the detailed LLM log files under `~/.haze/logs/` (they capture full prompts, messages, and tool I/O). File logging is only enabled with `haze --debug`, which also turns on the on-screen debug panel. Use the `/logs` command to review past log files once logging has been enabled.
|
|
209
254
|
|
|
210
255
|
## Agent tools
|
|
@@ -217,7 +262,7 @@ Haze exposes a deliberately small toolset:
|
|
|
217
262
|
- `editFile` — unique text replacements, with line-number-prefix tolerance for common model mistakes.
|
|
218
263
|
- `replaceLines` — line-range edits when exact replacements are awkward; slightly-too-large EOF ranges are clamped.
|
|
219
264
|
- `writeFile` — create files and parent directories.
|
|
220
|
-
- `bash` — run tests, builds, git commands, inspections, scripts, installs, and other shell workflows with command-aware output reduction and compact validation output.
|
|
265
|
+
- `bash` — run tests, builds, git/gh commands, inspections, scripts, installs, and other shell workflows with command-aware output reduction (git, gh, search, JSON, diffs, logs) and compact validation output.
|
|
221
266
|
- `readToolOutput` — page through full/raw output omitted from an oversized or reduced tool result.
|
|
222
267
|
- `fetch` — read a public `http(s)` URL and return readable content (Markdown for docs, pretty JSON, or text). Private/loopback/metadata hosts and non-`http(s)` schemes are blocked; output is bounded and retrievable via `readToolOutput`.
|
|
223
268
|
- `writeTasks` — replace the task list at meaningful phase changes; completed lists auto-clear on the next user turn.
|
|
@@ -251,6 +296,8 @@ Use them for parallel investigation across separate areas of a codebase. Do not
|
|
|
251
296
|
|
|
252
297
|
Haze saves durable workspace sessions in `~/.haze/sessions`. Use `/session` to see the current file, `/new` to start fresh, `/resume` to restore the latest session, and `/compact` to summarize older model context. Sessions also persist compact structured work state: the active goal, touched files, validation evidence, blockers, and next action.
|
|
253
298
|
|
|
299
|
+
Session files are optimized for resume and audit, not token-by-token playback: completed user/assistant messages, tool lifecycle events, conversation snapshots, and work-state snapshots are persisted, but streaming `message_update` events are skipped. Large persisted tool outputs are replaced with previews and byte counts so a resumed model can reread current files instead of carrying stale megabytes forward.
|
|
300
|
+
|
|
254
301
|
Long turns use bounded tool slices. Older successful tool results are compacted while failures and recent evidence remain verbatim, synthetic Haze control nudges are not persisted as user requests, and token-pressure compaction preserves the structured work state.
|
|
255
302
|
|
|
256
303
|
Haze loads project instructions from:
|
|
@@ -259,7 +306,7 @@ Haze loads project instructions from:
|
|
|
259
306
|
- `~/.haze/AGENTS.md`
|
|
260
307
|
- `CLAUDE.md` / `AGENTS.md` files from filesystem root to the current workspace
|
|
261
308
|
|
|
262
|
-
At the same scope, `AGENTS.md` overrides `CLAUDE.md`; global Haze guidance in `~/.haze/AGENTS.md` overrides global Claude guidance in `~/.claude/CLAUDE.md`. Nested `CLAUDE.md` / `AGENTS.md` files below the workspace are scoped: Haze surfaces them only when file tools operate inside that directory or its subdirectories, and mutating tools stop once so the model can review
|
|
309
|
+
At the same scope, `AGENTS.md` overrides `CLAUDE.md`; global Haze guidance in `~/.haze/AGENTS.md` overrides global Claude guidance in `~/.claude/CLAUDE.md`. Nested `CLAUDE.md` / `AGENTS.md` files below the workspace are scoped: Haze surfaces them only when file tools operate inside that directory or its subdirectories, injects newly discovered scoped guidance into the next model step, and mutating tools stop once so the model can review it before editing. Scoped context files are tracked by signature, so changed nested guidance can be read again later in the same session.
|
|
263
310
|
|
|
264
311
|
Use `AGENTS.md` for project conventions, commands, architecture notes, and things future-you does not want to re-explain. `/init` is intentionally budget-aware: it does one small discovery pass, preserves useful existing guidance, and asks for a compact file because context files are injected into every request.
|
|
265
312
|
|
|
@@ -269,7 +316,7 @@ Use `AGENTS.md` for project conventions, commands, architecture notes, and thing
|
|
|
269
316
|
- File tools follow `.gitignore` by default.
|
|
270
317
|
- Ignored files require an explicit override.
|
|
271
318
|
- Bash commands are classified and shown with working-directory metadata, but Haze does not use command confirmation gates.
|
|
272
|
-
- The `fetch` tool reads public `http(s)` URLs only; private, loopback, link-local, and cloud-metadata hosts and non-`http(s)` schemes are blocked,
|
|
319
|
+
- The `fetch` tool reads public `http(s)` URLs only; private, loopback, link-local, and cloud-metadata hosts and non-`http(s)` schemes are blocked, and each redirect hop is connected to the already validated public IP to avoid DNS-rebinding races.
|
|
273
320
|
- Mutating and destructive commands can run when they are relevant to the user's request; this is intentional for expert users.
|
|
274
321
|
- Haze is powerful enough to help and dumb enough to deserve supervision. Ideal software, basically.
|
|
275
322
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Task } from '../../core/tasks/taskStorage.js';
|
|
3
|
+
export declare const MAX_VISIBLE_TASKS = 5;
|
|
4
|
+
export declare function TaskBar({ tasks, width, expanded, padding }: {
|
|
5
|
+
tasks: Task[];
|
|
6
|
+
width: number;
|
|
7
|
+
expanded: boolean;
|
|
8
|
+
padding: number;
|
|
9
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { theme } from '../../ui/theme.js';
|
|
4
|
+
const TASK_STATUS_ICON = {
|
|
5
|
+
pending: '\u25CB',
|
|
6
|
+
in_progress: '\u25D0',
|
|
7
|
+
completed: '\u2713',
|
|
8
|
+
};
|
|
9
|
+
function taskStatusColor(status) {
|
|
10
|
+
switch (status) {
|
|
11
|
+
case 'completed': return theme.success;
|
|
12
|
+
case 'in_progress': return theme.warning;
|
|
13
|
+
default: return theme.muted;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export const MAX_VISIBLE_TASKS = 5;
|
|
17
|
+
export function TaskBar({ tasks, width, expanded, padding }) {
|
|
18
|
+
const maxTitleWidth = Math.max(10, width - 6);
|
|
19
|
+
const inProgress = tasks.filter(t => t.status === 'in_progress');
|
|
20
|
+
const pending = tasks.filter(t => t.status === 'pending');
|
|
21
|
+
const completed = tasks.filter(t => t.status === 'completed');
|
|
22
|
+
const limit = expanded ? tasks.length : MAX_VISIBLE_TASKS;
|
|
23
|
+
const ordered = [];
|
|
24
|
+
for (const t of inProgress) {
|
|
25
|
+
if (ordered.length < limit)
|
|
26
|
+
ordered.push(t);
|
|
27
|
+
}
|
|
28
|
+
for (const t of pending) {
|
|
29
|
+
if (ordered.length < limit)
|
|
30
|
+
ordered.push(t);
|
|
31
|
+
}
|
|
32
|
+
for (let i = completed.length - 1; i >= 0 && ordered.length < limit; i--) {
|
|
33
|
+
ordered.push(completed[i]);
|
|
34
|
+
}
|
|
35
|
+
const counts = `${inProgress.length > 0 ? `${inProgress.length} active` : ''}${pending.length > 0 ? `${inProgress.length > 0 ? ', ' : ''}${pending.length} pending` : ''}${completed.length > 0 ? `${inProgress.length + pending.length > 0 ? ', ' : ''}${completed.length} done` : ''}`;
|
|
36
|
+
return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [padding > 0 && Array.from({ length: padding }, (_, i) => _jsx(Text, { children: ' ' }, `pad-${i}`)), _jsxs(Text, { children: [_jsx(Text, { color: theme.purple, bold: true, children: "Tasks" }), counts ? _jsxs(Text, { color: theme.muted, children: [" (", counts, ")"] }) : null, tasks.length > MAX_VISIBLE_TASKS ? _jsxs(Text, { color: theme.muted, dimColor: true, children: [" \u00B7 ctrl+o ", expanded ? 'collapse' : 'expand'] }) : null] }), ordered.map(task => {
|
|
37
|
+
const title = task.title.length > maxTitleWidth ? task.title.slice(0, maxTitleWidth - 1) + '\u2026' : task.title;
|
|
38
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: taskStatusColor(task.status), children: [TASK_STATUS_ICON[task.status], " "] }), _jsx(Text, { color: task.status === 'completed' ? theme.muted : 'white', children: title })] }, task.id));
|
|
39
|
+
})] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
import type { Message } from '../commands/streaming.js';
|
|
3
|
+
export declare function toolCallCount(messages: Message[]): number;
|
|
4
|
+
export declare function estimateTokens(text: string): number;
|
|
5
|
+
export declare function compactHomePath(filePath: string, home?: string): string;
|
|
6
|
+
export declare function formatTokenCount(tokens: number): string;
|
|
7
|
+
export declare function displayMessagesFromConversation(conversation: ModelMessage[]): Message[];
|
|
8
|
+
export declare function estimateConversationTokens(messages: Message[]): {
|
|
9
|
+
input: number;
|
|
10
|
+
output: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { modelMessageText } from '../../core/agent/compaction.js';
|
|
3
|
+
export function toolCallCount(messages) {
|
|
4
|
+
return messages.reduce((total, message) => {
|
|
5
|
+
if (message.role !== 'tool')
|
|
6
|
+
return total;
|
|
7
|
+
const headerCount = /Tools: (\d+) calls?/.exec(message.text)?.[1];
|
|
8
|
+
if (headerCount)
|
|
9
|
+
return total + Number(headerCount);
|
|
10
|
+
const rows = message.text.split('\n').filter(line => /^\s+[✓✗…]\s/.test(line));
|
|
11
|
+
return total + rows.reduce((rowTotal, row) => rowTotal + Number(/×(\d+)/.exec(row)?.[1] ?? 1), 0);
|
|
12
|
+
}, 0);
|
|
13
|
+
}
|
|
14
|
+
export function estimateTokens(text) {
|
|
15
|
+
return Math.ceil(text.length / 4);
|
|
16
|
+
}
|
|
17
|
+
export function compactHomePath(filePath, home = os.homedir()) {
|
|
18
|
+
if (filePath === home)
|
|
19
|
+
return '~';
|
|
20
|
+
return filePath.startsWith(`${home}/`) ? `~/${filePath.slice(home.length + 1)}` : filePath;
|
|
21
|
+
}
|
|
22
|
+
export function formatTokenCount(tokens) {
|
|
23
|
+
if (tokens >= 1_000_000)
|
|
24
|
+
return `${(tokens / 1_000_000).toFixed(tokens >= 10_000_000 ? 0 : 1).replace(/\.0$/, '')}m`;
|
|
25
|
+
if (tokens >= 1_000)
|
|
26
|
+
return `${(tokens / 1_000).toFixed(tokens >= 10_000 ? 0 : 1).replace(/\.0$/, '')}k`;
|
|
27
|
+
return String(tokens);
|
|
28
|
+
}
|
|
29
|
+
export function displayMessagesFromConversation(conversation) {
|
|
30
|
+
return conversation.flatMap(message => {
|
|
31
|
+
if (message.role !== 'user' && message.role !== 'assistant')
|
|
32
|
+
return [];
|
|
33
|
+
const text = modelMessageText(message).trim();
|
|
34
|
+
return text ? [{ role: message.role, text }] : [];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function estimateConversationTokens(messages) {
|
|
38
|
+
const inputText = messages
|
|
39
|
+
.filter(message => message.role === 'user' || message.role === 'tool')
|
|
40
|
+
.map(message => message.text)
|
|
41
|
+
.join('\n');
|
|
42
|
+
const outputText = messages
|
|
43
|
+
.filter(message => message.role === 'assistant')
|
|
44
|
+
.map(message => message.text)
|
|
45
|
+
.join('\n');
|
|
46
|
+
return {
|
|
47
|
+
input: estimateTokens(inputText),
|
|
48
|
+
output: estimateTokens(outputText),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { LoadedSkill } from '../../skills/types.js';
|
|
3
|
+
import type { TextInputSuggestion } from '../../ui/components/TextInput.js';
|
|
4
|
+
import type { Mode } from '../commands/chatModes.js';
|
|
5
|
+
interface InputSuggestionState {
|
|
6
|
+
mode: Mode;
|
|
7
|
+
settings: HazeSettings;
|
|
8
|
+
skills: LoadedSkill[];
|
|
9
|
+
selectedProviderName?: string;
|
|
10
|
+
modelProviderFilter?: string;
|
|
11
|
+
selectedSkillName?: string;
|
|
12
|
+
selectedLspName?: string;
|
|
13
|
+
selectedMcpName?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function inputSuggestionsForState(state: InputSuggestionState): TextInputSuggestion[];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
2
|
+
import { providerSuggestions, providerActionSuggestions, presetSuggestions, modelSuggestions, lspSuggestions, lspActionSuggestions, lspPresetSuggestions, mcpSuggestions, mcpActionSuggestions, mcpPresetSuggestions, mcpTransportSuggestions, skillsSuggestions, skillsActionSuggestions } from '../commands/wizardSuggestions.js';
|
|
3
|
+
const CHAT_COMMAND_SUGGESTIONS = [
|
|
4
|
+
{ value: '/help', description: 'Show commands', kind: 'command' },
|
|
5
|
+
{ value: '/provider', description: 'Choose a provider', kind: 'command' },
|
|
6
|
+
{ value: '/model', description: 'Choose a model', kind: 'command' },
|
|
7
|
+
{ value: '/lsp', description: 'Manage LSP servers (semantic navigation)', kind: 'command' },
|
|
8
|
+
{ value: '/mcp', description: 'Manage MCP servers (Context7, etc.)', kind: 'command' },
|
|
9
|
+
{ value: '/settings', description: 'Show provider, model, API key, and context status', kind: 'command' },
|
|
10
|
+
{ value: '/context', description: 'Show token breakdown of system, tools, MCP, and messages', kind: 'command' },
|
|
11
|
+
{ value: '/skills', description: 'Manage Markdown skills (add, enable/disable, validate, remove)', kind: 'command' },
|
|
12
|
+
{ value: '/init', description: 'Create or update AGENTS.md project instructions', kind: 'command' },
|
|
13
|
+
{ value: '/session', description: 'Show current session path', kind: 'command' },
|
|
14
|
+
{ value: '/resume', description: 'Resume latest session for this workspace', kind: 'command' },
|
|
15
|
+
{ value: '/new', description: 'Start a new session', kind: 'command' },
|
|
16
|
+
{ value: '/compact ', description: 'Summarize older context and keep recent messages', kind: 'command' },
|
|
17
|
+
{ value: '/clear', description: 'Clear conversation history', kind: 'command' },
|
|
18
|
+
{ value: '/exit', description: 'Exit Haze', kind: 'command' },
|
|
19
|
+
{ value: '/quit', description: 'Exit Haze', kind: 'command' },
|
|
20
|
+
];
|
|
21
|
+
export function inputSuggestionsForState(state) {
|
|
22
|
+
const { mode, settings, skills } = state;
|
|
23
|
+
if (mode === 'provider')
|
|
24
|
+
return providerSuggestions(settings);
|
|
25
|
+
if (mode === 'providerAction')
|
|
26
|
+
return providerActionSuggestions(settings, state.selectedProviderName);
|
|
27
|
+
if (mode === 'providerAddPreset')
|
|
28
|
+
return presetSuggestions();
|
|
29
|
+
if (mode === 'model')
|
|
30
|
+
return modelSuggestions(settings, state.modelProviderFilter);
|
|
31
|
+
if (mode === 'skills')
|
|
32
|
+
return skillsSuggestions(settings, skills);
|
|
33
|
+
if (mode === 'skillsAction')
|
|
34
|
+
return skillsActionSuggestions(settings, skills, state.selectedSkillName);
|
|
35
|
+
if (mode === 'lsp')
|
|
36
|
+
return lspSuggestions(settings);
|
|
37
|
+
if (mode === 'lspAction')
|
|
38
|
+
return lspActionSuggestions(settings, state.selectedLspName);
|
|
39
|
+
if (mode === 'lspAddPreset')
|
|
40
|
+
return lspPresetSuggestions();
|
|
41
|
+
if (mode === 'mcp')
|
|
42
|
+
return mcpSuggestions(settings);
|
|
43
|
+
if (mode === 'mcpAction')
|
|
44
|
+
return mcpActionSuggestions(settings, state.selectedMcpName);
|
|
45
|
+
if (mode === 'mcpAddPreset')
|
|
46
|
+
return mcpPresetSuggestions();
|
|
47
|
+
if (mode === 'mcpAddTransport')
|
|
48
|
+
return mcpTransportSuggestions();
|
|
49
|
+
if (mode !== 'chat')
|
|
50
|
+
return [];
|
|
51
|
+
return [
|
|
52
|
+
...CHAT_COMMAND_SUGGESTIONS,
|
|
53
|
+
...skills.filter(skill => isSkillEnabled(settings, skill.name)).map(skill => ({ value: `/${skill.name}`, description: skill.description, kind: 'skill' })),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Message } from '../commands/streaming.js';
|
|
3
|
+
export declare function messageElapsedLabel(message: Message): string;
|
|
4
|
+
export declare function MessageView({ message, width }: {
|
|
5
|
+
message: Message;
|
|
6
|
+
width: number;
|
|
7
|
+
}): React.JSX.Element;
|
|
8
|
+
export declare function messageKey(message: Message, index: number): string;
|
|
9
|
+
export declare function orderedDisplayMessages(messages: Message[]): Message[];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import Spinner from 'ink-spinner';
|
|
4
|
+
import { formatElapsedTime, formatElapsedTimeWhole } from '../commands/formatters.js';
|
|
5
|
+
import { MarkdownText } from '../../ui/components/MarkdownText.js';
|
|
6
|
+
import { isSubstantiveAssistantText } from '../commands/streaming/assistantText.js';
|
|
7
|
+
import { theme } from '../../ui/theme.js';
|
|
8
|
+
function fullWidthLines(text, width, leftPadding = 0) {
|
|
9
|
+
const safeWidth = Math.max(1, width);
|
|
10
|
+
const prefix = ' '.repeat(leftPadding);
|
|
11
|
+
return text.replace(/\r\n|\r/g, '\n').split('\n').map(line => `${prefix}${line}`.padEnd(Math.max(safeWidth, line.length + leftPadding)));
|
|
12
|
+
}
|
|
13
|
+
function fullWidthBlankLine(width) {
|
|
14
|
+
return ''.padEnd(Math.max(1, width));
|
|
15
|
+
}
|
|
16
|
+
function ToolMessageText({ text, streaming }) {
|
|
17
|
+
const lines = text.split('\n');
|
|
18
|
+
return _jsx(Box, { flexDirection: "column", children: lines.map((line, index) => {
|
|
19
|
+
const diffRow = /^(\s*\d+\s+)([+-])(.*)$/.exec(line);
|
|
20
|
+
if (diffRow) {
|
|
21
|
+
const [, prefix, marker, rest] = diffRow;
|
|
22
|
+
const isAdd = marker === '+';
|
|
23
|
+
return _jsxs(Text, { color: "white", backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [_jsxs(Text, { color: isAdd ? theme.success : theme.danger, backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [prefix, marker] }), rest] }, `${index}-${line}`);
|
|
24
|
+
}
|
|
25
|
+
const contextRow = /^(\s*\d+\s+)\s(.*)$/.exec(line);
|
|
26
|
+
if (contextRow) {
|
|
27
|
+
const [, prefix, rest] = contextRow;
|
|
28
|
+
return _jsxs(Text, { color: "white", children: [_jsxs(Text, { color: theme.muted, children: [prefix, " "] }), rest] }, `${index}-${line}`);
|
|
29
|
+
}
|
|
30
|
+
const row = /^(\s*)([✓✗…])\s+(\S+)(.*)$/.exec(line);
|
|
31
|
+
if (!row) {
|
|
32
|
+
const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(line);
|
|
33
|
+
return _jsxs(Text, { color: theme.muted, children: [index === 0 && streaming ? _jsxs(_Fragment, { children: [_jsx(Spinner, { type: "dots" }), " "] }) : null, timer ? timer[1] : line, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
|
|
34
|
+
}
|
|
35
|
+
const [, indent, icon, toolName, rest] = row;
|
|
36
|
+
const iconColor = icon === '✓' ? theme.success : icon === '✗' ? theme.danger : theme.muted;
|
|
37
|
+
const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(rest);
|
|
38
|
+
return _jsxs(Text, { color: theme.muted, children: [indent, _jsx(Text, { color: iconColor, children: icon }), " ", _jsx(Text, { color: theme.purple, children: toolName }), timer ? timer[1] : rest, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
|
|
39
|
+
}) });
|
|
40
|
+
}
|
|
41
|
+
export function messageElapsedLabel(message) {
|
|
42
|
+
if (message.startedAt == null)
|
|
43
|
+
return '';
|
|
44
|
+
if (message.role === 'assistant' && !message.streaming && !isSubstantiveAssistantText(message.text))
|
|
45
|
+
return '';
|
|
46
|
+
const end = message.finishedAt ?? (message.streaming ? Date.now() : message.startedAt);
|
|
47
|
+
const elapsed = end - message.startedAt;
|
|
48
|
+
if (message.role === 'assistant' && !message.streaming && message.tokensPerSecond != null) {
|
|
49
|
+
return `✓ Done in ${formatElapsedTime(elapsed)} · ${Math.round(message.tokensPerSecond)} tok/s`;
|
|
50
|
+
}
|
|
51
|
+
return message.streaming ? formatElapsedTimeWhole(elapsed) : formatElapsedTime(elapsed);
|
|
52
|
+
}
|
|
53
|
+
export function MessageView({ message, width }) {
|
|
54
|
+
if (message.role === 'user') {
|
|
55
|
+
return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) }), _jsx(Text, { color: theme.success, bold: true, backgroundColor: theme.quoteBg, children: ' You asked'.padEnd(width) }), fullWidthLines(message.text, width, 2).map((line, lineIndex) => _jsx(Text, { color: "white", backgroundColor: theme.quoteBg, children: line }, lineIndex)), _jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) })] });
|
|
56
|
+
}
|
|
57
|
+
return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: message.role === 'assistant' ? theme.purple : message.role === 'tool' ? theme.blue : theme.muted, bold: true, children: message.role === 'assistant' ? 'haze' : message.role === 'tool' ? 'Tool' : 'Info' }), messageElapsedLabel(message) ? _jsxs(Text, { color: theme.muted, bold: false, children: [" \u00B7 ", messageElapsedLabel(message)] }) : null] }), message.role === 'tool'
|
|
58
|
+
? _jsx(ToolMessageText, { text: message.text, streaming: message.streaming })
|
|
59
|
+
: message.role === 'assistant' && !message.streaming
|
|
60
|
+
? _jsx(MarkdownText, { content: message.text })
|
|
61
|
+
: _jsx(Text, { children: message.text })] });
|
|
62
|
+
}
|
|
63
|
+
export function messageKey(message, index) {
|
|
64
|
+
return message.id ?? `${index}-${message.role}-${message.text}`;
|
|
65
|
+
}
|
|
66
|
+
export function orderedDisplayMessages(messages) {
|
|
67
|
+
return messages
|
|
68
|
+
.map((message, index) => ({ message, index }))
|
|
69
|
+
.sort((a, b) => {
|
|
70
|
+
if (a.message.displayOrder != null && b.message.displayOrder != null && a.message.displayOrder !== b.message.displayOrder) {
|
|
71
|
+
return a.message.displayOrder - b.message.displayOrder;
|
|
72
|
+
}
|
|
73
|
+
return a.index - b.index;
|
|
74
|
+
})
|
|
75
|
+
.map(item => item.message);
|
|
76
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
import { type HazeSession } from '../../core/session/sessionStore.js';
|
|
3
|
+
import type { AgentEvent } from '../../core/agent/events.js';
|
|
4
|
+
import type { WorkState } from '../../core/agent/workState.js';
|
|
5
|
+
import type { Message } from '../commands/streaming.js';
|
|
6
|
+
export declare function createSessionRecorder(getSession: () => HazeSession | undefined): {
|
|
7
|
+
recordUiMessage(message: Message): void;
|
|
8
|
+
recordConversation(messages: ModelMessage[]): void;
|
|
9
|
+
recordWorkState(state: WorkState): void;
|
|
10
|
+
recordEvent(event: AgentEvent): void;
|
|
11
|
+
};
|
|
12
|
+
export type SessionRecorder = ReturnType<typeof createSessionRecorder>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { appendSessionEntry } from '../../core/session/sessionStore.js';
|
|
2
|
+
function appendFireAndForget(session, entry) {
|
|
3
|
+
if (session)
|
|
4
|
+
void appendSessionEntry(session, entry).catch(() => undefined);
|
|
5
|
+
}
|
|
6
|
+
export function createSessionRecorder(getSession) {
|
|
7
|
+
return {
|
|
8
|
+
recordUiMessage(message) {
|
|
9
|
+
appendFireAndForget(getSession(), { type: 'ui_message', at: new Date().toISOString(), role: message.role, text: message.text });
|
|
10
|
+
},
|
|
11
|
+
recordConversation(messages) {
|
|
12
|
+
appendFireAndForget(getSession(), { type: 'conversation_snapshot', at: new Date().toISOString(), messages });
|
|
13
|
+
},
|
|
14
|
+
recordWorkState(state) {
|
|
15
|
+
appendFireAndForget(getSession(), { type: 'work_state_snapshot', at: new Date().toISOString(), state });
|
|
16
|
+
},
|
|
17
|
+
recordEvent(event) {
|
|
18
|
+
appendFireAndForget(getSession(), { type: 'event', at: event.at, name: event.type, text: JSON.stringify(event) });
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
|
+
export declare function startupContextInfo(contextFiles: ContextFile[]): string;
|
|
4
|
+
export declare function startupProviderInfo(settings: HazeSettings): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { activeModel, configuredProviders, providerHasKey } from '../../config/providers.js';
|
|
2
|
+
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
3
|
+
import { configuredMcpServers } from '../../config/mcpSettings.js';
|
|
4
|
+
export function startupContextInfo(contextFiles) {
|
|
5
|
+
const lines = contextFiles.map(file => `- ${file.path}`);
|
|
6
|
+
return [
|
|
7
|
+
'Context files sent with the system prompt',
|
|
8
|
+
...(lines.length > 0 ? lines : ['- none']),
|
|
9
|
+
].join('\n');
|
|
10
|
+
}
|
|
11
|
+
export function startupProviderInfo(settings) {
|
|
12
|
+
const selection = activeModel(settings);
|
|
13
|
+
const configuredCount = configuredProviders(settings).length;
|
|
14
|
+
const lspServers = configuredLspServers(settings);
|
|
15
|
+
const enabledLsp = lspServers.filter(server => server.enabled !== false);
|
|
16
|
+
const lspLine = enabledLsp.length > 0
|
|
17
|
+
? `- LSP: ${enabledLsp.length} configured (${enabledLsp.map(server => server.name).join(', ')}; tools appear only when the command is installed)`
|
|
18
|
+
: '- LSP: none configured (optional: install a language server, then /lsp presets and /lsp add typescript for semantic code navigation)';
|
|
19
|
+
const mcpServers = configuredMcpServers(settings);
|
|
20
|
+
const enabledMcp = mcpServers.filter(server => server.enabled !== false);
|
|
21
|
+
const mcpLine = enabledMcp.length > 0
|
|
22
|
+
? `- MCP: ${enabledMcp.length} configured (${enabledMcp.map(server => server.name).join(', ')}; tools load each turn)`
|
|
23
|
+
: '- MCP: none configured (optional: /mcp add context7 for up-to-date library docs)';
|
|
24
|
+
if (!selection) {
|
|
25
|
+
return [
|
|
26
|
+
'Provider configuration',
|
|
27
|
+
'- Provider: not configured',
|
|
28
|
+
'- Model: not set',
|
|
29
|
+
'- Base URL: not configured',
|
|
30
|
+
'- API key: missing',
|
|
31
|
+
`- Configured providers: ${configuredCount}`,
|
|
32
|
+
lspLine,
|
|
33
|
+
mcpLine,
|
|
34
|
+
'',
|
|
35
|
+
'Run /provider to choose or add a provider, then select a model.',
|
|
36
|
+
].join('\n');
|
|
37
|
+
}
|
|
38
|
+
const model = selection.model;
|
|
39
|
+
const modelSource = settings.model ? 'settings' : 'provider default';
|
|
40
|
+
const baseURL = selection.provider.url;
|
|
41
|
+
const apiKeySource = providerHasKey(settings, selection.provider) ? `provider ${selection.provider.name}` : 'missing';
|
|
42
|
+
const provider = selection.provider.name;
|
|
43
|
+
return [
|
|
44
|
+
'Provider configuration',
|
|
45
|
+
`- Provider: ${provider}`,
|
|
46
|
+
`- Model: ${model} (${modelSource})`,
|
|
47
|
+
`- Base URL: ${baseURL} (settings)`,
|
|
48
|
+
`- API key: ${apiKeySource === 'missing' ? 'not configured; local providers may not need one' : `configured via ${apiKeySource}`}`,
|
|
49
|
+
`- Configured providers: ${configuredCount}`,
|
|
50
|
+
lspLine,
|
|
51
|
+
mcpLine,
|
|
52
|
+
].join('\n');
|
|
53
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Task } from '../../core/tasks/taskStorage.js';
|
|
2
|
+
import type { TokenUsage } from '../commands/streaming.js';
|
|
3
|
+
export declare const EMPTY_TOKEN_USAGE: TokenUsage;
|
|
4
|
+
export declare function shouldClearCompletedTasks(tasks: Task[]): boolean;
|
|
5
|
+
export declare function accumulateTokenUsage(current: TokenUsage, usage: TokenUsage): TokenUsage;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const EMPTY_TOKEN_USAGE = { inputTokens: undefined, outputTokens: undefined, systemPrompt: 0, messages: 0, toolSchemas: 0, outputEstimate: 0, cacheReadTokens: 0, cacheWriteTokens: 0, noCacheTokens: 0, reasoningTokens: 0, logicalInputEstimate: 0, effectiveNonCachedInput: undefined };
|
|
2
|
+
export function shouldClearCompletedTasks(tasks) {
|
|
3
|
+
return tasks.length > 0 && tasks.every(task => task.status === 'completed');
|
|
4
|
+
}
|
|
5
|
+
export function accumulateTokenUsage(current, usage) {
|
|
6
|
+
return {
|
|
7
|
+
inputTokens: (current.inputTokens ?? 0) + (usage.inputTokens ?? 0) || usage.inputTokens,
|
|
8
|
+
outputTokens: (current.outputTokens ?? 0) + (usage.outputTokens ?? 0) || usage.outputTokens,
|
|
9
|
+
systemPrompt: current.systemPrompt + usage.systemPrompt,
|
|
10
|
+
messages: current.messages + usage.messages,
|
|
11
|
+
toolSchemas: current.toolSchemas + usage.toolSchemas,
|
|
12
|
+
outputEstimate: current.outputEstimate + usage.outputEstimate,
|
|
13
|
+
cacheReadTokens: current.cacheReadTokens + usage.cacheReadTokens,
|
|
14
|
+
cacheWriteTokens: current.cacheWriteTokens + usage.cacheWriteTokens,
|
|
15
|
+
noCacheTokens: current.noCacheTokens + usage.noCacheTokens,
|
|
16
|
+
reasoningTokens: current.reasoningTokens + usage.reasoningTokens,
|
|
17
|
+
logicalInputEstimate: current.logicalInputEstimate + usage.logicalInputEstimate,
|
|
18
|
+
effectiveNonCachedInput: (current.effectiveNonCachedInput ?? 0) + (usage.effectiveNonCachedInput ?? 0) || usage.effectiveNonCachedInput,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type Mode = 'chat' | 'provider' | 'providerAction' | 'model' | 'providerAddPreset' | 'providerAddName' | 'providerAddUrl' | 'providerAddKey' | 'providerAddModels' | 'providerAppendModels' | 'providerSetKey' | 'providerRemoveModels' | 'providerConfirmRemove' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsAddDescription' | 'skillsConfirmRemove' | 'lsp' | 'lspAction' | 'lspAddPreset' | 'lspAddName' | 'lspAddCommand' | 'lspConfirmRemove' | 'mcp' | 'mcpAction' | 'mcpAddPreset' | 'mcpAddName' | 'mcpAddTransport' | 'mcpAddUrl' | 'mcpAddCommand' | 'mcpAddKey' | 'mcpSetKey' | 'mcpConfirmRemove';
|
|
2
1
|
interface ChatOptions {
|
|
3
2
|
debug?: boolean;
|
|
4
3
|
version?: string;
|