Skip to content

Commit 902ed3c

Browse files
committed
feat(propagate): centralize .gitignore via a managed region
Add a concord-owned .gitignore region (gitignore-common) propagated into each member's .gitignore the same way as the AGENTS.md regions. inject-agents-regions.py now also handles hash-comment markers, so one injector serves both Markdown and .gitignore. Wire it into the Makefile (gitignore-sync/check), open-sync-pr.sh, and the propagate.yml triggers, and document the rule in REPO-LAYOUT. Defensive anchoring fixes the latent bug where unanchored directory ignores (config/, logs/, run/, build/, ...) silently swallowed nested packages of the same name: root-only artifacts are anchored with a leading slash so they match only at repo root, while genuinely global junk stays unanchored.
1 parent c4caaf4 commit 902ed3c

6 files changed

Lines changed: 145 additions & 64 deletions

File tree

‎.github/workflows/propagate.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ on:
4444
- "members.json"
4545
- "propagate/**"
4646
- "AGENTS-COMMON.md"
47+
- "gitignore-common"
4748
- "scripts/inject-agents-regions.py"
4849
- "scripts/open-sync-pr.sh"
4950
workflow_dispatch:

‎Makefile‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
PY ?= python3
66

7-
.PHONY: catalog catalog-check agents-sync agents-check help
7+
.PHONY: catalog catalog-check agents-sync agents-check gitignore-sync gitignore-check help
88

99
help:
1010
@echo "catalog regenerate .ai/skills/CATALOG.md from SKILL.md frontmatter"
1111
@echo "catalog-check fail if CATALOG.md is stale (CI guard)"
12-
@echo "agents-sync inject concord-owned AGENTS.md regions into sibling repos (../<member>)"
13-
@echo "agents-check show which sibling AGENTS.md regions would change (no writes)"
12+
@echo "agents-sync inject concord-owned AGENTS.md regions into sibling repos (../<member>)"
13+
@echo "agents-check show which sibling AGENTS.md regions would change (no writes)"
14+
@echo "gitignore-sync inject the concord-owned .gitignore region into sibling repos (../<member>)"
15+
@echo "gitignore-check show which sibling .gitignore regions would change (no writes)"
1416

1517
catalog:
1618
@$(PY) scripts/gen-skills-catalog.py
@@ -31,3 +33,13 @@ agents-check:
3133
@for m in $(MEMBERS); do \
3234
test -f ../$$m/AGENTS.md && { cp ../$$m/AGENTS.md /tmp/$$m.agents.bak; $(PY) scripts/inject-agents-regions.py AGENTS-COMMON.md ../$$m/AGENTS.md >/dev/null; diff -u /tmp/$$m.agents.bak ../$$m/AGENTS.md && echo "up to date: $$m" || true; mv /tmp/$$m.agents.bak ../$$m/AGENTS.md; } || echo "skip: ../$$m/AGENTS.md not found"; \
3335
done
36+
37+
gitignore-sync:
38+
@for m in $(MEMBERS); do \
39+
test -f ../$$m/.gitignore && $(PY) scripts/inject-agents-regions.py gitignore-common ../$$m/.gitignore || echo "skip: ../$$m/.gitignore not found"; \
40+
done
41+
42+
gitignore-check:
43+
@for m in $(MEMBERS); do \
44+
test -f ../$$m/.gitignore && { cp ../$$m/.gitignore /tmp/$$m.gitignore.bak; $(PY) scripts/inject-agents-regions.py gitignore-common ../$$m/.gitignore >/dev/null; diff -u /tmp/$$m.gitignore.bak ../$$m/.gitignore && echo "up to date: $$m" || true; mv /tmp/$$m.gitignore.bak ../$$m/.gitignore; } || echo "skip: ../$$m/.gitignore not found"; \
45+
done

‎REPO-LAYOUT.md‎

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -178,46 +178,21 @@ an agent or human runs by hand. Makefile targets wrap these.
178178

179179
## 4. Standard `.gitignore`
180180

181-
Tribulation's is the baseline; add the planning/AI local-state entries:
182-
183-
```gitignore
184-
# gradle
185-
.gradle/
186-
build/
187-
out/
188-
classes/
189-
190-
# loom dev runtime
191-
run/
192-
mods/
193-
logs/
194-
config/
195-
196-
# IDE
197-
.idea/
198-
*.iml
199-
*.ipr
200-
*.iws
201-
.settings/
202-
.vscode/
203-
.classpath
204-
.project
205-
*.launch
206-
207-
# local AI / planning state
208-
.claude/settings.local.json
209-
.claude/projects/
210-
.claude/scheduled_tasks.lock
211-
.plan/
212-
213-
# OS junk
214-
.DS_Store
215-
Thumbs.db
216-
217-
# stray runtime artifacts
218-
replay_pid*.log
219-
hs_err_pid*.log
220-
```
181+
The common ignores are a Concord-owned managed region, synced from concord's
182+
[`gitignore-common`](gitignore-common) into each member's `.gitignore` (between
183+
`# concord:gitignore:start` / `# concord:gitignore:end`) by `propagate.yml` — the
184+
same mechanism as the `AGENTS.md` regions. Edit the shared list in
185+
`gitignore-common`, never in a mod repo; put repo-specific ignores **outside** the
186+
marker block, where the sync never touches them. A member opts in by carrying the
187+
marker pair once (`make gitignore-sync` from concord seeds and refreshes siblings
188+
checked out as `../<member>`).
189+
190+
**Defensive anchoring.** Every ignore whose name could collide with a source,
191+
package, or resource directory — `build out bin classes net .gradle run mods logs
192+
config _site .plan` — is anchored with a leading `/` so it matches only at repo
193+
root, never a nested dir like `src/.../config/`. An unanchored `config/` silently
194+
swallows a Java package of that name. Genuinely global junk (IDE/OS files,
195+
`*.iml`, JVM crash dumps) stays unanchored so it is caught at any depth.
221196

