gl_run — Code Mode
One tool. Runs sandboxed JavaScript. Calls every other Ganglia tool through typed wrappers. Collapses N sequential tool calls into a single MCP round trip.
Minimal example
Section titled “Minimal example”gl_run({ code: "return gl.code.overview()" })Real usage
Section titled “Real usage”gl_run({ code: ` // Find dead code that has no tests — 1 call instead of 50 const dead = gl.code.dead({}); const coverage = dead.map(fn => gl.code.test_for({ name: fn.name })); return dead.filter((_, i) => coverage[i].tests.length === 0);` })Server runs the chain internally. Only the final filtered list comes back.
The gl namespace
Section titled “The gl namespace”All wrappers are synchronous from JS. Group by domain:
| Namespace | Use for |
|---|---|
gl.code.* | The 45 core graph tools — grep, get, dead, callers, impact, etc. |
gl.code.semantic_search / similar | Embedding-based retrieval |
gl.doc.* | External document index (markdown, CSV, etc.) |
gl.smart.* | MemOS comprehension layer |
gl.deliberation.* | Expert panel multi-perspective synthesis |
gl.call(name, args) | Escape hatch for any registered MCP tool |
Full typed API: ganglia://types/api.d.ts (MCP resource).
When to use
Section titled “When to use”- 3+ sequential tool calls — the math overwhelmingly favors
gl_run - Filter/transform/aggregate before returning — don’t force intermediate results through your context
- Map-style operations — “for each X, compute Y” patterns
When NOT to use
Section titled “When NOT to use”- Single-shot lookup (
code_get,code_grepdirectly) - Exploratory — you need to see each result to decide the next step
- The chain needs real
awaiton network I/O (sandbox is sync only)
Sandbox guarantees
Section titled “Sandbox guarantees”| Limit | Value |
|---|---|
| Memory | 256 MB |
| Time | 30 s |
| Filesystem | blocked |
| Network | blocked |
| Process | blocked |
Recursive gl_run | blocked |
QuickJS embedded directly in the gl binary. No external runtime.
Typo recovery
Section titled “Typo recovery”Got the wrong method name? The Proxy wrapper shows you what’s available:
> gl.code.rgep({pattern: "foo"})Error: Unknown method gl.code.rgep — available: annotate, build, callees, callers, ..., grep, hotspots, ...And for gl.call(name):
> gl.call("code_rgep", {...})Error: Unknown tool: code_rgep (did you mean `code_grep`?)Benchmark
Section titled “Benchmark”On a 462-file Rust project, 5 multi-step workflows:
| Metric | Individual tools | gl_run | Reduction |
|---|---|---|---|
| Schema tokens | 6,376 | 575 | 91% |
| Wire tokens | 4,014 | 2,316 | 1.7× |
| Effective LLM context | 170,424 | 9,191 | 18.9× |
Run it on your own codebase: python3 scripts/benchmark_code_mode.py <path>
See also
Section titled “See also”- Semantic search — find code by meaning, returnable from
gl_run - Code Mode overview — deeper architecture notes