mirror of
https://github.com/esengine/DeepSeek-Reasonix.git
synced 2026-11-07 10:45:59 -10:00
Bring in the finished Go rewrite (developed under the placeholder name "duo") as the v2 codebase. Code-only import — no upstream git history. Config- and plugin-driven coding agent: registry core, OpenAI-compatible providers, builtin tools, MCP (stdio + HTTP) plugins, permission + sandbox, custom slash commands, @-references, two-model collaboration. Renamed throughout: duo→reasonix, Duo→Reasonix, DUO→REASONIX — module path, imports, CLI name, cmd/ dirs, reasonix.toml, .reasonix/commands, and $REASONIX_* env prefixes. Kept the v2 MIT LICENSE (the Go project had none). Verified: go build ./... · go vet ./... · go test ./... all green; gofmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"reasonix/internal/tool"
|
|
)
|
|
|
|
func init() { tool.RegisterBuiltin(listDir{}) }
|
|
|
|
type listDir struct{}
|
|
|
|
func (listDir) Name() string { return "ls" }
|
|
|
|
func (listDir) Description() string {
|
|
return "List the entries of a directory. Directories are shown with a trailing slash; files show their byte size."
|
|
}
|
|
|
|
func (listDir) Schema() json.RawMessage {
|
|
return json.RawMessage(`{"type":"object","properties":{"path":{"type":"string","description":"Directory path (default \".\")"}}}`)
|
|
}
|
|
|
|
func (listDir) ReadOnly() bool { return true }
|
|
|
|
func (listDir) Execute(ctx context.Context, args json.RawMessage) (string, error) {
|
|
p := struct {
|
|
Path string `json:"path"`
|
|
}{Path: "."}
|
|
if len(args) > 0 {
|
|
if err := json.Unmarshal(args, &p); err != nil {
|
|
return "", fmt.Errorf("invalid args: %w", err)
|
|
}
|
|
}
|
|
if p.Path == "" {
|
|
p.Path = "."
|
|
}
|
|
|
|
entries, err := os.ReadDir(p.Path)
|
|
if err != nil {
|
|
return "", fmt.Errorf("ls %s: %w", p.Path, err)
|
|
}
|
|
|
|
var b strings.Builder
|
|
for _, e := range entries {
|
|
if e.IsDir() {
|
|
fmt.Fprintf(&b, "%s/\n", e.Name())
|
|
continue
|
|
}
|
|
size := int64(-1)
|
|
if info, err := e.Info(); err == nil {
|
|
size = info.Size()
|
|
}
|
|
fmt.Fprintf(&b, "%s\t%d\n", e.Name(), size)
|
|
}
|
|
if b.Len() == 0 {
|
|
return "(empty directory)", nil
|
|
}
|
|
return b.String(), nil
|
|
}
|