Skip to main content

Module introspect

Module introspect 

Source
Expand description

Cognition introspection — proves that each scientific subsystem is wired and actually active at runtime.

The Cognition v2 stack (power-law decay, Hebbian eviction, global-workspace ignition, replay consolidation, FEP prefetch, immune detection, …) is only useful if it is genuinely reached on the hot path — not dead code. Every subsystem calls tick at its real call site; flush persists the counters to a small JSON file so a separate process (lean-ctx introspect cognition) can report, per subsystem: wired (present in this build), active (call count > 0), last-run, and total count.

Determinism note (#498): this is diagnostic CLI output, never an MCP tool body, so wall-clock timestamps here do not affect provider prompt caching.

Structs§

Activity
Persisted activity record for a single subsystem.
Subsystem
One cognition subsystem in the activation registry. key is the stable identifier passed to tick; label/science are for human-readable reports only.

Constants§

SUBSYSTEMS
The full set of Cognition v2 subsystems that must be wired and active. Order is the natural reading order for the report (foundation → experiment).

Functions§

flush
Persist in-memory deltas to the shared JSON file (delta-merge so multiple processes accumulate). Best-effort: failures are swallowed — diagnostics must never break the hot path.
flush_if_due
Debounced flush: persists at most once per FLUSH_DEBOUNCE. Safe to call from post_dispatch on every tool call.
format_report
Render a human-readable cognition activity report.
snapshot
Snapshot of all known subsystems merged with persisted activity, for the in-process and CLI reports. Reads disk and overlays unflushed in-memory deltas so a freshly-active subsystem shows up even before the next flush.
snapshot_json
Machine-readable variant for --json.
tick
Record one activation of key. Cheap (one mutex + map update); call this at the real call site of each subsystem so the registry reflects reality.