Log Lens
by dbydd
README.md
# Log Lens (`agy-log-lens`)
English | [简体中文](README.zh-CN.md)
Interactive training log, Google Colab telemetry, and scientific experiment dashboard plugin (MCP App) for [Google Antigravity](https://antigravity.google).
Log Lens turns plain training logs, multi-stage `.live.json` / `*_results.json` snapshots, verification gate suites, and structured `@@` telemetry streams into faceted charts, pass/fail gate matrices, comparison tables, image previews, and searchable live tails inside Antigravity.

## Features
- **Tier 0 Zero-Intrusion Parsing**:
- **Training Logs (`*.log`)**: Extracts `ep X/Y` / `Epoch X/Y`, `[StageN X/Y]` progress offsets, inline `key=value` metrics (with scientific notation), throughput telemetry (`ms/step`, `tok/s`, `samples/s`), embedded JSON blocks (`[Init Val]`), `best=<val>@<step>`, and `[PASS]`/`[FAIL]`/`WARN`/`ERROR` events while filtering out dataset-count prose and checkpoint-resume noise.
- **Live & Multi-Stage JSON Snapshots (`*.live.json`, `*_results.json`)**: Automatically parses single-stage (`history`, `metrics`, `records`) and multi-stage (`stage2_history`, `stage3_history`) arrays, plus hierarchical verification suites (`checks`, `gates`, `all_passed`).
- **Google Colab Telemetry Pairing**: Pairs `cache/colab_tasks/<session>/job_<session>.log` with sibling `colab_job_status.json` to display GPU utilization, VRAM, power draw, `epoch_hint`, Drive sync status, and credential purge state.
- **Smart Auto-Faceting**: Separates `lr` onto its own log-scale facet, splits series whose magnitude differs by `>20x`, bounds correlation curves (`*_corr`, `*_r2`) to `[-1, 1]`, and highlights statistical spike anomalies in red.
- **Tier 1 `@@` Structured Telemetry Protocol**:
- Emit single-line `@@meta`, `@@metric`, `@@gate`, `@@table`, and `@@artifact` JSON records to `stdout` or `.exp.jsonl` / `.agvlog` files via the bundled zero-dependency Python helper [`helpers/python/agy_viz.py`](helpers/python/agy_viz.py).
- Unlocks target threshold bands, `bestStep` vertical markers, physical units, live upserted verification gates, highlighted baseline comparison tables, and inline diagnostic plots.
- **Four Antigravity UI Surfaces**:
- **Side Pane (`aux_pane`) & Full Page (`global`)** via `open_log_lens`: Multi-run overlay comparison (`comparePaths`), EMA smoothing slider, `Auto` / `Log-Y` / `Linear` scale toggle, drag-to-zoom, searchable log tail, and one-click **Send to Chat** (`updateModelContext`).
- **Inline Chat Card (`inline`)** via `preview_log_card`: Compact `<= 450px` summary card with sparklines, target badges, and gate counts.
- **Experiment File Viewer (`file`)** via `view_log_file`: Opens `*.agvlog` and `*.exp.jsonl` directly as interactive dashboards.
- **0-Token Incremental Live Polling**:
- Active/recent runs automatically start `2s` byte-cursor tailing via app-only `app_poll_source`, refreshing charts and Colab GPU telemetry without consuming LLM context tokens.
## Install
Prebuilt `dist/server.mjs` and self-contained `dist/app.html` are committed in the repository, so no Node build toolchain is required to install and use the plugin.
### Option 1: Install Globally
```bash
git clone https://github.com/dbydd/agy-log-lens.git ~/.gemini/config/plugins/log-lens
```
### Option 2: Sync into a Workspace
```bash
git clone https://github.com/dbydd/agy-log-lens.git
node agy-log-lens/scripts/sync-plugin.mjs --no-build /path/to/your/workspace
```
After installing, open **Customizations → Plugins** in Antigravity (or run `agy plugin list`) to verify `log-lens` is enabled.
## Usage
Ask Antigravity naturally, or let an agent invoke the MCP App tools directly:
| Tool | UI Surface | When to Use |
| :--- | :--- | :--- |
| `open_log_lens` | Side Pane / Full Page | Inspect the latest auto-discovered run (`{}`), watch a live Colab or local training log, or compare multiple runs (`comparePaths`). |
| `preview_log_card` | Inline Chat Card | Render a compact checkpoint summary with sparklines, min/max bounds, and gate statuses directly in chat. |
| `view_log_file` | File Viewer | Open `.agvlog` or `.exp.jsonl` files straight into the dashboard viewer. |
By default, Log Lens scans the active workspace under:
- `cache/colab_tasks/` & `cache/`
- `runs/`, `measured/`
- `artifacts/*/{measured,runs,cache,cache/colab_tasks}`
## Tier 1 `@@` Protocol & `agy_viz.py`
Drop [`helpers/python/agy_viz.py`](helpers/python/agy_viz.py) anywhere on your `PYTHONPATH` (or copy the single file into a Colab script — standard library only, Python 3.10+, duck-types PyTorch/NumPy scalars via `.item()`, and converts `NaN`/`Inf` to JSON `null`):
```python
from agy_viz import VizLogger
with VizLogger(
path="measured/run.exp.jsonl", # optional file output (also tees to stdout)
run="multiscale_v1",
stage="stage1",
x_key="epoch",
x_label="Epoch",
targets={
"val_rmse": {"lt": 0.15, "label": "Target < 0.15m"},
"ke_ratio": {"range": [0.85, 1.15], "label": "KE [0.85, 1.15]"},
},
units={"val_rmse": "m", "lr": "1"},
groups={"train_loss": "Loss", "val_rmse": "Validation"},
total_steps=60,
) as viz:
for ep in range(1, 61):
print(f"[Train] ep {ep}/60 loss={loss:.4f} val_rmse={rmse:.4f}", flush=True)
viz.metric(ep, train_loss=loss, val_rmse=rmse, lr=current_lr)
viz.gate("G1 Invariant Parity", passed=True, suite="Physics", value="1.9e-15", target="< 1e-12", step=60)
viz.table(
"Ablation Summary",
columns=["model", "val_rmse"],
rows=[{"model": "Baseline", "val_rmse": 0.24}, {"model": "Ours", "val_rmse": 0.11}],
highlight_best={"val_rmse": "min"},
)
viz.artifact("Rollout Error Field", "measured/rollout_ep60.png", step=60)
```
Or print raw `@@` protocol lines from any language:
```text
@@meta {"run":"exp1","xKey":"epoch","targets":{"val_rmse":{"lt":0.15}},"bestStep":40,"totalSteps":60}
@@metric {"step":1,"train_loss":0.245,"val_rmse":0.184,"lr":0.0003}
@@gate {"name":"Energy Conservation","status":"pass","pass":true,"suite":"G2","value":-0.03,"target":"< 0","step":1}
@@table {"title":"Baseline Comparison","columns":["model","val_rmse"],"rows":[{"model":"Baseline","val_rmse":0.24},{"model":"Ours","val_rmse":0.11}],"highlightBest":{"val_rmse":"min"}}
@@artifact {"label":"Rollout Error Map","path":"measured/rollout.png","step":40}
```
## Configuration
| Environment Variable | Description |
| :--- | :--- |
| `LOG_LENS_WORKSPACE` | Explicit workspace root used for automatic source discovery and relative path resolution (falls back to `AGY_WORKSPACE`, `AGY_WORKSPACE_ROOT`, `WORKSPACE_ROOT`, or `cwd`). |
| `LOG_LENS_EXTRA_ROOTS` | Optional delimiter-separated list (`:` on macOS/Linux, `;` on Windows) of external project/Drive roots scanned alongside the active workspace. |
| `COLAB_TASK_CACHE_DIR` | Optional extra directory scanned for `job_*.log` and `colab_job_status.json` Colab task sessions. |
## Development & Validation
Requires Node.js >= 20 and Python >= 3.10:
```bash
npm install
npm run typecheck
npm run build
npm test
npm run test:py
npm run validate
```
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues