Skip to content

Render Dang tool calls as code in dagger agent - #15164

Merged
vito merged 3 commits into
dang-agent-toolsfrom
dang-tool-rendering
Nov 14, 2026
Merged

vito merged 3 commits into
dang-agent-toolsfrom
dang-tool-rendering

Conversation

@vito

@vito vito commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Makes the Dang builtins from #15156 look good in dagger agent. A DangEval or DangCheck call now shows its snippet as code. A Timeout call shows up as the call it wraps.

What it looks like

These samples were captured from a live dagger agent session against an engine built from this branch, with a real model. ANSI is stripped. In color, the code uses Dang's own highlighter and the REPL's 16-color palette. The gutter and timeout= label are faint.

DangEval. The line numbers match the <check>:L:C positions in diagnostics.

  • DangEval 0.8s
  1 │ # greet loudly
  2 │ let greeting = "hi, " + "dang"
  3 │ [greeting, greeting.toUpper, 42]
  ┆ <check>:3:30: error: unify index 2: no common type between Int! and String!
  ┆ 1 error · workspace scope · nothing ran

DangEval with at. The scope is shown in the header, in cyan like a path.

  • DangEval notes 1.0s
  1 │ shout("dang")

DangCheck. With source it gets the same treatment. With only at and/or search, it's a one-line header.

  • DangCheck 0.2s
  1 │ ["a"].reduce
  ┆ List.reduce(initial: b) { acc: b, item: a => b }: b
  • DangCheck notes 1.0s
  • DangCheck search "sort" 0.2s
  • DangCheck .dagger/modules/notes/main.dang:12:5 search "escape html" 1.0s
  1 │ prefix + name

Timeout wrapping DangEval. It renders exactly like a DangEval, plus a timeout=2m label. The label is styled like Read's offset=20.

  • DangEval timeout=2m 3.8s
  1 │ container.from("alpine")
  2 │   .withExec(["echo", "hello from a timeout"])
  3 │   .stdout
  ┆ String! = "hello from a timeout\n"

Timeout wrapping other tools. A tool with a summary of its own keeps it. An unknown tool falls back to the generic header. A Timeout whose wrapped tool isn't known (an older engine) stays as it was.

  • ListServices timeout=30s 0.6s
  • Read main.go offset=20 timeout=30s 1.0s
  • Frobnicate(world) timeout=1h 1.0s
  • Timeout(5s) 1.0s

Narrow terminal (44 columns). Lines wrap under a blank line number.

  • DangEval timeout=2m 3.8s
  1 │ container.from("alpine")
  2 │   .withExec(["echo", "hello from a tim
    │ eout"])
  3 │   .stdout

Long snippet. A collapsed call shows 16 lines. Expanding it, or the final report, shows all of them.

  15 │ print(14)
  16 │ print(15)
     ┆ … 4 more lines

Prior art reused

Tool calls already get special rendering in two places:

  • The header. renderer.renderSpan → renderToolArgsSummary reads dagui.SpanSnapshot.ToolArgsSummary (dagql/dagui/toolargs.go). That function works from the LLMToolArgNames/LLMToolArgValues span attributes that core/mcp.go records. This is how Read gets a cyan path and offset=20.
  • Typed content under the row. Logs with a content type are rendered in the row's Vterm, e.g. text/x-diff via Vterm.WriteDiff, which is how edits show a highlighted patch.

This PR extends the header half and adds a sibling block under the row:

  • dagui.ToolCallView (dagql/dagui/toolcall.go) presents a tool call from its full arguments. It unwraps Timeout and exposes a Dang call's snippet.
  • renderSpan asks renderToolCallTitle first.
  • renderInlineLogs, and the final report's renderMessageLogs, put the snippet above the call's output. The snippet replaces the raw JSON args that verbosity ≥ 2 used to show for these calls.

Where the arguments come from

  • Span attributes. The engine now also records DangCheck/DangEval's at/search/source, and Timeout's arguments as JSON (core/mcp.go). These cover history replay, Cloud traces and reports.
  • The JSON arguments the call's display span streams (application/json logs). A live span's attributes only reach the client at start and end, so without this a running DangEval would show no code until it finished. That's exactly when you want to see it, e.g. a long run under Timeout. dagui.DB keeps that JSON only for these three tools, capped at 256 KiB per call.

Timeout

A Timeout runs its call under a nested display span of its own, and that span normally hides under the Timeout's roll-up. Once that span exists, the Timeout's header takes the tool's server and bare name from it: the model calls it editor_read, the header says editor Read.

A wrapped Read or Grep collapses its output the way the bare tool does. In the final report, the nested call isn't printed a second time; whatever it ran (checks, tests, …) rolls up under the Timeout's row instead. When the Timeout is expanded, the nested row doesn't repeat the snippet.

Degrading

  • No color (NO_COLOR, agent env, engine-side reports, which pin Ascii): plain text, nothing highlighted, the highlighter isn't even loaded.
  • Highlighting failures: dang.Highlight returns no spans and the code renders plain. It's also wrapped in a recover. A test checks that styled output, stripped of ANSI, always equals the plain output for broken, partial, multibyte and control-character sources, at several widths.
  • First use: the highlighter compiles its WebAssembly module on first use (~0.5s with a cold cache, then cached on disk under ~/.cache/dang/wazero). This happens in the background: the first snippets render plain and redraw once it's ready. Final renders wait for it.
  • Plain progress (--progress=plain) doesn't render tool-call rows specially today, and still doesn't.

Dependency

#15156 pins github.com/vito/dang/v2 at v2.5.0, which has everything this needs: dang.Highlight, and tree-sitter compiled to wasm and run by wazero (vito/dang#303, vito/dang#307, vito/dang#314), so there's no cgo.

The CLI now links pkg/dang for dang.Highlight. It still builds with CGO_ENABLED=0; I checked with a real build in golang:1.26-alpine against v2.5.0.

Testing

  • dagql/dagui/toolcall_test.go: unwrapping Timeout from attributes and from streamed JSON, falling back to attributes, the size cap, pruning args that arrive before their span, Wraps with snake_case server tools, collapse.
  • dagql/idtui/dang_render_test.go: transcript frames for each case above (Ascii, ANSI, 24 columns), long snippets, the final report, Timeout borrowing its nested call's label/collapse/rollups, rendering plain until the highlighter is warm.
  • core/mcp_test.go: the recorded header args.
  • golangci-lint passes. I also QA'd live in dagger agent with a real model against an engine built from this branch.

@vito
vito added this pull request to stack #15165 November 12, 2026 23:55
@vito
vito force-pushed the dang-tool-rendering branch 6 times, most recently from ff25393 to 3cb4055 Compare November 13, 2026 22:43
@vito
vito requested a review from a team as a code owner November 14, 2026 00:31
@vito
vito force-pushed the dang-tool-rendering branch from 3cb4055 to ce3ea47 Compare November 14, 2026 00:34
@grouville
grouville self-requested a review November 14, 2026 01:34
vito added 3 commits November 14, 2026 02:28
A tool call's span records its header arguments: the required ones, plus
a few useful optional ones. Also record the Dang builtins' `at`,
`search` and `source`, and a Timeout's `arguments` for the tool it
wraps, as JSON, so frontends can show a Dang call's snippet and present
a Timeout as the call it runs.

Signed-off-by: Alex Suraci <[email protected]>
ToolCallView is how a tool call presents: a Timeout as the call it
wraps, with its duration, and a Dang builtin as its snippet. A Timeout
recognizes its nested call by span name, the tool as the model calls it,
so snake_case tools of a server match too.

It reads a call's arguments from the JSON its display span streams,
which the DB now keeps for these tools, falling back to the span's
recorded arguments. The streamed JSON matters for running calls: a live
span's attributes only reach a client when it starts and ends, while its
streamed arguments arrive as soon as the model wrote them. The DB drops
streamed arguments it kept as soon as a span turns out not to render
from them.

Signed-off-by: Alex Suraci <[email protected]>
A DangEval or DangCheck call shows its snippet beneath its header in a
small editor view: line numbers in a faint gutter, the code highlighted
by Dang's own highlighter in the REPL's 16-color palette, lines wrapped
to the terminal, and a collapsed call cut to its first 16 lines. The
header names the scope (`at`) and a DangCheck's search. Without color,
or for a source that won't highlight, the snippet renders plain.

The highlighter compiles a WebAssembly module on first use, so it warms
in the background: live views render the first snippets plain and redraw
once it's ready, while final renders wait for it.

A Timeout presents as the call it wraps, with that call's own rendering
(a wrapped Read or Grep collapses and summarizes as the bare tool does),
noted `timeout=2m`. Its header takes the server and bare tool name from
the nested span once it runs, and expanding it shows the nested call
without repeating the snippet. The final report shows a Dang call's
snippet in full in place of its JSON arguments, shows a Timeout's call
once, and rolls up what that call ran under the Timeout's row.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the dang-tool-rendering branch from ce3ea47 to 93f1cff Compare November 14, 2026 02:29
@vito
vito merged commit 2a385e9 into main Nov 14, 2026
97 checks passed
@vito
vito deleted the dang-tool-rendering branch November 14, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants