Commit ff376ad
perf(templates): mtime-aware caches for cross_links + parsed templates (#5)
* fix(prefixes): add `gui` mapping for `guide` template kind
The schema in attune-rag has carried `guide` in the type enum since
v1, but `attune-help`'s prefix maps had no entry for it. A new
`type: guide` template would have been silently dropped from
cross-linking (`_find_template_file` would return None for any
`gui-*` id; `_COMPOUND_PREFIXES` would not match a `gui-` template
during retrieval ranking).
Found while resolving an open question in the template-corpus-tidy
spec — the spec asked which prefix `quickstart` should use, and the
answer was already-correct (`qui`). The investigation surfaced the
`guide` gap as a sibling problem.
Changes:
- `templates._PREFIX_MAP` gains `"gui": "guides"`. Map reordered
alphabetically; behaviour unchanged.
- `progression._COMPOUND_PREFIXES` gains `"gui-"`. Order tweaked so
the base prefixes are alphabetical (compounds for ref/tas/con
stay first per the longest-first contract documented in the
comment above the list).
- New `tests/test_template_prefixes.py` (4 tests) pins both maps
against the expected enum and explicitly asserts `qui` and `gui`.
Future schema-enum additions will fail this test until both maps
are updated, surfacing the kind of silent drop this commit fixes.
The schema enum lives in attune-rag and the prefix maps live here.
The new test mirrors the enum as a literal set with a comment
pointing at the schema; introducing a runtime dep on attune-rag
would violate ADR-002 (attune-help ships with zero required deps
beyond python-frontmatter).
250 attune-help tests pass; ruff clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* perf(templates): mtime-aware caches for cross_links + parsed templates
Two related fixes from code-review 2026-05-07:
1. ``_load_cross_links`` cached cross_links.json by directory path
alone — no mtime check. Long-running processes served stale data
after a regen until callers remembered to invoke
``invalidate_cross_links_cache``. Switch the cache key to include
``st_mtime_ns`` so file rewrites invalidate themselves.
2. ``_parse_template_file`` had no cache at all. Every ``populate()``
call re-read and re-parsed the .md (frontmatter + section split).
Add a module-level ``(path, mtime_ns) -> parsed_dict`` cache with a
thread lock. Same self-invalidating mtime model as #1.
Also expose ``invalidate_template_cache()`` for symmetry with the
existing ``invalidate_cross_links_cache()`` — useful for tests and
hard-reset scenarios; not needed for normal file edits.
Tests: 8 new in test_cross_links_cache.py covering first-call load,
mtime-stable cache hit, mtime-change reload, missing-file no-cache,
manual invalidation. Tests use ``os.utime`` to bump mtime explicitly
because macOS HFS+ stores 1s-resolution mtimes and naive rewrites in
the same second can otherwise look unchanged.
258 passed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent aadcdcd commit ff376ad
4 files changed
Lines changed: 350 additions & 22 deletions
File tree
- src/attune_help
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
86 | 88 | | |
87 | | - | |
88 | | - | |
89 | 89 | | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
92 | 94 | | |
93 | | - | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
| |||
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
34 | 52 | | |
35 | 53 | | |
36 | 54 | | |
| |||
78 | 96 | | |
79 | 97 | | |
80 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
81 | 104 | | |
| 105 | + | |
| 106 | + | |
82 | 107 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 108 | | |
| 109 | + | |
88 | 110 | | |
89 | 111 | | |
90 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
91 | 115 | | |
92 | | - | |
| 116 | + | |
93 | 117 | | |
94 | 118 | | |
95 | 119 | | |
| |||
132 | 156 | | |
133 | 157 | | |
134 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
135 | 165 | | |
136 | 166 | | |
137 | 167 | | |
138 | 168 | | |
139 | 169 | | |
140 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
141 | 185 | | |
142 | 186 | | |
143 | 187 | | |
| |||
170 | 214 | | |
171 | 215 | | |
172 | 216 | | |
173 | | - | |
| 217 | + | |
174 | 218 | | |
175 | 219 | | |
176 | 220 | | |
| |||
182 | 226 | | |
183 | 227 | | |
184 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
185 | 233 | | |
186 | 234 | | |
187 | 235 | | |
| |||
190 | 238 | | |
191 | 239 | | |
192 | 240 | | |
193 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
194 | 249 | | |
195 | 250 | | |
196 | 251 | | |
| |||
199 | 254 | | |
200 | 255 | | |
201 | 256 | | |
202 | | - | |
203 | | - | |
204 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
205 | 267 | | |
206 | | - | |
207 | | - | |
208 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
209 | 272 | | |
210 | 273 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 274 | + | |
216 | 275 | | |
217 | 276 | | |
218 | 277 | | |
219 | 278 | | |
220 | 279 | | |
221 | 280 | | |
| 281 | + | |
| 282 | + | |
222 | 283 | | |
223 | 284 | | |
224 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments