dvalincode 0.12.0 → 0.14.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/README.md +122 -24
- package/README.zh-CN.md +52 -4
- package/dist/agent/compact.d.ts +4 -2
- package/dist/agent/compact.js +41 -7
- package/dist/agent/compact.js.map +1 -1
- package/dist/agent/loop.js +30 -31
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/modes.d.ts +2 -2
- package/dist/agent/modes.js +6 -3
- package/dist/agent/modes.js.map +1 -1
- package/dist/agent/runner.d.ts +14 -6
- package/dist/agent/runner.js +370 -75
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session.d.ts +3 -1
- package/dist/agent/session.js +23 -2
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/types.d.ts +10 -5
- package/dist/agent/types.js +12 -2
- package/dist/agent/types.js.map +1 -1
- package/dist/audit/log.d.ts +4 -1
- package/dist/audit/log.js.map +1 -1
- package/dist/audit/report.js +5 -0
- package/dist/audit/report.js.map +1 -1
- package/dist/cli.js +6 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/chat.js +1 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/dvalin.d.ts +9 -0
- package/dist/commands/dvalin.js +222 -0
- package/dist/commands/dvalin.js.map +1 -0
- package/dist/commands/provider.js +3 -3
- package/dist/commands/provider.js.map +1 -1
- package/dist/commands/tui.js +2 -2
- package/dist/commands/tui.js.map +1 -1
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +238 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/context.d.ts +4 -0
- package/dist/core/context.js +8 -1
- package/dist/core/context.js.map +1 -1
- package/dist/core/guiUpdate.d.ts +27 -0
- package/dist/core/guiUpdate.js +65 -0
- package/dist/core/guiUpdate.js.map +1 -0
- package/dist/core/policy.d.ts +6 -3
- package/dist/core/policy.js +8 -1
- package/dist/core/policy.js.map +1 -1
- package/dist/core/selfUpdate.d.ts +108 -0
- package/dist/core/selfUpdate.js +180 -0
- package/dist/core/selfUpdate.js.map +1 -0
- package/dist/core/subprocessSandbox.d.ts +16 -0
- package/dist/core/subprocessSandbox.js +168 -28
- package/dist/core/subprocessSandbox.js.map +1 -1
- package/dist/core/trust.d.ts +8 -0
- package/dist/core/trust.js +1 -10
- package/dist/core/trust.js.map +1 -1
- package/dist/core/workspace.js +2 -1
- package/dist/core/workspace.js.map +1 -1
- package/dist/providers/anthropic.d.ts +14 -0
- package/dist/providers/anthropic.js +244 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/manager.d.ts +3 -0
- package/dist/providers/manager.js +13 -2
- package/dist/providers/manager.js.map +1 -1
- package/dist/providers/openaiCompatible.d.ts +12 -1
- package/dist/providers/openaiCompatible.js +21 -6
- package/dist/providers/openaiCompatible.js.map +1 -1
- package/dist/providers/pool.js +3 -4
- package/dist/providers/pool.js.map +1 -1
- package/dist/providers/trustedBaseUrls.js +1 -0
- package/dist/providers/trustedBaseUrls.js.map +1 -1
- package/dist/providers/types.d.ts +20 -4
- package/dist/remediation/automate.d.ts +18 -0
- package/dist/remediation/automate.js +78 -0
- package/dist/remediation/automate.js.map +1 -0
- package/dist/remediation/localScan.js +9 -1
- package/dist/remediation/localScan.js.map +1 -1
- package/dist/remediation/sarif.js +18 -4
- package/dist/remediation/sarif.js.map +1 -1
- package/dist/remediation/scannerSuite.d.ts +43 -0
- package/dist/remediation/scannerSuite.js +248 -0
- package/dist/remediation/scannerSuite.js.map +1 -0
- package/dist/server/routes/config.js +2 -3
- package/dist/server/routes/config.js.map +1 -1
- package/dist/server/routes/remediation.js +34 -0
- package/dist/server/routes/remediation.js.map +1 -1
- package/dist/server/scannerWorkspaceGrants.d.ts +7 -0
- package/dist/server/scannerWorkspaceGrants.js +48 -0
- package/dist/server/scannerWorkspaceGrants.js.map +1 -0
- package/dist/server/security.js +20 -6
- package/dist/server/security.js.map +1 -1
- package/dist/server/wsHandler.js.map +1 -1
- package/dist/skills/store.js +28 -0
- package/dist/skills/store.js.map +1 -1
- package/dist/tools/registry.d.ts +7 -0
- package/dist/tools/registry.js +30 -0
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/runCheck.js +1 -0
- package/dist/tools/runCheck.js.map +1 -1
- package/dist/tools/runSecuritySuite.d.ts +14 -0
- package/dist/tools/runSecuritySuite.js +35 -0
- package/dist/tools/runSecuritySuite.js.map +1 -0
- package/dist/tools/shell.d.ts +3 -1
- package/dist/tools/shell.js +16 -6
- package/dist/tools/shell.js.map +1 -1
- package/dist/tui/app.d.ts +1 -0
- package/dist/tui/app.js +110 -16
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/presets.d.ts +2 -2
- package/dist/tui/presets.js +1 -0
- package/dist/tui/presets.js.map +1 -1
- package/dist/tui/render.js +2 -1
- package/dist/tui/render.js.map +1 -1
- package/dist/version.d.ts +8 -0
- package/dist/version.js +9 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://github.com/arthurpanhku/dvalincode/releases/latest"><img src="https://img.shields.io/github/v/release/arthurpanhku/dvalincode?style=for-the-badge&color=818cf8&label=Release" alt="Release"></a>
|
|
11
11
|
<a href="https://github.com/arthurpanhku/dvalincode/releases"><img src="https://img.shields.io/github/downloads/arthurpanhku/dvalincode/total?style=for-the-badge&color=blue&label=Downloads" alt="Downloads"></a>
|
|
12
|
-
<a href="#-tests"><img src="https://img.shields.io/badge/Tests-
|
|
12
|
+
<a href="#-tests"><img src="https://img.shields.io/badge/Tests-229%20%2F%20229%20%E2%9C%93-success?style=for-the-badge" alt="Tests"></a>
|
|
13
13
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="License"></a>
|
|
14
14
|
<a href="https://scorecard.dev/viewer/?uri=github.com/arthurpanhku/dvalincode"><img src="https://api.scorecard.dev/projects/github.com/arthurpanhku/dvalincode/badge" alt="OpenSSF Scorecard"></a>
|
|
15
15
|
<a href="docs/governance/ISO-42001-AIMS.md"><img src="https://img.shields.io/badge/ISO%2FIEC%2042001-AIMS%20Aligned-0F766E?style=for-the-badge" alt="ISO/IEC 42001 AIMS aligned"></a>
|
|
@@ -59,17 +59,18 @@ dvalincode report verify # re-derive the hash chain of the last run's audit l
|
|
|
59
59
|
---
|
|
60
60
|
|
|
61
61
|
<table>
|
|
62
|
-
<tr><td><b
|
|
63
|
-
<tr><td><b
|
|
64
|
-
<tr><td><b
|
|
62
|
+
<tr><td><b>🏠 Home</b></td><td>One place for read-only <b>Ask</b> and approval-gated <b>Collaborate</b> workflows. Switch intent without leaving the project or conversation.</td></tr>
|
|
63
|
+
<tr><td><b>⚡ Code</b></td><td>Focused autonomous coding with full tool access and Ask / Plan / Auto / Bypass permission levels. Security and browser routines no longer compete with the core coding workflow.</td></tr>
|
|
64
|
+
<tr><td><b>🛡️ Dvalin</b></td><td>Dedicated white-box security engineering: orchestrate the built-in scanner plus installed Semgrep CE, Trivy, and OSV-Scanner; triage findings; create isolated fixes; run tests and re-scan; then explicitly publish a reviewable draft PR. <a href="docs/DVALIN.md">Dvalin guide →</a></td></tr>
|
|
65
65
|
<tr><td><b>🏦 Regulated teams</b></td><td>Designed for finance, healthcare, security-sensitive SaaS, and internal platform teams that need AI coding under policy, audit, data minimization, and supply-chain review — not just developer convenience.</td></tr>
|
|
66
|
-
<tr><td><b>🛡️ Secure remediation</b></td><td>Run a
|
|
66
|
+
<tr><td><b>🛡️ Secure remediation</b></td><td>Run a multi-engine scan or import SARIF from CodeQL, GitHub Code Scanning, Semgrep, or compatible scanners, then create an isolated remediation worktree and turn findings into focused repair tasks with source context, verification evidence, and PR-ready reporting. <a href="docs/SECURE-REMEDIATION.md">Workflow →</a></td></tr>
|
|
67
67
|
<tr><td><b>📚 Skills</b></td><td>Upload, download, and inspect local skill bundles. DvalinCode ships built-in secure-code-scan and secure-code-remediation skills, plus agent tools for listing skills, reading skill instructions, scanning, listing cases, and preparing remediation worktrees. <a href="docs/SKILLS.md">Format →</a></td></tr>
|
|
68
68
|
<tr><td><b>🛡️ Audit trail</b></td><td>Every run emits a tamper-evident, hash-chained JSONL log — every file read/written, every command, every approval. A Run Report renders it as Markdown; <code>dvalincode report verify</code> proves the chain is intact. <a href="docs/AUDIT-TRAIL.md">Threat model →</a></td></tr>
|
|
69
69
|
<tr><td><b>🔒 Org policy & <code>trust</code></b></td><td>A company — not the developer — bounds the agent. A <code>dvalin.policy.json</code> constrains modes, shell commands, file paths, tools, and models; a repo policy can only ever <i>narrow</i> the machine-level one, never widen it. Each run records the governing policy's hash. <code>dvalincode trust</code> prints the install's live security posture — active policy + hashes, audit status, runtime — so a reviewer can verify it directly. <a href="docs/POLICY-REFERENCE.md">Policy reference →</a> · <a href="docs/APPROVABILITY-PLAN.md">Approvability plan →</a></td></tr>
|
|
70
70
|
<tr><td><b>🏛️ Governance evidence</b></td><td>OpenSSF Scorecard, CodeQL, Dependabot, pinned GitHub Actions, CODEOWNERS, and ISO/IEC 42001 AIMS alignment docs are maintained as reviewable project evidence. <a href="docs/security/OPENSSF-SCORECARD.md">Scorecard map →</a> · <a href="docs/governance/ISO-42001-AIMS.md">ISO 42001 alignment →</a></td></tr>
|
|
71
71
|
<tr><td><b>🖥️ First-class GUI</b></td><td>Modern web UI with code highlighting, file <code>@</code>-references, <code>/</code> slash commands, Git branch indicator, live token + cost counter, multi-profile LLM config, and a dark / light / system theme switcher.</td></tr>
|
|
72
72
|
<tr><td><b>🖥️ Terminal or web — one binary</b></td><td>Run it bare for an interactive <b>terminal agent</b> with streaming output, inline approvals, and red/green diffs, or <code>dvalincode serve</code> to host the <b>web GUI</b> for browser/remote use. Both frontends drive the same agent core.</td></tr>
|
|
73
|
+
<tr><td><b>🖥️ Native desktop app</b></td><td><code>DvalinCode.app</code> — a real dock application (OS-native webview, no Electron) over the same engine. On macOS the one-line installer puts it in <code>/Applications</code> automatically; launch it straight from Launchpad.</td></tr>
|
|
73
74
|
<tr><td><b>🪶 Zero-dependency binary</b></td><td>Single ~25MB executable per platform. No Node, no Python, no Docker.</td></tr>
|
|
74
75
|
<tr><td><b>🔐 Local-first</b></td><td>Sessions, config, profiles, and audit logs live in <code>~/.dvalincode/</code>. <code>.dvalincodeignore</code> blocks the agent from reading sensitive files. <code>AGENTS.md</code> in your repo becomes persistent project instructions.</td></tr>
|
|
75
76
|
<tr><td><b>💾 Portable & exportable</b></td><td>Export <b>all</b> local data (memory, sessions, config, audit) to one file and import it on another machine — your setup moves with you. Any conversation downloads as a clean <b>Markdown</b> transcript.</td></tr>
|
|
@@ -145,10 +146,10 @@ pass security approval before it can reach production repositories:
|
|
|
145
146
|
- **Regulated-use posture** — local-first data handling, policy-controlled
|
|
146
147
|
autonomy, minimized audit records, and release supply-chain evidence for
|
|
147
148
|
finance, healthcare, security-sensitive SaaS, and internal enterprise use.
|
|
148
|
-
- **
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
- **Dvalin security engineering** — the dedicated Dvalin workspace combines the
|
|
150
|
+
built-in scanner with installed Semgrep CE, Trivy, and OSV-Scanner, normalizes
|
|
151
|
+
SARIF findings, drives isolated test-backed fixes, and explicitly prepares a
|
|
152
|
+
reviewable draft PR without auto-merging it.
|
|
152
153
|
[Workflow →](docs/SECURE-REMEDIATION.md)
|
|
153
154
|
|
|
154
155
|
These documents are implementation evidence and operating procedures; they do
|
|
@@ -156,7 +157,86 @@ not claim third-party ISO certification.
|
|
|
156
157
|
|
|
157
158
|
---
|
|
158
159
|
|
|
159
|
-
## ⭐ What's New in v0.
|
|
160
|
+
## ⭐ What's New in v0.13.0 — Dvalin security engineering
|
|
161
|
+
|
|
162
|
+
- **Home unifies Chat and Cowork** — the GUI now has a single Home workspace
|
|
163
|
+
with read-only Ask and approval-gated Collaborate intents, while keeping the
|
|
164
|
+
same project and conversation context.
|
|
165
|
+
- **Code is focused again** — the old Security and Routines panels have been
|
|
166
|
+
removed from Code so its sidebar is dedicated to projects and autonomous
|
|
167
|
+
implementation.
|
|
168
|
+
- **Dvalin is a first-class workspace** — orchestrate the built-in scanner plus
|
|
169
|
+
installed Semgrep CE, Trivy, and OSV-Scanner; import SARIF; score and triage
|
|
170
|
+
findings; persist remediation cases; and create isolated repair worktrees.
|
|
171
|
+
- **One flow from evidence to draft PR** — selected findings can launch an
|
|
172
|
+
evidence-backed Agent fix, run focused tests/typecheck/build and a fresh scan,
|
|
173
|
+
review the diff, and explicitly publish a draft PR without automatic merge.
|
|
174
|
+
- **Agent loops converge sooner and cost less** — investigation-before-edit and
|
|
175
|
+
stall detection reduce repeated failed actions, general tool output is
|
|
176
|
+
bounded, prompts remain append-only for cache reuse, and provider usage now
|
|
177
|
+
accounts for cache hits/misses.
|
|
178
|
+
- **Provider and evaluation upgrades** — native Anthropic prompt caching and
|
|
179
|
+
cache accounting are supported, and the SWE-bench Docker harness reports
|
|
180
|
+
official scores, policy violations, stalls, and token/cache metrics.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## ⭐ What's New in v0.12.4 — finish the task before stopping
|
|
185
|
+
|
|
186
|
+
- **Process narration no longer ends a task** — responses such as “let me
|
|
187
|
+
verify the file” are recognized as pending work, and the agent immediately
|
|
188
|
+
continues with the promised action instead of treating them as a final answer.
|
|
189
|
+
- **Truncated responses automatically recover** — provider finish reasons are
|
|
190
|
+
preserved, so output cut off by a token limit triggers another model step.
|
|
191
|
+
- **Normal coding turns get room to finish** — the per-turn action limit is now
|
|
192
|
+
an emergency 100-action guard rather than a routine 15-action stopping point;
|
|
193
|
+
stricter organization policy limits still take precedence.
|
|
194
|
+
- **Completion is explicit** — Code mode is instructed to return a tool-free
|
|
195
|
+
answer only after the requested work and focused validation are complete.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## ⭐ What's New in v0.12.3 — resilient long-running Code mode
|
|
200
|
+
|
|
201
|
+
- **Long coding turns keep going** — Code mode now compacts context during an
|
|
202
|
+
active tool loop, accounts for the full provider request when estimating
|
|
203
|
+
tokens, and raises the default iteration checkpoint from 10 to 40.
|
|
204
|
+
- **Interruptions are resumable** — completed tool state is persisted when a
|
|
205
|
+
turn is interrupted or its connection closes, so a follow-up `continue`
|
|
206
|
+
resumes from the actual workspace progress.
|
|
207
|
+
- **Visible, quieter agent activity** — running sessions show a sidebar loading
|
|
208
|
+
state, each response reports elapsed work time, and its Action timeline is
|
|
209
|
+
available on click while raw Tool Calls stay collapsed by default.
|
|
210
|
+
- **GitHub workflows from Code mode** — network-aware `git` and GitHub CLI
|
|
211
|
+
(`gh`) operations now support pull, push, PR creation, and Actions/repository
|
|
212
|
+
commands through the governed shell approval path.
|
|
213
|
+
- **Safer releases** — package and CLI versions are synchronized, and
|
|
214
|
+
`prepublishOnly` runs the build, typecheck, and test suite before publishing.
|
|
215
|
+
- **Simple tasks stay simple** — the Action budget is enforced across the whole
|
|
216
|
+
turn instead of resetting on every model iteration, and Code mode is prompted
|
|
217
|
+
to take the shortest direct path and stop when focused validation passes.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## ⭐ What's New in v0.12.2 — 🖥️ Desktop app milestone: it just works
|
|
222
|
+
|
|
223
|
+
- **🖥️ The native desktop app now works out of the box on macOS** — `DvalinCode.app`
|
|
224
|
+
opens a real dock window (WKWebView, no Electron) over the embedded engine.
|
|
225
|
+
Two threading bugs that shipped in every earlier desktop build are fixed:
|
|
226
|
+
the blocking webview loop no longer starves the embedded server (blank
|
|
227
|
+
window), and the webview runs on the main thread as macOS requires (no
|
|
228
|
+
window at all) — the server now lives in a child process of the same binary.
|
|
229
|
+
- **📦 The one-line installer installs the app** — on macOS,
|
|
230
|
+
`curl … install.sh | bash` now also puts `DvalinCode.app` (with the
|
|
231
|
+
DvalinCode icon) into `/Applications`, so the desktop window launches
|
|
232
|
+
straight from Launchpad after a CLI install. Opt out with
|
|
233
|
+
`DVALINCODE_NO_APP=1`; pin with `DVALINCODE_GUI_VERSION`.
|
|
234
|
+
- **✅ Desktop is no longer "experimental" on macOS** — the window and the
|
|
235
|
+
embedded server are verified working; Windows and Linux desktop builds are
|
|
236
|
+
cross-compiled and remain a preview.
|
|
237
|
+
|
|
238
|
+
<details>
|
|
239
|
+
<summary>v0.9.0 — 🛡️ Secure remediation · Skills · CodeQL hardening</summary>
|
|
160
240
|
|
|
161
241
|
- **🛡️ Secure remediation workflow** — run a built-in local scan or import SARIF
|
|
162
242
|
from CodeQL, GitHub Code Scanning, Semgrep, and compatible scanners; findings
|
|
@@ -172,6 +252,8 @@ not claim third-party ISO certification.
|
|
|
172
252
|
- **🎨 App icons** — dark and light theme application icons now ship with the web
|
|
173
253
|
bundle and desktop build inputs.
|
|
174
254
|
|
|
255
|
+
</details>
|
|
256
|
+
|
|
175
257
|
<details>
|
|
176
258
|
<summary>v0.8.0 — 🔒 Governance: controllable · transparent · auditable</summary>
|
|
177
259
|
|
|
@@ -311,11 +393,12 @@ not claim third-party ISO certification.
|
|
|
311
393
|
curl -fsSL https://raw.githubusercontent.com/arthurpanhku/dvalincode/main/scripts/install.sh | bash
|
|
312
394
|
```
|
|
313
395
|
|
|
314
|
-
Detects your OS + arch, downloads the right binary, installs to `~/.dvalincode/`, and adds it to your `PATH`. After reload:
|
|
396
|
+
Detects your OS + arch, downloads the right binary, installs to `~/.dvalincode/`, and adds it to your `PATH`. On macOS it also installs the native **DvalinCode.app** into `/Applications` (skip with `DVALINCODE_NO_APP=1`), so the desktop window launches straight from Launchpad. After reload:
|
|
315
397
|
|
|
316
398
|
```sh
|
|
317
399
|
source ~/.zshrc # or ~/.bashrc
|
|
318
400
|
dvalincode # interactive terminal agent
|
|
401
|
+
dvalincode dvalin . # white-box security scan (GUI-independent)
|
|
319
402
|
dvalincode serve # start the web GUI, open the browser
|
|
320
403
|
dvalincode serve --host 0.0.0.0 --no-open # host it on a server for remote/browser use
|
|
321
404
|
```
|
|
@@ -340,11 +423,32 @@ Verify against `SHA256SUMS.txt` (included in each release).
|
|
|
340
423
|
|
|
341
424
|
> **macOS Gatekeeper:** binaries are unsigned. On first run, either clear the quarantine flag with `xattr -dr com.apple.quarantine ~/.dvalincode`, or right-click the binary in Finder → Open → confirm.
|
|
342
425
|
|
|
426
|
+
### Staying up to date
|
|
427
|
+
|
|
428
|
+
DvalinCode updates itself — no need to re-run the installer:
|
|
429
|
+
|
|
430
|
+
```sh
|
|
431
|
+
dvalincode update --check # is a newer release out? (read-only)
|
|
432
|
+
dvalincode update # download, verify, and install the latest
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
It finds the newest release on GitHub, and for a binary install downloads the
|
|
436
|
+
matching archive, **verifies it against the release's `SHA256SUMS.txt` before
|
|
437
|
+
swapping anything in**, then replaces `~/.dvalincode/` in place. npm installs are
|
|
438
|
+
updated via `npm i -g`, and source checkouts are pointed at `git pull`. Add
|
|
439
|
+
`-y` to skip the prompt, `--prerelease` to track pre-releases, or `--json` for
|
|
440
|
+
scripting.
|
|
441
|
+
|
|
442
|
+
The macOS desktop app checks the separate `gui-v*` release track when it starts.
|
|
443
|
+
When a newer GUI is available, it asks before downloading, verifies the archive
|
|
444
|
+
against `SHA256SUMS-gui.txt`, validates the app version, then replaces and
|
|
445
|
+
restarts `DvalinCode.app`. A failed replacement rolls back to the previous app.
|
|
446
|
+
|
|
343
447
|
---
|
|
344
448
|
|
|
345
449
|
## 🎬 First-time setup
|
|
346
450
|
|
|
347
|
-
**Terminal (default):** run `dvalincode`. On first launch it walks you through a one-time provider setup (pick a provider, paste your API key, choose a model) and saves it to `~/.dvalincode/config.json`. Then you're at the prompt — type to chat, `/mode` to switch between Chat / Cowork / Code, `/help` for commands.
|
|
451
|
+
**Terminal (default):** run `dvalincode`. On first launch it walks you through a one-time provider setup (pick a provider, paste your API key, choose a model) and saves it to `~/.dvalincode/config.json`. Then you're at the prompt — type to chat, `/mode` to switch between Chat / Cowork / Code / Dvalin, `/help` for commands. In the GUI, Chat and Cowork are grouped under **Home**.
|
|
348
452
|
|
|
349
453
|
**Web GUI:** run `dvalincode serve` and:
|
|
350
454
|
|
|
@@ -361,11 +465,11 @@ Both share the same config and sessions in `~/.dvalincode/`.
|
|
|
361
465
|
|
|
362
466
|
| Category | Feature | Notes |
|
|
363
467
|
|---|---|---|
|
|
364
|
-
| **Modes** |
|
|
468
|
+
| **Modes** | Home / Code / Dvalin | Home contains read-only Ask and approval-gated Collaborate; Code is focused autonomous development; Dvalin is the scan-to-fix security workspace |
|
|
365
469
|
| **Code permissions** | Ask Permissions / Plan Mode / Auto Mode / Bypass permissions | Verified behavior: Ask requests approval before writes/commands, Plan is read-only and does not write files, Auto runs operations automatically, Bypass runs without confirmation prompts |
|
|
366
470
|
| **Workspaces** | Open folder / Import Git / Add worktree | Cowork and Code can switch to a local folder, clone a Git project, or create a Git worktree from the UI |
|
|
367
471
|
| **Governance** | OpenSSF Scorecard / ISO 42001 AIMS alignment | Scorecard, CodeQL, Dependabot, pinned Actions, AI impact assessment, risk register, and review cadence are documented under `docs/security/` and `docs/governance/` |
|
|
368
|
-
| **Secure remediation** |
|
|
472
|
+
| **Secure remediation** | Built-in + Semgrep CE + Trivy + OSV-Scanner / SARIF / cases / worktrees / tests / draft PR | Dvalin detects installed engines, normalizes SARIF, scores risk, persists cases, drives evidence-backed fixes, verifies changes, and publishes only after an explicit user action |
|
|
369
473
|
| **Skills** | Upload / download / built-in security skills | Skills live under `~/.dvalincode/skills`; built-ins guide security scanning and remediation with dedicated agent tools. [Format →](docs/SKILLS.md) |
|
|
370
474
|
| **Composer** | `@` file references | Type `@` for a fuzzy file search; selected files get inlined into the prompt |
|
|
371
475
|
| | `/` slash commands | `/clear` `/compact` `/git` `/plan` `/undo` `/help` |
|
|
@@ -462,7 +566,7 @@ RESTORE → COMPACT → COMMAND → BUILD → RUN → SAVE → RESPOND → DONE
|
|
|
462
566
|
npm test
|
|
463
567
|
```
|
|
464
568
|
|
|
465
|
-
**
|
|
569
|
+
**229 tests · 40 files · all green.**
|
|
466
570
|
|
|
467
571
|
---
|
|
468
572
|
|
|
@@ -531,9 +635,9 @@ Yes — use Ollama. Pull a model (<code>ollama pull qwen2.5-coder</code>), then
|
|
|
531
635
|
</details>
|
|
532
636
|
|
|
533
637
|
<details>
|
|
534
|
-
<summary><b>Why
|
|
638
|
+
<summary><b>Why Home, Code, and Dvalin?</b></summary>
|
|
535
639
|
<br>
|
|
536
|
-
|
|
640
|
+
They represent different outcomes and safety defaults. <b>Home</b> groups read-only Ask and approval-gated Collaborate. <b>Code</b> is the focused software-development agent. <b>Dvalin</b> is a security pipeline with scanner evidence, remediation cases, isolated worktrees, verification, and explicit draft-PR publication. You can switch at any time while keeping project context.
|
|
537
641
|
</details>
|
|
538
642
|
|
|
539
643
|
<details>
|
|
@@ -551,7 +655,7 @@ Every run writes a JSONL audit log to <code>~/.dvalincode/audit/run-<timestam
|
|
|
551
655
|
<details>
|
|
552
656
|
<summary><b>Will it overwrite my files without asking?</b></summary>
|
|
553
657
|
<br>
|
|
554
|
-
Depends on the mode. <b>
|
|
658
|
+
Depends on the mode. <b>Home → Ask</b> never writes. <b>Home → Collaborate</b> requires approval per file (with inline red/green diff before you click Allow). <b>Code</b> and <b>Dvalin</b> honor their selected permission level; use Auto only for trusted workspaces or isolated branches.
|
|
555
659
|
</details>
|
|
556
660
|
|
|
557
661
|
<details>
|
|
@@ -562,12 +666,6 @@ The binary is unsigned. Run this once to clear the quarantine flag:
|
|
|
562
666
|
Or right-click the binary in Finder → Open → confirm once.
|
|
563
667
|
</details>
|
|
564
668
|
|
|
565
|
-
<details>
|
|
566
|
-
<summary><b>How do I save a routine in Code mode?</b></summary>
|
|
567
|
-
<br>
|
|
568
|
-
Switch to Code mode, click the <b>+</b> next to "ROUTINES" in the sidebar. Enter a name (e.g. "Deploy preview") and a prompt or slash command (e.g. "<code>/git</code>" or "Build the project and deploy to staging"). Routines persist in your browser's <code>localStorage</code>.
|
|
569
|
-
</details>
|
|
570
|
-
|
|
571
669
|
<details>
|
|
572
670
|
<summary><b>Does <code>AGENTS.md</code> get sent every turn?</b></summary>
|
|
573
671
|
<br>
|
package/README.zh-CN.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://github.com/arthurpanhku/dvalincode/releases/latest"><img src="https://img.shields.io/github/v/release/arthurpanhku/dvalincode?style=for-the-badge&color=818cf8&label=Release" alt="Release"></a>
|
|
11
11
|
<a href="https://github.com/arthurpanhku/dvalincode/releases"><img src="https://img.shields.io/github/downloads/arthurpanhku/dvalincode/total?style=for-the-badge&color=blue&label=Downloads" alt="Downloads"></a>
|
|
12
|
-
<a href="#-测试"><img src="https://img.shields.io/badge/Tests-
|
|
12
|
+
<a href="#-测试"><img src="https://img.shields.io/badge/Tests-229%20%2F%20229%20%E2%9C%93-success?style=for-the-badge" alt="Tests"></a>
|
|
13
13
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="License"></a>
|
|
14
14
|
<a href="https://scorecard.dev/viewer/?uri=github.com/arthurpanhku/dvalincode"><img src="https://api.scorecard.dev/projects/github.com/arthurpanhku/dvalincode/badge" alt="OpenSSF Scorecard"></a>
|
|
15
15
|
<a href="docs/governance/ISO-42001-AIMS.md"><img src="https://img.shields.io/badge/ISO%2FIEC%2042001-AIMS%20Aligned-0F766E?style=for-the-badge" alt="ISO/IEC 42001 AIMS aligned"></a>
|
|
@@ -70,6 +70,7 @@ dvalincode report verify # 重新推导上次运行审计日志的哈希链
|
|
|
70
70
|
<tr><td><b>🏛️ 治理证据</b></td><td>仓库维护 OpenSSF Scorecard、CodeQL、Dependabot、固定 SHA 的 GitHub Actions、CODEOWNERS,以及 ISO/IEC 42001 AIMS 对齐文档,作为可审查的项目治理证据。<a href="docs/security/OPENSSF-SCORECARD.md">Scorecard 映射 →</a> · <a href="docs/governance/ISO-42001-AIMS.md">ISO 42001 对齐 →</a></td></tr>
|
|
71
71
|
<tr><td><b>🖥️ 一流的 GUI</b></td><td>现代化 Web UI,包含代码语法高亮、<code>@</code> 文件引用、<code>/</code> 斜杠命令、Git 分支显示、实时 Token 与费用统计、多 LLM Profile,以及暗色 / 浅色 / 跟随系统的主题切换。</td></tr>
|
|
72
72
|
<tr><td><b>🖥️ 终端或 Web,同一个二进制</b></td><td>直接运行进入交互式<b>终端代理</b>,支持流式输出、行内审批和红绿 diff;或 <code>dvalincode serve</code> 启动 <b>Web GUI</b> 供浏览器/远程使用。两个前端共用同一套 agent 内核。</td></tr>
|
|
73
|
+
<tr><td><b>🖥️ 原生桌面应用</b></td><td><code>DvalinCode.app</code> —— 真正的 Dock 应用(系统原生 webview,非 Electron),驱动同一套引擎。macOS 上一行安装命令会自动装进 <code>/Applications</code>,从启动台直接打开。</td></tr>
|
|
73
74
|
<tr><td><b>🪶 零依赖二进制</b></td><td>每平台单文件可执行程序 ~25MB。无需 Node、Python、Docker。</td></tr>
|
|
74
75
|
<tr><td><b>🔐 本地优先</b></td><td>Session、配置、Profile、审计日志均保存在 <code>~/.dvalincode/</code>。<code>.dvalincodeignore</code> 阻止 Agent 访问敏感文件。仓库根目录的 <code>AGENTS.md</code> 作为项目级持久指令自动加载。</td></tr>
|
|
75
76
|
<tr><td><b>💾 可导出、可迁移</b></td><td>把<b>所有</b>本地数据(记忆、Session、配置、审计)导出为一个文件,在另一台机器导入 —— 整套环境随身带走。任意对话都能下载为干净的 <b>Markdown</b> 记录。</td></tr>
|
|
@@ -141,7 +142,39 @@ DvalinCode 维护项目级治理证据,便于开源用户和企业安全评审
|
|
|
141
142
|
|
|
142
143
|
---
|
|
143
144
|
|
|
144
|
-
## ⭐ v0.
|
|
145
|
+
## ⭐ v0.12.3 新功能 —— 长时间 Code 模式更可靠
|
|
146
|
+
|
|
147
|
+
- **长编程任务持续执行** —— Code 模式现在会在工具循环执行过程中动态压缩上下文,
|
|
148
|
+
Token 估算覆盖完整 provider 请求,并将默认迭代检查点从 10 提升到 40。
|
|
149
|
+
- **中断后可以续接** —— 回合被中断或连接关闭时,会保存已经完成的工具状态;后续发送
|
|
150
|
+
`continue` 即可从工作区的真实进度继续。
|
|
151
|
+
- **Agent 活动清晰而安静** —— 运行中的 session 会在侧栏显示 loading 状态;每次回复
|
|
152
|
+
显示工作耗时,点击即可查看 Action 时间线,原始 Tool Call 默认保持折叠。
|
|
153
|
+
- **Code 模式支持 GitHub 工作流** —— 具备网络感知的 `git` 与 GitHub CLI(`gh`)
|
|
154
|
+
操作现在可通过受控 shell 审批路径执行 pull、push、创建 PR,以及 Actions / 仓库命令。
|
|
155
|
+
- **更安全的发布流程** —— package 与 CLI 版本保持同步,`prepublishOnly` 会在发布前运行
|
|
156
|
+
构建、类型检查和完整测试。
|
|
157
|
+
- **简单需求保持简单** —— Action 预算现在对整轮生效,不再每次模型迭代重置;Code 模式
|
|
158
|
+
会优先选择最短直接路径,并在针对性验证通过后停止。
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## ⭐ v0.12.2 新功能 —— 🖥️ 桌面应用里程碑:开箱即用
|
|
163
|
+
|
|
164
|
+
- **🖥️ 原生桌面应用在 macOS 上开箱即用** —— `DvalinCode.app` 现在能真正打开
|
|
165
|
+
一个原生 Dock 窗口(WKWebView,非 Electron),驱动内嵌引擎。修复了此前所有
|
|
166
|
+
桌面构建都存在的两个线程问题:阻塞式 webview 循环不再饿死内嵌服务器(空白
|
|
167
|
+
窗口),webview 按 macOS 要求跑在主线程(否则窗口根本不出现)—— 服务器改由
|
|
168
|
+
同一二进制的子进程承载。
|
|
169
|
+
- **📦 一行安装命令即装桌面应用** —— macOS 上 `curl … install.sh | bash`
|
|
170
|
+
现在会把带 DvalinCode 图标的 `DvalinCode.app` 装进 `/Applications`,
|
|
171
|
+
CLI 装完即可从启动台直接打开桌面窗口。`DVALINCODE_NO_APP=1` 可跳过,
|
|
172
|
+
`DVALINCODE_GUI_VERSION` 可固定版本。
|
|
173
|
+
- **✅ macOS 桌面版不再是"实验性"** —— 窗口与内嵌服务器均已验证可用;
|
|
174
|
+
Windows 与 Linux 桌面构建为交叉编译,仍属预览。
|
|
175
|
+
|
|
176
|
+
<details>
|
|
177
|
+
<summary>v0.9.0 —— 🛡️ 安全修复闭环 · Skills · CodeQL 加固</summary>
|
|
145
178
|
|
|
146
179
|
- **🛡️ 安全修复闭环** —— 支持运行内置本地扫描,或导入 CodeQL、GitHub
|
|
147
180
|
Code Scanning、Semgrep 及兼容扫描器的 SARIF;发现项会转成本地修复 case,
|
|
@@ -153,6 +186,8 @@ DvalinCode 维护项目级治理证据,便于开源用户和企业安全评审
|
|
|
153
186
|
现在都经过显式 root-containment 校验,并新增路径遍历与 skill 导入边界回归测试。
|
|
154
187
|
- **🎨 应用图标** —— Web bundle 与桌面构建输入现在包含暗色和亮色主题应用图标。
|
|
155
188
|
|
|
189
|
+
</details>
|
|
190
|
+
|
|
156
191
|
<details>
|
|
157
192
|
<summary>v0.8.0 —— 🔒 治理:可控 · 透明 · 可审计</summary>
|
|
158
193
|
|
|
@@ -291,11 +326,13 @@ DvalinCode 维护项目级治理证据,便于开源用户和企业安全评审
|
|
|
291
326
|
curl -fsSL https://raw.githubusercontent.com/arthurpanhku/dvalincode/main/scripts/install.sh | bash
|
|
292
327
|
```
|
|
293
328
|
|
|
294
|
-
自动检测系统和架构、下载对应二进制、安装到 `~/.dvalincode/`、添加到 `PATH
|
|
329
|
+
自动检测系统和架构、下载对应二进制、安装到 `~/.dvalincode/`、添加到 `PATH`。macOS 上还会把原生桌面应用 **DvalinCode.app** 装进 `/Applications`(可用 `DVALINCODE_NO_APP=1` 跳过),装完即可直接从启动台打开图形界面。重新加载 shell 后:
|
|
295
330
|
|
|
296
331
|
```sh
|
|
297
332
|
source ~/.zshrc # 或 ~/.bashrc
|
|
298
333
|
dvalincode # 交互式终端代理
|
|
334
|
+
dvalincode dvalin . # 白盒安全扫描
|
|
335
|
+
dvalincode dvalin . --fix --verify --draft-pr # 隔离修复、验证并创建草稿 PR
|
|
299
336
|
dvalincode serve # 启动 Web GUI 并打开浏览器
|
|
300
337
|
dvalincode serve --host 0.0.0.0 --no-open # 部署到服务器,供远程/浏览器访问
|
|
301
338
|
```
|
|
@@ -320,6 +357,17 @@ dvalincode serve --host 0.0.0.0 --no-open # 部署到服务器,供远程/浏
|
|
|
320
357
|
|
|
321
358
|
> **macOS Gatekeeper:** 二进制未签名。首次运行可执行 `xattr -dr com.apple.quarantine ~/.dvalincode`,或在 Finder 中右键 → 打开一次。
|
|
322
359
|
|
|
360
|
+
### 保持更新
|
|
361
|
+
|
|
362
|
+
DvalinCode 可自我更新,无需重新运行安装脚本:
|
|
363
|
+
|
|
364
|
+
```sh
|
|
365
|
+
dvalincode update --check # 检查是否有新版本(只读)
|
|
366
|
+
dvalincode update # 下载、校验并安装最新版本
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
它会在 GitHub 上找到最新 release;对二进制安装,会下载对应平台的归档,**在替换任何文件之前先用 release 的 `SHA256SUMS.txt` 校验**,然后就地替换 `~/.dvalincode/`。npm 安装通过 `npm i -g` 更新,源码检出则提示 `git pull`。可用 `-y` 跳过确认、`--prerelease` 跟踪预发布、`--json` 用于脚本。
|
|
370
|
+
|
|
323
371
|
---
|
|
324
372
|
|
|
325
373
|
## 🎬 首次配置
|
|
@@ -444,7 +492,7 @@ RESTORE → COMPACT → COMMAND → BUILD → RUN → SAVE → RESPOND → DONE
|
|
|
444
492
|
npm test
|
|
445
493
|
```
|
|
446
494
|
|
|
447
|
-
**
|
|
495
|
+
**229 个测试 · 40 个文件 · 全部通过。**
|
|
448
496
|
|
|
449
497
|
---
|
|
450
498
|
|
package/dist/agent/compact.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { ChatMessage, ChatRequest, ProviderAdapter } from '../providers/types.js';
|
|
1
|
+
import type { ChatMessage, ChatRequest, ProviderAdapter, ToolDef } from '../providers/types.js';
|
|
2
2
|
export declare function estimateTokens(messages: ChatMessage[]): number;
|
|
3
|
-
|
|
3
|
+
/** Estimate the complete provider request, not just visible chat content. */
|
|
4
|
+
export declare function estimateRequestTokens(messages: ChatMessage[], systemPrompt: string, tools?: ToolDef[]): number;
|
|
5
|
+
export declare function summarizeWithLLM(messages: ChatMessage[], provider: ProviderAdapter, runtime?: ChatRequest['runtime'], signal?: AbortSignal): Promise<string>;
|
|
4
6
|
export declare function buildCompactedHistory(summary: string): ChatMessage[];
|
package/dist/agent/compact.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export function estimateTokens(messages) {
|
|
2
|
-
const total = messages.reduce((acc, m) => acc + (m.content?.length ?? 0), 0);
|
|
2
|
+
const total = messages.reduce((acc, m) => acc + (m.content?.length ?? 0) + JSON.stringify(m.tool_calls ?? []).length, 0);
|
|
3
3
|
return Math.ceil(total / 4);
|
|
4
4
|
}
|
|
5
|
+
/** Estimate the complete provider request, not just visible chat content. */
|
|
6
|
+
export function estimateRequestTokens(messages, systemPrompt, tools = []) {
|
|
7
|
+
return estimateTokens(messages) + Math.ceil((systemPrompt.length + JSON.stringify(tools).length) / 4);
|
|
8
|
+
}
|
|
5
9
|
const COMPACT_PROMPT = `Summarize this coding session using exactly this format:
|
|
6
10
|
|
|
7
11
|
## Goal
|
|
@@ -17,22 +21,52 @@ const COMPACT_PROMPT = `Summarize this coding session using exactly this format:
|
|
|
17
21
|
- <remaining work items in priority order>
|
|
18
22
|
|
|
19
23
|
Be concise. Each bullet is one line. Omit sections with no content.`;
|
|
20
|
-
export async function summarizeWithLLM(messages, provider, runtime) {
|
|
21
|
-
const transcript = messages
|
|
22
|
-
.filter((m) => m.role === 'user' || m.role === 'assistant')
|
|
23
|
-
.map((m) => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content.slice(0, 1000)}`)
|
|
24
|
-
.join('\n\n');
|
|
24
|
+
export async function summarizeWithLLM(messages, provider, runtime, signal) {
|
|
25
|
+
const transcript = compactTranscript(messages);
|
|
25
26
|
const resp = await provider.chat({
|
|
26
27
|
messages: [{ role: 'user', content: `${COMPACT_PROMPT}\n\n---\n${transcript}` }],
|
|
27
28
|
maxTokens: 600,
|
|
28
29
|
temperature: 0.3,
|
|
29
30
|
runtime,
|
|
31
|
+
signal,
|
|
30
32
|
});
|
|
31
33
|
return resp.content;
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Keep compaction itself safely below the model context window while retaining
|
|
37
|
+
* both the original objective and the latest implementation/tool state.
|
|
38
|
+
*/
|
|
39
|
+
function compactTranscript(messages, maxChars = 64_000) {
|
|
40
|
+
const entries = messages
|
|
41
|
+
// Preserve an earlier compacted summary when compaction happens more than
|
|
42
|
+
// once in a long turn; ordinary system messages are supplied separately.
|
|
43
|
+
.filter((m) => m.role !== 'system' || m.content.startsWith('[Conversation summary]'))
|
|
44
|
+
.map((m) => {
|
|
45
|
+
const label = m.role === 'system'
|
|
46
|
+
? 'Previous session summary'
|
|
47
|
+
: m.role === 'user'
|
|
48
|
+
? 'User'
|
|
49
|
+
: m.role === 'assistant'
|
|
50
|
+
? 'Assistant'
|
|
51
|
+
: `Tool ${m.name ?? ''}`.trim();
|
|
52
|
+
const calls = m.tool_calls?.length ? `\nTool calls: ${JSON.stringify(m.tool_calls)}` : '';
|
|
53
|
+
return `${label}: ${m.content}${calls}`.slice(0, 4_000);
|
|
54
|
+
});
|
|
55
|
+
const first = entries[0];
|
|
56
|
+
const selected = [];
|
|
57
|
+
let used = first ? first.length : 0;
|
|
58
|
+
for (let i = entries.length - 1; i >= (first ? 1 : 0); i--) {
|
|
59
|
+
const entry = entries[i];
|
|
60
|
+
if (used + entry.length + 2 > maxChars)
|
|
61
|
+
break;
|
|
62
|
+
selected.unshift(entry);
|
|
63
|
+
used += entry.length + 2;
|
|
64
|
+
}
|
|
65
|
+
return [first, ...selected].filter((entry) => Boolean(entry)).join('\n\n');
|
|
66
|
+
}
|
|
33
67
|
export function buildCompactedHistory(summary) {
|
|
34
68
|
return [
|
|
35
|
-
{ role: 'system', content:
|
|
69
|
+
{ role: 'system', content: `[Conversation summary]\n\n${summary}` },
|
|
36
70
|
{ role: 'user', content: 'Context was compacted. Continue from the Pending list.' },
|
|
37
71
|
{ role: 'assistant', content: 'Understood. I have the session summary and am ready to continue.' },
|
|
38
72
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact.js","sourceRoot":"","sources":["../../src/agent/compact.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,QAAuB;IACpD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"compact.js","sourceRoot":"","sources":["../../src/agent/compact.ts"],"names":[],"mappings":"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"}
|
package/dist/agent/loop.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TurnState, DEFAULT_TURN_CONFIG } from './types.js';
|
|
2
|
-
import { AgentRunner } from './runner.js';
|
|
3
|
-
import {
|
|
2
|
+
import { AgentRunner, TurnInterruptedError } from './runner.js';
|
|
3
|
+
import { buildCompactedHistory, estimateRequestTokens, summarizeWithLLM } from './compact.js';
|
|
4
4
|
import { AuditSink, newRunId, resolveGitHead } from '../audit/log.js';
|
|
5
5
|
import { minimizedDescriptor } from '../audit/minimize.js';
|
|
6
6
|
import { policyHash } from '../core/policy.js';
|
|
@@ -104,7 +104,12 @@ export class AgentLoop {
|
|
|
104
104
|
// next turn. Wires up `contextTokenLimit` / `compactThreshold`, which
|
|
105
105
|
// were defined but previously never consulted by the state machine.
|
|
106
106
|
const triggerTokens = this.config.contextTokenLimit * this.config.compactThreshold;
|
|
107
|
-
|
|
107
|
+
const toolDefs = this.registry.list().map(tool => ({
|
|
108
|
+
name: tool.name,
|
|
109
|
+
description: tool.description,
|
|
110
|
+
parameters: tool.parametersSchema ?? tool.inputSchema.toJSONSchema?.() ?? {},
|
|
111
|
+
}));
|
|
112
|
+
if (estimateRequestTokens(messages, this.systemPrompt, toolDefs) > triggerTokens) {
|
|
108
113
|
state = TurnState.COMPACT;
|
|
109
114
|
}
|
|
110
115
|
else {
|
|
@@ -113,7 +118,7 @@ export class AgentLoop {
|
|
|
113
118
|
break;
|
|
114
119
|
}
|
|
115
120
|
case TurnState.COMPACT: {
|
|
116
|
-
const compacted = await this.handleCompact(messages);
|
|
121
|
+
const compacted = await this.handleCompact(messages, signal, true);
|
|
117
122
|
messages = compacted.messages;
|
|
118
123
|
state = TurnState.BUILD;
|
|
119
124
|
break;
|
|
@@ -169,6 +174,7 @@ export class AgentLoop {
|
|
|
169
174
|
config: this.config,
|
|
170
175
|
systemPrompt: this.systemPrompt,
|
|
171
176
|
sharedUndoStack: this.sharedUndoStack,
|
|
177
|
+
compactHistory: async (current, compactSignal) => (await this.handleCompact(current, compactSignal, true)).messages,
|
|
172
178
|
});
|
|
173
179
|
try {
|
|
174
180
|
const result = await runner.runTurn(userMessage, messages, onEvent, signal);
|
|
@@ -180,6 +186,10 @@ export class AgentLoop {
|
|
|
180
186
|
auditHead = sink?.head();
|
|
181
187
|
}
|
|
182
188
|
catch (err) {
|
|
189
|
+
if (err instanceof TurnInterruptedError) {
|
|
190
|
+
iterationsUsed = err.iterationsUsed;
|
|
191
|
+
usage = err.usage;
|
|
192
|
+
}
|
|
183
193
|
const status = err instanceof Error && err.message === 'interrupted' ? 'interrupted' : 'error';
|
|
184
194
|
this.finishRun(sink, status, iterationsUsed, usage);
|
|
185
195
|
throw err;
|
|
@@ -210,44 +220,33 @@ export class AgentLoop {
|
|
|
210
220
|
iterations,
|
|
211
221
|
inputTokens: usage?.inputTokens,
|
|
212
222
|
outputTokens: usage?.outputTokens,
|
|
223
|
+
cachedInputTokens: usage?.cachedInputTokens,
|
|
224
|
+
cacheMissInputTokens: usage?.cacheMissInputTokens,
|
|
225
|
+
cacheWriteInputTokens: usage?.cacheWriteInputTokens,
|
|
213
226
|
warnings: warnings.length > 0 ? warnings : undefined,
|
|
214
227
|
});
|
|
215
228
|
}
|
|
216
|
-
async handleCompact(messages) {
|
|
217
|
-
if (messages.length <= 10) {
|
|
229
|
+
async handleCompact(messages, signal, force = false) {
|
|
230
|
+
if (!force && messages.length <= 10) {
|
|
218
231
|
return { messages, output: 'Context is already small enough.' };
|
|
219
232
|
}
|
|
220
|
-
const conversationText = messages
|
|
221
|
-
.filter(m => m.role !== 'system')
|
|
222
|
-
.map(m => `[${m.role}]: ${m.content}`)
|
|
223
|
-
.join('\n\n');
|
|
224
233
|
try {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
runtime: {
|
|
234
|
-
policy: this.context.policy,
|
|
235
|
-
audit: this.context.audit,
|
|
236
|
-
model: this.auditOptions.model,
|
|
237
|
-
},
|
|
238
|
-
});
|
|
239
|
-
const systemMsg = messages.find(m => m.role === 'system');
|
|
240
|
-
const summaryMsg = {
|
|
241
|
-
role: 'assistant',
|
|
242
|
-
content: `[Conversation summary]\n${summaryResponse.content}`,
|
|
243
|
-
};
|
|
244
|
-
const kept = systemMsg ? [systemMsg, summaryMsg] : [summaryMsg];
|
|
234
|
+
const summary = await summarizeWithLLM(messages, this.provider, {
|
|
235
|
+
policy: this.context.policy,
|
|
236
|
+
audit: this.context.audit,
|
|
237
|
+
model: this.auditOptions.model,
|
|
238
|
+
}, signal);
|
|
239
|
+
if (signal?.aborted)
|
|
240
|
+
throw new Error('interrupted');
|
|
241
|
+
const kept = buildCompactedHistory(summary);
|
|
245
242
|
return {
|
|
246
243
|
messages: kept,
|
|
247
244
|
output: `Compacted: reduced from ${messages.length} to ${kept.length} messages using LLM summarization.`,
|
|
248
245
|
};
|
|
249
246
|
}
|
|
250
|
-
catch {
|
|
247
|
+
catch (err) {
|
|
248
|
+
if (signal?.aborted)
|
|
249
|
+
throw new Error('interrupted');
|
|
251
250
|
// Fallback: keep last 20 messages
|
|
252
251
|
const systemMsg = messages.find(m => m.role === 'system');
|
|
253
252
|
const recentMessages = messages.filter(m => m.role !== 'system').slice(-20);
|