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.
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package builtin_test
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/tools/builtin"
|
|
)
|
|
|
|
func TestMutationQueue_Serializes(t *testing.T) {
|
|
q := builtin.NewMutationQueue()
|
|
path := "/tmp/test.txt"
|
|
|
|
var counter atomic.Int64
|
|
var maxConcurrent atomic.Int64
|
|
var wg sync.WaitGroup
|
|
|
|
for i := range 50 {
|
|
_ = i
|
|
wg.Go(func() {
|
|
release := q.Acquire(path)
|
|
defer release()
|
|
|
|
cur := counter.Add(1)
|
|
// Track max concurrency for this path.
|
|
for {
|
|
old := maxConcurrent.Load()
|
|
if cur <= old || maxConcurrent.CompareAndSwap(old, cur) {
|
|
break
|
|
}
|
|
}
|
|
counter.Add(-1)
|
|
})
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
if maxConcurrent.Load() > 1 {
|
|
t.Fatalf("expected max concurrency of 1, got %d", maxConcurrent.Load())
|
|
}
|
|
}
|
|
|
|
func TestMutationQueue_DifferentPaths_Parallel(t *testing.T) {
|
|
q := builtin.NewMutationQueue()
|
|
|
|
var wg sync.WaitGroup
|
|
started := make(chan struct{}, 2)
|
|
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
release := q.Acquire("/path/a")
|
|
started <- struct{}{}
|
|
<-started // wait for both to acquire
|
|
release()
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
release := q.Acquire("/path/b")
|
|
started <- struct{}{}
|
|
<-started // wait for both to acquire
|
|
release()
|
|
}()
|
|
|
|
wg.Wait()
|
|
// If we get here without deadlocking, different paths don't block each other.
|
|
}
|