Skip to content

Commit b514421

Browse files
committed
🐳 feat: update Dockerfile and integrate IPC module
Refactor Dockerfile to use Go 1.25 and streamline the build process. Introduce the `pkg/ipc` module for managing Unix Domain Socket communication. Update daemon logic to utilize the new IPC methods for socket path management, enhancing maintainability and clarity.
1 parent 301fa63 commit b514421

9 files changed

Lines changed: 168 additions & 33 deletions

File tree

Dockerfile

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
# Stage 1: Build
2-
FROM golang:1.21-alpine AS builder
2+
FROM golang:1.25-alpine AS builder
33

4-
# Install build dependencies
54
RUN apk add --no-cache git build-base
65

76
WORKDIR /app
8-
9-
# Copy the entire workspace
107
COPY . .
8+
WORKDIR /app/cmd/vibeaura
9+
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /vibeaura .
1110

12-
# Build the main CLI tool
13-
# Using go build from the root, targeting the vibeaura command
14-
RUN go build -o /app/vibeaura ./cmd/vibeaura
15-
16-
# Stage 2: Runtime
17-
FROM alpine:latest
18-
19-
RUN apk add --no-cache ca-certificates
11+
FROM alpine:3.20
2012

21-
WORKDIR /root/
13+
RUN apk add --no-cache ca-certificates git
2214

23-
# Copy the binary from the builder stage
24-
COPY --from=builder /app/vibeaura /usr/local/bin/vibeaura
15+
COPY --from=builder /vibeaura /usr/local/bin/vibeaura
2516

26-
# Expose port for the daemon/gRPC if needed (defaulting to a common one)
27-
EXPOSE 50051
17+
RUN mkdir -p /run/agentic /root/.vibeauracle
18+
ENV AGENTIC_RUN_DIR=/run/agentic
2819

29-
# Default command
3020
ENTRYPOINT ["vibeaura"]
31-
CMD ["--help"]
21+
CMD ["daemon", "start"]

cmd/vibeaura/daemon.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/nathfavour/vibeauracle/brain"
1212
"github.com/nathfavour/vibeauracle/daemon"
13+
vipc "github.com/nathfavour/vibeauracle/pkg/ipc"
1314
"github.com/spf13/cobra"
1415
)
1516

@@ -20,8 +21,7 @@ type Processor interface {
2021
}
2122

2223
func ensureDaemonRunning(p Processor) {
23-
home, _ := os.UserHomeDir()
24-
socketPath := filepath.Join(home, ".vibeauracle", "vibeaura.sock")
24+
socketPath := vipc.SocketPath()
2525

2626
// 1. Check if socket exists and is alive
2727
if _, err := os.Stat(socketPath); err == nil {
@@ -53,8 +53,7 @@ var daemonStartCmd = &cobra.Command{
5353
b := brain.New()
5454

5555
// Determine socket path
56-
home, _ := os.UserHomeDir()
57-
socketPath := filepath.Join(home, ".vibeauracle", "vibeaura.sock")
56+
socketPath := vipc.SocketPath()
5857

5958
d := daemon.NewServer(socketPath, b)
6059

cmd/vibeaura/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/nathfavour/vibeauracle/reactor v0.0.0-00010101000000-000000000000
2121
github.com/nathfavour/vibeauracle/sys v0.0.0
2222
github.com/nathfavour/vibeauracle/tooling v0.0.0-00010101000000-000000000000
23+
github.com/nathfavour/vibeauracle/pkg/ipc v0.0.0
2324
github.com/spf13/cobra v1.10.2
2425
golang.org/x/image v0.23.0
2526
golang.org/x/mod v0.32.0
@@ -233,3 +234,5 @@ replace github.com/nathfavour/vibeauracle/reactor => ../../internal/reactor
233234
replace github.com/nathfavour/vibeauracle/connect => ../../internal/connect
234235

235236
replace github.com/nathfavour/vibeauracle/internal/watcher => ../../internal/watcher
237+
238+
replace github.com/nathfavour/vibeauracle/pkg/ipc => ../../pkg/ipc

internal/sys/anyisland.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ type AnyislandHandshakeResponse struct {
2121
AnyislandVersion string `json:"anyisland_version,omitempty"`
2222
}
2323

24+
func anyislandSocketPath() string {
25+
if v := os.Getenv("ANYISLAND_SOCKET"); v != "" {
26+
return v
27+
}
28+
if v := os.Getenv("ANYISLAND_IPC_SOCK"); v != "" {
29+
return v
30+
}
31+
if run := os.Getenv("AGENTIC_RUN_DIR"); run != "" {
32+
return filepath.Join(run, "anyisland.sock")
33+
}
34+
home, _ := os.UserHomeDir()
35+
return filepath.Join(home, ".anyisland", "anyisland.sock")
36+
}
37+
2438
// IsManagedByAnyisland checks if the current process is managed by Anyisland
2539
// by performing a handshake with the local anyisland daemon socket.
2640
func IsManagedByAnyisland() bool {
27-
home, err := os.UserHomeDir()
28-
if err != nil {
29-
return false
30-
}
31-
32-
socketPath := filepath.Join(home, ".anyisland", "anyisland.sock")
41+
socketPath := anyislandSocketPath()
3342
if _, err := os.Stat(socketPath); os.IsNotExist(err) {
3443
return false
3544
}

pkg/engine/engine.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"os/exec"
88
"path/filepath"
99
"strings"
10+
11+
vipc "github.com/nathfavour/vibeauracle/pkg/ipc"
1012
)
1113

12-
// DefaultEngine runs vibeaura against a workspace directory.
14+
// DefaultEngine mutates codebases via vibeauracle UDS, falling back to CLI.
1315
type DefaultEngine struct {
1416
Binary string
1517
}
@@ -23,13 +25,18 @@ func NewDefaultEngine() *DefaultEngine {
2325
}
2426

2527
func (e *DefaultEngine) Mutate(ctx context.Context, req MutationRequest) (*MutationResult, error) {
26-
if req.WorkDir == "" {
27-
return nil, fmt.Errorf("workdir is required")
28-
}
2928
if req.Payload == "" {
3029
return nil, fmt.Errorf("payload is required")
3130
}
3231

32+
if out, err := vipc.Query(req.Payload); err == nil {
33+
return &MutationResult{Success: true, ExitCode: 0, Output: strings.TrimSpace(out)}, nil
34+
}
35+
36+
if req.WorkDir == "" {
37+
return nil, fmt.Errorf("workdir is required when vibeauracle UDS is unavailable")
38+
}
39+
3340
workDir, err := filepath.Abs(req.WorkDir)
3441
if err != nil {
3542
return nil, err

pkg/engine/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module github.com/nathfavour/vibeauracle/pkg/engine
22

33
go 1.21
4+
5+
require github.com/nathfavour/vibeauracle/pkg/ipc v0.0.0
6+
7+
replace github.com/nathfavour/vibeauracle/pkg/ipc => ../ipc

pkg/ipc/client.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package ipc
2+
3+
import (
4+
"bufio"
5+
"encoding/json"
6+
"fmt"
7+
"net"
8+
"time"
9+
)
10+
11+
type Request struct {
12+
Type string `json:"type"`
13+
Method string `json:"method"`
14+
ID string `json:"id"`
15+
Payload interface{} `json:"payload"`
16+
}
17+
18+
type Response struct {
19+
Type string `json:"type"`
20+
ID string `json:"id"`
21+
Payload json.RawMessage `json:"payload"`
22+
}
23+
24+
type QueryResult struct {
25+
Content string `json:"content"`
26+
Reasoning string `json:"reasoning"`
27+
}
28+
29+
// Query sends a mutation/query payload over the vibeauracle UDS.
30+
func Query(content string) (string, error) {
31+
conn, err := net.DialTimeout("unix", SocketPath(), 5*time.Second)
32+
if err != nil {
33+
return "", fmt.Errorf("vibeauracle uds: %w", err)
34+
}
35+
defer conn.Close()
36+
37+
id := fmt.Sprintf("polygeist-%d", time.Now().UnixNano())
38+
req := Request{
39+
Type: "request",
40+
Method: "query",
41+
ID: id,
42+
Payload: map[string]string{
43+
"content": content,
44+
"intent": "vibe",
45+
},
46+
}
47+
data, err := json.Marshal(req)
48+
if err != nil {
49+
return "", err
50+
}
51+
if _, err := conn.Write(append(data, '\n')); err != nil {
52+
return "", err
53+
}
54+
55+
scanner := bufio.NewScanner(conn)
56+
scanner.Buffer(make([]byte, 0, 64*1024), 10*1024*1024)
57+
if !scanner.Scan() {
58+
return "", fmt.Errorf("no response from vibeauracle")
59+
}
60+
61+
var resp Response
62+
if err := json.Unmarshal(scanner.Bytes(), &resp); err != nil {
63+
return "", err
64+
}
65+
if resp.Type == "error" {
66+
return "", fmt.Errorf("%s", string(resp.Payload))
67+
}
68+
69+
var result QueryResult
70+
if err := json.Unmarshal(resp.Payload, &result); err != nil {
71+
return string(resp.Payload), nil
72+
}
73+
if result.Content != "" {
74+
return result.Content, nil
75+
}
76+
return result.Reasoning, nil
77+
}
78+
79+
// Ping checks whether the vibeauracle daemon is reachable.
80+
func Ping() error {
81+
conn, err := net.DialTimeout("unix", SocketPath(), 2*time.Second)
82+
if err != nil {
83+
return err
84+
}
85+
defer conn.Close()
86+
87+
id := fmt.Sprintf("ping-%d", time.Now().UnixNano())
88+
req := Request{Type: "request", Method: "ping", ID: id}
89+
data, _ := json.Marshal(req)
90+
if _, err := conn.Write(append(data, '\n')); err != nil {
91+
return err
92+
}
93+
scanner := bufio.NewScanner(conn)
94+
if !scanner.Scan() {
95+
return fmt.Errorf("no pong")
96+
}
97+
return nil
98+
}

pkg/ipc/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/nathfavour/vibeauracle/pkg/ipc
2+
3+
go 1.21

pkg/ipc/paths.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ipc
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
// SocketPath returns the vibeauracle UDS path.
9+
// Override with VIBEAURA_SOCKET, VIBEIPC_SOCK, or AGENTIC_RUN_DIR.
10+
func SocketPath() string {
11+
if v := os.Getenv("VIBEAURA_SOCKET"); v != "" {
12+
return v
13+
}
14+
if v := os.Getenv("VIBEIPC_SOCK"); v != "" {
15+
return v
16+
}
17+
if run := os.Getenv("AGENTIC_RUN_DIR"); run != "" {
18+
return filepath.Join(run, "vibeaura.sock")
19+
}
20+
home, _ := os.UserHomeDir()
21+
return filepath.Join(home, ".vibeauracle", "vibeaura.sock")
22+
}

0 commit comments

Comments
 (0)