Skip to content
Merged
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
12 changes: 6 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ This API is consumed by LLMs. Design with that in mind:
## Commands

```bash
make check # fmt, lint, test
make install # LaunchAgent + CLI + MCP config
make restart # Restart LaunchAgent for code changes
make reinstall # pip install -e . + restart (for pyproject.toml)
make check # fmt, lint, test
make install-server # LaunchAgent + CLI + MCP config (idempotent, restarts service)
make restart # Lightweight service restart (no dependency sync)
make logs # Tail server logs
```

### When to Restart

| Change | Action |
|--------|--------|
| `server.py`, `queries.py`, `patterns.py`, `storage.py` | `make restart` |
| `server.py`, `queries.py`, `patterns.py`, `storage.py` | `make install-server` (or `make restart`) |
| `cli.py` only | None (CLI runs fresh) |
| `pyproject.toml` | `make reinstall` |
| `pyproject.toml` | `make install-server` |

---

Expand Down
66 changes: 51 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: check fmt lint test clean install uninstall restart reinstall dev venv
.PHONY: check fmt lint test clean install install-server install-client uninstall restart dev venv logs

# Run all quality gates (format check, lint, tests)
check: fmt lint test
Expand Down Expand Up @@ -28,9 +28,11 @@ venv:
dev:
uv sync --extra dev

# Full installation: venv + deps + service + CLI + MCP
install:
@echo "Installing dependencies..."
# Server installation: runs session-analytics service locally (idempotent)
# Use this on the machine that will host the database
# Re-run to pick up code changes (restarts service automatically)
install-server:
@echo "Installing server..."
uv sync
@echo ""
@if [ "$$(uname)" = "Darwin" ]; then \
Expand All @@ -52,12 +54,48 @@ install:
echo " claude mcp add --transport http --scope user agent-session-analytics http://localhost:8081/mcp"; \
fi
@echo ""
@echo "Installation complete!"
@echo "Server installation complete!"
@if ! echo "$$PATH" | tr ':' '\n' | grep -q "$$HOME/.local/bin"; then \
echo ""; \
echo "Make sure ~/.local/bin is in your PATH:"; \
echo ' export PATH="$$HOME/.local/bin:$$PATH"'; \
fi

# Client installation: connects to a remote session-analytics server (idempotent)
# Usage: make install-client REMOTE_URL=https://your-server.tailnet.ts.net/mcp
# Re-run to update remote URL or pick up CLI changes
install-client:
@if [ -z "$(REMOTE_URL)" ]; then \
echo "Error: REMOTE_URL is required"; \
echo "Usage: make install-client REMOTE_URL=https://your-server.tailnet.ts.net/mcp"; \
exit 1; \
fi
@echo "Installing client (connecting to $(REMOTE_URL))..."
uv sync
@echo ""
@echo "Installing CLI..."
./scripts/install-cli.sh
@echo ""
@echo "Configuring Claude Code MCP..."
@CLAUDE_CMD=$$(command -v claude || echo "$$HOME/.local/bin/claude"); \
if [ -x "$$CLAUDE_CMD" ]; then \
$$CLAUDE_CMD mcp remove --scope user agent-session-analytics 2>/dev/null || true; \
$$CLAUDE_CMD mcp add --transport http --scope user agent-session-analytics "$(REMOTE_URL)" && \
echo "Added agent-session-analytics to Claude Code ($(REMOTE_URL))"; \
else \
echo "Note: claude not found. Run manually:"; \
echo " claude mcp add --transport http --scope user agent-session-analytics $(REMOTE_URL)"; \
fi
@echo ""
@echo "Client installation complete!"
@echo ""
@echo "Make sure ~/.local/bin is in your PATH:"
@echo ' export PATH="$$HOME/.local/bin:$$PATH"'
@echo "Add to your shell profile (~/.zshrc, ~/.bashrc, or ~/.extra):"
@echo ' export AGENT_SESSION_ANALYTICS_URL="$(REMOTE_URL)"'

# Restart the service (pick up code changes)
# Alias for install-server (backwards compatibility)
install: install-server

# Restart the service (server only, lightweight alternative to install-server)
restart:
@if [ "$$(uname)" = "Darwin" ]; then \
PLIST="$$HOME/Library/LaunchAgents/com.evansenter.agent-session-analytics.plist"; \
Expand All @@ -73,7 +111,7 @@ restart:
exit 1; \
fi; \
else \
echo "LaunchAgent not installed. Run: make install"; \
echo "LaunchAgent not installed. Run: make install-server"; \
exit 1; \
fi; \
else \
Expand All @@ -88,12 +126,6 @@ restart:
fi; \
fi

# Reinstall: uv sync + restart service (picks up code changes)
reinstall:
@echo "Reinstalling package..."
uv sync
@$(MAKE) restart

# Uninstall: service + CLI + MCP config
uninstall:
@echo "Uninstalling..."
Expand All @@ -113,3 +145,7 @@ uninstall:
@echo ""
@echo "Uninstall complete!"
@echo "Note: venv and source code remain in place."

# Tail the server log (server only)
logs:
@tail -f ~/.claude/contrib/agent-session-analytics/agent-session-analytics.log