tools.limbic_chart module

Chart Stargazer’s limbic vectors over time.

Reads from the mementropic limbic ledger (Redis ZSETs in DB0) and produces Plotly line charts of NCM node values with datetime axes.

Supports per-channel scoping and global heart history.

async tools.limbic_chart.run(scope='channel', channel_id='', nodes='', hours=24.0, chart_type='line', ctx=None)[source]

Chart Stargazer’s NCM limbic vectors over time and save the image to disk.

The limbic_chart tool handler. It reads the mementropic limbic ledger for the requested scope (this channel, or the global __heart__ history) over a time window, selects which NCM nodes to plot (an explicit list, or the top five most volatile by standard deviation), renders a dark-themed Plotly line/area chart, exports it to a PNG file in a temp directory, and returns that path plus plotting metadata. The hours window is clamped to [0.5, 168].

Interactions: obtains the DB0 client via _get_db0_client() and reads the ledger ZSET with ZRANGEBYSCORE keyed by redis_ledger_key; imports canonical_ncm_keys / redis_ledger_key / _parse_ledger_member from mementropic.limbic_ledger to decode each ledger member into a (timestamp, vector) pair; builds the figure with Plotly graph_objects and rasterizes it via fig.to_image offloaded with asyncio.to_thread(); writes the PNG to a tempfile.mkdtemp() directory; serializes its result with json.dumps. Missing Plotly/kaleido or any render error is caught and logged. Dispatched by name through tool_loader from this module’s TOOL_NAME/run single-tool definition; no direct Python callers.

Parameters:
  • scope (str) – "channel" for this channel’s shard history, or "heart" for the global heart history. Defaults to "channel".

  • channel_id (str) – Override channel id; defaults to ctx.channel_id.

  • nodes (str) – Comma-separated NCM node names to plot; when empty, the top five most volatile nodes are auto-selected.

  • hours (float) – Time window in hours (clamped to [0.5, 168]); defaults to 24.

  • chart_type (str) – "line" (default), "area", or "radar".

  • ctx (ToolContext | None) – The tool context supplying Redis (DB0) and the channel id; None yields an error JSON.

Returns:

JSON; on success includes chart_path, scope, channel_id, nodes_plotted, data_points, and a time_range; otherwise {"success": False, "error": ...} (no context/channel/Redis, no ledger data, unknown node names, missing dependency, or render failure).

Return type:

str