Central Intelligence Unit (CIU)¶
Status¶
The Central Intelligence Unit (CIU) is under active development.
This document describes the current design and behavior so future threads can extend CIU (e.g., CIU terminal, filters) and then update this doc accordingly.
High‑Level Design¶
- CIU core (
CIU) - Central collection point for structured system events (“reports”) coming from CIU officers.
- Applies routing policy based on subsystem and severity, then forwards reports to output sinks (currently the main terminal only).
-
Owns severity and subsystem color themes for a consistent visual log style.
-
Report structure (
CIUReport) - Represents a single event: core fields (severity, subsystem, code, message) plus optional metadata key–value pairs.
-
Metadata is stored in
HashMap<const char*, const char*>from the DracOS data structures library for flexible tagging and later analysis. -
Officer abstraction (
CIUOfficer) - Lightweight adapter that subsystems instantiate with their identity (e.g.,
"SHELL","NETWORK"). - Provides convenience methods for emitting warnings/errors/etc. without repeating boilerplate at call sites.
-
Builds
CIUReportobjects and forwards them to CIU core. -
Output sinks
- Main terminal sink: formats and prints CIU reports to the active terminal using existing colored
printfutilities. - CIU terminal sink: planned; routing flags already support sending events to a dedicated CIU debug terminal in the future.
CIUReport¶
Responsibilities¶
- Capture the essential structure of a single CIU event:
- Severity and subsystem identity.
- A short, stable code for the event.
- A human‑readable message.
- Provide an optional metadata map for richer tagging and debugging context.
- Support low‑boilerplate enrichment at call sites (chainable
metacalls).
Structure¶
CIUReport is a simple data class:
- Core fields (required):
CIUSeverity severity- Enum:
Trace,Info,Warning,Error,Critical.
- Enum:
const char* subsystem- Subsystem identity (e.g.,
"SHELL","NETWORK","KERNEL").
- Subsystem identity (e.g.,
const char* code- Stable identifier string (e.g.,
"NETWORK_NOT_INITIALIZED","SHELL_NOT_INITIALIZED").
- Stable identifier string (e.g.,
-
const char* message- Short human‑readable description.
-
Metadata (optional):
HashMap<const char*, const char*> metadata;-
Used for arbitrary tags such as:
PHASE–"boot","runtime","shutdown".CATEGORY–"init","io","config","logic".MODULE– usually__FILE_NAME__.FUNCTION– usually__func__.- Additional keys as needed per subsystem.
-
Builder helper:
CIUReport& meta(const char* key, const char* value);- Inserts the key–value pair into
metadataand returns*thisfor chaining.
- Inserts the key–value pair into
Example (network dependency failure in CommandRegistry):
CIUReport report(CIUSeverity::Warning,
"SHELL",
"NETWORK_NOT_INITIALIZED",
"NETWORK COMMANDS UNAVAILABLE");
report.meta("PHASE", "boot")
.meta("CATEGORY", "init")
.meta("MODULE", __FILE_NAME__)
.meta("FUNCTION", __func__);
// officer.send(report);
This produces a structured event with a stable code and a set of tags describing where and when it happened.
CIUOfficer¶
Role¶
- Acts as a middleman between subsystems and CIU core.
- Encapsulates the subsystem identity so call sites do not repeat it.
- Offers simple, one‑line helpers for common severities, plus a
sendmethod for fully customized reports.
Structure and usage¶
- Construction:
-
Each subsystem creates its own static officer with a chosen identity:
-
Main entrypoint:
-
void send(CIUReport& report);- Takes a pre‑built report (with metadata if needed) and forwards it to CIU core (
CIU::Report).
- Takes a pre‑built report (with metadata if needed) and forwards it to CIU core (
-
Convenience methods:
void trace(const char* code, const char* message);void info(const char* code, const char* message);void warning(const char* code, const char* message);void error(const char* code, const char* message);void critical(const char* code, const char* message);- Each helper:
- Constructs a
CIUReportwith the officer’ssubsystemand the given code/message. - Calls
send(report)internally.
- Constructs a
Example (simple warning without metadata):
Example (warning with metadata):
CIUReport report(CIUSeverity::Warning,
"SHELL",
"NETWORK_NOT_INITIALIZED",
"NETWORK COMMANDS UNAVAILABLE");
report.meta("PHASE", "boot")
.meta("CATEGORY", "init");
officer.send(report);
CIU Core¶
Responsibilities¶
- Initialize CIU internal state (
Init()/IsReady()). - Accept reports from officers (
Report(const CIUReport&)). - Resolve routing policies based on subsystem and severity.
- Delegate rendering to sinks (currently main terminal only).
Initialization and lifecycle¶
CIU::Init():- Called from
kernelMainafter the heap is initialized and before subsystems start logging. - Sets up:
- Default routing table (severity → sinks).
- Severity color map.
- Subsystem color map.
-
Sets
CIU::ready = true. -
CIU::IsReady(): - Returns whether CIU initialization has completed.
If a report arrives before CIU is ready, CIU emits a fallback message to the main terminal indicating that CIU is not ready and prints the code/message.
Routing policy¶
- Routing table:
- Backed by
HashMap<uint32_t, CIURouteFlags> routingMap;. - Keys are derived from
(subsystem, severity)viaMakeRouteKey(subsystem, severity). -
Values are
CIURouteFlags:bool toMainTerminal;bool toCIUTerminal;(reserved for future CIU terminal).
-
Default severity policy (via wildcard
"*"subsystem): Trace→ CIU terminal only (planned).Info→ CIU terminal only (planned).Warning→ main terminal + CIU terminal.Error→ main terminal + CIU terminal.-
Critical→ main terminal + CIU terminal. -
Resolution:
- For a given report:
- Look up a subsystem‑specific rule
(subsystem, severity). - If none exists, fall back to wildcard rule
("*", severity). - If no rule is found at all, default to “no sinks”.
- Look up a subsystem‑specific rule
This makes it easy to adjust behavior per subsystem or per severity without touching call sites.
Color theming¶
- Severity colors:
HashMap<uint8_t, CIUColor> colorMap;-
Maps
CIUSeverityvalues to foreground/backgroundVGAColorpairs. -
Subsystem colors:
HashMap<uint32_t, CIUColor> subsystemColorMap;- Maps hashed subsystem names to a distinct accent color.
Both maps are set up in SetupDefaultColors() so the visual theme is centralized and easy to tweak.
Main Terminal Output¶
Format¶
The main terminal sink prints CIU reports in a compact tagged format:
- Header:
[SUBSYSTEM]– colored using the subsystem accent.[SEVERITY]– colored using the severity color.MESSAGE– printed in severity color.-
(CODE)– printed in a neutral label color. -
Metadata (if present):
-
Printed on one or more lines below the header as key–value pairs.
-
For example (one key per line style):
-
Keys and values come from the report’s
metadatamap usingGetKeys/Get.
Example: missing network dependency¶
When CommandRegistry::ValidateNetworkDependencies() fails due to a missing "NET.ICMP" dependency:
- Subsystem prints a user‑facing message:
- CIU officer emits a structured report:
CIUReport report(CIUSeverity::Warning,
"SHELL",
"NETWORK_NOT_INITIALIZED",
"NETWORK COMMANDS UNAVAILABLE");
report.meta("PHASE", "boot")
.meta("CATEGORY", "init")
.meta("MODULE", __FILE_NAME__)
.meta("FUNCTION", __func__);
officer.send(report);
- CIU main terminal output:
[SHELL][WARNING] NETWORK COMMANDS UNAVAILABLE (NETWORK_NOT_INITIALIZED)
{PHASE=boot}
{CATEGORY=init}
{MODULE=commandregistry.cc}
{FUNCTION=ValidateNetworkDependencies}
This gives a quick visual clue plus precise context for debugging.
Invariants and Current Limitations¶
- CIU must be initialized after the heap and before subsystems start logging.
- Reports rely on stable
const char*strings forsubsystem,code, and metadata keys/values. - Routing currently only drives the main terminal; CIU terminal and other sinks are not implemented yet.
- Metadata ordering is not guaranteed beyond what is implemented in CIU (e.g., current behavior is based on iteration over the metadata map, possibly with simple sorting helpers).
- CIU does not yet:
- Persist logs beyond in‑memory terminal output.
- Perform rate limiting or deduplication.
- Support dynamic reconfiguration of routing or colors at runtime.
Future CIU threads may:
- Implement the dedicated CIU terminal and enable
toCIUTerminalrouting. - Add per‑subsystem log level controls.
- Introduce basic correlation IDs and higher‑level “intelligence summaries”.
- Extend metadata conventions and terminal formatting as more subsystems adopt CIU.