@theglitchking/babel-fish 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,7 +17,7 @@ from fnmatch import fnmatch
|
|
|
17
17
|
import re
|
|
18
18
|
import subprocess
|
|
19
19
|
import sys
|
|
20
|
-
from datetime import datetime
|
|
20
|
+
from datetime import datetime, timezone
|
|
21
21
|
from pathlib import Path
|
|
22
22
|
from typing import Any
|
|
23
23
|
|
|
@@ -34,6 +34,10 @@ MAP_DIR = SCRIPT_DIR
|
|
|
34
34
|
SECTIONS_DIR = MAP_DIR / "sections"
|
|
35
35
|
CHECKSUMS = MAP_DIR / "checksums.json"
|
|
36
36
|
LEARNED_VOC = MAP_DIR / "learned-vocabulary.json"
|
|
37
|
+
GLOSSARY = MAP_DIR / "glossary.json"
|
|
38
|
+
# Bump when the glossary.json shape changes. Consumers should refuse a major
|
|
39
|
+
# they do not recognise rather than guess.
|
|
40
|
+
GLOSSARY_SCHEMA_VERSION = "1.0"
|
|
37
41
|
|
|
38
42
|
# Resolve project root: two levels up from .claude/project-map/
|
|
39
43
|
PROJECT_ROOT = MAP_DIR.parent.parent
|
|
@@ -1452,6 +1456,50 @@ def build_doc_pointers_section() -> str:
|
|
|
1452
1456
|
return '\n'.join(lines) + '\n'
|
|
1453
1457
|
|
|
1454
1458
|
|
|
1459
|
+
# ── Glossary side-channel ─────────────────────────────────────────────────────
|
|
1460
|
+
|
|
1461
|
+
def _relative_source() -> str:
|
|
1462
|
+
vocab_md = SECTIONS_DIR / '01-vocabulary.md'
|
|
1463
|
+
try:
|
|
1464
|
+
return str(vocab_md.relative_to(PROJECT_ROOT))
|
|
1465
|
+
except ValueError:
|
|
1466
|
+
return str(vocab_md)
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
def write_glossary(vocab: list[dict], stack: dict) -> Path:
|
|
1470
|
+
"""Structured vocabulary for machine consumers.
|
|
1471
|
+
|
|
1472
|
+
01-vocabulary.md stays human-facing. Consumers read this instead of parsing
|
|
1473
|
+
prose: the markdown is a rendered table whose Notes column mixes
|
|
1474
|
+
descriptions with metadata and carries pipe-escaping (`a \\| b`), which is
|
|
1475
|
+
fine to read and hostile to parse.
|
|
1476
|
+
"""
|
|
1477
|
+
entries = [
|
|
1478
|
+
{
|
|
1479
|
+
'key': v.get('alias', ''),
|
|
1480
|
+
'canonical_path': v.get('location', ''),
|
|
1481
|
+
'section': v.get('type', ''),
|
|
1482
|
+
'description': v.get('notes', '') or None,
|
|
1483
|
+
}
|
|
1484
|
+
for v in sorted(vocab, key=lambda x: x.get('alias', ''))
|
|
1485
|
+
if v.get('alias')
|
|
1486
|
+
]
|
|
1487
|
+
payload = {
|
|
1488
|
+
'schema_version': GLOSSARY_SCHEMA_VERSION,
|
|
1489
|
+
'generated_at': datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
|
|
1490
|
+
# SECTIONS_DIR is bound to the script's location, which is not under
|
|
1491
|
+
# PROJECT_ROOT when --project-root points elsewhere. Report a relative
|
|
1492
|
+
# path when there is one, the absolute path otherwise.
|
|
1493
|
+
'source': _relative_source(),
|
|
1494
|
+
'project': stack.get('name', PROJECT_ROOT.name),
|
|
1495
|
+
'entry_count': len(entries),
|
|
1496
|
+
'entries': entries,
|
|
1497
|
+
}
|
|
1498
|
+
GLOSSARY.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + '\n',
|
|
1499
|
+
encoding='utf-8')
|
|
1500
|
+
return GLOSSARY
|
|
1501
|
+
|
|
1502
|
+
|
|
1455
1503
|
# ╔══════════════════════════════════════════════════════════════════════════╗
|
|
1456
1504
|
# ║ PROJECT MAP TOC ║
|
|
1457
1505
|
# ╚══════════════════════════════════════════════════════════════════════════╝
|
|
@@ -1622,6 +1670,9 @@ def main() -> None:
|
|
|
1622
1670
|
print("[generate] Building vocabulary...")
|
|
1623
1671
|
vocab = VocabularyBuilder().build(routes, models, schemas, features, stack, skills)
|
|
1624
1672
|
|
|
1673
|
+
glossary_path = write_glossary(vocab, stack)
|
|
1674
|
+
print(f"[generate] Glossary → {glossary_path.name} ({len(vocab)} entries)")
|
|
1675
|
+
|
|
1625
1676
|
print("[generate] Tracing import chains...")
|
|
1626
1677
|
chains = ImportChainTracer().trace(routes)
|
|
1627
1678
|
|
|
@@ -12,6 +12,7 @@ well-formedness; these measure usefulness.
|
|
|
12
12
|
from __future__ import annotations
|
|
13
13
|
|
|
14
14
|
import importlib.util
|
|
15
|
+
import pathlib
|
|
15
16
|
import shutil
|
|
16
17
|
import sys
|
|
17
18
|
import tempfile
|
|
@@ -173,6 +174,69 @@ def test_plugin_repo_map_is_not_empty(g):
|
|
|
173
174
|
assert "no vocabulary generated yet" not in section, "section 01 still renders the stub"
|
|
174
175
|
|
|
175
176
|
|
|
177
|
+
# ── Glossary side-channel (#10) ──────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
def test_glossary_json_written_and_shaped(g):
|
|
180
|
+
"""Consumers read this instead of parsing the markdown table."""
|
|
181
|
+
import json
|
|
182
|
+
skills = g.SkillParser().parse()
|
|
183
|
+
vocab = g.VocabularyBuilder().build([], [], [], [], g.load_stack(), skills)
|
|
184
|
+
path = g.write_glossary(vocab, g.load_stack())
|
|
185
|
+
assert path.exists(), "glossary.json not written"
|
|
186
|
+
data = json.loads(path.read_text())
|
|
187
|
+
|
|
188
|
+
for field in ("schema_version", "generated_at", "source", "project",
|
|
189
|
+
"entry_count", "entries"):
|
|
190
|
+
assert field in data, f"missing {field}: {sorted(data)}"
|
|
191
|
+
assert data["entry_count"] == len(data["entries"])
|
|
192
|
+
assert data["schema_version"].count(".") == 1, data["schema_version"]
|
|
193
|
+
|
|
194
|
+
for e in data["entries"]:
|
|
195
|
+
assert set(e) == {"key", "canonical_path", "section", "description"}, e
|
|
196
|
+
assert e["key"], e
|
|
197
|
+
keys = [e["key"] for e in data["entries"]]
|
|
198
|
+
assert keys == sorted(keys), "entries must be sorted by key"
|
|
199
|
+
assert len(keys) == len(set(keys)), "keys must be unique"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def test_glossary_source_path_is_real(g):
|
|
203
|
+
"""v1.0 of the contract named `.babel-fish/`, which was never written."""
|
|
204
|
+
import json
|
|
205
|
+
data = json.loads(g.write_glossary([], g.load_stack()).read_text())
|
|
206
|
+
assert ".babel-fish" not in data["source"], data["source"]
|
|
207
|
+
assert data["source"].endswith("01-vocabulary.md"), data["source"]
|
|
208
|
+
assert pathlib.PurePath(data["source"]).parent.name == "sections", data["source"]
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_glossary_values_are_unescaped(g):
|
|
212
|
+
"""The markdown table escapes pipes into values (`auto \\| nudge`). JSON
|
|
213
|
+
must carry the real string — that escaping is the clearest reason not to
|
|
214
|
+
parse the rendered table."""
|
|
215
|
+
import json
|
|
216
|
+
vocab = [{"alias": "policy", "type": "command", "location": "commands/policy.md",
|
|
217
|
+
"notes": "Get or set the policy (auto | nudge | off)"}]
|
|
218
|
+
data = json.loads(g.write_glossary(vocab, g.load_stack()).read_text())
|
|
219
|
+
assert data["entries"][0]["description"] == "Get or set the policy (auto | nudge | off)"
|
|
220
|
+
assert "\\|" not in data["entries"][0]["description"]
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_empty_glossary_is_valid(g):
|
|
224
|
+
"""An empty vocabulary is a valid glossary, not an error."""
|
|
225
|
+
import json
|
|
226
|
+
data = json.loads(g.write_glossary([], g.load_stack()).read_text())
|
|
227
|
+
assert data["entries"] == [] and data["entry_count"] == 0
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_glossary_survives_foreign_project_root(g):
|
|
231
|
+
"""SECTIONS_DIR is bound to the script location, which is NOT under
|
|
232
|
+
PROJECT_ROOT when --project-root points elsewhere. That combination raised
|
|
233
|
+
ValueError from relative_to()."""
|
|
234
|
+
import json
|
|
235
|
+
g.write_glossary([], g.load_stack()) # PROJECT_ROOT is the temp fixture here
|
|
236
|
+
data = json.loads(g.GLOSSARY.read_text())
|
|
237
|
+
assert data["source"].endswith("01-vocabulary.md"), data["source"]
|
|
238
|
+
|
|
239
|
+
|
|
176
240
|
def main() -> int:
|
|
177
241
|
tests = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
|
|
178
242
|
failed = []
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "Official marketplace for babel-fish - Codebase introspection and vocabulary translation for AI coding assistants",
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.4.0"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "babel-fish",
|
|
14
14
|
"description": "Auto-generates a project map, vocabulary translation layer, and developer skill for any codebase. Introspects routes, models, services, features, infrastructure, and session history to give Claude instant full-stack context. Self-updates via pre-commit hook.",
|
|
15
|
-
"version": "2.
|
|
15
|
+
"version": "2.4.0",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "TheGlitchKing"
|
|
18
18
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-fish",
|
|
3
3
|
"description": "Auto-generates a project map, vocabulary translation layer, and developer skill for any codebase. Introspects routes, models, services, features, infrastructure, and session history to give Claude instant full-stack context. Self-updates via pre-commit hook.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TheGlitchKing",
|
|
7
7
|
"email": "theglitchking@users.noreply.github.com"
|
package/.githooks/pre-commit
CHANGED
|
@@ -14,7 +14,8 @@ if echo "$STAGED_FILES" | grep -qE "$EXTENSIONS_PATTERN" 2>/dev/null; then
|
|
|
14
14
|
echo "[codebase-mapper] Regenerating project map..."
|
|
15
15
|
if $PYTHON "$MAP_SCRIPT" 2>/dev/null; then
|
|
16
16
|
git add .claude/project-map/PROJECT_MAP.md .claude/project-map/checksums.json \
|
|
17
|
-
.claude/project-map/sections/*.md .claude/project-map/learned-vocabulary.json
|
|
17
|
+
.claude/project-map/sections/*.md .claude/project-map/learned-vocabulary.json \
|
|
18
|
+
.claude/project-map/glossary.json 2>/dev/null || true
|
|
18
19
|
fi
|
|
19
20
|
fi
|
|
20
21
|
fi
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.4.0] - 2026-09-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **`glossary.json` — a structured vocabulary artifact for machine consumers**
|
|
10
|
+
([#10](https://github.com/TheGlitchKing/babel-fish/issues/10)). Written to
|
|
11
|
+
`.claude/project-map/glossary.json` on every map build and staged by the
|
|
12
|
+
pre-commit hook. Consumers read this instead of parsing `01-vocabulary.md`.
|
|
13
|
+
|
|
14
|
+
The markdown was never a good parsing target: its `Notes` column mixes
|
|
15
|
+
descriptions with metadata, and pipe-escaping leaks into values — this repo's
|
|
16
|
+
own output contained `(auto \| nudge \| off)`. The JSON carries the real
|
|
17
|
+
string.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- **The glossary contract described a format babel-fish has never emitted.**
|
|
22
|
+
`glossary-contract.md` v1.0 specified bullet entries
|
|
23
|
+
(`- **key** → \`path\` — desc`) and stated that non-conforming bullets are
|
|
24
|
+
ignored; the generator has always written a markdown table. A consumer built
|
|
25
|
+
strictly to that spec would extract **zero entries**. Rewritten (v2.0) around
|
|
26
|
+
`glossary.json`, with the markdown documented as human-facing output that is
|
|
27
|
+
not parsed.
|
|
28
|
+
|
|
29
|
+
- **Both sides of that contract documented a directory neither produces.** The
|
|
30
|
+
contract, the integration guide and the README referred to `.babel-fish/`;
|
|
31
|
+
babel-fish writes `.claude/project-map/`. The same error is mirrored in
|
|
32
|
+
semantic-memory's `smart-middle-activation.md` and `corpora-json.md`, where it
|
|
33
|
+
would have made Phase 3.1.0 find nothing — silently. Corrected here and filed
|
|
34
|
+
there as
|
|
35
|
+
[semantic-memory#28](https://github.com/the-glitch-kingdom/semantic-memory/issues/28).
|
|
36
|
+
|
|
37
|
+
- **`--project-root` crashed the generator.** `write_glossary()` computed the
|
|
38
|
+
source path with `SECTIONS_DIR.relative_to(PROJECT_ROOT)`, but `SECTIONS_DIR`
|
|
39
|
+
is bound to the script's own location, so pointing `--project-root` elsewhere
|
|
40
|
+
raised `ValueError`. Found by a test written for the new artifact.
|
|
41
|
+
|
|
42
|
+
- `integration-with-semantic-memory.md` no longer describes a setup that does
|
|
43
|
+
not exist. semantic-memory 1.5.1 ships no `translate` verbs, no `project-map`
|
|
44
|
+
corpus and no glossary reader; the guide now says so at the top instead of
|
|
45
|
+
giving instructions for it.
|
|
46
|
+
|
|
47
|
+
### Note
|
|
48
|
+
|
|
49
|
+
The consumer is unbuilt, so nothing was pinned to the old format. Issue #10
|
|
50
|
+
originally advised caution about "a breaking change to a format a downstream
|
|
51
|
+
consumer pins to" — checking semantic-memory's source showed zero
|
|
52
|
+
`translate`/`reverse_translate`/`list_vocabulary` verbs in its 164-entry tool
|
|
53
|
+
surface and no `glossary` string in `src/`. That freed the format choice
|
|
54
|
+
entirely.
|
|
55
|
+
|
|
5
56
|
## [2.3.0] - 2026-09-04
|
|
6
57
|
|
|
7
58
|
### Fixed
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://github.com/TheGlitchKing/babel-fish)
|
|
10
10
|
|
|
11
11
|
> [!NOTE]
|
|
12
|
-
> **Pairs with [`semantic-memory`](https://github.com/TheGlitchKing/semantic-sidekick) (formerly `semantic-sidekick`).** When both are installed, semantic-memory consumes babel-fish's auto-generated `.
|
|
12
|
+
> **Pairs with [`semantic-memory`](https://github.com/TheGlitchKing/semantic-sidekick) (formerly `semantic-sidekick`).** When both are installed, semantic-memory consumes babel-fish's auto-generated `.claude/project-map/` output as a `project-map` corpus AND reads the structured `glossary.json` babel-fish emits alongside it. That gives your AI a deterministic `translate("deals page") → "features/deal-pipeline/DealPipeline.tsx"` MCP verb instead of relying on semantic-search-luck. See [`.documentation/api/glossary-contract.md`](./.documentation/api/glossary-contract.md) for the producer/consumer data contract and [`.documentation/quickstart/integration-with-semantic-memory.md`](./.documentation/quickstart/integration-with-semantic-memory.md) for the setup walkthrough. babel-fish standalone behavior is unchanged — semantic-memory is purely additive.
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theglitchking/babel-fish",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Gives your AI coding assistant instant, accurate knowledge of every route, model, service, feature, and infrastructure element in your codebase.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|