forked from l3hox/forge-user
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
374 lines (330 loc) · 16.4 KB
/
Copy pathMakefile
File metadata and controls
374 lines (330 loc) · 16.4 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
# Forge Framework — build, install, and test
FORGE_ROOT := $(CURDIR)
MODULES := $(FORGE_ROOT)/Modules
CORE := $(FORGE_ROOT)/Core
BIN_DIR := $(HOME)/.local/bin
# Module list from defaults.yaml (yq preferred, forge yaml as fallback)
MODULE_LIST := $(shell yq '.modules[]' defaults.yaml 2>/dev/null || yaml list defaults.yaml modules 2>/dev/null)
CLAUDE_SKILLS := $(FORGE_ROOT)/.claude/skills
CLAUDE_AGENTS := $(FORGE_ROOT)/.claude/agents
USER_ROOT := $(shell awk '/^ root:/{gsub(/"/,"",$$2); if($$2!="") {print $$2; exit}}' config.yaml 2>/dev/null || true)
VAULT_SKILLS := $(if $(USER_ROOT),$(FORGE_ROOT)/$(USER_ROOT)/Orchestration/Skills,)
INSTALL_SKILLS := $(MODULES)/forge-lib/target/release/install-skills
INSTALL_AGENTS := $(MODULES)/forge-lib/target/release/install-agents
CORE_SRC := $(shell find $(CORE)/src -name '*.rs')
TLP_SRC := $(shell find $(MODULES)/forge-tlp/src -name '*.rs')
REFLECT_SRC := $(shell find $(MODULES)/forge-reflect/src -name '*.rs')
JOURNALS_SRC := $(shell find $(MODULES)/forge-journals/src -name '*.rs')
OBSIDIAN_SRC := $(shell find $(MODULES)/forge-obsidian/src -name '*.rs')
LIB_SRC := $(shell find $(MODULES)/forge-lib/src -name '*.rs' 2>/dev/null)
.PHONY: all build install install-binaries install-hooks install-skills install-agents uninstall test check clean clean-plugins deps templates check-submodules lint security
.PHONY:
.PHONY: validate prune
# --- Submodule check ---
# Detect empty module directories from a non-recursive git clone.
define check_submodules
@if [ ! -f "$(MODULES)/forge-tlp/Cargo.toml" ]; then \
echo ""; \
echo "ERROR: Git submodules are not initialized."; \
echo "Run: git submodule update --init --recursive"; \
echo ""; \
exit 1; \
fi
endef
all: build
# --- Build (with source-level dependency tracking) ---
$(CORE)/target/release/yaml $(CORE)/target/release/dispatch: $(CORE)/Cargo.toml $(CORE_SRC)
cargo build --release --manifest-path $(CORE)/Cargo.toml
$(MODULES)/forge-tlp/target/release/safe-read \
$(MODULES)/forge-tlp/target/release/safe-write \
$(MODULES)/forge-tlp/target/release/blind-metadata \
$(MODULES)/forge-tlp/target/release/tlp-guard: $(MODULES)/forge-tlp/Cargo.toml $(TLP_SRC)
cargo build --release --manifest-path $(MODULES)/forge-tlp/Cargo.toml
$(MODULES)/forge-reflect/target/release/reflect \
$(MODULES)/forge-reflect/target/release/insight \
$(MODULES)/forge-reflect/target/release/surface: $(MODULES)/forge-reflect/Cargo.toml $(REFLECT_SRC)
cargo build --release --manifest-path $(MODULES)/forge-reflect/Cargo.toml
$(MODULES)/forge-journals/target/release/build-templates: $(MODULES)/forge-journals/Cargo.toml $(JOURNALS_SRC)
cargo build --release --manifest-path $(MODULES)/forge-journals/Cargo.toml
$(MODULES)/forge-obsidian/target/release/obsidian-base: $(MODULES)/forge-obsidian/Cargo.toml $(OBSIDIAN_SRC)
cargo build --release --manifest-path $(MODULES)/forge-obsidian/Cargo.toml
$(MODULES)/forge-lib/target/release/strip-front \
$(MODULES)/forge-lib/target/release/install-agents \
$(MODULES)/forge-lib/target/release/install-skills \
$(MODULES)/forge-lib/target/release/validate-module: $(MODULES)/forge-lib/Cargo.toml $(LIB_SRC)
$(MAKE) -C $(MODULES)/forge-lib build
build: check-submodules $(CORE)/target/release/yaml \
$(CORE)/target/release/dispatch \
$(MODULES)/forge-tlp/target/release/safe-read \
$(MODULES)/forge-tlp/target/release/safe-write \
$(MODULES)/forge-tlp/target/release/blind-metadata \
$(MODULES)/forge-tlp/target/release/tlp-guard \
$(MODULES)/forge-reflect/target/release/reflect \
$(MODULES)/forge-reflect/target/release/insight \
$(MODULES)/forge-reflect/target/release/surface \
$(MODULES)/forge-journals/target/release/build-templates \
$(MODULES)/forge-obsidian/target/release/obsidian-base \
$(MODULES)/forge-lib/target/release/strip-front \
$(MODULES)/forge-lib/target/release/install-agents \
$(MODULES)/forge-lib/target/release/install-skills \
$(MODULES)/forge-lib/target/release/validate-module
check-submodules:
$(check_submodules)
# --- Templates (post-build) ---
templates: $(MODULES)/forge-journals/target/release/build-templates $(MODULES)/forge-tlp/target/release/safe-read
FORGE_MODULE_ROOT="$(MODULES)/forge-journals" \
FORGE_ROOT="$(FORGE_ROOT)" \
$< --safe-read $(MODULES)/forge-tlp/target/release/safe-read
# --- Install ---
install: build install-binaries install-hooks install-skills install-agents templates
@echo "Installation complete. Restart your session."
install-binaries:
@mkdir -p $(BIN_DIR)
@ln -sf $(CORE)/target/release/yaml $(BIN_DIR)/yaml
@ln -sf $(CORE)/target/release/dispatch $(BIN_DIR)/dispatch
@ln -sf $(MODULES)/forge-tlp/target/release/safe-read $(BIN_DIR)/safe-read
@ln -sf $(MODULES)/forge-tlp/target/release/safe-write $(BIN_DIR)/safe-write
@ln -sf $(MODULES)/forge-tlp/target/release/blind-metadata $(BIN_DIR)/blind-metadata
@ln -sf $(MODULES)/forge-tlp/target/release/tlp-guard $(BIN_DIR)/tlp-guard
@ln -sf $(MODULES)/forge-reflect/target/release/insight $(BIN_DIR)/insight
@ln -sf $(MODULES)/forge-reflect/target/release/reflect $(BIN_DIR)/reflect
@ln -sf $(MODULES)/forge-reflect/target/release/surface $(BIN_DIR)/surface
@ln -sf $(MODULES)/forge-journals/target/release/build-templates $(BIN_DIR)/build-templates
@ln -sf $(MODULES)/forge-obsidian/target/release/obsidian-base $(BIN_DIR)/obsidian-base
@ln -sf $(MODULES)/forge-lib/target/release/strip-front $(BIN_DIR)/strip-front
@ln -sf $(MODULES)/forge-lib/target/release/install-agents $(BIN_DIR)/install-agents
@ln -sf $(MODULES)/forge-lib/target/release/install-skills $(BIN_DIR)/install-skills
@ln -sf $(MODULES)/forge-lib/target/release/validate-module $(BIN_DIR)/validate-module
@echo " binaries symlinked to $(BIN_DIR)"
install-hooks:
@mkdir -p .claude
@python3 -c '\
import json, os; \
sf = ".claude/settings.json"; \
s = json.load(open(sf)) if os.path.exists(sf) else {}; \
events = { \
"SessionStart": [ \
{"hooks": [{"type": "command", "command": "dispatch SessionStart"}]}, \
{"hooks": [{"type": "command", "command": "dispatch SessionStart --prompt"}]} \
], \
"PreToolUse": [{"matcher": "", "hooks": [{"type": "command", "command": "dispatch PreToolUse"}]}], \
"PostToolUse": [{"matcher": "", "hooks": [{"type": "command", "command": "dispatch PostToolUse"}]}], \
"Stop": [{"hooks": [{"type": "command", "command": "dispatch Stop"}]}], \
"PreCompact": [{"hooks": [{"type": "command", "command": "dispatch PreCompact"}]}], \
"UserPromptSubmit": [{"hooks": [{"type": "command", "command": "dispatch UserPromptSubmit"}]}], \
"SubagentStop": [{"hooks": [{"type": "command", "command": "dispatch SubagentStop"}]}], \
"SessionEnd": [{"hooks": [{"type": "command", "command": "dispatch SessionEnd"}]}], \
"Notification": [{"hooks": [{"type": "command", "command": "dispatch Notification"}]}] \
}; \
s["hooks"] = events; \
f = open(sf, "w"); json.dump(s, f, indent=2); f.write("\n"); f.close()'
@echo " hooks installed to .claude/settings.json"
install-skills:
@mkdir -p $(CLAUDE_SKILLS)
@for m in $(if $(PATH_FILTER),$(PATH_FILTER),$(CORE) $(MODULES)/*); do \
if [ -d "$$m/skills" ]; then \
"$(INSTALL_SKILLS)" "$$m/skills" --provider claude --dst "$(CLAUDE_SKILLS)"; \
fi; \
done
@if [ -z "$(PATH_FILTER)" ] && [ -n "$(VAULT_SKILLS)" ] && [ -d "$(VAULT_SKILLS)" ]; then \
"$(INSTALL_SKILLS)" "$(VAULT_SKILLS)" --provider claude --dst "$(CLAUDE_SKILLS)"; \
fi
@count=$$(ls -d $(CLAUDE_SKILLS)/*/ 2>/dev/null | wc -l | tr -d ' '); \
echo " $$count skills installed to $(CLAUDE_SKILLS)"
install-agents:
@"$(INSTALL_AGENTS)" "$(MODULES)/forge-council/agents" --scope all
clean-plugins:
@command rm -rf "$(CLAUDE_SKILLS)" "$(CLAUDE_AGENTS)"
@echo " cleaned $(CLAUDE_SKILLS) and $(CLAUDE_AGENTS)"
# --- Uninstall ---
uninstall:
@for b in yaml dispatch safe-read safe-write blind-metadata tlp-guard reflect insight surface build-templates obsidian-base strip-front install-agents install-skills validate-module; do \
if [ -L "$(BIN_DIR)/$$b" ]; then command rm -f "$(BIN_DIR)/$$b"; echo " removed $$b"; fi; \
done
@echo "Uninstalled from $(BIN_DIR)"
# --- Test ---
test:
cargo test --manifest-path $(CORE)/Cargo.toml
@for m in $(MODULE_LIST); do \
if [ -f "$(MODULES)/$$m/Makefile" ] && grep -q '^test:' "$(MODULES)/$$m/Makefile" 2>/dev/null; then \
echo "--- $$m ---"; \
$(MAKE) -C "$(MODULES)/$$m" FORGE_LIB=$(MODULES)/forge-lib test || exit 1; \
fi; \
done
@echo "=== Shell Tests ==="
@for m in $(MODULE_LIST); do \
if [ -f "$(MODULES)/$$m/tests/test.sh" ]; then \
echo "--- $$m ---"; \
bash "$(MODULES)/$$m/tests/test.sh" || exit 1; \
fi; \
done
# --- Check (dry-run audit) ---
check:
@echo "=== Prerequisites ==="
@command -v cargo >/dev/null && echo " ok cargo" || echo " MISSING cargo"
@command -v python3 >/dev/null && echo " ok python3" || echo " MISSING python3"
@command -v git >/dev/null && echo " ok git" || echo " MISSING git"
@command -v gh >/dev/null && echo " ok gh" || echo " MISSING gh (brew install gh)"
@echo "=== Security Tools ==="
@command -v mdschema >/dev/null && echo " ok mdschema" || echo " MISSING mdschema (brew install jackchuka/tap/mdschema)"
@command -v shellcheck >/dev/null && echo " ok shellcheck" || echo " MISSING shellcheck (brew install shellcheck)"
@command -v semgrep >/dev/null && echo " ok semgrep" || echo " MISSING semgrep (brew install semgrep)"
@command -v trufflehog >/dev/null && echo " ok trufflehog" || echo " MISSING trufflehog (brew install trufflehog)"
@command -v bandit >/dev/null && echo " ok bandit" || echo " MISSING bandit (pipx install bandit)"
@echo "=== Binaries ==="
@for b in yaml dispatch safe-read safe-write blind-metadata tlp-guard reflect insight surface build-templates obsidian-base strip-front install-agents install-skills validate-module; do \
command -v $$b >/dev/null && echo " ok $$b" || echo " MISSING $$b (run make install)"; \
done
@echo "=== Modules ==="
@for m in forge-obsidian forge-steering forge-avatar forge-tlp forge-journals forge-reflect; do \
test -f $(MODULES)/$$m/module.yaml && echo " ok $$m" || echo " MISSING $$m"; \
done
@echo "=== Skill Discovery ==="
@if [ -d $(CLAUDE_SKILLS) ]; then \
count=$$(ls -d $(CLAUDE_SKILLS)/*/ 2>/dev/null | wc -l | tr -d ' '); \
echo " ok $$count skills in .claude/skills/"; \
else \
echo " FAIL: no skills installed (run make install)"; \
fi
@echo "=== Platform Modules ==="
@for m in forge-apple forge-microsoft forge-google forge-proton; do \
if test -f $(MODULES)/$$m/module.yaml; then \
if ls $(MODULES)/$$m/skills/*/SKILL.md >/dev/null 2>&1; then \
echo " ok $$m"; \
else \
echo " scaffold $$m"; \
fi; \
fi; \
done
# --- Validate (ecosystem integrity) ---
validate:
@echo "=== Module Versions ==="
@for m in $(MODULE_LIST); do \
if [ -f "$(MODULES)/$$m/module.yaml" ]; then \
v=$$(awk '/^version:/{print $$2; exit}' "$(MODULES)/$$m/module.yaml"); \
echo " ok $$m: $$v"; \
fi; \
done
@echo "=== Installed Skills ==="
@if [ -d $(CLAUDE_SKILLS) ]; then \
count=$$(ls -d $(CLAUDE_SKILLS)/*/ 2>/dev/null | wc -l | tr -d ' '); \
missing=0; \
for sd in $(CLAUDE_SKILLS)/*/; do \
s=$$(basename "$$sd"); \
if [ ! -f "$$sd/SKILL.yaml" ]; then \
echo " MISSING SKILL.yaml: $$s"; \
missing=$$((missing + 1)); \
fi; \
done; \
echo " $$count skills installed ($$missing missing SKILL.yaml)"; \
else \
echo " FAIL: no skills installed (run make install)"; \
fi
@echo "=== Hooks ==="
@if [ -f .claude/settings.json ]; then \
hook_count=$$(python3 -c "import json; h=json.load(open('.claude/settings.json')).get('hooks',{}); print(len(h))" 2>/dev/null || echo 0); \
echo " $$hook_count hook events configured"; \
else \
echo " FAIL: no .claude/settings.json (run make install)"; \
fi
@echo "=== Lib Consistency ==="
@echo " ok (Core/lib removed — canonical source is Modules/forge-lib)"
@echo "=== Permission Sanity ==="
@if [ -f .claude/settings.local.json ]; then \
python3 -c "\
import json; \
data = json.load(open('.claude/settings.local.json')); \
entries = data.get('permissions', {}).get('allow', []); \
total = len(entries); \
bash_e = [e for e in entries if e.startswith('Bash(')]; \
web_e = [e for e in entries if e.startswith('WebFetch(')]; \
print(f' {total} entries (Bash: {len(bash_e)}, WebFetch: {len(web_e)}, other: {total - len(bash_e) - len(web_e)})'); \
dangerous = [e for e in entries if e in ['Bash(bash:*)', 'Bash(env:*)']]; \
[print(f' DANGEROUS: {e}') for e in dangerous]; \
warn = [e for e in entries if e in ['Bash(source:*)', 'Bash(find:*)', 'Bash(osascript:*)']]; \
[print(f' WARN: {e} (broad wildcard)') for e in warn]; \
print(' WARNING: >100 entries, consider pruning') if total > 100 else None"; \
fi
# --- Prune (cross-ecosystem cleanup) ---
prune:
@echo "=== Removing cross-ecosystem platform directories ==="
@for d in .gemini .codex .opencode; do \
if [ -d "$$d" ]; then \
echo " removing $$d/"; \
command rm -rf "$$d"; \
echo " removed $$d/"; \
fi; \
done
@echo "Pruned. Run 'bash Core/bin/forge-update.sh --platform all' to regenerate."
# --- Dependencies ---
deps:
@command -v cargo >/dev/null || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
@command -v gh >/dev/null || { echo " MISSING gh — install from https://cli.github.com/"; exit 1; }
@if [ "$$(uname)" = "Darwin" ] && [ -f "$(MODULES)/forge-apple/module.yaml" ]; then \
if ! command -v brew >/dev/null; then \
echo ""; \
echo " macOS detected with forge-apple submodule."; \
echo " Homebrew recommended: https://brew.sh/"; \
echo " See Modules/forge-apple/INSTALL.md for macOS dependencies."; \
echo ""; \
else \
echo " ok brew (macOS deps available — see Modules/forge-apple/INSTALL.md)"; \
fi; \
fi
@echo "=== Security Tools ==="
@if command -v brew >/dev/null; then \
command -v mdschema >/dev/null || { echo " installing mdschema..."; brew install jackchuka/tap/mdschema; }; \
command -v shellcheck >/dev/null || { echo " installing shellcheck..."; brew install shellcheck; }; \
command -v semgrep >/dev/null || { echo " installing semgrep..."; brew install semgrep; }; \
command -v trufflehog >/dev/null || { echo " installing trufflehog..."; brew install trufflehog; }; \
echo " ok brew security tools"; \
else \
echo " SKIP security tools (brew not available)"; \
fi
@command -v pipx >/dev/null && { command -v bandit >/dev/null || { echo " installing bandit..."; pipx install bandit; }; } || \
echo " SKIP bandit (pipx not available — pip install pipx)"
# --- Lint ---
lint:
@echo "=== Core (fmt + clippy) ==="
cargo fmt --manifest-path $(CORE)/Cargo.toml --check
cargo clippy --manifest-path $(CORE)/Cargo.toml -- -D warnings
@echo "=== Modules ==="
@for m in $(MODULE_LIST); do \
if [ -f "$(MODULES)/$$m/Makefile" ] && grep -q '^lint:' "$(MODULES)/$$m/Makefile" 2>/dev/null; then \
echo "--- $$m ---"; \
$(MAKE) -C "$(MODULES)/$$m" FORGE_LIB=$(MODULES)/forge-lib lint || exit 1; \
fi; \
done
@echo "=== Shell (shellcheck) ==="
@if command -v shellcheck >/dev/null; then \
find $(CORE) $(MODULES) -name '*.sh' -not -path '*/target/*' | xargs shellcheck -S warning 2>/dev/null || true; \
else \
echo " SKIP shellcheck (not installed)"; \
fi
@echo "=== Markdown Schema (mdschema) ==="
@for m in $(MODULE_LIST); do \
if grep -q 'lint-schema' "$(MODULES)/$$m/Makefile" 2>/dev/null; then \
echo " $$m"; \
$(MAKE) -C "$(MODULES)/$$m" FORGE_LIB=$(MODULES)/forge-lib lint-schema; \
fi; \
done
@echo "=== Semgrep (OWASP) ==="
@if command -v semgrep >/dev/null; then \
semgrep scan --config=p/owasp-top-ten --metrics=off --quiet . || true; \
else \
echo " SKIP semgrep (not installed)"; \
fi
# --- Security scan ---
security:
@echo "=== OWASP Scan (semgrep) ==="
@semgrep scan --config=p/owasp-top-ten --metrics=off .
@echo "=== Secret Validation (trufflehog) ==="
@trufflehog git file://. --since-commit HEAD --results=verified,unknown --fail
# --- Clean ---
clean:
cargo clean --manifest-path $(CORE)/Cargo.toml 2>/dev/null || true
@for m in $(MODULE_LIST); do \
if [ -f "$(MODULES)/$$m/Makefile" ] && grep -q '^clean:' "$(MODULES)/$$m/Makefile" 2>/dev/null; then \
$(MAKE) -C "$(MODULES)/$$m" FORGE_LIB=$(MODULES)/forge-lib clean; \
fi; \
done