The chat agent had two tools -- memory_edit and skill_activate -- so it
could not read a file, search a tree or run a command. ai-sdk's runtime
already drives a tool loop for it (MaxSteps 8, toolExecute wired as the
executor), so the loop was never the missing piece: the registry was empty
of anything useful.
Lifted from tau internal/agent/tools at commit f5289ea, per the recorded
copy-and-mutate strategy: every file carries a provenance header naming its
tau source path, the commit, and the mutations made, so refreshing from
upstream is a diff rather than archaeology.
internal/tools/builtin/ the lifted tools, ~3.1k lines
internal/tools/provider/builtin/ the adapter to tools.ToolEntry
Six tools: read, write, edit, shell, grep, find. Tau's own tests came with
them and pass unmodified, which is the evidence that the lift is faithful.
Deliberately not lifted:
- agent.go (1214 lines): subagent spawning, and the only real coupling in
the package -- 10 tau packages including chat, sessions, store and
registry. Nothing the chat agent needs to do work.
- skill.go: depends on tau's skills package; archie has internal/skill and
already exposes skill_activate.
- docs.go: serves tau's own embedded documentation via tau/docs.
Not lifting the coordinator either. It is tau's agent loop (6.4k lines over
ten packages) and archie already has one in the ai-sdk runtime; porting it
would leave two loops competing. Its cancellation and tool events are worth
having, but they are a few hundred lines built against the existing path
rather than six thousand lifted onto a second one.
The adapter bridges two shape differences: archie hands handlers decoded
arguments where tau's executor takes raw JSON, and tau reports tool-level
failure in Result.IsError rather than as an error -- surfaced as a real
error so the runtime and the guardrail engine both see it. Tools are
classified idempotent or mutating for guardrails and budgets; that is
categorisation, not a jail.
chat.workspace roots the tools and defaults to empty, which registers none
of them. They read, write and execute, so the directory has to be a
deliberate choice rather than whatever the daemon started in -- in the
container that is /.
Verified: go build, go vet, gofmt clean; full suite passes.
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
package builtin
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const verboseGoTestOutput = `=== RUN TestAlpha
|
|
--- PASS: TestAlpha (0.00s)
|
|
=== RUN TestBeta
|
|
beta_test.go:12: some chatty log line
|
|
--- PASS: TestBeta (0.01s)
|
|
PASS
|
|
ok github.com/example/pkg 0.014s
|
|
? github.com/example/pkg/empty [no test files]
|
|
ok github.com/example/other (cached)
|
|
`
|
|
|
|
func TestCollapseGoTest_KeepsOnlyPackageSummaries(t *testing.T) {
|
|
got, collapsed := collapseGoTestOutput("go test ./... -v", verboseGoTestOutput, true)
|
|
if !collapsed {
|
|
t.Fatal("expected a passing go test run to be collapsed")
|
|
}
|
|
for _, want := range []string{
|
|
"ok \tgithub.com/example/pkg\t0.014s",
|
|
"? \tgithub.com/example/pkg/empty\t[no test files]",
|
|
"ok \tgithub.com/example/other\t(cached)",
|
|
} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("summary line missing: %q\ngot:\n%s", want, got)
|
|
}
|
|
}
|
|
for _, unwanted := range []string{"=== RUN", "--- PASS", "chatty log line"} {
|
|
if strings.Contains(got, unwanted) {
|
|
t.Errorf("per-test noise %q survived:\n%s", unwanted, got)
|
|
}
|
|
}
|
|
if !strings.Contains(got, "collapsed") {
|
|
t.Errorf("expected a notice explaining the collapse, got:\n%s", got)
|
|
}
|
|
}
|
|
|
|
// A failing run is the case where the detail is the whole point.
|
|
func TestCollapseGoTest_LeavesFailingRunsAlone(t *testing.T) {
|
|
failing := verboseGoTestOutput + "--- FAIL: TestGamma (0.00s)\nFAIL\n"
|
|
got, collapsed := collapseGoTestOutput("go test ./...", failing, false)
|
|
if collapsed {
|
|
t.Fatal("a failing run must not be collapsed")
|
|
}
|
|
if got != failing {
|
|
t.Fatal("a failing run's output must be returned verbatim")
|
|
}
|
|
}
|
|
|
|
func TestCollapseGoTest_IgnoresOtherCommands(t *testing.T) {
|
|
for _, cmd := range []string{"git status", "go build ./...", "gotestsum --format short"} {
|
|
if _, collapsed := collapseGoTestOutput(cmd, verboseGoTestOutput, true); collapsed {
|
|
t.Errorf("%q must not be treated as a go test invocation", cmd)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Nothing to gain from collapsing output that is already just summaries, and
|
|
// doing so would append a confusing notice.
|
|
func TestCollapseGoTest_SkipsAlreadyTerseOutput(t *testing.T) {
|
|
terse := "ok \tgithub.com/example/pkg\t0.014s\n"
|
|
if _, collapsed := collapseGoTestOutput("go test ./...", terse, true); collapsed {
|
|
t.Error("already-terse output should be left alone")
|
|
}
|
|
}
|
|
|
|
// Guard against collapsing a run that produced no recognisable summary at all,
|
|
// which would leave the model with nothing.
|
|
func TestCollapseGoTest_SkipsWhenNoSummaryLines(t *testing.T) {
|
|
odd := "=== RUN TestAlpha\n--- PASS: TestAlpha (0.00s)\nPASS\n"
|
|
if _, collapsed := collapseGoTestOutput("go test ./...", odd, true); collapsed {
|
|
t.Error("output with no package summary lines should be left alone")
|
|
}
|
|
}
|