222197
---
223198

‎gitignore-common‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Concord — shared .gitignore region (Concord-owned).
2+
#
3+
# The block between the concord:gitignore markers below is synced verbatim into
4+
# each member repo's .gitignore by propagate.yml (via inject-agents-regions.py).
5+
# Edit the shared ignores HERE, never in a mod repo. Lines OUTSIDE the markers in
6+
# a member .gitignore are repo-owned and never touched by the sync; a member opts
7+
# in by carrying the marker pair once.
8+
#
9+
# Defensive anchoring: every ignore whose name could collide with a source,
10+
# package, or resource directory is anchored with a leading "/" so it only
11+
# matches at repo root — never a nested dir like src/.../config/. Genuinely
12+
# global junk (IDE/OS files, JVM crash dumps) stays unanchored so it is caught
13+
# at any depth.
14+
15+
# concord:gitignore:start
16+
# Concord-managed — synced from concord; edit there, not here. Root-only build,
17+
# runtime, and tooling artifacts are anchored with a leading "/" so they can
18+
# never match a nested package/resource directory of the same name. Put
19+
# repo-specific ignores OUTSIDE this block.
20+
21+
# Gradle / compile output
22+
/.gradle/
23+
/build/
24+
/out/
25+
/bin/
26+
/classes/
27+
/net/
28+
29+
# Loom dev runtime
30+
/run/
31+
/mods/
32+
/logs/
33+
/config/
34+
35+
# Generated website (concord template)
36+
/_site/
37+
38+
# Local AI / planning state
39+
/.plan/
40+
.claude/settings.local.json
41+
.claude/projects/
42+
.claude/scheduled_tasks.lock
43+
44+
# IDE / editor (global — these names never collide with a source dir)
45+
.idea/
46+
.vscode/
47+
.settings/
48+
.classpath
49+
.project
50+
*.iml
51+
*.ipr
52+
*.iws
53+
*.launch
54+
55+
# OS junk
56+
.DS_Store
57+
Thumbs.db
58+
59+
# JVM crash dumps & loom dev-runtime logs (never source; match anywhere)
60+
hs_err_pid*.log
61+
replay_pid*.log
62+
gametest_output.log
63+
# concord:gitignore:end

‎scripts/inject-agents-regions.py‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/usr/bin/env python3
2-
"""Sync Concord-owned regions into a member repo's AGENTS.md.
2+
"""Sync a Concord-owned region from a source file into a target file.
33
4-
Reads the canonical region bodies from AGENTS-COMMON.md (the text between each
5-
`<!-- concord:NAME:start -->` / `<!-- concord:NAME:end -->` pair) and replaces
6-
the matching region in the target AGENTS.md, leaving everything outside the
7-
markers — and the marker lines themselves — untouched.
4+
Reads the canonical region bodies from a source (the text between each
5+
`concord:NAME:start` / `concord:NAME:end` marker pair) and replaces the matching
6+
region in the target, leaving everything outside the markers — and the marker
7+
lines themselves — untouched.
8+
9+
Markers may be written in either comment style, so one script serves both
10+
Markdown (AGENTS.md) and hash-comment files (.gitignore, YAML):
11+
12+
<!-- concord:NAME:start --> | # concord:NAME:start
13+
... | ...
14+
<!-- concord:NAME:end --> | # concord:NAME:end
815
916
A region is only written if the target already carries BOTH markers, so this is
1017
inert on a repo that hasn't opted in; seeding the markers once is the per-repo
1118
opt-in. Idempotent: re-running with no upstream change rewrites nothing.
1219
13-
python3 scripts/inject-agents-regions.py <regions-source> <target-agents-md>
20+
python3 scripts/inject-agents-regions.py <regions-source> <target-file>
1421
1522
Exit status: 0 and prints "changed" if the target was modified, "unchanged"
1623
otherwise; 2 on a malformed region source. Used by propagate.yml and for the
@@ -22,17 +29,26 @@
2229
import re
2330
import sys
2431

32+
# A start/end marker in either comment style. The `<!--`/`-->` wrappers are
33+
# optional so the same pattern matches both Markdown and hash-comment files.
34+
_OPEN = r"(?:<!--[ \t]*|#[ \t]*)"
35+
_CLOSE = r"(?:[ \t]*-->)?"
36+
37+
38+
def _start(name: str) -> str:
39+
return _OPEN + r"concord:" + name + r":start" + _CLOSE
40+
2541

26-
def _markers(name: str) -> tuple[str, str]:
27-
return f"<!-- concord:{name}:start -->", f"<!-- concord:{name}:end -->"
42+
def _end(name: str) -> str:
43+
return _OPEN + r"concord:" + name + r":end" + _CLOSE
2844

2945

3046
def parse_regions(source: str) -> dict[str, str]:
3147
"""Map region name -> inner body (exclusive of the marker lines)."""
3248
pattern = re.compile(
33-
r"<!-- concord:(?P<name>[a-z0-9-]+):start -->\n"
49+
_OPEN + r"concord:(?P<name>[a-z0-9-]+):start" + _CLOSE + r"\n"
3450
r"(?P<body>.*?)"
35-
r"\n<!-- concord:(?P=name):end -->",
51+
r"\n" + _OPEN + r"concord:(?P=name):end" + _CLOSE,
3652
re.DOTALL,
3753
)
3854
regions = {m.group("name"): m.group("body") for m in pattern.finditer(source)}
@@ -47,16 +63,19 @@ def inject(target: str, regions: dict[str, str]) -> tuple[str, list[str], list[s
4763
applied, skipped = [], []
4864
out = target
4965
for name, body in regions.items():
50-
start, end = _markers(name)
51-
if start not in out or end not in out:
52-
skipped.append(name)
53-
continue
54-
# Replace whatever sits between the marker lines with the canonical body,
55-
# preserving the markers and a single blank-free newline boundary.
66+
# Match the marker pair in the target and capture the actual marker lines
67+
# (whatever comment style they use) so they are preserved verbatim.
5668
block = re.compile(
57-
re.escape(start) + r"\n.*?\n" + re.escape(end), re.DOTALL
69+
r"(?P<start>" + _start(re.escape(name)) + r")\n"
70+
r".*?\n"
71+
r"(?P<end>" + _end(re.escape(name)) + r")",
72+
re.DOTALL,
5873
)
59-
out = block.sub(f"{start}\n{body}\n{end}", out, count=1)
74+
m = block.search(out)
75+
if m is None:
76+
skipped.append(name)
77+
continue
78+
out = out[: m.start()] + f"{m.group('start')}\n{body}\n{m.group('end')}" + out[m.end() :]
6079
applied.append(name)
6180
return out, applied, skipped
6281

‎scripts/open-sync-pr.sh‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#
1010
# Concord-owned payloads synced here:
1111
# - everything under propagate/ (e.g. .github/ISSUE_TEMPLATE/*.yml)
12-
# - AGENTS.md, but only its <!-- concord:* --> regions, and only if the member
13-
# already carries the markers (unseeded repos are left untouched).
12+
# - AGENTS.md and .gitignore, but only their concord:* regions, and only if the
13+
# member already carries the markers (unseeded repos are left untouched).
1414
#
1515
# Usage: scripts/open-sync-pr.sh <owner/repo>
1616
# Env: GH_TOKEN with Contents: write + Pull requests: write on the member.
@@ -48,6 +48,17 @@ if agents=$(gh api "repos/$REPO/contents/AGENTS.md?ref=$DEFAULT" 2>/dev/null) \
4848
fi
4949
fi
5050

51+
# 3) .gitignore region — same treatment as AGENTS.md (markers in hash-comment form).
52+
if gitignore=$(gh api "repos/$REPO/contents/.gitignore?ref=$DEFAULT" 2>/dev/null) \
53+
&& [ "$(printf '%s' "$gitignore" | jq -r '.encoding // empty')" = "base64" ]; then
54+
printf '%s' "$gitignore" | jq -r '.content' | base64 -d > "$work/.gitignore"
55+
if python3 scripts/inject-agents-regions.py gitignore-common "$work/.gitignore"; then
56+
DESIRED[".gitignore"]="$work/.gitignore"
57+
else
58+
echo " warn: skipping .gitignore for $REPO (inject failed)" >&2
59+
fi
60+
fi
61+
5162
# Which desired files actually differ from the default branch?
5263
changed=()
5364
declare -A BASE_SHA
@@ -92,7 +103,7 @@ existing=$(gh pr list -R "$REPO" --head "$BRANCH" --state open --json number -q
92103
if [ -z "$existing" ]; then
93104
gh pr create -R "$REPO" --base "$DEFAULT" --head "$BRANCH" \
94105
--title "chore: sync concord-owned files" \
95-
--body "Automated sync from concord@$SHORT (issue templates, AGENTS.md shared regions). Generated by propagate.yml — merge to adopt; the branch refreshes on each concord change."
106+
--body "Automated sync from concord@$SHORT (issue templates, AGENTS.md + .gitignore shared regions). Generated by propagate.yml — merge to adopt; the branch refreshes on each concord change."
96107
echo "$REPO: opened PR"
97108
else
98109
echo "$REPO: refreshed existing PR #$existing"

0 commit comments

Comments
 (0)