* chore(plugin): delete the unwired capability-host health surface
plugin.Host.Health, plugin.Host.Manifests, ModuleStatus and their private
safeHealth helper were implemented, exhaustively tested, and called from nowhere
but their own tests. AGENTS.md forbids speculative surfaces, and no settled
design places plugin module status anywhere that exists:
- docs/prds/status-health-surface.md Phase 2 is self-described as "a proposed
resolution, awaiting Sam's sign-off -- not yet implemented", and does not
mention plugin status even in that unapproved list.
- The readiness subsystem enumerates exactly five probes -- state_db, config,
disk, model, gateway (internal/app/archied/readiness.go) -- with no plugin
probe.
- docs/architecture/plugins-and-extensions.md names no operator-visible plugin
status surface.
- The only bead naming it is closed.
plugin.Host itself stays: it is the daemon's live capability host, constructed
and Start/Stop-ed from internal/app/archied. Only the unconsumed observability
methods go.
host_contract_test.go encoded the defect -- it asserted plugin.Host *defines*
"Health" and "Manifests" -- so those two names are removed from its list, which
is now exactly the shipped lifecycle: Register, Start, Stop. The three tests
covering the deleted surface are removed with it.
The Yaegi symbol table (internal/plugin/pluginextract) was regenerated rather
than hand-edited, so ModuleStatus leaves the reflected type set with it.
Reachability evidence: Host.Health and Host.Manifests appear only in their own
tests; plugin.Host is otherwise reached from bootstrap.go and gateway.go for
Register/Start/Stop. Note that "task reachability" does NOT flag these -- the
address-taken constructor is a known blind spot of the whole-program RTA.
* chore(plugin): delete the dead Module.Health chain wired to nothing
Extends the capability-host observability deletion: plugin.Module.Health
was a required interface method with real implementations in
tools/provider/mcp and tools/provider/builtin, aggregated by
tools/provider.Registry.Health via a provider-package-local safeHealth,
and backed by per-module LifecycleState bookkeeping in plugin.Host
(registeredModule.state, setModuleState). None of it had a caller before
this change -- Host.Health was the only thing that would ever have read
a registered module's Health(), and Host.Health was already deleted as
unreachable. registeredModule.state was write-only: nothing ever read it.
Deleted:
- plugin.Module.Health, plugin.Health/HealthStatus (+ consts),
plugin.LifecycleState (+ consts), legacyModule.Health,
registeredModule.state, Host.setModuleState and its call sites.
- tools/provider.Registry.Health, tools/provider.safeHealth.
- tools/provider/mcp.Provider.Health, tools/provider/builtin.Provider.Health.
- Tests exclusively covering the above, and fakes' now-unnecessary Health
methods (plugin/host_test.go, pluginextract/reachability_test.go,
tools/provider/{provider,optional}_test.go, tools/provider/mcp/provider_test.go,
app/agentworker/mcp_providers_test.go).
internal/plugin/pluginextract's generated file was regenerated via
`go generate ./internal/plugin/...` and the yaegi wrapper nil-guards
(dropped by fresh generation, as documented in reachability_test.go)
were reapplied by hand to WManifest/WStart/WStop/WName/WVersion,
following this repo's established post-regen pattern.
219 lines
7.5 KiB
Go
219 lines
7.5 KiB
Go
// Package builtin adapts the lifted tau file and shell tools to the typed
|
|
// tool-provider family.
|
|
//
|
|
// The tools themselves live in internal/tools/builtin, copied from tau with
|
|
// provenance headers. This package is the seam: it translates tau's tool
|
|
// shape (a JSON-schema struct plus an Executor taking raw JSON and a UI
|
|
// bridge) into archie's tools.ToolEntry, so the ai-sdk runtime's existing
|
|
// tool loop can call them without either side knowing about the other.
|
|
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/plugin"
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
toolsbuiltin "github.com/samcharles93/archie-core/internal/tools/builtin"
|
|
"github.com/samcharles93/archie-core/internal/tools/command"
|
|
)
|
|
|
|
// toolset groups these tools for progressive disclosure and guardrails.
|
|
const toolset = "workspace"
|
|
|
|
// Provider exposes the built-in file and shell tools.
|
|
type Provider struct {
|
|
// workspace is the directory file and shell operations are rooted at.
|
|
workspace string
|
|
|
|
// unrestricted lifts the workspace jail from the file tools. See
|
|
// config.ChatConfig.UnrestrictedFilesystem for when that is wanted.
|
|
unrestricted bool
|
|
|
|
// workspaceIndex narrows grep's candidate files. Optional: nil leaves
|
|
// grep on its direct walk, which is the behaviour when no index is
|
|
// configured or its build has not finished.
|
|
workspaceIndex toolsbuiltin.GrepIndex
|
|
|
|
// registry holds the constructed tools. Built once in Start so
|
|
// Discover cannot partially fail.
|
|
registry *toolsbuiltin.Registry
|
|
}
|
|
|
|
// New creates a provider rooted at workspace. An empty workspace is a
|
|
// configuration error, reported by Start rather than silently defaulting to
|
|
// the daemon's own working directory.
|
|
//
|
|
// unrestricted lets the file tools reach absolute paths outside workspace;
|
|
// relative paths still resolve against it either way.
|
|
// A workspace index is optional and variadic to match
|
|
// toolsbuiltin.RegisterBuiltins, which has always taken one the same way.
|
|
// Only the first is used.
|
|
func New(workspace string, unrestricted bool, indexes ...toolsbuiltin.GrepIndex) *Provider {
|
|
p := &Provider{workspace: workspace, unrestricted: unrestricted}
|
|
if len(indexes) > 0 {
|
|
p.workspaceIndex = indexes[0]
|
|
}
|
|
return p
|
|
}
|
|
|
|
// Manifest declares the adapter's tool capability.
|
|
func (p *Provider) Manifest() plugin.Manifest {
|
|
return plugin.Manifest{
|
|
ID: "workspace.tools",
|
|
Name: "Workspace tools",
|
|
Version: "1.0.0",
|
|
APIVersion: plugin.HostAPIVersion,
|
|
Capabilities: []plugin.CapabilityKind{"tools"},
|
|
}
|
|
}
|
|
|
|
// Start constructs the tools against the configured workspace.
|
|
func (p *Provider) Start(ctx context.Context) error {
|
|
if err := ctx.Err(); err != nil {
|
|
return err
|
|
}
|
|
if p.workspace == "" {
|
|
return errors.New("workspace tool provider: workspace directory is not configured")
|
|
}
|
|
// Set before the tools are built. Confinement is consulted per call, so
|
|
// ordering only matters in that it must precede the first tool call, but
|
|
// keeping it next to construction is where a reader will look for it.
|
|
toolsbuiltin.SetPathConfinement(!p.unrestricted)
|
|
|
|
registry := toolsbuiltin.NewRegistry()
|
|
// Forwarded only when present. Passing a nil interface would still work
|
|
// today (grep nil-checks it), but an explicit branch keeps a typed-nil
|
|
// index from reaching a call on a nil receiver.
|
|
var indexes []toolsbuiltin.GrepIndex
|
|
if p.workspaceIndex != nil {
|
|
indexes = append(indexes, p.workspaceIndex)
|
|
}
|
|
if err := toolsbuiltin.RegisterBuiltins(registry, p.workspace, indexes...); err != nil {
|
|
return fmt.Errorf("workspace tool provider: register builtins: %w", err)
|
|
}
|
|
p.registry = registry
|
|
return nil
|
|
}
|
|
|
|
// Discover returns the built-in tools as executable entries.
|
|
func (p *Provider) Discover(ctx context.Context) ([]tools.ToolEntry, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
if p.registry == nil {
|
|
return nil, errors.New("workspace tool provider: not started")
|
|
}
|
|
|
|
all := p.registry.All()
|
|
entries := make([]tools.ToolEntry, 0, len(all))
|
|
for _, tool := range all {
|
|
entry, err := toEntry(tool)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
entries = append(entries, entry)
|
|
}
|
|
return entries, nil
|
|
}
|
|
|
|
// Stop releases the constructed tools.
|
|
func (p *Provider) Stop(context.Context) error {
|
|
p.registry = nil
|
|
return nil
|
|
}
|
|
|
|
// toEntry converts one tau tool into an archie tool entry.
|
|
func toEntry(tool toolsbuiltin.Tool) (tools.ToolEntry, error) {
|
|
var schema tools.JSONSchema
|
|
if len(tool.Schema.Parameters) > 0 {
|
|
if err := json.Unmarshal(tool.Schema.Parameters, &schema); err != nil {
|
|
return tools.ToolEntry{}, fmt.Errorf("workspace tool %s: decode schema: %w", tool.Schema.Name, err)
|
|
}
|
|
}
|
|
return tools.ToolEntry{
|
|
Name: tool.Schema.Name,
|
|
Description: tool.Schema.Description,
|
|
Toolset: toolset,
|
|
Schema: schema,
|
|
Classification: classify(tool.Schema.Name),
|
|
Handler: handlerFor(tool),
|
|
}, nil
|
|
}
|
|
|
|
// handlerFor adapts a tau Executor to an archie Handler.
|
|
//
|
|
// Two shape differences are bridged here. Archie hands the handler decoded
|
|
// arguments while tau's executor takes raw JSON, and tau's executor reports
|
|
// a tool-level failure in Result.IsError rather than as an error. The
|
|
// latter is surfaced as a real error so the runtime's own failure handling
|
|
// and the guardrail engine both see it.
|
|
func handlerFor(tool toolsbuiltin.Tool) tools.Handler {
|
|
return func(ctx context.Context, input map[string]any) (any, error) {
|
|
if err := screen(tool.Schema.Name, input); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
params := json.RawMessage("{}")
|
|
if len(input) > 0 {
|
|
encoded, err := json.Marshal(input)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("tool %s: encode input: %w", tool.Schema.Name, err)
|
|
}
|
|
params = encoded
|
|
}
|
|
|
|
// NonInteractiveBridge refuses prompts rather than blocking. None
|
|
// of the lifted tools prompt; a future one that does will fail
|
|
// loudly here instead of hanging a chat turn forever.
|
|
result, err := tool.Execute(ctx, params, toolsbuiltin.NonInteractiveBridge{})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("tool %s: %w", tool.Schema.Name, err)
|
|
}
|
|
if result.IsError {
|
|
if result.ErrorKind != "" {
|
|
return nil, fmt.Errorf("tool %s: %s: %s", tool.Schema.Name, result.ErrorKind, result.Content)
|
|
}
|
|
return nil, fmt.Errorf("tool %s: %s", tool.Schema.Name, result.Content)
|
|
}
|
|
return result.Content, nil
|
|
}
|
|
}
|
|
|
|
// screen applies the always-on command rules before a tool runs.
|
|
//
|
|
// This lives in the adapter rather than in the lifted shell tool so that
|
|
// the copied files stay diffable against tau, and so the rules are archie's
|
|
// to change. It is a floor, not a sandbox: anything with a shell has ways
|
|
// around a rule list, and the point is only that the failures with no
|
|
// recovery are not reachable by an ordinary mistake.
|
|
func screen(name string, input map[string]any) error {
|
|
if name != "shell" {
|
|
return nil
|
|
}
|
|
line, _ := input["command"].(string)
|
|
if err := command.Hardline(line); err != nil {
|
|
return fmt.Errorf("tool shell: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// classify tags each tool so the guardrail engine and result-limit enforcement
|
|
// can reason about it. This is categorisation, not a jail: it describes
|
|
// what a tool does and does not gate whether it may run.
|
|
//
|
|
// shell is classified mutating because it can be, not because it always
|
|
// is -- the classification cannot inspect the command.
|
|
func classify(name string) tools.ToolClassification {
|
|
switch name {
|
|
case "read", "grep", "find":
|
|
return tools.ClassIdempotent
|
|
case "write", "edit", "shell":
|
|
return tools.ClassMutating
|
|
default:
|
|
return 0
|
|
}
|
|
}
|