forked from coder/mux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
362 lines (294 loc) · 13.7 KB
/
Makefile
File metadata and controls
362 lines (294 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# Build System
# ============
# This Makefile orchestrates the mux build process.
#
# Quick Start:
# make help - Show all available targets
# make dev - Start development server with hot reload
# make build - Build all targets (parallel when possible)
# make static-check - Run all static checks (lint + typecheck + fmt-check)
# make test - Run tests
#
# Parallelism:
# Runs in parallel by default for faster builds. Use -j1 for sequential execution.
# Individual targets can opt out with .NOTPARALLEL if needed.
#
# Backwards Compatibility:
# All commands also work via `bun run` (e.g., `bun run dev` calls `make dev`)
#
# Adding New Targets:
# Add `## Description` after the target to make it appear in `make help`
#
# Build Reproducibility:
# AVOID CONDITIONAL BRANCHES (if/else) IN BUILD TARGETS AT ALL COSTS.
# Branches reduce reproducibility - builds should fail fast with clear errors
# if dependencies are missing, not silently fall back to different behavior.
# Enable parallel execution by default (only if user didn't specify -j)
ifeq (,$(filter -j%,$(MAKEFLAGS)))
MAKEFLAGS += -j
endif
# Include formatting rules
include fmt.mk
.PHONY: all build dev start clean help
.PHONY: build-renderer version build-icons build-static
.PHONY: lint lint-fix typecheck static-check
.PHONY: test test-unit test-integration test-watch test-coverage test-e2e
.PHONY: dist dist-mac dist-win dist-linux
.PHONY: vscode-ext vscode-ext-install
.PHONY: docs docs-build docs-watch
.PHONY: storybook storybook-build test-storybook chromatic
.PHONY: benchmark-terminal
.PHONY: ensure-deps
.PHONY: check-eager-imports check-bundle-size check-startup
# Build tools
TSGO := bun run node_modules/@typescript/native-preview/bin/tsgo.js
# Node.js version check
REQUIRED_NODE_VERSION := 20
NODE_VERSION := $(shell node --version | sed 's/v\([0-9]*\).*/\1/')
define check_node_version
@if [ "$(NODE_VERSION)" -lt "$(REQUIRED_NODE_VERSION)" ]; then \
echo "Error: Node.js v$(REQUIRED_NODE_VERSION) or higher is required"; \
echo "Current version: v$(NODE_VERSION)"; \
echo ""; \
echo "To upgrade Node.js:"; \
echo " 1. Install 'n' version manager: curl -L https://raw.githubusercontent.com/tj/n/master/bin/n | sudo bash -s -- lts"; \
echo " 2. Or use 'n' if already installed: sudo n $(REQUIRED_NODE_VERSION)"; \
echo ""; \
exit 1; \
fi
endef
# Detect if browser opener is available that Storybook can use
# Storybook uses 'open' package which tries xdg-open on Linux, open on macOS, start on Windows
HAS_BROWSER_OPENER := $(shell command -v xdg-open >/dev/null 2>&1 && echo "yes" || echo "no")
STORYBOOK_OPEN_FLAG := $(if $(filter yes,$(HAS_BROWSER_OPENER)),,--no-open)
TS_SOURCES := $(shell find src -type f \( -name '*.ts' -o -name '*.tsx' \))
# Default target
all: build
# Sentinel file to track when dependencies are installed
# Depends on package.json and bun.lock - rebuilds if either changes
node_modules/.installed: package.json bun.lock
@echo "Dependencies out of date or missing, running bun install..."
@bun install
@touch node_modules/.installed
# Legacy target for backwards compatibility
ensure-deps: node_modules/.installed
## Help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
## Development
dev: node_modules/.installed build-main ## Start development server (Vite + tsgo watcher for 10x faster type checking)
@bun x concurrently -k \
"bun x concurrently \"$(TSGO) -w -p tsconfig.main.json\" \"bun x tsc-alias -w -p tsconfig.main.json\"" \
"vite"
dev-server: node_modules/.installed build-main ## Start server mode with hot reload (backend :3000 + frontend :5173). Use VITE_HOST=0.0.0.0 BACKEND_HOST=0.0.0.0 for remote access
@echo "Starting dev-server..."
@echo " Backend (IPC/WebSocket): http://$(or $(BACKEND_HOST),localhost):$(or $(BACKEND_PORT),3000)"
@echo " Frontend (with HMR): http://$(or $(VITE_HOST),localhost):$(or $(VITE_PORT),5173)"
@echo ""
@echo "For remote access: make dev-server VITE_HOST=0.0.0.0 BACKEND_HOST=0.0.0.0"
@bun x concurrently -k \
"bun x concurrently \"$(TSGO) -w -p tsconfig.main.json\" \"bun x tsc-alias -w -p tsconfig.main.json\"" \
"bun x nodemon --watch dist/main.js --watch dist/main-server.js --delay 500ms --exec 'NODE_ENV=development node dist/main.js server --host $(or $(BACKEND_HOST),localhost) --port $(or $(BACKEND_PORT),3000)'" \
"MUX_VITE_HOST=$(or $(VITE_HOST),127.0.0.1) MUX_VITE_PORT=$(or $(VITE_PORT),5173) VITE_BACKEND_URL=http://$(or $(BACKEND_HOST),localhost):$(or $(BACKEND_PORT),3000) vite"
start: node_modules/.installed build-main build-preload build-static ## Build and start Electron app
@NODE_ENV=development bun x electron --remote-debugging-port=9222 .
## Build targets (can run in parallel)
build: node_modules/.installed src/version.ts build-renderer build-main build-preload build-icons build-static ## Build all targets
build-main: node_modules/.installed dist/main.js ## Build main process
dist/main.js: src/version.ts tsconfig.main.json tsconfig.json $(TS_SOURCES)
@echo "Building main process..."
@NODE_ENV=production $(TSGO) -p tsconfig.main.json
@NODE_ENV=production bun x tsc-alias -p tsconfig.main.json
build-preload: node_modules/.installed dist/preload.js ## Build preload script
dist/preload.js: src/preload.ts $(TS_SOURCES)
@echo "Building preload script..."
@NODE_ENV=production bun build src/preload.ts \
--format=cjs \
--target=node \
--external=electron \
--sourcemap=inline \
--outfile=dist/preload.js
build-renderer: node_modules/.installed src/version.ts ## Build renderer process
@echo "Building renderer..."
@bun x vite build
build-static: ## Copy static assets to dist
@echo "Copying static assets..."
@mkdir -p dist
@cp static/splash.html dist/splash.html
@cp -r public/* dist/
# Always regenerate version file (marked as .PHONY above)
version: ## Generate version file
@./scripts/generate-version.sh
src/version.ts: version
# Platform-specific icon targets
ifeq ($(shell uname), Darwin)
build-icons: build/icon.icns build/icon.png ## Generate Electron app icons from logo (macOS builds both)
else
build-icons: build/icon.png ## Generate Electron app icons from logo (Linux builds PNG only)
endif
# Detect ImageMagick command (magick on v7+, convert on older versions)
MAGICK_CMD := $(shell command -v magick 2>/dev/null || command -v convert 2>/dev/null || echo "magick")
build/icon.png: docs/img/logo.webp
@echo "Generating Linux icon..."
@mkdir -p build
@$(MAGICK_CMD) docs/img/logo.webp -resize 512x512 build/icon.png
build/icon.icns: docs/img/logo.webp
@echo "Generating macOS icon..."
@mkdir -p build/icon.iconset
@for size in 16 32 64 128 256 512; do \
$(MAGICK_CMD) docs/img/logo.webp -resize $${size}x$${size} build/icon.iconset/icon_$${size}x$${size}.png; \
if [ $$size -le 256 ]; then \
double=$$((size * 2)); \
$(MAGICK_CMD) docs/img/logo.webp -resize $${double}x$${double} build/icon.iconset/icon_$${size}x$${size}@2x.png; \
fi; \
done
@iconutil -c icns build/icon.iconset -o build/icon.icns
@rm -rf build/icon.iconset
## Quality checks (can run in parallel)
static-check: lint typecheck fmt-check check-eager-imports ## Run all static checks (includes startup performance checks)
lint: node_modules/.installed ## Run ESLint (typecheck runs in separate target)
@./scripts/lint.sh
lint-fix: node_modules/.installed ## Run linter with --fix
@./scripts/lint.sh --fix
typecheck: node_modules/.installed src/version.ts ## Run TypeScript type checking (uses tsgo for 10x speedup)
@bun x concurrently -g \
"$(TSGO) --noEmit" \
"$(TSGO) --noEmit -p tsconfig.main.json"
check-deadcode: node_modules/.installed ## Check for potential dead code (manual only, not in static-check)
@echo "Checking for potential dead code with ts-prune..."
@echo "(Note: Some unused exports are legitimate - types, public APIs, entry points, etc.)"
@echo ""
@bun x ts-prune -i '(test|spec|mock|bench|debug|storybook)' \
| grep -v "used in module" \
| grep -v "src/App.tsx.*default" \
| grep -v "src/types/" \
| grep -v "telemetry/index.ts" \
|| echo "✓ No obvious dead code found"
## Testing
test-integration: node_modules/.installed build-main ## Run all tests (unit + integration)
@bun test src
@TEST_INTEGRATION=1 bun x jest tests
test-unit: node_modules/.installed build-main ## Run unit tests
@bun test src
test: test-unit ## Alias for test-unit
test-watch: ## Run tests in watch mode
@./scripts/test.sh --watch
test-coverage: ## Run tests with coverage
@./scripts/test.sh --coverage
test-e2e: ## Run end-to-end tests
@$(MAKE) build
@MUX_E2E_LOAD_DIST=1 MUX_E2E_SKIP_BUILD=1 PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 bun x playwright test --project=electron $(PLAYWRIGHT_ARGS)
## Distribution
dist: build ## Build distributable packages
@bun x electron-builder --publish never
# Parallel macOS builds - notarization happens concurrently
dist-mac: build ## Build macOS distributables (x64 + arm64)
@if [ -n "$$CSC_LINK" ]; then \
echo "🔐 Code signing enabled - building sequentially to avoid keychain conflicts..."; \
bun x electron-builder --mac --x64 --publish never && \
bun x electron-builder --mac --arm64 --publish never; \
else \
echo "Building macOS architectures in parallel..."; \
bun x electron-builder --mac --x64 --publish never & pid1=$$! ; \
bun x electron-builder --mac --arm64 --publish never & pid2=$$! ; \
wait $$pid1 && wait $$pid2; \
fi
@echo "✅ Both architectures built successfully"
dist-mac-release: build ## Build and publish macOS distributables (x64 + arm64)
@if [ -n "$$CSC_LINK" ]; then \
echo "🔐 Code signing enabled - building sequentially to avoid keychain conflicts..."; \
bun x electron-builder --mac --x64 --publish always && \
bun x electron-builder --mac --arm64 --publish always; \
else \
echo "Building and publishing macOS architectures in parallel..."; \
bun x electron-builder --mac --x64 --publish always & pid1=$$! ; \
bun x electron-builder --mac --arm64 --publish always & pid2=$$! ; \
wait $$pid1 && wait $$pid2; \
fi
@echo "✅ Both architectures built and published successfully"
dist-mac-x64: build ## Build macOS x64 distributable only
@echo "Building macOS x64..."
@bun x electron-builder --mac --x64 --publish never
dist-mac-arm64: build ## Build macOS arm64 distributable only
@echo "Building macOS arm64..."
@bun x electron-builder --mac --arm64 --publish never
dist-win: build ## Build Windows distributable
@bun x electron-builder --win --publish never
dist-linux: build ## Build Linux distributable
@bun x electron-builder --linux --publish never
## VS Code Extension (delegates to vscode/Makefile)
vscode-ext: ## Build VS Code extension (.vsix)
@$(MAKE) -C vscode build
vscode-ext-install: ## Build and install VS Code extension locally
@$(MAKE) -C vscode install
## Documentation
docs: ## Serve documentation locally
@./scripts/docs.sh
docs-build: ## Build documentation
@./scripts/docs_build.sh
docs-watch: ## Watch and rebuild documentation
@cd docs && mdbook watch
## Storybook
storybook: node_modules/.installed ## Start Storybook development server
$(check_node_version)
@bun x storybook dev -p 6006 $(STORYBOOK_OPEN_FLAG)
storybook-build: node_modules/.installed src/version.ts ## Build static Storybook
$(check_node_version)
@bun x storybook build
test-storybook: node_modules/.installed ## Run Storybook interaction tests (requires Storybook to be running or built)
$(check_node_version)
@bun x test-storybook
chromatic: node_modules/.installed ## Run Chromatic for visual regression testing
$(check_node_version)
@bun x chromatic --exit-zero-on-changes
## Benchmarks
benchmark-terminal: ## Run Terminal-Bench with the mux agent (use TB_DATASET/TB_SAMPLE_SIZE/TB_TIMEOUT/TB_ARGS to customize)
@TB_DATASET=$${TB_DATASET:-terminal-bench-core==0.1.1}; \
TB_TIMEOUT=$${TB_TIMEOUT:-1800}; \
CONCURRENCY_FLAG=$${TB_CONCURRENCY:+--n-concurrent $$TB_CONCURRENCY}; \
LIVESTREAM_FLAG=$${TB_LIVESTREAM:+--livestream}; \
TASK_ID_FLAGS=""; \
if [ -n "$$TB_SAMPLE_SIZE" ]; then \
echo "Ensuring dataset $$TB_DATASET is downloaded..."; \
uvx terminal-bench datasets download --dataset "$$TB_DATASET" 2>&1 | grep -v "already exists" || true; \
echo "Sampling $$TB_SAMPLE_SIZE tasks from $$TB_DATASET..."; \
TASK_IDS=$$(python3 benchmarks/terminal_bench/sample_tasks.py --dataset "$$TB_DATASET" --sample-size "$$TB_SAMPLE_SIZE" --format space) || { \
echo "Error: Failed to sample tasks" >&2; \
exit 1; \
}; \
if [ -z "$$TASK_IDS" ]; then \
echo "Error: Sampling returned no task IDs" >&2; \
exit 1; \
fi; \
for task_id in $$TASK_IDS; do \
TASK_ID_FLAGS="$$TASK_ID_FLAGS --task-id $$task_id"; \
done; \
echo "Selected task IDs: $$TASK_IDS"; \
fi; \
echo "Using timeout: $$TB_TIMEOUT seconds"; \
echo "Running Terminal-Bench with dataset $$TB_DATASET"; \
export MUX_TIMEOUT_MS=$$((TB_TIMEOUT * 1000)); \
uvx terminal-bench run \
--dataset "$$TB_DATASET" \
--agent-import-path benchmarks.terminal_bench.mux_agent:CmuxAgent \
--global-agent-timeout-sec $$TB_TIMEOUT \
$$CONCURRENCY_FLAG \
$$LIVESTREAM_FLAG \
$$TASK_ID_FLAGS \
$${TB_ARGS}
## Clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf dist release build/icon.icns build/icon.png
@echo "Done!"
## Startup Performance Checks
check-eager-imports: ## Check for eager AI SDK imports in critical files
@./scripts/check_eager_imports.sh
check-bundle-size: build ## Check that bundle sizes are within limits
@./scripts/check_bundle_size.sh
check-startup: check-eager-imports check-bundle-size ## Run all startup performance checks
# Parallel build optimization - these can run concurrently
.NOTPARALLEL: build-main # TypeScript can handle its own parallelism