Skip to content

Commit 57087cd

Browse files
author
Test User
committed
docs(agents): expand terraphim-grep examples with role-based thesaurus and maintenance refs #3025
1 parent 9a694dd commit 57087cd

1 file changed

Lines changed: 52 additions & 4 deletions

File tree

AGENTS.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ directory-`path`-filter bug (returns nothing for directory paths; tracked at
8484

8585
### Content Search (find text inside files)
8686

87-
Use `terraphim-grep` via Bash:
87+
Use `terraphim-grep` via Bash. It is installed with the `code-search` feature by default
88+
and works without a thesaurus in search-only mode.
8889

8990
```bash
9091
# Search code for a symbol (works without a thesaurus)
@@ -97,9 +98,56 @@ terraphim-grep "DeviceStorage::init" --haystack code -C 3
9798
terraphim-grep "haystack" --haystack code --paths terraphim_server/src/
9899
```
99100

100-
`terraphim-grep` is installed with the `code-search` feature by default and is always
101-
available at `~/.cargo/bin/terraphim-grep` or on `$PATH` after `cargo install`. It works
102-
without a thesaurus in search-only mode.
101+
### Role-based search with a project thesaurus
102+
103+
For KG-boosted ranking, keep a project-level `.terraphim/` directory in the repo root.
104+
terraphim-grep auto-discovers `.terraphim/thesaurus-<role>.json`.
105+
106+
```bash
107+
# Use an explicit thesaurus
108+
terraphim-grep "session persistence" --paths . --thesaurus .terraphim/thesaurus.json -n 8 -C 2
109+
110+
# Structured output with concepts and boost scores
111+
terraphim-grep "provider" --paths . --thesaurus .terraphim/thesaurus.json --json
112+
```
113+
114+
Concept markdown format (`.terraphim/kg/<concept>.md`):
115+
116+
```markdown
117+
# Provider
118+
119+
Abstract LLM backend implementing the Provider trait.
120+
121+
synonyms:: provider, llm backend, anthropic, openai, gemini, cohere, azure, bedrock, vertex, copilot, kimi
122+
```
123+
124+
Generate `.terraphim/thesaurus.json` from `kg/*.md`:
125+
126+
```bash
127+
python3 - <<'PY'
128+
import os, json, glob
129+
data, cid = {}, 100
130+
for f in sorted(glob.glob(".terraphim/kg/*.md")):
131+
nterm = os.path.splitext(os.path.basename(f))[0]
132+
txt = open(f, encoding="utf-8").read()
133+
syn = next((l.split("::",1)[1] for l in txt.splitlines()
134+
if l.strip().lower().startswith("synonyms::")), "")
135+
for t in dict.fromkeys([nterm] + [s.strip().lower() for s in syn.split(",") if s.strip()]):
136+
data.setdefault(t.lower(), {"id": cid, "nterm": nterm})
137+
cid += 1
138+
json.dump({"name": "Project Engineer", "data": data}, open(".terraphim/thesaurus.json","w"), indent=2)
139+
PY
140+
```
141+
142+
### Maintaining the thesaurus
143+
144+
1. Keep `kg/*.md` in version control.
145+
2. Regenerate `thesaurus.json` after any concept or code-identifier change.
146+
3. Enrich concepts with real code anchors mined by ast-grep (struct/trait/impl names).
147+
4. Use name-based mapping rules and avoid file-wide catch-alls that add noise.
148+
149+
Full details and a working enrichment loop are in `docs/terraphim-grep-offline-setup.md`
150+
and the `terraphim-grep-offline` skill.
103151

104152
### File-Name Lookup (find files by name/pattern)
105153

0 commit comments

Comments
 (0)