-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
271 lines (222 loc) · 10.1 KB
/
Copy pathMakefile
File metadata and controls
271 lines (222 loc) · 10.1 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
# Makefile for CORE — The Self-Improving System Architect
#
# UPDATED: Layer-Aware paths (Mind/Body/Will).
# Removed references to the legacy 'features' directory.
# ---- Shell & defaults --------------------------------------------------------
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
# ---- Configurable knobs ------------------------------------------------------
POETRY ?= poetry
APP ?= src.api.main:create_app
HOST ?= 0.0.0.0
PORT ?= 8000
RELOAD ?= --reload
ENV_FILE ?= .env
# Internal helpers
PY := $(POETRY) run python
CORE_ADMIN := $(POETRY) run core-admin
OUTPUT_PATH := docs/10_CAPABILITY_REFERENCE.md
# Daemon PID file — lives in var/ (runtime, gitignored)
DAEMON_PID := var/run/core-daemon.pid
DAEMON_LOG := var/log/core-daemon.log
# ---- Phony targets -----------------------------------------------------------
.PHONY: \
help install lock run stop \
daemon daemon-start daemon-stop daemon-status daemon-restart daemon-logs \
audit check-constitution check-ui validate \
lint format test coverage dev-sync \
dupes traces refusals cli-tree clean nuke \
docs vectorize integrate \
migrate export-db sync-knowledge \
patterns state context
# ---- Help (auto-documented) --------------------------------------------------
help: ## Show this help message
@echo "CORE Development Makefile (Layered Architecture v2.3)"
@echo "------------------------------------------------------------"
@echo "Usage: make [target]"
@echo ""
@awk 'BEGIN {FS":.*##"} /^[a-zA-Z0-9_.-]+:.*##/ {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "Tip: run 'core-admin --help' to see the resource-based CLI hierarchy."
# ---- Setup -------------------------------------------------------------------
install: ## Install dependencies (poetry install)
@echo "📦 Installing dependencies..."
$(POETRY) install
lock: ## Resolve and lock dependencies
@echo "🔒 Resolving and locking dependencies..."
$(POETRY) lock
# ---- Run / Stop --------------------------------------------------------------
run: ## Start the FastAPI server (uvicorn)
@echo "🚀 Starting FastAPI server at http://$(HOST):$(PORT)"
$(POETRY) run uvicorn $(APP) --factory --host $(HOST) --port $(PORT) $(RELOAD) --env-file $(ENV_FILE)
stop: ## Kill any process listening on $(PORT)
@echo "🛑 Stopping any process on port $(PORT)..."
@command -v lsof >/dev/null 2>&1 && lsof -t -i:$(PORT) | xargs kill -9 2>/dev/null || true
# ==============================================================================
# DAEMON — Background worker control
# ==============================================================================
daemon: daemon-status ## Alias: show daemon status
daemon-start: ## Start the CORE daemon in the background
@mkdir -p var/run var/log
@if [ -f $(DAEMON_PID) ] && kill -0 "$$(cat $(DAEMON_PID))" 2>/dev/null; then \
echo "⚠️ Daemon already running (PID $$(cat $(DAEMON_PID)))"; \
exit 0; \
fi
@echo "🟢 Starting CORE daemon..."
@nohup $(POETRY) run python -c "import asyncio; from cli.commands.daemon import _run_daemon; asyncio.run(_run_daemon())" >> $(DAEMON_LOG) 2>&1 & echo $$! > $(DAEMON_PID)
@sleep 2
@if kill -0 "$$(cat $(DAEMON_PID))" 2>/dev/null; then \
echo "✅ Daemon started (PID $$(cat $(DAEMON_PID))) — logs: $(DAEMON_LOG)"; \
else \
echo "❌ Daemon failed to start. Check logs: $(DAEMON_LOG)"; \
rm -f $(DAEMON_PID); \
exit 1; \
fi
daemon-stop: ## Stop the CORE daemon gracefully
@{ \
if [ ! -f $(DAEMON_PID) ]; then \
echo "ℹ️ No PID file found — daemon may not be running"; \
exit 0; \
fi; \
PID=$$(cat $(DAEMON_PID)); \
if kill -0 "$$PID" 2>/dev/null; then \
echo "🛑 Stopping CORE daemon (PID $$PID)..."; \
kill -TERM "$$PID"; \
for i in 1 2 3 4 5; do \
sleep 1; \
kill -0 "$$PID" 2>/dev/null || break; \
done; \
if kill -0 "$$PID" 2>/dev/null; then \
echo "⚠️ Daemon did not stop gracefully — sending SIGKILL"; \
kill -KILL "$$PID"; \
fi; \
echo "✅ Daemon stopped"; \
else \
echo "ℹ️ Daemon not running (stale PID $$PID)"; \
fi; \
rm -f $(DAEMON_PID); \
}
daemon-restart: daemon-stop daemon-start ## Restart the CORE daemon
daemon-status: ## Show daemon status
@if [ -f $(DAEMON_PID) ] && kill -0 "$$(cat $(DAEMON_PID))" 2>/dev/null; then \
echo "🟢 Daemon is RUNNING (PID $$(cat $(DAEMON_PID)))"; \
echo " Logs: $(DAEMON_LOG)"; \
elif [ -f $(DAEMON_PID) ]; then \
echo "🔴 Daemon is STOPPED (stale PID file)"; \
rm -f $(DAEMON_PID); \
else \
echo "🔴 Daemon is STOPPED"; \
fi
daemon-logs: ## Tail daemon logs (Ctrl+C to exit)
@if [ ! -f $(DAEMON_LOG) ]; then \
echo "ℹ️ No daemon log found at $(DAEMON_LOG)"; \
exit 0; \
fi
@tail -f $(DAEMON_LOG)
# ==============================================================================
# QUALITY GATES & VALIDATION (Composing Atomic Resource Actions)
# ==============================================================================
check-constitution: ## Check constitutional compliance (audit)
@echo "⚖️ Running constitutional audit..."
$(CORE_ADMIN) code audit
check-ui: ## Check for UI leaks in Body layer (Headless enforcement)
@echo "🔍 Checking Body-layer UI contracts..."
$(CORE_ADMIN) code check-ui
audit: dev-sync check-constitution check-ui ## Full audit: sync → constitution → ui
@echo "✅ Full system audit complete"
validate: audit ## Alias for audit (pre-commit validation)
@echo "✅ Validation complete"
# ==============================================================================
# ---- Individual Resource Actions (Neurons) -----------------------------------
lint: ## Check code format and quality (read-only)
$(CORE_ADMIN) code lint
format: ## Fix code style and import order
@echo "✨ Formatting code (Black/Ruff)..."
$(CORE_ADMIN) code format --write
@echo "🧹 Sorting imports..."
$(CORE_ADMIN) code format-imports --write
test: ## Run test suite
@echo "🧪 Running tests with pytest..."
$(POETRY) run pytest --cov=src --cov-report=json --cov-fail-under=38
coverage: ## Check coverage compliance
@echo "📈 Checking coverage meets constitutional requirement..."
$(CORE_ADMIN) code audit --verbose
# ==============================================================================
# DEV-SYNC: Atomic Operations Composed (The "Limb" Pipeline)
# ==============================================================================
dev-sync: ## Synchronize local state (IDs -> Dedup -> Format -> DB -> Vectors)
@echo "🔄 CORE Development Sync Pipeline"
@echo "=================================="
@echo "1️⃣ Fixing symbol IDs..."
@$(CORE_ADMIN) symbols fix-ids --write
@echo "2️⃣ Resolving duplicate IDs..."
@$(CORE_ADMIN) symbols resolve-duplicates --write
@echo "3️⃣ Formatting code & imports..."
@$(MAKE) format
@echo "4️⃣ Syncing knowledge graph..."
@$(CORE_ADMIN) symbols sync --write
@echo "5️⃣ Updating memory (vectors)..."
@$(CORE_ADMIN) vectors sync-code --write
@echo "6️⃣ Generating operational summary..."
@$(CORE_ADMIN) admin summary
@echo "✅ Dev-sync complete"
# ==============================================================================
# ---- Forensics & Analytics (Admin Resource) ----------------------------------
dupes: ## Check for duplicate code (semantic analysis)
@echo "👯 Running semantic duplication analysis..."
$(CORE_ADMIN) code audit-duplicates --threshold 0.96
traces: ## View recent autonomous decision traces
$(CORE_ADMIN) admin traces
refusals: ## View constitutional refusal logs
$(CORE_ADMIN) admin refusals
patterns: ## Analyze architectural pattern usage
$(CORE_ADMIN) admin patterns
state: ## Show current database and migration status
$(CORE_ADMIN) database status
# ---- Maintenance & Lifecycle -------------------------------------------------
migrate: ## Apply pending DB schema migrations
$(CORE_ADMIN) database migrate --apply
export-db: ## Export DB tables to canonical YAML
$(CORE_ADMIN) database export
sync-knowledge: ## Scan codebase and sync symbols to DB (SSOT)
$(CORE_ADMIN) database sync --write
vectorize: ## Full vectorization (Constitution + Code)
@echo "🧠 Vectorizing constitution..."
$(CORE_ADMIN) vectors sync --write
@echo "🧠 Vectorizing code symbols..."
$(CORE_ADMIN) vectors sync-code --write
integrate: ## Finalize changes and integrate into system
$(CORE_ADMIN) proposals integrate --message "feat: Integrate changes via make"
# ---- Docs --------------------------------------------------------------------
docs: ## Generate capability documentation
@echo "📚 Generating capability documentation..."
$(CORE_ADMIN) project docs
# ---- Context (LLM session packets) ------------------------------------------
context: ## Build context packets for upload to Claude.ai Project Files
@echo "📦 Building context packets (intent + specs + tree)..."
@$(POETRY) run python infra/scripts/dev/context_builder.py --intent --specs
# Output: context_intent_specs.txt + context_tree.txt — upload both to Claude.ai Project Files.
# ---- Clean -------------------------------------------------------------------
clean: ## Remove temporary files and caches
@echo "🧹 Cleaning temporary files..."
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -prune -exec rm -rf {} +
rm -rf .pytest_cache .ruff_cache .mypy_cache .cache
rm -rf build dist *.egg-info var/workflows/pending_writes work/testing
@echo "✅ Clean complete."
nuke: ## Danger! Remove ALL untracked files
@echo "☢️ Running 'git clean -fdx' in 3s..."
@sleep 3
git clean -fdx
# ---- Web dashboard (ADR-125) ------------------------------------------------
web-install: ## Install web/ npm dependencies
cd web && npm install
web-dev: ## Start Vite dev server (proxies /v1 and /auth to :8000)
cd web && npm run dev
web-build: ## Production build → web/dist/
cd web && npm run build
web-generate-schema: ## Snapshot live FastAPI OpenAPI spec → web/openapi.json
curl -s http://localhost:8000/openapi.json | jq -S . > web/openapi.json
web-generate-api: ## Run Orval to regenerate web/src/api/ from web/openapi.json
cd web && npx orval