Repository navigation
llm: add DangCheck and DangEval builtin tools - #15156
Merged
Merged
Conversation
vito
force-pushed
the
dang-agent-tools
branch
from
November 14, 2026 00:31
2ad7fbf to
000d9d8
Compare
vito
marked this pull request as ready for review
November 14, 2026 00:41
grouville
self-requested a review
November 14, 2026 01:34
grouville
approved these changes
Nov 14, 2026
Dang 2.5 is what the DangCheck and DangEval tools parse snippets with, and what new Dang SDK modules default to later in this series. It also drops the tree-sitter and go-pointer indirect dependencies. Signed-off-by: Alex Suraci <[email protected]>
DangEval runs each snippet in an in-engine nested client that acts for the conversation without its host access. ClientMetadata gains three engine-internal (json:"-") fields for such clients: - ServedDeps: the schema to serve instead of the core API alone, or, with a module context, modules served beside the module's own API (the conversation's bound tool objects, without constructors). - CallerAgent: the agent the client acts for, so message provenance resolves for calls that run no function. - InertAttachables: set by ServeHTTPToNestedClient and recorded when sealing, so a client nested under an inert one says so too. ClientScope snapshots metadata as JSON, so it carries InertAttachables and CallerAgent beside the snapshot like UseRecipeIDsByDefault; without that, requests of an inert client claimed a host and failed with PermissionDenied looking for its outer .env. A host-inert client now gets an empty outer .env, as module code does. TestInertClientSecretReplay pins that a host-less replay of an object holding a host secret loads, and leaves the host client able to read it. Signed-off-by: Alex Suraci <[email protected]>
Two always-registered LLM tools for agents writing Dang: DangCheck type-checks and describes without running anything (ReadOnly, so a turn's probes run in parallel), DangEval runs a snippet. Their descriptions carry the workflow, since no skill points at them. Only core/sdk/dang/v2 may import Dang, so core defines the DangTools interface and the SDK registers the implementation. Core provides the environment a call sees: - the default scope: the conversation's schema, the bound workspace's installed modules (a value workspace's loaded from its own tree, cached per recipe, broken modules dropped and reported), and the bound tool objects; - the bindings `ws`, `chat` (only where a scope uses it) and `me`, with writes applied when a snippet reassigns `ws`, `chat` or a tool object; - CallerAgent resolution for the snippet's nested client, so its calls act for the conversation's agent. Results are bounded like module tool output (line clamp, ReadLogs pointer), logged once to the call's span (LLMTool.LogsOwnResult), and nudge toward the dang-language skill on errors until it has been read in the conversation. Signed-off-by: Alex Suraci <[email protected]>
The language service behind core's Dang builtins, registered with core.RegisterDangTools. DangCheck type-checks a snippet, file or module (`at`) and describes expressions, members and search hits without running anything. DangEval runs a snippet in a host-inert nested client against the conversation's full schema, or a module's API with `at`. Every scope binds `ws`, `chat`, `me` and the conversation's tool objects; assignment is DangEval's only write. Errors show what exists, name a bound value that fails to load, and note installed modules that didn't. Long string results are shown as ''' blocks, which stay verbatim under Dang 2.5, and reassignments are found by parsing at 2.5, 2.4 and 2.1. Signed-off-by: Alex Suraci <[email protected]>
From v1.0.0-beta.28, a Dang SDK module that declares no `dang` version is parsed as Dang 2.5, not 2.4: beta.28 is the first engine to embed 2.5, and no released engine ever defaulted to 2.4. Dang24ModuleVersion becomes Dang25ModuleVersion. Older modules keep 2.1 (1.0 before v0.21.5), entrypoints stay pinned at 2.1, and an explicit `dang = "2.4"` is still honored. The changelog entry (now linking danglang.org/v2.5), the SDK README and the dang-dagger-modules skill describe 2.5's string changes and how to migrate. Tests gain interpolation cases that tell 2.5 from 2.4, and the skipped-module listing now expects 2.5's quoted syntax errors. Signed-off-by: Alex Suraci <[email protected]>
Document DangCheck and DangEval on the LLM type: their bindings (`ws`, `chat`, `me`, bound tool objects), DangEval's writes by assignment, and that withWorkspace loads any workspace's modules from its own files. Signed-off-by: Alex Suraci <[email protected]>
Integration tests drive DangCheck and DangEval through an LLM against a fixture workspace with two Dang modules: scopes and `at`, bound tool objects, writes by assignment to `ws`, `chat` and tool objects, output bounds and the skill nudge, broken and removed modules, and host-inert replays of git modules and objects holding host secrets. The toolset count in TestToolReturningLLMContinues gains the two builtins. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
dang-agent-tools
branch
from
November 14, 2026 02:27
000d9d8 to
28cfaeb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two always-registered engine builtins for agents writing Dang:
DangCheck(source, at, search):ReadOnly, so a turn's probes run in parallel. It parses and infers only: it gives diagnostics, or a description of what a snippet is, plus ranked search. Nothing runs.DangEval(source!, at): type-checks first, then runs the snippet and shows its printed output,TYPE = value(viadang.Describe, so laziness is visible) and, for an object or interface result, its member names. A footer gives the duration and the number of engine calls. Type errors and failures are reported as the tool's result, as DangCheck reports diagnostics, not as tool errors.Scope. The default scope is the conversation's schema,
MCP.loadBase, which every tool of the conversation shares. It includes the workspace's installed modules for value workspaces (a snapshot, an agent's checkout) as well as live ones. Modules are loaded best effort from the workspace as of each call, pendingdagger.tomland source edits included, so a module a snippet installs or uninstalls joins or leaves the next call's scope. A bound tool object's own module wins over another revision the workspace installs. When a name isn't found and installed modules failed to load, the report ends with a note naming them and why.Output is bounded like a module tool's.
LLMTool.LogsOwnResult). The span therefore shows the report once, and it is the full report, not the bounded result the model sees. A skill nudge is logged after the report. A tool call that errors before producing a report still logs its error.toolCallReportOpts, span tree hidden). A chain of API calls surfaces nothing, so its result is the report alone, bounded like a module tool's flat output: lines are clamped at 2,000 bytes, and past 16 KiB the middle gives way to... N lines omitted (use ReadLogs(span: X, scope: "own") to read more) ....''', Dang's verbatim quotes ((no final newline)when it lacks one; text that itself holds'''stays verbatim, with a note that the block ends at its last line);Skill nudge. When a snippet fails to parse or type-check and the conversation hasn't read the
dang-languageskill, the result ends withSee the dang-language skill (ReadSkill) for Dang's syntax and semantics.Runtime failures and successes never get it. Reads are tracked internally, with no API: a successful ReadSkill call on the conversation's record, or earlier in the same step.Bindings. Both tools see these in every scope (the default scope, and
ata module, a file or a position), each holding its state as of the call:ws, the conversation's workspace;chat, the conversation itself (anLLM). It is only bound in a conversation's step, not underdagger mcp, and only where the snippet or the scope's files mention it, because its ID carries the whole history;me, theAgentthat owns the conversation:Agent!when there is one, otherwise a nullAgent;editor,dangDev, …).If a module declares the same name at its top level, the module's declaration wins. The descriptions list the conversation's actual bindings rather than an example.
editor.grep(source: ws, regex: "x")type-checks and runs through the eval's host-inert client.Writes happen by assignment only. When a DangEval snippet succeeds:
wsbecomes the conversation's workspace throughMCP.rebindWorkspace, as a tool returning a Workspace does, so commits and resets carry over.chatbecomes the conversation the step resumes from, the same way a tool returning anLLMdoes (adoptLLM, scheduled as a continuation). Sochat = editor.install(llm: chat, ref: "…")gives the conversation a module's tools mid-turn. AnyLLMis accepted, the same as with such a tool.chatmust be reassigned alone: assigning it withwsor a tool object is a type error ("reassignchatalone; its workspace and tools come with it"), because an LLM carries its own workspace and tools. Readingeditorto build the newchatis fine.meis a type error.A failed snippet writes nothing. A Workspace or Changeset the snippet only returns is shown with a "not applied" hint and
0 writes. A footer line reports the writes (ws written (1 file),notes state updated); read-only probes print nothing about writes.Writes are all or nothing: every final value is loaded and validated before any is applied, and a write that fails undoes the earlier ones (
commitDangWrites).This follows the settled two-tool scheme. No skill is added; the nudge points at the existing
dang-languageone. The tool descriptions carry the workflow. Withws,chat,meand a tool object all bound, the descriptions are 949 bytes (DangCheck) and 964 bytes (DangEval). A description changes when the conversation's bindings do, e.g. when a tool object is installed. Both are always registered; the LLM reference docs (docs/current_docs/partials/types/_llm.mdx) say what DangEval can reach.Where it lives
core/llm_dang_tools.godefines a smallDangToolsinterface plusRegisterDangTools, andMCP.loadDangToolsregisters both tools next toloadArtifactTools.dangToolResultshapes the result (bounds, trace-report sections, the nudge). The default scope starts fromMCP.loadBase, the conversation's base schema, and adds the bound objects' modules over it (MCP.dangScope).core/sdk/dang/v2/tools*.goholds the implementation. Only this package imports Dang, and it registers itself ininit.tools.gois engine glue. It resolvesatin the conversation's workspace:.dangfile, or bypath:line:col. It finds the module throughfindUpofdagger-module.toml/dagger.jsonplusWorkspace.moduleSource, then mountsWorkspace.directory(...), which includes pending edits.Where there's nothing to scope to, the call says why as its result, not a tool error: an unknown name lists what is installed, a module that failed to load gives its failure, and DangCheck of a module with no
.dangfiles names its SDK. The schema isModuleSource.introspectionSchemaJsonplusensureModuleSelfTypes, and the Dang version comes from the module source. Eval usesdangshared.WithNestedClientServerwith inert attachables and the module as its context.tools_check.goandtools_eval.gohold the Dang work over anfs.FS+ schema + GraphQL client, unit-tested without an engine.How each output is computed:
analysis.Analyzein full mode, orFocuson the fileanalysis.Overlayas<check>.dangbeside the module's files,Focuson itata positionAnalyze(Focus: file), thenScopeAt, thenInferFormsWithPhaseson a clone of that scopeanalysis.DocforType.member,SelectedMemberforexpr.member,Lookupfor a name; the declaration site comes fromInspectanalysis.Members; listings are capped at 40 with signatures and docs, then names onlyTypeMembersonly for an object or interfaceanalysis.Search(scope, query, 20)dang.LoadDir(FS, Eager: module scope), thenModule.Eval, thendang.Describe(a long multi-line string as a'''block);TypeMembersnames only for an object or interfaceOther details:
wsis declared aslet ws: Workspace! = Dagger.node(id: "<conversation workspace>").{{... on Workspace!}}, and tool objects are declared the same way. It is lazy, so an eval that doesn't read it makes no call. The names are qualified, so a module's local type, such asNotesatnotes, can't capture them.reportEvalResultfinds which bound names the snippet reassigns, then reads their final values back from the same run and applies them before the eval's client shuts down.atresolves them.output:heading, so the span's own logs read line for line as the report does. Any string a query selectingplaintextreturned is scrubbed (***) from both. Outside a conversation's tool call (dagger mcp), there is no span of the call's own to point at, so the report only goes through the usual tool-result guard.analysis.Options.DiagnosticContextand render throughanalysis.Render(renderDiagnostics). A type error about a name lists the closest names and the receiver's members.error: messageform.atapath:line:colgets no context yet, because it is inferred outsideanalysis.github.com/vito/dang/v2from v2.4.1 to v2.5.0, which brings Dang 2.5 ("..."/"""..."""interpolate${...}and process escapes,'...'is verbatim), diagnostic context (analysis: diagnostics carry the answer (DiagnosticContext) vito/dang#298), declaration snapshots solet before = wsworks (effects: let declarations snapshot before writes vito/dang#301), structural Dang interfaces, and cgo-free tree-sitter. Snippets in the default scope are now Dang 2.5 (dang.CurrentVersion). A snippet ending in an assignment tows, a tool object orchatno longer prints the(not evaluated…)hint (describe: no eval hint on assignment results vito/dang#313); one that reassigns a module's own binding, which writes nothing, keeps it.dangversion default to Dang 2.5 fromengineVersionv1.0.0-beta.28 (was 2.4, which no release shipped). Older modules keep 2.1, entrypoints stay at 2.1, and an explicitdang = "2.4"is honored.Tool descriptions (exact, for a conversation with an agent and an
editortool object)DangCheck
source: Dang to check as one more file of the scope; its last expression is described.at: Scope: a module installed in the workspace (by name), a Dang module's directory, a .dang file of one, or path:line:col in one. Default: the workspace scope.search: Words to find in names and docs, e.g. "sort" or "escape html".DangEval
source(required): Dang statements to run; the last expression is the result.at: A module installed in the workspace (by name), a Dang module's directory, or a .dang file of one. Default: the workspace scope.Examples (from the integration test's transcript)
The last line is the nudge; it is gone once the conversation has read the skill.
A long result, bounded like a module tool's output, with its middle in the call's own logs:
Checks a snippet runs are reported as for a module tool call, with the Dang report as OUTPUT (a test module
probewith a passing and a failing@check):A type error with diagnostic context (from the unit tests, at the position where the snippet calls
findFirston a list):Where the scheme meets the code
engine.ClientMetadata.ServedDepsis a new engine-internal field, likeSDKEntrypoint. It gives an inert nested client a*core.SchemaBuilderto serve instead, the way a module client serves its module's dependencies. DangEval passes the conversation's deps (fromMCP.loadBase, plus the bound objects' modules) and type-checks against the same schema, so DangCheck and DangEval agree, installed modules included. Host attachables stay inert. Withata module, the nested client gets that module as its context (the one the default scope loaded, elseasModule), so the module's dependencies and its own API are callable.MCP.baseServernow loads a value workspace's installed modules from its own tree, as it loads a live workspace's from its owning client, so a snapshot or an agent's checkout gets them in every tool's schema, not only the Dang tools'. Loading is best effort: a broken module is left out, and if the installed modules don't fit together the schema goes without them. A value workspace is keyed by its recipe, so its modules load once per session (SchemaBuilderMemo.WorkspaceModules), failures included. Where the workspace installs another revision of a bound tool object's module that no client serves, or an edit breaks that module, the bound object's module stays in its place.ensureModuleSelfTypes). Root self-call fields only exist at runtime.ClientMetadata.InertAttachables(server-set) makesouterEnvFilereturn an empty file, as for module code, so DangEval can load workspace modules and the git modules behind bound tool objects.engine.ClientScopecarries the flag throughNewClientScope,Metadata,CloneandDelegate, because the scope's JSON snapshot used to drop it.sealClientMetadataLockedwrites it in for clients nested under an inert one.cmd://gh auth token) still loads when rebuilt in a host-less client. The secret just can't be read there, and the host client keeps reading its own copy. RefusingQuery.secretin host-less clients was tried and reverted, because it broke loading such objects.ServedDepsalso adds the bound tools' modules beside a module client's own API.engine.ClientMetadata.CallerAgentis a new engine-internal field, never sent on the wire, likeServedDeps. DangEval sets it on the snippet's client fromcore.CallerAgent(ctx), andengine.ClientScopecarries it. After the loop context and the function call,core.CallerAgentfalls back to the agent on the request's client scope. It reads the scope, not the metadata, because workspace operations swap in the workspace owner's metadata but keep the scope. Some.wait…from the agent's own turn fails with "cannot block on itself" instead of hanging, andsendfrom a snippet records its sender. A synthetic FunctionCall would have broken Workspace auto-injection in snippets.spanResultdoes for module tools. The report already is those logs line for line, and a capture would also hoist the snippet's nested exec output into it.Tests
core/sdk/dang/v2/tools_test.go(unit, SDL schema plus a fake client) covers:wsata position, seeing localswswrites it;wsis writableata module;TestCommitDangWritesAllOrNothing);let before = wsfollowed byws = …shows both and writes onlyws.(no final newline), long lines cut in the middle); one-line strings keeping head and tail within a line for narrow, wide and escaped text; a flat list's 512 elements and nested collections' default; members only for an object (none for scalars, lists, records or null).TestDangRejected: parse and type errors are rejected (the nudge's trigger), runtime errors, successes and a module's own diagnostics aren't.at: installed git and other-SDK modules (TestDangInstalledModuleGlobals,TestDangCheckModuleWithoutDangFiles), a badatas a result (TestDangAtReport), and the unloaded-modules note (TestDangUnloadedNote).core/llm_dang_tools_test.go(unit):TestDangToolResultBounds: truncation with thescope: "own"ReadLogs pointer, rune-safe line clamps the result guard leaves alone, and only the guard outside a conversation's tool call.TestDangSpanResult, against a real telemetry store: an API chain renders the report alone; a passing check adds OUTPUT, CHECKS and the footer; a failing one leads with FAILURES.TestDangToolResultSkillNudge: the nudge on parse and type errors, not on success or runtime errors, gone after ReadSkill reads the skill (a failed read doesn't count).TestMessagesReadSkill: reading the skill from the conversation's record.TestDangToolCallLogsReportOnce: throughCallContent, with a fake implementation, the span logs carry the report exactly once for Check, Eval and a rejected source (report, then nudge). Tool errors and bad arguments still log their error.core/moddeps_test.go(TestSchemaBuilderMemoWorkspaceModules): a value workspace's modules load once per session, failures included.core/integration/llm_dang_tools_test.go(TestLLM/TestDangTools) is end to end with a canned model over a workspace with a Dang module (dagger-module.toml). It covers:at;ws = ws.withNewFile(…), written and then read back;0 writes;at: notes;notes = notes.withGreeting(…)updating its state, both in the default scope andat: notes;wssurviving to a later call;let before = wsstays readable afterws = …([false, true]), and the write persists;closest:line in a type error;vault.revealvia tool call, DangEval and shell; a snippet's ownsecret(uri:)succeeds);asChecks.{{pass}}on a passing and a failing@checkgives OUTPUT, CHECKS and FAILURES;atnaming it and a badatreported as a result;ws.withModule) or uninstalled (ws.withoutModule) by a snippet joins or leaves the next call's scope, live and snapshot;chatandme:chat = installer.install(llm: chat, ref: …)makes the module's tool callable in the next step, and the module callable from Dang;chatwithws, andchatwith a tool object, are rejected with nothing applied;mefails in DangCheck and DangEval;meis null without an agent, andme.handlereads correctly in an agent's conversation;me.wait.statefails right away with "cannot block on itself", and a snippet'ssendto a peer is recorded as from that agent, so the peer sees the[message #1 from agent "owner"]header.core/agent_tool_context_test.go(TestCallerAgentFromNestedClientMetadata): the caller agent survives the client scope, the scope clone, and owner metadata swapped in.core/schema(TestInertClientSecretReplay): a host-less rebuild of an object holding a host secret loads, and the host client still reads the secret afterwards.engine/server/served_deps_test.goalso coversInertAttachablessurviving client scopes.engine/server/served_deps_test.go: the served schema survives the client-metadata snapshot.Not covered: enriched module-load errors (a follow-up), an LSP/edit hook, completion. Tool modules from private or SSH git remotes can't be reloaded from a snippet's host-inert client, because no credentials are delegated to it; public remotes work.