Skip to content

Commit caeeb48

Browse files
committed
Initial commit
1 parent c5734f3 commit caeeb48

6 files changed

Lines changed: 120 additions & 60 deletions

File tree

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
66
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
77
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT)"
88

9-
# Apple code signing (set via environment or use default)
10-
APPLE_DEVELOPER_ID ?= 9E5DE6F9BC4DF45371D1121683B21D1638CDB875
9+
# Apple code signing (set APPLE_DEVELOPER_ID env var to enable)
10+
# Example: APPLE_DEVELOPER_ID=YOUR_CERT_HASH make build-signed
1111

1212
.PHONY: all build build-signed clean install test lint
1313

@@ -18,15 +18,17 @@ build:
1818
go build $(LDFLAGS) -o $(BINARY_NAME) .
1919

2020
build-signed: build
21-
@echo "Signing binary..."
22-
@if [ "$$(uname)" = "Darwin" ]; then \
21+
@if [ "$$(uname)" = "Darwin" ] && [ -n "$(APPLE_DEVELOPER_ID)" ]; then \
22+
echo "Signing binary..."; \
2323
codesign --force --options runtime --sign "$(APPLE_DEVELOPER_ID)" $(BINARY_NAME); \
2424
echo "Binary signed successfully"; \
25+
elif [ "$$(uname)" = "Darwin" ]; then \
26+
echo "Skipping code signing (set APPLE_DEVELOPER_ID to enable)"; \
2527
else \
2628
echo "Skipping code signing (not macOS)"; \
2729
fi
2830

29-
install: build-signed
31+
install: build
3032
@echo "Installing to ~/.local/bin..."
3133
@mkdir -p ~/.local/bin
3234
@cp $(BINARY_NAME) ~/.local/bin/$(BINARY_NAME)

install.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ set -e
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
cd "$SCRIPT_DIR"
77

8-
# Apple Code Signing Configuration
9-
# Set these environment variables or they will use defaults
10-
APPLE_DEVELOPER_ID="${APPLE_DEVELOPER_ID:-9E5DE6F9BC4DF45371D1121683B21D1638CDB875}"
8+
# Apple Code Signing Configuration (optional)
9+
# Set APPLE_DEVELOPER_ID environment variable to enable signing
10+
# Example: export APPLE_DEVELOPER_ID="your-certificate-hash"
1111

1212
echo "=========================================="
1313
echo " Logdump Installation Script"
@@ -36,8 +36,8 @@ if ! go build -o logdump .; then
3636
exit 1
3737
fi
3838

39-
# Sign the binary (macOS only)
40-
if [[ "$OSTYPE" == "darwin"* ]]; then
39+
# Sign the binary (macOS only, requires APPLE_DEVELOPER_ID)
40+
if [[ "$OSTYPE" == "darwin"* ]] && [[ -n "$APPLE_DEVELOPER_ID" ]]; then
4141
echo "Signing binary with Developer ID..."
4242
if command -v codesign &> /dev/null; then
4343
codesign --force --options runtime --sign "$APPLE_DEVELOPER_ID" logdump
@@ -50,6 +50,8 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
5050
else
5151
echo "Warning: codesign not found, skipping signing"
5252
fi
53+
elif [[ "$OSTYPE" == "darwin"* ]]; then
54+
echo "Skipping code signing (set APPLE_DEVELOPER_ID to enable)"
5355
fi
5456

5557
# Install binary

internal/config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ func expandPath(path string) string {
9191
return path
9292
}
9393

94-
func findConfigFile() string {
95-
return FindConfigFile(false)
96-
}
97-
9894
// FindConfigFile locates the config file. If globalOnly is true, only checks global config location.
9995
func FindConfigFile(globalOnly bool) string {
10096
var locations []string

internal/logtail/logtail.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type Stream struct {
3030
Reader *bufio.Reader
3131
LineNumber int
3232
Done chan struct{}
33-
mu sync.RWMutex
3433
}
3534

3635
type Manager struct {
@@ -61,11 +60,6 @@ func NewManagerWithOptions(tailOnly bool) *Manager {
6160
}
6261

6362
func (m *Manager) Tail(cfg config.StreamConfig) error {
64-
patterns := cfg.Patterns
65-
if len(patterns) == 0 {
66-
patterns = []string{"*.log"}
67-
}
68-
6963
matches, err := filepath.Glob(filepath.Join(cfg.Path, "*"))
7064
if err != nil {
7165
return err
@@ -128,7 +122,7 @@ func (m *Manager) watchDirectory(cfg config.StreamConfig) {
128122
matches, _ := filepath.Glob(filepath.Join(cfg.Path, "*"))
129123
for _, match := range matches {
130124
if cfg.Matches(match) {
131-
m.addFile(cfg, match)
125+
_ = m.addFile(cfg, match)
132126
}
133127
}
134128
}
@@ -144,18 +138,27 @@ func (s *Stream) read(ctx context.Context, entries chan<- LogEntry, tailOnly boo
144138

145139
// If tailOnly, start at end of file (skip history)
146140
if tailOnly {
147-
offset, _ = s.File.Seek(0, io.SeekEnd)
141+
var err error
142+
offset, err = s.File.Seek(0, io.SeekEnd)
143+
if err != nil {
144+
return
145+
}
148146
}
149147

150148
for {
151149
select {
152150
case <-ctx.Done():
153151
return
154152
default:
155-
fileSize, _ := s.File.Seek(0, io.SeekEnd)
153+
fileSize, err := s.File.Seek(0, io.SeekEnd)
154+
if err != nil {
155+
return
156+
}
156157

157158
if offset < fileSize {
158-
s.File.Seek(offset, io.SeekStart)
159+
if _, err := s.File.Seek(offset, io.SeekStart); err != nil {
160+
return
161+
}
159162
reader := bufio.NewReader(s.File)
160163
for {
161164
line, err := reader.ReadString('\n')
@@ -185,7 +188,11 @@ func (s *Stream) read(ctx context.Context, entries chan<- LogEntry, tailOnly boo
185188
}(entry)
186189
}
187190
}
188-
offset, _ = s.File.Seek(0, io.SeekCurrent)
191+
newOffset, err := s.File.Seek(0, io.SeekCurrent)
192+
if err != nil {
193+
return
194+
}
195+
offset = newOffset
189196
}
190197
}
191198

internal/mcp/mcp.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewServer(manager *logtail.Manager, cfg *config.Config) *Server {
109109
// Open MCP activity log file
110110
home, _ := os.UserHomeDir()
111111
logDir := filepath.Join(home, ".local", "share", "logdump", "logs")
112-
os.MkdirAll(logDir, 0755)
112+
_ = os.MkdirAll(logDir, 0755)
113113

114114
logFile, err := os.OpenFile(
115115
filepath.Join(logDir, "mcp-activity.log"),
@@ -141,8 +141,8 @@ func (s *Server) logActivity(message string) {
141141
}
142142

143143
line := fmt.Sprintf("[%s] [AGENT: %s] %s\n", timestamp, agent, message)
144-
s.logFile.WriteString(line)
145-
s.logFile.Sync()
144+
_, _ = s.logFile.WriteString(line)
145+
_ = s.logFile.Sync()
146146
}
147147

148148
func (s *Server) logToolCall(toolName string, args map[string]interface{}, resultCount int) {
@@ -166,8 +166,8 @@ func (s *Server) logToolCall(toolName string, args map[string]interface{}, resul
166166
}
167167

168168
line := fmt.Sprintf("[%s] [AGENT: %s] TOOL: %s(args: %s)%s\n", timestamp, agent, toolName, string(argsJSON), resultInfo)
169-
s.logFile.WriteString(line)
170-
s.logFile.Sync()
169+
_, _ = s.logFile.WriteString(line)
170+
_ = s.logFile.Sync()
171171
}
172172

173173
func (s *Server) RunStdio(ctx context.Context) error {
@@ -195,7 +195,7 @@ func (s *Server) handleStdio(ctx context.Context, in io.Reader, out io.Writer) e
195195

196196
var req MCPRequest
197197
if data, err := json.Marshal(rawReq); err == nil {
198-
json.Unmarshal(data, &req)
198+
_ = json.Unmarshal(data, &req)
199199
}
200200

201201
if req.JSONRPC == "" {
@@ -255,7 +255,7 @@ func (s *Server) handleWebSocket(w http.ResponseWriter, r *http.Request) {
255255

256256
var req MCPRequest
257257
if data, err := json.Marshal(rawReq); err == nil {
258-
json.Unmarshal(data, &req)
258+
_ = json.Unmarshal(data, &req)
259259
}
260260

261261
if req.JSONRPC == "" {
@@ -965,7 +965,6 @@ func (s *Server) handleResourcesRead(ctx context.Context, req MCPRequest, id int
965965

966966
uri := params.URI
967967
var text string
968-
var mimeType string = "text/plain"
969968

970969
if strings.HasPrefix(uri, "logdump://stream/") {
971970
streamName := strings.TrimPrefix(uri, "logdump://stream/")
@@ -975,7 +974,6 @@ func (s *Server) handleResourcesRead(ctx context.Context, req MCPRequest, id int
975974
lines = append(lines, fmt.Sprintf("[%s] %s | %s", e.Timestamp.Format("15:04:05.000"), e.Source, e.Content))
976975
}
977976
text = strings.Join(lines, "\n")
978-
mimeType = "text/plain"
979977
} else if strings.HasPrefix(uri, "logdump://group/") {
980978
groupName := strings.TrimPrefix(uri, "logdump://group/")
981979
s.groupsMu.RLock()
@@ -994,7 +992,6 @@ func (s *Server) handleResourcesRead(ctx context.Context, req MCPRequest, id int
994992
}
995993
}
996994
text = strings.Join(lines, "\n")
997-
mimeType = "text/plain"
998995
} else {
999996
return MCPResponse{
1000997
Error: &MCPError{
@@ -1019,7 +1016,7 @@ func (s *Server) handleResourcesRead(ctx context.Context, req MCPRequest, id int
10191016
"contents": []map[string]interface{}{
10201017
{
10211018
"uri": params.URI,
1022-
"mimeType": mimeType,
1019+
"mimeType": "text/plain",
10231020
"text": text,
10241021
},
10251022
},

0 commit comments

Comments
 (0)