-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathMakefile
More file actions
453 lines (404 loc) · 17.7 KB
/
Copy pathMakefile
File metadata and controls
453 lines (404 loc) · 17.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# Makefile for Efrit - AI-Powered Emacs Coding Assistant
# Configuration
EMACS = emacs
EMACS_BATCH = $(EMACS) --batch --no-init-file
PACKAGE_NAME = efrit
VERSION = 0.3.0
# Source files
EL_FILES = $(wildcard lisp/*.el lisp/core/*.el lisp/support/*.el lisp/interfaces/*.el lisp/tools/*.el)
ELC_FILES = $(EL_FILES:.el=.elc)
# Test files
TEST_FILES = $(wildcard test/test-*.el)
TEST_SCRIPTS = $(wildcard test/*.sh bin/*.sh)
# Documentation files
DOC_FILES = README.md CONTRIBUTING.md AUTHORS AGENTS.md LICENSE
# Distribution files
DIST_FILES = lisp/ test/ bin/ plans/ $(DOC_FILES) Makefile .gitignore
.PHONY: all compile test clean distclean install uninstall check help dist mcp-install mcp-build mcp-test mcp-start mcp-clean coverage coverage-simple coverage-report coverage-check lint lint-defun lint-toplevel clean-orphan-elc checkdoc
# Default target
all: compile
# Help target
help:
@echo "Efrit $(VERSION) - Makefile targets:"
@echo ""
@echo "Building:"
@echo " compile - Byte compile all Elisp files"
@echo " clean - Remove compiled files"
@echo " distclean - Remove all generated files"
@echo ""
@echo "Code Quality:"
@echo " check - Check syntax and compilation"
@echo " lint - Full linting (checkdoc + byte-compile + style)"
@echo " lint-defun - Check for nested defun forms (paren mismatch detection)"
@echo " checkdoc - Check docstring quality"
@echo ""
@echo "Testing:"
@echo " test - Run all tests"
@echo " test-simple - Run basic tests only"
@echo " test-loop - Test TODO loop detection (safe)"
@echo " test-integration - Run REAL integration test (⚠️ BURNS TOKENS!)"
@echo " test-auto - Run automated Tier 1 tests (⚠️ BURNS TOKENS!)"
@echo " test-tier TIER=n - Run specific tier tests (⚠️ BURNS TOKENS!)"
@echo ""
@echo "MCP Server:"
@echo " mcp-install - Install MCP server dependencies"
@echo " mcp-build - Build MCP server"
@echo " mcp-test - Run MCP server tests"
@echo " mcp-start - Start MCP server"
@echo " mcp-clean - Clean MCP server artifacts"
@echo ""
@echo "Coverage:"
@echo " coverage - Run tests with coverage tracking"
@echo " coverage-simple - Run simple function-level coverage"
@echo " coverage-report - Generate coverage report (requires prior run)"
@echo ""
@echo "Development:"
@echo " lint - Check code style and conventions"
@echo " debug - Build with debug information"
@echo ""
@echo "Distribution:"
@echo " dist - Create distribution tarball"
@echo " install - Install to Emacs site-lisp"
@echo " uninstall - Remove from Emacs site-lisp"
# Compilation
compile: clean-orphan-elc lisp/core/efrit-config.elc lisp/core/efrit-log.elc lisp/core/efrit-common.elc lisp/core/efrit-tools.elc $(ELC_FILES) lint-toplevel
# Remove .elc files whose .el source is gone; stale orphans silently
# shadow renamed/deleted modules at require time
clean-orphan-elc:
@for elc in $$(find lisp -name '*.elc'); do \
if [ ! -f "$${elc%.elc}.el" ]; then \
echo "Removing orphaned $$elc"; \
rm -f "$$elc"; \
fi; \
done
# Dependency hierarchy: efrit-config first, then efrit-log, efrit-common, efrit-tools, then everything else
lisp/core/efrit-log.elc: lisp/core/efrit-config.elc
lisp/core/efrit-common.elc: lisp/core/efrit-config.elc
lisp/core/efrit-tools.elc: lisp/core/efrit-config.elc lisp/core/efrit-log.elc lisp/core/efrit-common.elc
# Core module dependencies
lisp/core/efrit-chat.elc: lisp/core/efrit-config.elc lisp/core/efrit-common.elc lisp/core/efrit-tools.elc lisp/interfaces/efrit-agent.elc
lisp/core/efrit-session.elc: lisp/core/efrit-config.elc lisp/core/efrit-log.elc lisp/core/efrit-common.elc
lisp/core/efrit-executor.elc: lisp/core/efrit-log.elc lisp/core/efrit-common.elc
# Support module dependencies
lisp/support/efrit-ui.elc: lisp/core/efrit-common.elc lisp/core/efrit-log.elc
# Interface module dependencies
lisp/interfaces/efrit-remote-queue.elc: lisp/core/efrit-tools.elc lisp/core/efrit-config.elc
lisp/interfaces/efrit-agent.elc: lisp/core/efrit-tools.elc lisp/core/efrit-config.elc
lisp/interfaces/efrit-do.elc: lisp/core/efrit-tools.elc lisp/core/efrit-config.elc lisp/core/efrit-common.elc lisp/core/efrit-session.elc
# Root module dependencies
lisp/efrit.elc: lisp/core/efrit-config.elc lisp/core/efrit-tools.elc
lisp/%.elc: lisp/%.el
@echo "Compiling $<..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $<
lisp/core/%.elc: lisp/core/%.el
@echo "Compiling $<..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $<
lisp/support/%.elc: lisp/support/%.el
@echo "Compiling $<..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $<
lisp/interfaces/%.elc: lisp/interfaces/%.el
@echo "Compiling $<..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $<
lisp/tools/%.elc: lisp/tools/%.el
@echo "Compiling $<..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $<
# Check syntax without full compilation dependencies
check:
@echo "Checking syntax of Elisp files..."
@for file in $(EL_FILES); do \
echo "Checking $$file..."; \
$(EMACS_BATCH) --eval "(check-parens)" $$file || exit 1; \
done
@echo "✅ All syntax checks passed"
# Checkdoc validation (docstring quality)
checkdoc:
@echo "Checking docstrings..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(require 'checkdoc)" \
--eval "(setq checkdoc-autofix-style 'query)" \
$(foreach file,$(EL_FILES),--eval "(checkdoc-file \"$(file)\")") \
--eval '(if checkdoc-diagnostic-buffer (progn (set-buffer checkdoc-diagnostic-buffer) (message (buffer-string)) (error "Checkdoc found issues")))' \
2>&1 | grep -v "^$$" || true
@echo "✅ Docstring checks passed"
# Linting (code style + byte-compile warnings + docstrings)
lint: checkdoc lint-defun lint-toplevel
@echo "Checking code style..."
@for file in $(EL_FILES); do \
echo "Linting $$file..."; \
if ! grep -q "lexical-binding: t" $$file; then \
echo "❌ Missing lexical-binding: t in $$file"; \
exit 1; \
fi; \
done
@echo "Running byte-compile with warnings-as-errors..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
--eval "(setq byte-compile-error-on-warn nil)" \
--eval "(setq load-prefer-newer t)" \
-f batch-byte-compile $(EL_FILES)
@echo "✅ Code style and warnings checks passed"
# Detect definition forms swallowed by compensating paren errors (see 098182c):
# every def form must be at top level (or in an allowed wrapper), and any
# "not known to be defined" warning for a symbol defined in the same file fails.
lint-toplevel:
@echo "Checking top-level definition forms..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"$(PWD)/lisp\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/core\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/support\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/interfaces\")" \
--eval "(add-to-list 'load-path \"$(PWD)/lisp/tools\")" \
-l test/lint-toplevel.el
# Check for nested/indented defun forms (catches paren mismatches)
# Uses Emacs to properly detect nested forms (not inside condition-case/cl-eval-when)
lint-defun:
@echo "Checking for nested defun forms..."
@$(EMACS_BATCH) --eval " \
(defun lint--check-enclosing-form (pos allowed-forms) \
\"Check if POS is inside one of ALLOWED-FORMS (up to 3 levels).\" \
(save-excursion \
(goto-char pos) \
(catch 'found \
(dotimes (_ 3) \
(ignore-errors \
(backward-up-list 1 t t) \
(when (looking-at \"(\") \
(forward-char 1) \
(let ((sym (intern-soft (thing-at-point 'symbol t)))) \
(when (member sym allowed-forms) \
(throw 'found t))))))))) \
(let ((errors nil) \
(allowed '(condition-case cl-eval-when eval-when-compile))) \
(dolist (file (directory-files-recursively \"lisp\" \"\\\\.el$$\")) \
(with-temp-buffer \
(insert-file-contents file) \
(goto-char (point-min)) \
(while (re-search-forward \"^[ \\t]+[ \\t]*(defun \" nil t) \
(let* ((defun-pos (match-beginning 0)) \
(line-num (line-number-at-pos defun-pos))) \
(unless (lint--check-enclosing-form defun-pos allowed) \
(push (format \"%s:%d\" (file-name-nondirectory file) line-num) errors)))))) \
(if errors \
(progn \
(message \"❌ Found nested defun forms:\") \
(dolist (e (nreverse errors)) (message \" %s\" e)) \
(message \"\") \
(message \"defun should start at column 0. Indented defun usually means\") \
(message \"mismatched parens caused one function to be nested inside another.\") \
(kill-emacs 1)) \
(message \"✅ No unexpected nested defun forms found\")))"
# Testing
test: compile
@echo "Running test suite..."
@cd test && ./efrit-test-simple.sh
@./bin/launch-autonomous-efrit.sh test || echo "⚠️ Autonomous tests skipped (optional)"
test-simple:
@echo "Running basic tests..."
@cd test && ./efrit-test-simple.sh
test-loop: compile
@echo "Testing TODO loop detection (safe, no API calls)..."
@$(EMACS_BATCH) -L lisp -l test/test-todo-loop-debug.el
@echo "✅ TODO loop test completed"
test-integration: compile
@echo "⚠️ WARNING: This will make REAL API calls and BURN TOKENS!"
@echo "⚠️ Make sure you have Claude API credits available."
@echo -n "Press Enter to continue or Ctrl+C to cancel: "
@read dummy
@echo "🚀 Running REAL integration test..."
@$(EMACS_BATCH) -L lisp -l test/test-real-integration.el
@echo "✅ Integration test completed"
# Automated test runner (burns tokens!)
test-auto: compile
@echo "⚠️ WARNING: This runs the automated test suite and BURNS TOKENS!"
@echo "Running automated Tier 1 tests..."
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L test \
--eval "(require 'efrit-test-runner)" \
--eval "(efrit-test-register-tier1-samples)" \
--eval "(efrit-test-run-tier 1)"
@echo "✅ Automated tests completed"
test-tier: compile
@echo "Usage: make test-tier TIER=n (where n is 1-6)"
@echo "⚠️ WARNING: This BURNS TOKENS!"
@if [ -z "$(TIER)" ]; then echo "Error: TIER not specified"; exit 1; fi
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L test \
--eval "(require 'efrit-test-specs)" \
--eval "(efrit-test-register-all-tiers)" \
--eval "(efrit-test-run-tier $(TIER))"
# Debug build (with extra information)
debug:
@echo "Building with debug information..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"./lisp\")" \
--eval "(setq byte-compile-debug t)" \
--eval "(setq byte-compile-verbose t)" \
-f batch-byte-compile $(EL_FILES)
# Coverage targets
coverage: compile
@echo "Running tests with coverage tracking..."
@echo "⚠️ WARNING: This BURNS TOKENS!"
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L lisp/tools -L test \
--eval "(require 'efrit-coverage)" \
--eval "(require 'efrit-test-runner)" \
--eval "(efrit-coverage-start)" \
--eval "(efrit-test-register-tier1-samples)" \
--eval "(efrit-test-run-tier 1)" \
--eval "(efrit-coverage-stop)" \
--eval "(efrit-coverage-report)" \
--eval "(efrit-coverage-report-lcov)" \
--eval "(efrit-coverage-report-json)"
@echo "✅ Coverage report generated in user-emacs-directory/.efrit/coverage/"
coverage-simple: compile
@echo "Running simple function-level coverage..."
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L lisp/tools -L test \
--eval "(require 'efrit)" \
--eval "(require 'efrit-do)" \
--eval "(require 'efrit-chat)" \
--eval "(require 'efrit-coverage)" \
--eval "(efrit-coverage-simple-start)" \
--eval "(efrit-config-data-file \"test\")" \
--eval "(efrit-coverage-simple-report)" \
--eval "(efrit-coverage-simple-stop)"
coverage-report: compile
@echo "Generating coverage report from existing data..."
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L lisp/tools -L test \
--eval "(require 'efrit-coverage)" \
--eval "(efrit-coverage-report)"
coverage-check: compile
@echo "Checking coverage threshold..."
@$(EMACS_BATCH) -L lisp -L lisp/core -L lisp/interfaces -L lisp/support -L lisp/tools -L test \
--eval "(require 'efrit-coverage)" \
--eval "(efrit-coverage-check-threshold $(or $(THRESHOLD),0))"
# MCP Server targets
mcp-install:
@echo "Installing MCP server dependencies..."
@cd mcp && npm install
mcp-build: mcp-install
@echo "Building MCP server..."
@cd mcp && npm run build
mcp-test: mcp-build
@echo "Running MCP server tests..."
@cd mcp && npm test
mcp-start: mcp-build
@echo "Starting MCP server..."
@cd mcp && npm start
mcp-clean:
@echo "Cleaning MCP server artifacts..."
@rm -rf mcp/node_modules mcp/dist mcp/coverage
# Update existing targets to include MCP
build: compile mcp-build
test: test-simple mcp-test
# Cleaning
clean: mcp-clean
@echo "Removing compiled files..."
@rm -f lisp/*.elc lisp/core/*.elc lisp/support/*.elc lisp/interfaces/*.elc
@rm -f lisp/*.elc~ lisp/core/*.elc~ lisp/support/*.elc~ lisp/interfaces/*.elc~
distclean: clean
@echo "Removing all generated files..."
@rm -f efrit-$(VERSION).tar.gz
@rm -rf dist/
# Installation to system
EMACS_SITE_LISP = $(shell $(EMACS) --batch --eval "(princ (car site-lisp-directory-list))" 2>/dev/null || echo "/usr/local/share/emacs/site-lisp")
install: compile
@echo "Installing to $(EMACS_SITE_LISP)/$(PACKAGE_NAME)..."
@mkdir -p $(EMACS_SITE_LISP)/$(PACKAGE_NAME)
@cp -r lisp/* $(EMACS_SITE_LISP)/$(PACKAGE_NAME)/
@chmod +x bin/launch-autonomous-efrit.sh
@cp bin/launch-autonomous-efrit.sh /usr/local/bin/ 2>/dev/null || echo "⚠️ Could not install launcher script (run as root?)"
@echo "✅ Installation complete"
@echo "Add this to your init.el:"
@echo " (add-to-list 'load-path \"$(EMACS_SITE_LISP)/$(PACKAGE_NAME)\")"
@echo " (require 'efrit)"
uninstall:
@echo "Removing from $(EMACS_SITE_LISP)/$(PACKAGE_NAME)..."
@rm -rf $(EMACS_SITE_LISP)/$(PACKAGE_NAME)
@rm -f /usr/local/bin/launch-autonomous-efrit.sh
@echo "✅ Uninstallation complete"
# Distribution
dist: distclean
@echo "Creating distribution tarball..."
@mkdir -p dist/efrit-$(VERSION)
@cp -r $(DIST_FILES) dist/efrit-$(VERSION)/
@cd dist && tar -czf ../efrit-$(VERSION).tar.gz efrit-$(VERSION)/
@rm -rf dist/
@echo "✅ Created efrit-$(VERSION).tar.gz"
# Development helpers
dev-setup:
@echo "Setting up development environment..."
@echo "Checking prerequisites..."
@which $(EMACS) > /dev/null || (echo "❌ Emacs not found"; exit 1)
@$(EMACS_BATCH) --version | head -1
@echo "Project structure:"
@find . -name "*.el" | head -10
@echo "✅ Development environment ready"
# Continuous integration target
ci: check lint compile test
@echo "✅ All CI checks passed"
# Show current configuration
config:
@echo "Efrit Build Configuration:"
@echo " Version: $(VERSION)"
@echo " Emacs: $(EMACS)"
@echo " Source files: $(words $(EL_FILES)) files"
@echo " Test files: $(words $(TEST_FILES)) files"
@echo " Site lisp: $(EMACS_SITE_LISP)"
@echo " Structure: Professional elisp project layout"
# Development convenience targets
quick-test: compile
@echo "Running quick development tests..."
@$(EMACS_BATCH) \
--eval "(add-to-list 'load-path \"./lisp\")" \
--eval "(require 'efrit)" \
--eval "(message \"✅ Efrit loads successfully\")"
# Show project structure
tree:
@echo "Efrit Project Structure:"
@tree -I '.git|*.elc|.DS_Store' -a || find . -name ".*" -prune -o -type f -print | sort