Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (108 loc) · 5.04 KB
/
Copy pathMakefile
File metadata and controls
130 lines (108 loc) · 5.04 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
# kai-agent — local agent + UI runner
#
# Quick start:
# make run # build UI + start uvicorn on :3001 (single port, opens browser)
# make dev # uvicorn (:3001) + Vite hot-reload (:5173) in parallel
# make stop # kill any uvicorn this Makefile launched
# make test # run the Phase 1+2 + UI Python test suite
# make build # build the React bundle into ui/static/ only
# make ui-install # one-time npm install inside ui/web/
# make clean # remove ui/static/ + ui/web/node_modules
#
# All run targets force KAI_LOCAL_MODE=1 so the agent never talks to
# kai-backend. Sandbox the test by prefixing: KAI_HOME=/tmp/foo make run
REPO_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# Defaults to the repo's .venv; override for conda/pyenv/system Python, e.g.
# make run PYTHON=python
PYTHON ?= $(REPO_ROOT)/.venv/bin/python
WEB_DIR := $(REPO_ROOT)/ui/web
STATIC := $(REPO_ROOT)/ui/static
PID_FILE := $(REPO_ROOT)/.kai-ui.pid
PORT ?= 3001
HOST ?= 127.0.0.1
NO_BROWSER ?= 0
# Coloured headings for human output. NO_COLOR=1 disables.
ifeq ($(NO_COLOR),1)
C_HEAD :=
C_OK :=
C_END :=
else
C_HEAD := \033[1;36m
C_OK := \033[1;32m
C_END := \033[0m
endif
define _say
@printf "$(C_HEAD)▸ %s$(C_END)\n" "$(1)"
endef
.PHONY: help run dev build stop test ui-install clean check-venv check-ui-extras
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN{FS=":.*?## "}{printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
# -- Preflight checks ---------------------------------------------------------
check-venv:
@test -x "$(PYTHON)" || { \
echo "error: .venv not found at $(REPO_ROOT)/.venv"; \
echo " run: uv sync (or pip install -e .)"; exit 1; }
check-ui-extras: check-venv
@$(PYTHON) -c "import fastapi, uvicorn, sse_starlette" >/dev/null 2>&1 || { \
echo "error: ui extras missing. Install with:"; \
echo " uv pip install 'fastapi>=0.115' 'uvicorn[standard]>=0.32' 'sse-starlette>=2.1'"; \
exit 1; }
# -- Frontend build ----------------------------------------------------------
ui-install: ## npm install inside ui/web/ (first run only)
$(call _say,installing ui/web npm deps)
@cd $(WEB_DIR) && npm install --silent
$(WEB_DIR)/node_modules: $(WEB_DIR)/package.json
@$(MAKE) -s ui-install
build: $(WEB_DIR)/node_modules ## Build the React bundle into ui/static/
$(call _say,building UI bundle into ui/static/)
@cd $(WEB_DIR) && npm run build --silent
gen-api: check-venv $(WEB_DIR)/node_modules ## Regenerate ui/web/src/api/generated.ts from the FastAPI schema
$(call _say,regenerating frontend API types from OpenAPI)
@$(PYTHON) scripts/dump_openapi.py
@cd $(WEB_DIR) && npm run gen:api --silent
$(call _say,done — review git diff of src/api/generated.ts)
# -- Run targets -------------------------------------------------------------
run: check-ui-extras build ## Bundled mode: single uvicorn on :3001
$(call _say,starting uvicorn on http://$(HOST):$(PORT)/)
@if [ "$(NO_BROWSER)" != "1" ]; then \
( sleep 1.5; command -v open >/dev/null && open "http://$(HOST):$(PORT)/" || true ) & \
fi
@KAI_LOCAL_MODE=1 $(PYTHON) -m uvicorn ui.server:app \
--host $(HOST) --port $(PORT) --log-level info
dev: check-ui-extras $(WEB_DIR)/node_modules ## Dev mode: uvicorn + Vite hot reload, parallel
$(call _say,dev mode — uvicorn :$(PORT) + Vite :5173)
@trap 'kill 0' INT TERM EXIT; \
KAI_LOCAL_MODE=1 $(PYTHON) -m uvicorn ui.server:app \
--host $(HOST) --port $(PORT) --reload --log-level info & \
( cd $(WEB_DIR) && VITE_API_TARGET="http://$(HOST):$(PORT)" \
npm run dev -- --port 5173 --host 127.0.0.1 ) & \
if [ "$(NO_BROWSER)" != "1" ]; then \
( sleep 2.5; command -v open >/dev/null && open "http://127.0.0.1:5173/" || true ) & \
fi; \
wait
run-bg: check-ui-extras build ## Background bundled mode (writes PID to .kai-ui.pid)
$(call _say,starting uvicorn in background on http://$(HOST):$(PORT)/)
@( KAI_LOCAL_MODE=1 nohup $(PYTHON) -m uvicorn ui.server:app \
--host $(HOST) --port $(PORT) --log-level info \
> /tmp/kai-ui-$(PORT).log 2>&1 & echo $$! > $(PID_FILE) )
@sleep 2
@printf "$(C_OK)✓ pid $$(cat $(PID_FILE)) — http://$(HOST):$(PORT)/ — log: /tmp/kai-ui-$(PORT).log$(C_END)\n"
stop: ## Stop the server started via run-bg
@if [ -f "$(PID_FILE)" ]; then \
PID=$$(cat $(PID_FILE)); \
kill $$PID 2>/dev/null && echo "stopped pid $$PID" || echo "pid $$PID not running"; \
rm -f $(PID_FILE); \
else \
echo "no $(PID_FILE) — nothing to stop"; \
fi
# -- Tests + cleanup ---------------------------------------------------------
test: check-venv ## Run the Phase 1+2 + UI Python test suite
$(call _say,running pytest)
@$(PYTHON) -m pytest tests/local_storage tests/local_mcp tests/local_execution \
tests/ui tests/integration/test_local_chat_e2e.py \
--no-header -p no:cacheprovider -o addopts='-n auto'
clean: ## Remove ui/static/ and ui/web/node_modules
$(call _say,cleaning build artifacts)
@rm -rf $(STATIC) $(WEB_DIR)/node_modules $(WEB_DIR)/.vite