Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {

// Open or create an AgentFS database
afs, err := agentfs.Open(ctx, agentfs.AgentFSOptions{
ID: "my-agent", // Creates ~/.agentfs/my-agent.db
ID: "my-agent", // Creates .agentfs/my-agent.db
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -124,7 +124,7 @@ func main() {
func Open(ctx context.Context, opts AgentFSOptions) (*AgentFS, error)

type AgentFSOptions struct {
ID string // Agent ID (creates ~/.agentfs/{id}.db)
ID string // Agent ID (creates .agentfs/{id}.db)
Path string // Explicit database path (takes precedence)
ChunkSize int // Chunk size for file data (default: 4096)
Pool PoolOptions // Connection pool configuration
Expand Down
12 changes: 4 additions & 8 deletions sdk/go/agentfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var validIDPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
// Open creates or opens an AgentFS database.
//
// If opts.Path is provided, it is used directly as the database path.
// If opts.ID is provided (without Path), the database is stored at ~/.agentfs/{id}.db
// If opts.ID is provided (without Path), the database is stored at .agentfs/{id}.db
// At least one of Path or ID must be provided.
func Open(ctx context.Context, opts AgentFSOptions) (*AgentFS, error) {
dbPath, err := resolveDBPath(opts)
Expand Down Expand Up @@ -246,13 +246,9 @@ func resolveDBPath(opts AgentFSOptions) (string, error) {
return "", fmt.Errorf("invalid agent ID: must match pattern %s", validIDPattern.String())
}

// Default to ~/.agentfs/{id}.db
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("failed to get home directory: %w", err)
}

return filepath.Join(home, ".agentfs", opts.ID+".db"), nil
// Default to .agentfs/{id}.db in the current working directory,
// matching the other SDKs and the CLI.
return filepath.Join(".agentfs", opts.ID+".db"), nil
}

// initSchema creates all tables and indexes if they don't exist
Expand Down
19 changes: 13 additions & 6 deletions sdk/go/agentfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,29 @@ func TestOpen(t *testing.T) {
})

t.Run("with ID", func(t *testing.T) {
// Create a temp home directory
tmpHome := t.TempDir()
oldHome := os.Getenv("HOME")
os.Setenv("HOME", tmpHome)
defer os.Setenv("HOME", oldHome)
tmpDir := t.TempDir()
oldWorkingDir, err := os.Getwd()
if err != nil {
t.Fatalf("Getwd failed: %v", err)
}
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Chdir failed: %v", err)
}
defer os.Chdir(oldWorkingDir)

afs, err := Open(ctx, AgentFSOptions{ID: "test-agent"})
if err != nil {
t.Fatalf("Open failed: %v", err)
}
defer afs.Close()

expectedPath := filepath.Join(tmpHome, ".agentfs", "test-agent.db")
expectedPath := filepath.Join(".agentfs", "test-agent.db")
if afs.Path() != expectedPath {
t.Errorf("Path() = %q, want %q", afs.Path(), expectedPath)
}
if _, err := os.Stat(expectedPath); err != nil {
t.Errorf("database was not created in the working directory: %v", err)
}
})

t.Run("invalid ID", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// AgentFSOptions configures how AgentFS opens or creates a database
type AgentFSOptions struct {
// ID is the agent identifier. If provided without Path, the database
// will be stored at ~/.agentfs/{id}.db
// will be stored at .agentfs/{id}.db
// Must match pattern: ^[a-zA-Z0-9_-]+$
ID string

Expand Down
Loading