-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
368 lines (337 loc) · 14.2 KB
/
Copy pathMakefile
File metadata and controls
368 lines (337 loc) · 14.2 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
.DEFAULT_GOAL := help
# ====================================================================================
# VARIABLES
# ====================================================================================
COMMANDS_SRC_DIR := $(dir $(lastword $(MAKEFILE_LIST)))commands
COMMANDS_TARGET_DIRS := $(HOME)/.cursor/commands $(HOME)/.claude/commands $(HOME)/.codex/prompts $(HOME)/.config/opencode/command $(HOME)/.config/amp/commands $(HOME)/.kilocode/workflows $(HOME)/Documents/Cline/Rules
RULES_SRC_DIR := $(dir $(lastword $(MAKEFILE_LIST)))rules
RULES_TARGET_DIR := $(dir $(lastword $(MAKEFILE_LIST))).ruler
SKILLS_SRC_DIR := $(dir $(lastword $(MAKEFILE_LIST)))skills
SKILLS_RULER_DIR := $(dir $(lastword $(MAKEFILE_LIST))).ruler/skills
SKILLS_TARGET_DIRS := $(HOME)/.claude/skills $(HOME)/.cursor/skills $(HOME)/.codex/skills $(HOME)/.roo/skills $(HOME)/.gemini/skills $(HOME)/.agents/skills $(HOME)/.vibe/skills $(HOME)/.config/opencode/skills
SKILLS_STATE_DIR := $(HOME)/.cache/dotagents/skills
SKILLS_MANIFEST_DIR := $(SKILLS_STATE_DIR)/manifests
SKILLS_SPEC_STATE_FILE := $(SKILLS_STATE_DIR)/skills.txt.normalized
SKILLS_EXTERNAL_SOURCE_DIR := $(HOME)/.agents/skills
MCP_SRC := $(dir $(lastword $(MAKEFILE_LIST))).ruler/mcp.json
MCP_TARGET_DIRS := $(HOME)/.cursor $(HOME)/.claude $(HOME)/.codex
MCP_SETTINGS_TARGETS := $(addsuffix /settings.local.json,$(MCP_TARGET_DIRS)) $(dir $(lastword $(MAKEFILE_LIST)))../.claude/settings.local.json
# NOTE: Do not sync `.codex/` wholesale. It's runtime state (auth, history, sessions) and
# can clobber Nix-managed `~/.codex/config.toml` during `make switch` (dotfiles repo).
DOTDIRS := .agent .agents .amazonq .augment .claude .cursor .gemini .idx .junie .kilocode .kiro .opencode .openhands .pi .qwen .roo .skillz .trae .vibe .vscode .windsurf .zed
DOTDIRS_SRC_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SKILLS_FILE := $(dir $(lastword $(MAKEFILE_LIST)))SKILLS.txt
# ====================================================================================
# ROOT TARGETS
# ====================================================================================
ifeq ($(DOTAGENTS_SKIP_SYNC),)
.PHONY: sync
sync: ruler-prepare ## Sync project commands, skills, and MCP configuration to assistant-specific directories.
@$(MAKE) ruler-apply-global
@$(MAKE) commands-sync
@$(MAKE) skills-install
@$(MAKE) skills-sync
@$(MAKE) mcp-sync
@$(MAKE) ruler-dotdirs-sync
endif
.PHONY: ruler-prepare
ruler-prepare: ## Prepare the project for development.
@make ruler-commands-copy
@make ruler-rules-copy
@make ruler-skills-copy
# ====================================================================================
# COMMANDS
# ====================================================================================
.PHONY: commands-sync
commands-sync: ## Sync project commands to assistant-specific directories (overwrites, preserves other files).
@for target in $(COMMANDS_TARGET_DIRS); do \
if mkdir -p $$target && rsync -a $(COMMANDS_SRC_DIR)/ $$target/; then \
echo "Synced $(COMMANDS_SRC_DIR) → $$target"; \
else \
echo "Failed syncing $(COMMANDS_SRC_DIR) → $$target"; \
exit 1; \
fi; \
done
.PHONY: ruler-commands-copy
ruler-commands-copy: ## Copy commands to .ruler directory.
@cp $(COMMANDS_SRC_DIR)/*.md $(dir $(lastword $(MAKEFILE_LIST))).ruler/
# ====================================================================================
# RULES
# ====================================================================================
.PHONY: ruler-rules-copy
ruler-rules-copy: ## Copy rules to .ruler directory.
@rsync -a $(RULES_SRC_DIR)/ $(RULES_TARGET_DIR)/
@echo "Synced $(RULES_SRC_DIR) → $(RULES_TARGET_DIR)"
# ====================================================================================
# SKILLS
# ====================================================================================
.PHONY: skills-clean
skills-clean: ## Remove all globally installed skills and cached install state.
@for target in $(SKILLS_TARGET_DIRS); do \
if [ -d "$$target" ]; then \
rm -rf "$$target"/*; \
echo "Cleaned $$target"; \
fi; \
done
@if [ -d "$(SKILLS_STATE_DIR)" ]; then \
rm -rf "$(SKILLS_STATE_DIR)"; \
echo "Cleared $(SKILLS_STATE_DIR)"; \
fi
.PHONY: skills-managed-clean
skills-managed-clean: ## Remove managed external skills recorded from SKILLS.txt.
@manifest_dir="$(SKILLS_MANIFEST_DIR)"; \
if [ -d "$$manifest_dir" ]; then \
for manifest in "$$manifest_dir"/*.skills; do \
if [ ! -f "$$manifest" ]; then \
continue; \
fi; \
while IFS= read -r skill || [ -n "$$skill" ]; do \
if [ -z "$$skill" ]; then \
continue; \
fi; \
for target in $(SKILLS_TARGET_DIRS); do \
if [ -e "$$target/$$skill" ] || [ -L "$$target/$$skill" ]; then \
rm -rf "$$target/$$skill"; \
echo "Removed $$target/$$skill"; \
fi; \
done; \
done < "$$manifest"; \
done; \
fi
@if [ -d "$(SKILLS_STATE_DIR)" ]; then \
rm -rf "$(SKILLS_STATE_DIR)"; \
echo "Cleared $(SKILLS_STATE_DIR)"; \
fi
.PHONY: skills-install
skills-install: ## Ensure skills from SKILLS.txt are installed and reconcile managed removals.
@state_dir="$(SKILLS_STATE_DIR)"; \
manifest_dir="$(SKILLS_MANIFEST_DIR)"; \
spec_state="$(SKILLS_SPEC_STATE_FILE)"; \
external_source="$(SKILLS_EXTERNAL_SOURCE_DIR)"; \
tmp_spec=$$(mktemp); \
spec_changed=0; \
failed=0; \
mkdir -p "$$state_dir" "$$manifest_dir" "$$external_source"; \
list_external_skills() { \
if [ -d "$$external_source" ]; then \
find "$$external_source" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -exec basename {} \; | LC_ALL=C sort -u; \
fi; \
}; \
remove_repo_skills() { \
manifest_file="$$1"; \
if [ ! -f "$$manifest_file" ]; then \
return 0; \
fi; \
while IFS= read -r skill || [ -n "$$skill" ]; do \
if [ -z "$$skill" ]; then \
continue; \
fi; \
for target in $(SKILLS_TARGET_DIRS); do \
if [ -e "$$target/$$skill" ] || [ -L "$$target/$$skill" ]; then \
rm -rf "$$target/$$skill"; \
fi; \
done; \
done < "$$manifest_file"; \
}; \
list_repo_skills() { \
repo="$$1"; \
bun x skills add $$repo --global --yes --list </dev/null 2>&1 \
| sed 's/\x1b\[[0-9;]*m//g' \
| sed 's/\x1b\[?25[hl]//g' \
| sed 's/\x1b\[999D\x1b\[J//g' \
| grep -E '^│[[:space:]]{4}[a-z]' \
| sed 's/^│[[:space:]]*//'; \
}; \
install_repo() { \
repo="$$1"; \
normalized_skills="$$2"; \
manifest_file="$$3"; \
cleanup_old="$$4"; \
if [ "$$cleanup_old" = "1" ]; then \
remove_repo_skills "$$manifest_file"; \
fi; \
if [ -n "$$normalized_skills" ]; then \
skill_args=$$(printf '%s\n' "$$normalized_skills" | tr ',' '\n' | sed '/^$$/d' | while IFS= read -r s; do printf " --skill %s" "$$s"; done); \
echo "Installing selected skills from $$repo..."; \
if bun x skills add $$repo --global --yes $$skill_args </dev/null; then \
printf '%s\n' "$$normalized_skills" | tr ',' '\n' | sed '/^$$/d' | LC_ALL=C sort > "$$manifest_file"; \
echo "✓ Installed $$repo (selective)"; \
else \
echo "✗ Failed to install $$repo (continuing...)"; \
failed=1; \
fi; \
else \
echo "Installing all skills from $$repo..."; \
if bun x skills add $$repo --global --yes </dev/null; then \
list_repo_skills "$$repo" | LC_ALL=C sort > "$$manifest_file"; \
echo "✓ Installed $$repo (all)"; \
else \
echo "✗ Failed to install $$repo (continuing...)"; \
failed=1; \
fi; \
fi; \
}; \
while IFS= read -r raw_line || [ -n "$$raw_line" ]; do \
line=$$(printf '%s' "$$raw_line" | sed 's/^[[:space:]]*//; s/[[:space:]]*$$//'); \
case "$$line" in \
''|\#*) continue ;; \
esac; \
repo=$$(printf '%s\n' "$$line" | awk '{print $$1}'); \
skills_csv=$$(printf '%s\n' "$$line" | awk '{print $$2}'); \
normalized_skills=$$(printf '%s\n' "$$skills_csv" | tr ',' '\n' | sed '/^$$/d' | LC_ALL=C sort | paste -sd, -); \
printf '%s|%s\n' "$$repo" "$$normalized_skills" >> "$$tmp_spec"; \
done < "$(SKILLS_FILE)"; \
if [ "$${DOTAGENTS_FORCE_SKILLS_INSTALL:-0}" = "1" ]; then \
echo "Forcing managed external skill reinstall..."; \
$(MAKE) skills-managed-clean; \
mkdir -p "$$state_dir" "$$manifest_dir" "$$external_source"; \
while IFS='|' read -r repo normalized_skills || [ -n "$$repo$$normalized_skills" ]; do \
manifest_file="$$manifest_dir/$$(printf '%s' "$$repo" | sed 's#[^A-Za-z0-9_.-]#_#g').skills"; \
install_repo "$$repo" "$$normalized_skills" "$$manifest_file" 0; \
done < "$$tmp_spec"; \
else \
if [ -f "$$spec_state" ] && ! cmp -s "$$tmp_spec" "$$spec_state"; then \
echo "Detected SKILLS.txt changes; applying incremental update..."; \
while IFS='|' read -r old_repo old_skills || [ -n "$$old_repo$$old_skills" ]; do \
if ! grep -qF "$$old_repo|" "$$tmp_spec"; then \
echo "Removing $$old_repo (deleted from SKILLS.txt)..."; \
manifest_file="$$manifest_dir/$$(printf '%s' "$$old_repo" | sed 's#[^A-Za-z0-9_.-]#_#g').skills"; \
remove_repo_skills "$$manifest_file"; \
rm -f "$$manifest_file"; \
fi; \
done < "$$spec_state"; \
fi; \
while IFS='|' read -r repo normalized_skills || [ -n "$$repo$$normalized_skills" ]; do \
manifest_file="$$manifest_dir/$$(printf '%s' "$$repo" | sed 's#[^A-Za-z0-9_.-]#_#g').skills"; \
reinstall_repo=0; \
if [ -f "$$spec_state" ]; then \
old_line=$$(grep "^$$repo|" "$$spec_state" 2>/dev/null || true); \
new_line="$$repo|$$normalized_skills"; \
if [ -n "$$old_line" ] && [ "$$old_line" != "$$new_line" ]; then \
reinstall_repo=1; \
echo "Reinstalling $$repo (skills selection changed)"; \
fi; \
fi; \
if [ "$$reinstall_repo" = "0" ]; then \
if [ ! -f "$$manifest_file" ] || [ ! -s "$$manifest_file" ]; then \
reinstall_repo=1; \
echo "Reinstalling $$repo (missing or empty manifest)"; \
else \
while IFS= read -r skill || [ -n "$$skill" ]; do \
if [ -z "$$skill" ]; then \
continue; \
fi; \
if [ ! -e "$$external_source/$$skill" ] && [ ! -L "$$external_source/$$skill" ]; then \
reinstall_repo=1; \
echo "Reinstalling $$repo (missing $$external_source/$$skill)"; \
break; \
fi; \
done < "$$manifest_file"; \
fi; \
fi; \
if [ "$$reinstall_repo" = "1" ]; then \
install_repo "$$repo" "$$normalized_skills" "$$manifest_file" 1; \
else \
echo "Skipping $$repo (installed state matches SKILLS.txt)"; \
fi; \
done < "$$tmp_spec"; \
fi; \
cp "$$tmp_spec" "$$spec_state"; \
rm -f "$$tmp_spec"; \
if [ "$$failed" = "1" ]; then \
echo "Some skills failed to install (see above)."; \
else \
echo "Managed external skills are in sync."; \
fi
.PHONY: skills-refresh
skills-refresh: ## Force a clean reinstall of external skills and re-sync local repo skills.
@$(MAKE) skills-managed-clean
@DOTAGENTS_FORCE_SKILLS_INSTALL=1 $(MAKE) skills-install
@$(MAKE) skills-sync
.PHONY: skills-install-repo
skills-install-repo: ## Install a single skill repo. Usage: make skills-install-repo REPO=owner/repo [SKILLS=a,b,c]
@if [ -z "$(REPO)" ]; then \
echo "Error: REPO is required. Usage: make skills-install-repo REPO=owner/repo"; \
exit 1; \
fi
@if [ -n "$(SKILLS)" ]; then \
echo "Installing selected skills from $(REPO) ($(SKILLS))..."; \
bun x skills add $(REPO) --global --yes $(shell echo "$(SKILLS)" | tr ',' '\n' | sed '/^$$/d' | while read -r s; do printf " --skill $$s"; done); \
else \
echo "Installing all skills from $(REPO)..."; \
bun x skills add $(REPO) --global --yes; \
fi
@echo "✓ Installed $(REPO)"
.PHONY: ruler-skills-copy
ruler-skills-copy: ## Copy skills from root to .ruler/skills directory (overwrites, preserves other files).
@rsync -a $(SKILLS_SRC_DIR)/ $(SKILLS_RULER_DIR)/
@echo "Synced $(SKILLS_SRC_DIR) → $(SKILLS_RULER_DIR)"
.PHONY: skills-sync
skills-sync: ## Sync root skills to agent-specific directories (preserves externally installed skills).
@for target in $(SKILLS_TARGET_DIRS); do \
if mkdir -p $$target && rsync -a $(SKILLS_SRC_DIR)/ $$target/; then \
echo "Synced $(SKILLS_SRC_DIR) → $$target"; \
else \
echo "Failed syncing $(SKILLS_SRC_DIR) → $$target"; \
exit 1; \
fi; \
done
# ====================================================================================
# MCP
# ====================================================================================
.PHONY: mcp-sync
mcp-sync: ## Sync MCP configuration from .ruler/mcp.json to CLI tools.
@if [ ! -f $(MCP_SRC) ]; then \
echo "Error: $(MCP_SRC) not found"; \
exit 1; \
fi
@for target in $(MCP_TARGET_DIRS); do \
if mkdir -p $$target && cp $(MCP_SRC) $$target/mcp.json; then \
echo "Synced $(MCP_SRC) → $$target/mcp.json"; \
else \
echo "Failed syncing $(MCP_SRC) → $$target/mcp.json"; \
exit 1; \
fi; \
done
@keys=$$(jq -c '.mcpServers | keys' $(MCP_SRC)); \
for settings in $(MCP_SETTINGS_TARGETS); do \
if [ -f "$$settings" ]; then \
jq --argjson keys "$$keys" '.enabledMcpjsonServers = $$keys' "$$settings" > "$$settings.tmp" && \
mv "$$settings.tmp" "$$settings"; \
echo "Updated enabledMcpjsonServers in $$settings"; \
fi; \
done
# ====================================================================================
# RULER GLOBAL
# ====================================================================================
.PHONY: ruler-apply-global
ruler-apply-global: ruler-prepare ## Apply Ruler outputs to global paths.
@bash -c 'set -e; \
ruler_src="$(abspath $(dir $(lastword $(MAKEFILE_LIST))))/.ruler"; \
ruler_home="$$HOME/.ruler"; \
rsync -a --delete "$$ruler_src/" "$$ruler_home/"; \
bun x @intellectronica/ruler apply --project-root "$$HOME" --config "$$ruler_home/ruler.toml" --local-only'
.PHONY: ruler-dotdirs-sync
ruler-dotdirs-sync: ## Sync repo dot directories to $HOME equivalents.
@bash -c 'set -e; \
root="$(DOTDIRS_SRC_DIR)"; \
dirs="$(DOTDIRS)"; \
for d in $$dirs; do \
src="$$root/$$d"; \
target="$$HOME/$$d"; \
if [ -d "$$src" ]; then \
mkdir -p "$$target"; \
rsync -a "$$src/" "$$target/"; \
echo "Synced $$src → $$target"; \
fi; \
done'
# ====================================================================================
# HELP
# ====================================================================================
ifeq ($(DOTAGENTS_SKIP_HELP),)
.PHONY: help
help: ## Show this help message.
@echo "Usage: make <target>"
@echo
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
endif