Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
606 lines (531 loc) · 32.7 KB
/
Copy pathMakefile
File metadata and controls
606 lines (531 loc) · 32.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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
VERSION := $(or $(shell git describe --tags --always 2>/dev/null | sed 's/^v//'),dev)
LDFLAGS := -X main.version=$(VERSION)
# golangci-lint is the Go lint gate (Go Report Card successor). Pinned so
# local and CI run the same analyzer versions; keep in sync with
# .github/workflows/test.yml. Config lives in .golangci.yml.
#
# `make tools` installs the exact prebuilt release binary, not a fresh
# `go install` build. golangci-lint bundles a gofmt-compatible formatter that
# embeds whatever Go standard library (go/printer's comment-alignment
# heuristics have moved between point releases) it was compiled against. A
# `go install ...@$(GOLANGCI_LINT_VERSION)` compiles against whatever Go
# toolchain happens to be on the developer's PATH, while
# golangci-lint-action's default `install-mode: binary` downloads the
# official release artifact — built once, by the golangci-lint project, on
# its own pinned Go version. Two builds of the same source at different Go
# versions can format identical input differently, which is exactly the
# false-negative-locally / fail-in-CI split this project hit (see the
# gofmt-agnostic rewrite in internal/mission/migrate_test.go). Fetching the
# same release asset CI fetches removes the toolchain as a variable: gofmt's
# formatting logic is pure Go text processing with no OS/arch dependence, so
# even a darwin/arm64 developer and the linux/amd64 CI runner make identical
# formatting decisions once both are running a binary built from the same
# release commit at the same Go version — only the raw bytes of the two
# binaries differ, never their verdict on a given source file.
# Resolve the install dir the way `go install` does: GOBIN if set, else
# GOPATH/bin — so `make tools` and this path agree for anyone with GOBIN set.
GOLANGCI_LINT_VERSION := v2.13.1
# Every recipe runs the Go toolchain named by go.mod's `toolchain` line, not
# whatever Go is first on the developer's PATH. golangci-lint v2.13.1's
# go/types export-data reader accepts format version 4 at most, while a
# go1.27.x standard library emits version 5, so under GOTOOLCHAIN=auto a newer
# system Go (e.g. go1.27.3 against `toolchain go1.26.5`) wins and the linter
# fails with "export data version 5 is greater than maximum supported version
# 4". go1.26 emits version 4. go.mod's toolchain line is the Go that CI runs
# (actions/setup-go reads go.mod) and the Go this linter can read, so
# exporting it here makes a local `make lint`, `make test`, and `make build`
# run the same Go as CI. The awk takes only a `toolchain go1.x` line, so
# `toolchain default` or a missing line leaves GOTOOLCHAIN unset (Go's own
# default applies), and it strips a trailing CR so a CRLF go.mod cannot export
# an invalid value that would break every recipe.
GO_TOOLCHAIN := $(shell awk '$$1=="toolchain" && $$2 ~ /^go1\./ {sub(/\r$$/,"",$$2); print $$2}' go.mod)
ifneq ($(GO_TOOLCHAIN),)
export GOTOOLCHAIN := $(GO_TOOLCHAIN)
endif
GOBIN := $(shell go env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(shell go env GOPATH)/bin
endif
GOLANGCI_LINT := $(GOBIN)/golangci-lint
.PHONY: help lint docs docs-pdf test check validate-content fuzz-check sync-embed format build install dev clean clean-latex dist tools doctor undev test-behavioral test-e2e test-e2e-smoke e2e-bin baseline-tokens calibrate-tokens
help: ## Show available targets
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-12s %s\n", $$1, $$2}'
lint: ## Lint (golangci-lint + windows vet + shellcheck + ruff + mypy)
@test -x $(GOLANGCI_LINT) || { echo "golangci-lint not found at $(GOLANGCI_LINT) — run 'make tools' to install $(GOLANGCI_LINT_VERSION)"; exit 1; }
$(GOLANGCI_LINT) run ./...
GOOS=windows go vet ./... # the windows build, tests included: a unix-only helper or test file must carry its build tag
shellcheck plugin/hooks/*.sh install.sh .githooks/* scripts/test-changed.sh scripts/test-push.sh scripts/test-shard.sh scripts/test-timed.sh scripts/test-snapshot.sh scripts/smoke-release.sh
cd tests/e2e && uv run ruff check .
cd tests/e2e && uv run ruff format --check .
cd tests/e2e && uv run mypy src/ tests/
cd tests/e2e && uv run pytest tests/ -m "not e2e"
docs: ## Lint markdown
npx --yes markdownlint-cli2 "**/*.md" "#node_modules" "#internal/autorepair/testdata/corpus" "#internal/autorepair/testdata/damage"
# LaTeX PDFs are checked in (prfaq.pdf, docs/*.pdf). Regenerating them
# is opt-in — `make docs-pdf` — not part of `make check`, so CI doesn't
# need a TeX toolchain. Passing no bib-backend flag lets latexmk pick
# biber vs bibtex from the auxiliary files the first pdflatex run
# generates (a .bcf implies biber; a .aux with \bibdata implies bibtex).
# prfaq.tex is biblatex + backend=biber → latexmk emits a .bcf → biber;
# docs/*.tex cite nothing → no bib backend runs at all. `-c` after the
# build sweeps latexmk's intermediates; the explicit basename+extension
# loop below sweeps the ones `-c` keeps when a .bib is present (.bbl).
# Net: only .tex and .pdf remain on disk after docs-pdf.
LATEX_TEX := prfaq.tex $(wildcard docs/*.tex)
LATEX_INTERMEDIATE_EXTS := aux bbl bcf blg fdb_latexmk fls log out run.xml synctex.gz toc
docs-pdf: ## Rebuild prfaq.pdf + docs/*.pdf from .tex sources, then sweep intermediates
@command -v latexmk >/dev/null || { echo "latexmk not found — install a TeX distribution (MacTeX, TeX Live)"; exit 1; }
@for f in $(LATEX_TEX); do \
echo "==> latexmk $$f"; \
latexmk -pdf -interaction=nonstopmode -halt-on-error -cd "$$f" || exit 1; \
latexmk -c -cd "$$f" >/dev/null; \
base=$${f%.tex}; \
for ext in $(LATEX_INTERMEDIATE_EXTS); do \
rm -f "$$base.$$ext"; \
done; \
done
# Scoped to intermediates that sit next to a KNOWN .tex source in LATEX_TEX.
# A repo-wide `find -name '*.log' -delete` would also catch coverage.out,
# .beads/daemon.log, worktree checkouts under sibling repos, etc. — none of
# which are ours to remove. Keying on LATEX_TEX basenames means we only touch
# files whose provenance is a .tex we know about.
clean-latex: ## Remove LaTeX build intermediates (keeps .pdf/.tex/.bib)
@for f in $(LATEX_TEX); do \
base=$${f%.tex}; \
for ext in $(LATEX_INTERMEDIATE_EXTS); do \
rm -f "$$base.$$ext"; \
done; \
done
# Several packages run real git and subprocesses against wall-clock deadlines.
# Running every package at once (go test's default -p is GOMAXPROCS) on a
# developer machine starves those deadlines and times out the long packages
# under -race. Raise TEST_PARALLEL on a quiet host.
TEST_PARALLEL ?= 2
TEST_PUSH_PARALLEL ?= 4
TEST_PACKAGES ?= ./...
GO_COVERAGE_TEST = go test -race -count=1 -timeout 30m -p $(TEST_PARALLEL)
package_coverage = $(GO_COVERAGE_TEST) -coverprofile="$(1)" ./...
test: ## Run tests with race detection and write coverage to coverage.out
$(GO_COVERAGE_TEST) -coverprofile=coverage.out $(TEST_PACKAGES)
.PHONY: hooks test-changed test-push test-push-suite test-subprocess-fast
hooks: ## Opt in to the repository's development Git hooks
python3 scripts/install-dev-hooks.py
GITLEAKS := go run github.com/zricethezav/gitleaks/v8@v8.30.1
GITLEAKS_LOG_OPTS ?= HEAD
.PHONY: secret-scan-staged secret-scan-history
secret-scan-staged: ## Scan staged Git changes for secrets
$(GITLEAKS) git --staged --redact=100 --no-banner .
secret-scan-history: ## Scan Git history for secrets (defaults to all commits reachable from HEAD)
$(GITLEAKS) git --log-opts="--diff-merges=first-parent $(GITLEAKS_LOG_OPTS)" --redact=100 --no-banner .
test-changed: ## Run Go checks in packages affected by staged paths
@if [ -n "$$ETHOS_STAGED_PATHS" ]; then \
bash scripts/test-changed.sh; \
else \
bash scripts/test-timed.sh pre-commit 30 env -u GOTOOLCHAIN bash scripts/test-snapshot.sh staged $(MAKE) test-changed; \
fi
test-push: ## Run the full default suite and a fast boundary check before pushing
GORACE="$$GORACE atexit_sleep_ms=0" $(if $(ETHOS_TEST_PUSH_SNAPSHOT),,bash scripts/test-timed.sh pre-push 180) $(MAKE) test-push-suite test-subprocess-fast
test-push-suite:
bash scripts/test-push.sh $(TEST_PUSH_PARALLEL)
test-subprocess-fast: ## Exercise dormant and unresolvable Git hook entry points
go test -race -count=1 -run '^TestHooks(DormantRepositoryRunsNoProbe|FailLoudWhenRevParseFails)$$' ./plugin/hooks
.PHONY: test-unit test-subprocess test-performance test-live test-agent test-nightly test-release-candidate test-post-release test-quarantine test-quarantine-run
TEST_KIND_ARGS ?= ./...
test-unit: ## Run default Go tests that do not launch a real subprocess
python3 scripts/test-kind.py unit -race -count=1 -timeout 30m -p $(TEST_PARALLEL) $(TEST_KIND_ARGS)
test-subprocess: ## Run default Go tests that launch real local subprocesses
python3 scripts/test-kind.py subprocess -race -count=1 -timeout 30m -p $(TEST_PARALLEL) $(TEST_KIND_ARGS)
test-performance: ## Report race-instrumented long-session redaction timing
go test -race -count=1 -run '^TestRedactLiveLongSessionBudget$$' -v ./internal/hook
test-live: test-behavioral ## Run live provider and judge tests
test-agent: test-behavioral ## Run real-agent behavioral tests
test-nightly: ## Review quarantines and run the live suite under the Nightly budget
bash scripts/test-timed.sh nightly 3600 bash -c '"$$@" test-quarantine && "$$@" test-behavioral' bash $(MAKE)
test-release-candidate: ## Verify the native candidate in checksummed dist/
@version=$$(sed -n 's/^VERSION="\([^"]*\)"$$/\1/p' install.sh); \
bash scripts/test-timed.sh release-candidate 300 sh scripts/smoke-release.sh candidate "$$version" install.sh dist
test-post-release: ## Verify the published release against the staged dist/checksums.txt
@version=$$(sed -n 's/^VERSION="\([^"]*\)"$$/\1/p' install.sh); \
bash scripts/test-timed.sh post-release 120 sh scripts/smoke-release.sh published "$$version" install.sh dist
test-quarantine: ## List quarantined Go tests and validate ownership and expiry
python3 scripts/test-quarantine.py list tests/quarantine.tsv
test-quarantine-run: ## Run only the Go tests in the quarantine inventory
python3 scripts/test-quarantine.py run tests/quarantine.tsv
check: test-quarantine
.PHONY: coverage-check
export COVERAGE_BASE ?= origin/main
coverage-check: ## Ratchet package statement coverage against the merge base with COVERAGE_BASE
@set -eu; \
base_ref=$$(git rev-parse --verify --end-of-options "$${COVERAGE_BASE}^{commit}"); \
base=$$(git merge-base HEAD "$$base_ref"); \
toolchain=$$(go env GOVERSION); \
export GOTOOLCHAIN="$$toolchain"; \
unset ETHOS_TEST_COVERDIR; \
printf 'Statement coverage: HEAD %s, merge base %s\n' "$$(git rev-parse HEAD)" "$$base"; \
$(call package_coverage,coverage.out); \
mkdir -p .tmp; \
scratch=$$(mktemp -d "$(CURDIR)/.tmp/coverage-base.XXXXXXXX"); \
trap 'if test -e "$$scratch/base/.git"; then git worktree remove --force "$$scratch/base"; fi; rm -f "$$scratch/base.out"; rmdir "$$scratch"' EXIT; \
git worktree add --detach "$$scratch/base" "$$base"; \
(cd "$$scratch/base" && $(call package_coverage,$$scratch/base.out)); \
go run ./cmd/coverage-check -profile coverage.out -base-profile "$$scratch/base.out"
.PHONY: coverage-subprocess coverage-release-companion
STATEMENT_REPORTS := $(CURDIR)/.tmp/statement-coverage
define coverage_text
go tool covdata textfmt -i="$(1)" -o="$(2)"; \
awk 'NR > 1 && $$3 > 0 { covered = 1 } END { exit !covered }' "$(2)" || \
{ echo "No executed statements found in $(2)" >&2; exit 1; }
endef
# These observers assert the installed binary's filesystem writes; Go counters
# are additional writes. The regular package suite runs them uninstrumented.
SUBPROCESS_COVER_SKIP := ^(TestEnabledInstalledHooksTransientWrites|TestEnabledInstalledPreCommitArchivalPlacement)$$
coverage-subprocess: ## Report statement coverage for subprocess suites, including their built Go binaries
@set -eu; \
mkdir -p "$(STATEMENT_REPORTS)"; \
scratch=$$(mktemp -d "$(STATEMENT_REPORTS)/subprocess.XXXXXXXX"); \
trap 'rm -rf "$$scratch"' EXIT; \
ETHOS_TEST_COVERDIR="$$scratch" $(GO_COVERAGE_TEST) -coverprofile="$$scratch/packages.out" \
-skip '$(SUBPROCESS_COVER_SKIP)' \
./cmd/ethos ./cmd/validate-content ./internal/autorepair ./internal/hook ./internal/mcp ./plugin/hooks ./test; \
$(call coverage_text,$$scratch,$$scratch/children.out); \
go run ./cmd/coverage-check -merge "$$scratch/packages.out" "$$scratch/children.out" > "$$scratch/combined.out"; \
cp "$$scratch/children.out" "$(STATEMENT_REPORTS)/subprocess-children.out"; \
cp "$$scratch/combined.out" "$(STATEMENT_REPORTS)/subprocess-combined.out"; \
go tool cover -func="$$scratch/combined.out" > "$$scratch/functions.txt"; \
printf 'Subprocess suites and child binaries statement coverage: '; tail -n 1 "$$scratch/functions.txt"
coverage-release-companion: ## Report statement coverage for the native release smoke using an instrumented companion
@set -eu; \
mkdir -p "$(STATEMENT_REPORTS)"; \
scratch=$$(mktemp -d "$(STATEMENT_REPORTS)/release.XXXXXXXX"); \
trap 'rm -rf "$$scratch"' EXIT; \
mkdir "$$scratch/counters"; \
version=$$(sed -n 's/^VERSION="\([^"]*\)"$$/\1/p' install.sh); \
asset=ethos-$$(go env GOOS)-$$(go env GOARCH); \
CGO_ENABLED=0 go build -cover -covermode=atomic -ldflags="-s -w -X main.version=$$version" -o "$$scratch/$$asset" ./cmd/ethos; \
(cd "$$scratch" && shasum -a 256 "$$asset" > checksums.txt); \
ETHOS_RELEASE_COVERDIR="$$scratch/counters" bash scripts/test-timed.sh release-companion 300 \
sh scripts/smoke-release.sh candidate "$$version" install.sh "$$scratch"; \
$(call coverage_text,$$scratch/counters,$$scratch/release.out); \
cp "$$scratch/release.out" "$(STATEMENT_REPORTS)/release-companion.out"; \
go tool cover -func="$$scratch/release.out" > "$$scratch/functions.txt"; \
printf 'Native release companion statement coverage: '; tail -n 1 "$$scratch/functions.txt"
validate-content: ## Validate all ethos content files
go run ./cmd/validate-content
# Z specification .tex files are identified by content, not by a
# hardcoded name list: any .tex file anywhere under docs/, at any
# nesting depth, carrying `usepackage{fuzz}` or `usepackage[opts]{fuzz}`
# (the package every Z spec loads to get fuzz's Z notation macros) is a
# Z spec and gets type-checked. A new spec landing under docs/ -- top
# level or nested -- is picked up on its next `make check` with no
# Makefile edit. FUZZ_SPECS is re-evaluated on every `make` invocation
# (grep, not a cached list), so concurrent branches adding spec-*.tex
# files are covered as soon as they land in the working tree.
#
# `find docs -name '*.tex' -exec grep ... {} +`, not `grep -r
# --include='*.tex' ... docs`: --include is a GNU grep extension. On
# macOS's stock BSD grep, an unrecognized --include exits the whole
# `grep -r` nonzero, $(shell ...) captures empty output, and FUZZ_SPECS
# silently comes back empty -- the "nothing to check" branch then
# reports a clean local skip while actually omitting every spec on a
# macOS developer's machine. `find` plus `-E`/`\{...\}` extended-regex
# brace escaping are POSIX and behave identically under GNU and BSD
# grep; `-r` combined with `--include` was the only GNU-specific part.
#
# `fuzz <file>` with no flags performs a full type-check and is silent
# on success (exit 0, no output) — unlike `-t`, which additionally
# dumps every global definition's inferred type, drowning a real error
# in noise. A type/scope error prints one `"file", line N: message`
# line per error and a nonzero exit; see ethos-cy70's mission evidence
# for a captured failing/passing transcript against a throwaway fixture.
#
# Local vs CI presence of the fuzz binary is NOT graceful in both
# places. A developer machine without fuzz built (it has no
# distributed binary — z-spec/install.sh --fuzz-only compiles it from
# source) degrades to a loud one-line skip, so this target never blocks
# local iteration on a toolchain most edits never touch. CI has no such
# excuse: .github/workflows/test.yml installs fuzz explicitly so this
# gate can actually fail there, and a missing fuzz in CI is treated as
# a broken environment (hard failure), never a silent or quiet skip —
# that asymmetry is the whole point of the gate (ethos-cy70).
#
# Non-Z .tex docs (docs/agent-identity-spec.tex, docs/architecture.tex,
# docs/testing-strategy.tex, prfaq.tex) get NO compile gate here.
# Decision, not an oversight: `make docs-pdf` above already documents
# why a LaTeX compile step is opt-in rather than part of `check` — it
# needs a full TeX distribution (MacTeX/TeX Live) that CI does not
# otherwise install, and none of these four are executable
# specifications the way the fuzz-typed ones are, so there is no
# analogous "silently drifted against the code" failure mode to close.
# Deferred; tracked under ethos-cy70 if a future need (e.g. CI PDF
# regeneration checks) reopens it.
FUZZ_SPECS := $(shell find docs -name '*.tex' -exec grep -El 'usepackage(\[[^]]*\])?\{fuzz\}' {} +)
fuzz-check: ## Type-check Z specification .tex files with fuzz (ethos-cy70)
@if [ -z "$(FUZZ_SPECS)" ]; then \
if [ -n "$$CI" ]; then \
echo "fuzz-check: detection matched zero files -- gate broken (specs exist on this branch)" >&2; \
exit 1; \
fi; \
echo "fuzz-check: no .tex file under docs/ carries usepackage{fuzz} -- nothing to type-check"; \
exit 0; \
fi; \
if ! command -v fuzz >/dev/null 2>&1; then \
if [ -n "$$CI" ]; then \
echo "fuzz-check: fuzz type-checker not found on PATH -- CI must have fuzz installed for this gate to run (ethos-cy70); fix the workflow, this is not a skippable condition in CI" >&2; \
exit 1; \
fi; \
echo "fuzz-check: *** fuzz not installed -- SKIPPING Z spec type-check on this machine (build it with '<z-spec repo>/install.sh --fuzz-only', or run 'z-spec doctor' to check toolchain state) ***"; \
exit 0; \
fi; \
status=0; \
for f in $(FUZZ_SPECS); do \
echo "fuzz $$f"; \
fuzz "$$f" || status=1; \
done; \
exit $$status
sync-embed: ## Copy docs/ETHOS-SETUP.md to its DES-071 tier-C embed source
cp docs/ETHOS-SETUP.md internal/enable/setup/ETHOS-SETUP.md
test-behavioral: ## Run L4 behavioral tests (requires ANTHROPIC_API_KEY and claude CLI)
@test -n "$$ANTHROPIC_API_KEY" || { echo "ANTHROPIC_API_KEY is required" >&2; exit 1; }
@command -v claude >/dev/null || { echo "claude CLI is required" >&2; exit 1; }
go test -race -count=1 -tags behavioral -timeout 10m -v ./tests/behavioral/
e2e-bin: ## Build the ethos binary a non-hermetic E2E scenario's hooks run
@mkdir -p .tmp/e2e-bin
CGO_ENABLED=0 go build $(if $(ETHOS_TEST_COVERDIR),-cover -covermode=atomic) -o .tmp/e2e-bin/ethos ./cmd/ethos/
test-e2e-smoke: WIRE_MARKS := e2e and smoke
test-e2e-smoke: WIRE_PROFILE := wire-smoke.out
test-e2e: WIRE_MARKS := e2e
test-e2e: WIRE_PROFILE := wire-full.out
test-e2e-smoke: ## Run the E2E (L4) smoke scenarios and report Ethos statement coverage
test-e2e: ## Run the full E2E (L4) sweep and report Ethos statement coverage
test-e2e-smoke test-e2e:
@set -eu; \
mkdir -p "$(STATEMENT_REPORTS)"; \
scratch=$$(mktemp -d "$(STATEMENT_REPORTS)/wire.XXXXXXXX"); \
trap 'rm -rf "$$scratch"' EXIT; \
$(MAKE) e2e-bin ETHOS_TEST_COVERDIR="$$scratch"; \
(cd tests/e2e && ETHOS_TEST_COVERDIR="$$scratch" uv run pytest -m "$(WIRE_MARKS)"); \
$(call coverage_text,$$scratch,$$scratch/wire.out); \
cp "$$scratch/wire.out" "$(STATEMENT_REPORTS)/$(WIRE_PROFILE)"; \
go tool cover -func="$$scratch/wire.out" > "$$scratch/functions.txt"; \
printf 'Wire Ethos statement coverage: '; tail -n 1 "$$scratch/functions.txt"
baseline-tokens: ## Recapture E2E token baselines (operator-invoked)
@echo "not yet implemented in initial land"
calibrate-tokens: ## Calibrate the offline tokenizer against Anthropic's API (operator-invoked)
@echo "not yet implemented in initial land"
.PHONY: check-opencode doctor-opencode smoke-opencode smoke-opencode-children smoke-opencode-discovery smoke-opencode-health smoke-opencode-formatter
OPENCODE_PROFILE ?= bifrost
ifeq ($(OPENCODE_PROFILE),direct-openai)
opencode_profile_flag := --nightly
else ifneq ($(OPENCODE_PROFILE),bifrost)
opencode_profile_flag = $(error Unknown OPENCODE_PROFILE: $(OPENCODE_PROFILE))
endif
check-opencode: ## Check native OpenCode configuration offline (CI-safe)
python3 -B scripts/opencode.py check
python3 -B -m unittest discover -s scripts -p 'opencode_test.py'
doctor-opencode: ## Check live OpenCode discovery and six MCP connections
python3 -B scripts/opencode.py doctor $(opencode_profile_flag)
smoke-opencode: ## Exercise real native child/tool execution (uses model credits)
python3 -B scripts/opencode.py smoke
smoke-opencode-children: ## Smoke all specialist child reads only (uses model credits)
python3 -B scripts/opencode.py smoke --stage children
smoke-opencode-discovery: ## Smoke maintained procedure discovery only (uses model credits)
python3 -B scripts/opencode.py smoke --stage discovery $(opencode_profile_flag)
smoke-opencode-health: ## Smoke root Code Mode health calls only (uses model credits)
python3 -B scripts/opencode.py smoke --stage health
smoke-opencode-formatter: ## Smoke formatter byte preservation only (uses model credits)
python3 -B scripts/opencode.py smoke --stage formatter
.PHONY: check-storage check-plugin-cache check-installed
check-storage: ## Exercise offline storage boundaries through the real CLI, wrappers and Git hooks
python3 -B -m unittest discover -s scripts -p 'storage_acceptance_test.py'
python3 -B scripts/storage_acceptance.py
check-plugin-cache: ## Test Claude plugin cache switching
python3 -B scripts/plugin_cache_test.py
check-installed: ## Install a coverage-instrumented ethos and exercise the installed CLI, MCP and Git hooks
@set -eu; \
sandbox=$$(mktemp -d "$${RUNNER_TEMP:-/tmp}/ethos-installed.XXXXXXXX"); \
trap 'rm -rf "$$sandbox"' EXIT; \
sandbox=$$(cd "$$sandbox" && pwd -P); \
case "$$sandbox/" in "$(CURDIR)/"*) echo "installer sandbox must be outside the checkout" >&2; exit 1;; esac; \
mkdir -p "$$sandbox/home" "$$sandbox/work" "$$sandbox/tmp" "$$sandbox/install-coverage" "$$sandbox/coverage"; \
CGO_ENABLED=0 go build -cover -ldflags="$(LDFLAGS)" -o "$$sandbox/ethos" ./cmd/ethos; \
(cd "$$sandbox/work" && env -i HOME="$$sandbox/home" PATH=/usr/bin:/bin TMPDIR="$$sandbox/tmp" \
GIT_CONFIG_NOSYSTEM=1 GIT_CEILING_DIRECTORIES="$$sandbox" PUNT_TELEMETRY=off \
GOCOVERDIR="$$sandbox/install-coverage" ETHOS_LOCAL_BINARY="$$sandbox/ethos" \
sh "$(CURDIR)/install.sh" --no-plugin) > "$$sandbox/install.log" 2>&1 \
|| { cat "$$sandbox/install.log"; exit 1; }; \
cat "$$sandbox/install.log"; \
installed="$$sandbox/home/.local/bin/ethos"; \
cmp "$$sandbox/ethos" "$$installed"; \
if grep -Fq 'Could not seed starter content' "$$sandbox/install.log" || \
! test -s "$$sandbox/home/.punt-labs/ethos/.seed-manifest.json"; then \
echo 'installed ethos did not seed starter content' >&2; exit 1; \
fi; \
python3 -B scripts/storage_acceptance.py --binary "$$installed" --coverdir "$$sandbox/coverage"; \
go tool covdata textfmt -i="$$sandbox/coverage" -o="$$sandbox/coverage.out"; \
awk 'NR > 1 && $$3 > 0 { covered = 1 } END { exit !covered }' "$$sandbox/coverage.out"; \
go tool cover -func="$$sandbox/coverage.out" > "$$sandbox/functions.txt"; \
mkdir -p .tmp/opencode/installed-coverage; \
cp "$$sandbox/coverage.out" "$$sandbox/functions.txt" .tmp/opencode/installed-coverage/; \
printf 'Installed binary statement coverage (storage acceptance): '; \
tail -n 1 .tmp/opencode/installed-coverage/functions.txt
check: lint docs coverage-check validate-content fuzz-check check-opencode check-storage check-plugin-cache ## Run all quality gates
# The legacy corpus (internal/autorepair/testdata) is real on-disk state written
# by nine released binaries. Regenerating it builds each from its git tag, so it
# needs full tag history and takes minutes; it is deliberately not part of check.
.PHONY: legacy-corpus test-legacy-corpus
legacy-corpus: ## Regenerate internal/autorepair/testdata from the released tags (slow; not in check)
scripts/legacy-corpus.sh
test-legacy-corpus: ## Check the committed legacy corpus reproduces and is free of real paths and emails (not in check)
scripts/legacy_corpus_test.sh
format: ## Format code (applies the formatters golangci-lint gates)
$(GOLANGCI_LINT) fmt
build: ## Build binary
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o ethos ./cmd/ethos/
install: build ## Build and install to ~/.local/bin
mkdir -p $(HOME)/.local/bin
rm -f $(HOME)/.local/bin/ethos
cp ethos $(HOME)/.local/bin/ethos
# The symlink target is $(CURDIR)/plugin, not $(CURDIR): since DES-072 the
# shippable plugin surface lives in plugin/, and CLAUDE_PLUGIN_ROOT must be
# the same directory the git-subdir marketplace source checks out. Pointing
# it at the repo root would resolve ${CLAUDE_PLUGIN_ROOT}/hooks/*.sh to a
# path that no longer exists.
#
dev: install ## Install and symlink plugin cache for development
@python3 -B scripts/plugin_cache.py dev "$(HOME)" "$(CURDIR)" "$(PLUGIN_CACHE)"
undev: ## Restore plugin cache from backup
@python3 -B scripts/plugin_cache.py undev "$(HOME)" "$(CURDIR)" "$(PLUGIN_CACHE)"
clean: clean-latex ## Remove build artifacts
rm -f ethos coverage.out
rm -rf dist/
dist: clean ## Cross-compile for all platforms
mkdir -p dist
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w $(LDFLAGS)" -o dist/ethos-darwin-arm64 ./cmd/ethos/
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w $(LDFLAGS)" -o dist/ethos-darwin-amd64 ./cmd/ethos/
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w $(LDFLAGS)" -o dist/ethos-linux-arm64 ./cmd/ethos/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w $(LDFLAGS)" -o dist/ethos-linux-amd64 ./cmd/ethos/
# Fetches golangci-lint's official prebuilt release binary directly — the
# same artifact golangci-lint-action's default install-mode=binary
# downloads for CI — instead of compiling one against whatever local Go
# toolchain happens to be on PATH. See the GOLANGCI_LINT_VERSION comment
# above for why the artifact, not a fresh build, is the thing that must
# match CI.
#
# This does NOT shell out to golangci-lint's own install.sh. That script
# downloads and executes shell logic fetched fresh on every `make tools`
# run, on every developer's persistent workstation — a workstation that,
# in this org, holds GPG signing keys and pass-resolved credentials.
# Piping curl into sh puts code nobody in this repo has read in the path
# of every future `make tools`, invisible to `git blame` and to PR
# review, and re-fetched (not reviewed once) on every run. CI already
# runs the same prebuilt artifact via golangci-lint-action, so the trust
# root below is not new; what matters is that the fetch, verify, and
# extract logic are ordinary Makefile lines, reviewed once in this diff,
# not a script this repo never sees.
#
# The checksum check is a same-origin integrity check, not a stronger
# trust root: checksums.txt is published by the same account, in the
# same release, over the same channel as the tarball it describes. It
# catches transit corruption and accidental mismatches; it does not
# defend against a compromise of golangci-lint's own release pipeline,
# since whoever could swap the tarball could swap the checksums beside
# it. Git tags are mutable — the $(GOLANGCI_LINT_VERSION) URL below
# resolves live on every fetch, with no transparency log — so treat this
# as exactly the trust root CI already uses via golangci-lint-action, not
# an "immutable pin."
#
# The awk match below compares the filename FIELD exactly ($2), not a
# substring (grep -F). checksums.txt also lists sibling artifacts — e.g.
# "$tarball.sbom.json" — whose names have $tarball as a strict prefix; a
# substring match against the whole line hits both and trips the
# uniqueness guard below on every platform, aborting `make tools` even
# when the real entry is fine. Comparing field 2 for equality is immune
# to that, and to any other filename that merely contains $tarball
# elsewhere in its name.
#
# This explanatory comment lives here, above the target, rather than
# inline in the recipe body. An earlier version placed it inline as a
# backslash-continued `#` comment between two other backslash-continued
# shell statements. That construct is correct under POSIX sh (a `#`
# comment consumes characters up to but excluding the newline, so the
# trailing `\` is swallowed as comment text and the newline still ends
# the statement — verified directly under /bin/sh, /bin/dash, and
# /bin/bash) but it has now fooled two careful readers into opposite
# wrong conclusions: once when the `\` continuations were stripped
# (which really did break the recipe, by splitting it into separate
# shell invocations and losing variable state) and once when an
# automated reviewer flagged the restored `\`-continued comment as the
# thing breaking verification, extraction, and install (it does not —
# the recipe reaches and executes every statement after it). A
# correct-but-treacherous construct inside a security-relevant
# verification step is not worth keeping around for the next person to
# "fix" into an actual break in either direction, so the prose moves up
# here as ordinary Make comments and the recipe body keeps only
# executable statements.
# The fetches retry HTTP 5xx from the release CDN (10 attempts, 10s apart); each attempt is bounded at two minutes and retries stop starting after five; --retry-all-errors needs curl 7.71+ (ubuntu-latest and macos-latest runners are newer).
# If releases/download still fails after the retries, each file is fetched through the GitHub API asset route instead, because the two routes are served from
# different edges and one can stay down for hours while the other works. Verification is route-independent: the checksums file is fetched the same way and the
# tarball is checked against it exactly as before, so the trust root does not change with the route.
tools: ## Install development tools
@if [ -z "$(GOBIN)" ]; then \
echo "error: could not determine GOBIN — is Go installed and on PATH? ('go env GOBIN' and 'go env GOPATH' both came back empty)" >&2; \
exit 1; \
fi
@case "$(GOBIN)" in \
/bin|/sbin|/usr/bin|/usr/sbin|/usr/local/bin) \
echo "error: refusing to install into '$(GOBIN)' — that is a system directory, not a Go bin dir; check 'go env GOPATH' and 'go env GOBIN'" >&2; \
exit 1 ;; \
esac
@mkdir -p "$(GOBIN)"
@set -e; \
ver=$(GOLANGCI_LINT_VERSION); \
verNum=$${ver#v}; \
os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
arch=$$(uname -m); \
case "$$arch" in x86_64) arch=amd64 ;; aarch64) arch=arm64 ;; esac; \
name=golangci-lint-$${verNum}-$${os}-$${arch}; \
tarball=$${name}.tar.gz; \
checksums=golangci-lint-$${verNum}-checksums.txt; \
base=https://github.com/golangci/golangci-lint/releases/download/$${ver}; \
tmpdir=$$(mktemp -d "$${TMPDIR:-/tmp}/ethos-tools.XXXXXXXXXX"); \
trap 'rm -rf "$$tmpdir"' EXIT; \
echo "fetching $$tarball ($$ver, $$os/$$arch)"; \
retry="--connect-timeout 30 --max-time 120 --retry 10 --retry-delay 10 --retry-max-time 300 --retry-all-errors"; \
api=https://api.github.com/repos/golangci/golangci-lint/releases; \
api_curl() { \
if [ -n "$${GITHUB_TOKEN:-}" ]; then \
curl -sSfL $$retry -H "Authorization: Bearer $$GITHUB_TOKEN" "$$@"; \
else \
curl -sSfL $$retry "$$@"; \
fi; \
}; \
fetch() { \
f=$$1; \
if curl -sSfL $$retry -o "$$tmpdir/$$f" "$$base/$$f"; then return 0; fi; \
echo "releases/download failed for $$f; falling back to the GitHub API asset route" >&2; \
command -v jq >/dev/null 2>&1 || { echo "jq not found; cannot use the API fallback for $$f" >&2; return 1; }; \
meta=$$(api_curl "$$api/tags/$$ver") || { echo "API release lookup failed for $$ver" >&2; return 1; }; \
id=$$(printf '%s' "$$meta" | jq -r --arg n "$$f" '[.assets[] | select(.name == $$n) | .id][0] // empty') || { echo "could not parse the API release metadata for $$ver" >&2; return 1; }; \
if [ -z "$$id" ]; then echo "asset $$f not found in release $$ver via the API" >&2; return 1; fi; \
api_curl -H 'Accept: application/octet-stream' -o "$$tmpdir/$$f" "$$api/assets/$$id" || { echo "API asset download failed for $$f" >&2; return 1; }; \
}; \
fetch "$$tarball"; \
fetch "$$checksums"; \
line=$$(awk -v n="$$tarball" '$$2 == n {print}' "$$tmpdir/$$checksums" || true); \
count=$$(printf '%s\n' "$$line" | grep -c . || true); \
if [ "$$count" -ne 1 ]; then \
echo "expected exactly one checksum entry for $$tarball in $$checksums, found $$count" >&2; \
exit 1; \
fi; \
if command -v sha256sum >/dev/null 2>&1; then \
( cd "$$tmpdir" && echo "$$line" | sha256sum -c - ) || { echo "checksum verification failed for $$tarball" >&2; exit 1; }; \
elif command -v shasum >/dev/null 2>&1; then \
( cd "$$tmpdir" && echo "$$line" | shasum -a 256 -c - ) || { echo "checksum verification failed for $$tarball" >&2; exit 1; }; \
else \
echo "neither sha256sum nor shasum found; cannot verify $$tarball" >&2; exit 1; \
fi; \
tar -xzf "$$tmpdir/$$tarball" -C "$$tmpdir"; \
install "$$tmpdir/$$name/golangci-lint" "$(GOBIN)/golangci-lint"; \
echo "installed $(GOBIN)/golangci-lint $$ver"
doctor: build ## Run ethos doctor
./ethos doctor