wf-agent2/AGENTS.md

52 KiB

Codex-ready implementation plan: Linux event agent with collectors, commands, in-memory cache, protobuf v1, CLI, TOML config, and outbound senders

0. Goal and scope

Build a lightweight Linux agent in Python that:

  • connects to multiple event sources through dedicated collectors;
  • keeps those connections healthy and reconnects when needed;
  • receives raw events from sources such as:
    • systemd journal,
    • D-Bus,
    • wpa_supplicant ctrl_iface,
    • navigation system adapters,
    • future source adapters;
  • runs a collector-local pipeline:
    • prefilter by configurable rules,
    • validation,
    • normalization to protobuf_v1,
    • marking with configurable metadata rules;
  • forwards normalized events to director;
  • stores events in a low-overhead bounded in-memory cache;
  • maintains an outbox queue for outbound delivery;
  • supports operator, scheduled, and derivator-initiated commands through a unified control plane;
  • optionally derives higher-level events from short time windows of raw events;
  • exposes CLI commands for:
    • component status,
    • connection state,
    • counters and statistics,
    • cache inspection,
    • outbox inspection,
    • command execution,
    • task scheduling and inspection,
    • config validation,
    • test sends and dry runs.

Platform:

  • Linux
  • Python

Configuration model:

  • environment variables in .env
  • static/runtime settings in TOML

Internal data contract:

  • Protocol Buffers v3

1. High-level architecture

Collectors
  ├─ JournalCollector
  ├─ DbusCollector
  ├─ WpaCtrlCollector
  ├─ NavigationCollector
  └─ Future collectors

Each collector:
  connect/health/reconnect
  -> prefilter
  -> validate
  -> normalize(proto v1)
  -> mark(enrich metainfo by rules)
  -> send EventEnvelope to Director

Control plane initiators
  ├─ CLI
  ├─ Scheduler
  └─ Derivator

All command initiators:
  -> CommandRequest
  -> Command Coordinator
  -> Executor Router
  -> Executors
  -> Command Result Event
  -> Director

Director
  -> route to Core Cache
  -> route to Outbox Queue
  -> signal Derivator interest

Core Cache
  -> bounded in-memory ring buffer
  -> lightweight secondary indexes

Derivator
  -> reads short event windows from cache
  -> emits derived EventEnvelope back into Director
  -> may emit CommandRequest to Command Coordinator

Senders
  -> read only from Outbox Queue
  -> apply sender-type behavior
  -> use configured transport backend

CLI
  -> status
  -> stats
  -> inspect cache
  -> inspect outbox
  -> execute commands
  -> inspect tasks
  -> config validation
  -> health and test operations

2. Core architectural principles

2.1 Lightweight runtime core

Do not use SQLite as the primary operational cache in v1.

Use instead:

  • bounded in-memory ring buffer for short-lived cache;
  • bounded outbox queue in memory;
  • optional future spill-to-disk only if later required.

2.2 One internal canonical schema

All collectors emit the same canonical message type:

  • EventEnvelope in protobuf v1.

Command execution results also enter the same canonical event flow through director.

2.3 Runtime efficiency

Inside the hot path:

  • keep a compact runtime EventRecord struct/object for cache;
  • use protobuf as the normalized contract at module boundaries and delivery boundary;
  • avoid repeated full serialize/deserialize on each internal hop.

2.4 Collector-centered ingestion

Collectors are responsible for:

  • source connection lifecycle;
  • source-specific decoding;
  • pipeline execution;
  • delivery of canonical normalized events into director.

2.5 Explicit boundedness

All queues and buffers must be bounded.

Every bounded component must define overflow policy.

2.6 Unified control plane

Commands must not be executed directly by CLI, scheduler, or derivator.

All commands must go through:

  • CommandRequest
  • CommandCoordinator
  • executor routing
  • executor execution
  • command result event emission

This guarantees uniform policy, observability, and conflict handling.


3. Collectors

3.1 Collector responsibilities

Each collector is an active component that:

  • initializes source-specific connection;
  • checks connection state;
  • maintains connection health;
  • reconnects with backoff when needed;
  • receives raw events;
  • applies pipeline stages;
  • emits normalized EventEnvelope objects to director.

Standard collector lifecycle

INIT
  -> CONNECTING
  -> CONNECTED
  -> RUNNING
  -> DEGRADED (optional)
  -> RECONNECTING
  -> STOPPING
  -> STOPPED

Standard collector interface

Each collector implementation should expose a uniform interface:

  • start()
  • stop()
  • health()
  • stats()
  • reload_config()
  • connection_state()
  • pipeline_state()

3.2 Collector pipeline

Pipeline stages are identical conceptually for all collectors.

Stage 1. Prefilter

Purpose:

  • drop noise as early as possible;
  • reduce CPU and memory load;
  • avoid polluting cache and outbox.

Examples:

  • journal: accept only selected _SYSTEMD_UNIT, _COMM, _EXE, severity ranges;
  • D-Bus: accept only selected bus/interface/member/path combinations;
  • wpa_ctrl: accept only selected event names;
  • navigation: accept only certain event classes or robot ids.

Stage 2. Validation

Purpose:

  • verify source event structure;
  • reject malformed or incomplete records;
  • optionally downgrade malformed events into error-class normalized events.

Examples:

  • required journal fields missing;
  • D-Bus message without expected signature;
  • malformed CTRL-EVENT-* line;
  • navigation payload missing timestamp or coordinate frame.

Stage 3. Normalization

Purpose:

  • convert source-specific raw event into canonical protobuf v1 envelope.

Result:

  • EventEnvelope with source-specific payload and normalized hot fields.

Stage 4. Marking

Purpose:

  • add metadata values by config rules;
  • assign routing marks, workflow marks, severity overrides, classification tags.

Examples:

  • add workflow_tags = ["wifi", "roaming"] for relevant events;
  • set routing.outbox_enabled = true for warning/error events;
  • attach site=warehouse-a, robot_group=amr-west, collector_profile=rf-monitoring.

3.3 JournalCollector

Responsibilities

  • connect to systemd journal reader;
  • seek from tail or configured mode;
  • optionally restore cursor in future versions;
  • filter entries by configured rules;
  • normalize to RawJournalPayload.

Example event types

  • linux.raw.journal.entry
  • wifi.raw.journal.wpa_supplicant
  • wifi.raw.journal.network_manager
  • system.raw.journal.service_error

Example prefilter rules

  • _SYSTEMD_UNIT in ["wpa_supplicant.service", "NetworkManager.service"]
  • _COMM in ["wpa_supplicant", "dhclient"]
  • priority <= warning

3.4 DbusCollector

Responsibilities

  • connect to system bus;
  • subscribe to selected signals;
  • maintain healthy bus connection;
  • normalize signal messages into RawDbusPayload.

Example subscriptions

  • fi.w1.wpa_supplicant1
  • NetworkManager interfaces
  • custom navigation service interfaces

Example prefilter rules

  • interface == fi.w1.wpa_supplicant1.Interface
  • member in [PropertiesChanged, ScanDone, BSSAdded]
  • object_path matches configured prefixes

3.5 WpaCtrlCollector

Responsibilities

  • connect to wpa_supplicant ctrl_iface unix socket;
  • attach to unsolicited events;
  • maintain connection and reconnect;
  • optionally query selected commands such as status, signal_poll, scan_results as telemetry collection actions if configured as collector behavior;
  • normalize ctrl events into RawWpaPayload.

Example source URIs

  • wpa-ctrl://wlan0
  • wpa-ctrl://wlp3s0

Example event types

  • wifi.raw.wpa.connected
  • wifi.raw.wpa.disconnected
  • wifi.raw.wpa.scan_results
  • wifi.raw.wpa.signal_poll

Example prefilter rules

  • accept only selected CTRL-EVENT-* names;
  • suppress duplicate signal_poll events below configured rate;
  • keep all disconnect/failure events.

3.6 NavigationCollector

Responsibilities

  • connect to navigation system through an adapter interface;
  • receive navigation/raw mobility events;
  • normalize to NavigationPayload.

Example event types

  • nav.raw.pose
  • nav.raw.route_progress
  • nav.raw.position_quality

Example marks

  • map robot_id to logical fleet;
  • add workflow_tags = ["navigation", "location-aware-derivation"].

3.7 Collector supervisor

Introduce a small collector supervisor that:

  • starts enabled collectors;
  • tracks per-collector state;
  • performs watchdog checks;
  • exposes health to CLI;
  • handles reloadable config where possible.

4. Commands

4.1 Command model

A command is an explicit control-plane object.

Recommended logical structure:

CommandRequest
--------------
command_id
command_type
origin_kind        # CLI / SCHEDULER / DERIVATOR
origin_id
target_kind
target_id
priority
deadline_mono_ns
exclusive_key
dedup_key
cooldown_key
args
correlation_id
causation_event_id

Commands are not passive events.

They are control requests that must be coordinated before execution.

4.2 Command classes

At minimum support three classes of command origin.

Operator commands

Originator:

  • CLI

Examples:

  • system.set_regdomain
  • wpa.deassociate
  • wpa.add_network

Scheduled commands

Originator:

  • scheduler

Examples:

  • periodic wpa.scan
  • periodic wpa.signal_poll
  • periodic wpa.status

Derived commands

Originator:

  • derivator

Examples:

  • initiate extra scan after anomaly detection;
  • request signal poll after selected event patterns;
  • initiate corrective action allowed by policy.

4.3 Command result model

Command execution outcomes must be emitted as canonical events.

Recommended canonical event types:

  • control.command.accepted
  • control.command.rejected
  • control.command.started
  • control.command.succeeded
  • control.command.failed
  • control.command.deferred
  • control.command.suppressed

This keeps command execution observable in the same event pipeline.


5. Coordinator

5.1 Purpose

CommandCoordinator is the single control-plane arbitration point.

All command initiators must submit commands to it.

No initiator may call executors directly.

5.2 Responsibilities

CommandCoordinator must:

  • accept CommandRequest objects;
  • validate policy;
  • enforce priority ordering;
  • enforce mutual exclusion;
  • apply deduplication;
  • apply cooldown and rate limits;
  • route accepted commands to appropriate executors;
  • emit command-result events into director.

5.3 Why this module is required

Because there are multiple command initiators:

  • CLI
  • scheduler
  • derivator

Without a coordinator, policy and conflict handling would fragment across modules.

5.4 Arbitration rules

Recommended defaults:

  • Operator > Derivator > Scheduler
  • exclusive commands serialize per target
  • poll-like commands may be deduplicated or coalesced
  • dangerous commands may be denied for derivator origin

6. Executors

6.1 Purpose

Executors perform actions against controllable sources.

Collectors ingest events.

Executors execute commands.

These roles must remain separate.

6.2 Executor routing

Introduce an executor router that maps command types to executors.

Examples:

  • wpa.* -> WpaCtrlExecutor
  • system.set_regdomain -> SystemExecutor
  • future dbus.* -> DbusExecutor
  • future navigation.* -> NavigationExecutor

6.3 WpaCtrlExecutor

Responsibilities:

  • connect to wpa_supplicant control interface;
  • execute commands such as:
    • status
    • signal_poll
    • scan
    • scan_results
    • deassociate
    • add_network
    • set_network
    • enable_network
    • remove_network
  • normalize results into command-result events.

6.4 SystemExecutor

Responsibilities:

  • execute system-scoped commands;
  • example:
    • iw reg set <CC> behind system.set_regdomain

6.5 DbusExecutor

Optional in v1, but keep architecture ready for it.

6.6 Executor invariants

  • Executors do not ingest passive source streams.
  • Executors do not route directly to outbox.
  • Executors emit results as canonical events through director.

7. Scheduler

7.1 Purpose

Scheduler is responsible for periodic and one-shot configured tasks.

Scheduler must not execute source actions directly.

It must generate CommandRequest objects and send them to CommandCoordinator.

7.2 Supported task types

At minimum:

  • interval
  • one-shot
  • disabled

7.3 Examples

  • periodic active scan
  • periodic passive scan
  • periodic signal_poll
  • periodic status
  • one-shot set_regdomain

7.4 Invariants

  • Scheduler creates commands, not canonical events.
  • Periodic tasks use the same execution path as ad-hoc CLI commands.

8. Derivator-initiated commands

Derivator may initiate commands, but only through CommandCoordinator.

Derivator must not invoke executors directly.

Allowed pattern

Derivator -> CommandRequest -> CommandCoordinator -> Executor -> Command Result Event -> Director

Why this is necessary

Derived actions are policy-driven and may conflict with:

  • operator commands;
  • periodic commands;
  • safety restrictions.

Therefore derivator actions must pass through the same arbitration path as all other control requests.


9. Director

Director receives normalized events from collectors and command result events from executors and decides:

  • whether to append to cache;
  • whether to enqueue into outbox;
  • whether to mark the event as derivator-interesting.

Director should only use:

  • envelope metadata;
  • hot normalized fields;
  • marking results;
  • source type and severity.

Director should not deeply parse source payloads.


10. Cache core

10.1 Bounded in-memory ring buffer

Purpose:

  • short-lived event window for derivator;
  • operational visibility of message flow;
  • low-overhead event retention for recent events only.

Properties:

  • fixed capacity;
  • O(1) append;
  • old events overwritten when full;
  • no historical durability guarantees.

10.2 Runtime event struct

Recommended runtime structure:

EventRecord
-----------
slot_id: uint32
seq_no: uint64
event_id: uint64

source_kind: uint8
payload_kind: uint8
event_kind: uint8
severity: uint8
flags: uint32

event_type_id: uint16
source_instance_id: uint16

observed_mono_ns: uint64
observed_wall_ns: uint64
ingested_mono_ns: uint64

host_id: uint32
interface_id: uint32
workflow_mask: uint64

normalized_ssid_id: uint32
normalized_bssid: bytes[6]
normalized_freq_mhz: uint16
normalized_rssi_dbm: int16
normalized_event_code_id: uint32
normalized_reason_id: uint32

correlation_id: uint64
causation_id: uint64
parent_seq_no: uint64

payload_ref: uint32
payload_len: uint32
proto_ref: uint32  # optional cached protobuf/materialized blob ref

10.3 Secondary indexes

Required indexes:

  • by_interface: map<interface_id, deque<seq_no>>
  • by_event_type: map<event_type_id, deque<seq_no>>
  • by_source_kind: map<source_kind, deque<seq_no>>
  • by_ssid: map<normalized_ssid_id, deque<seq_no>>

Optional later:

  • by_bssid
  • by_workflow_tag
  • by_robot_id

Index references must use seq_no and validate staleness lazily.

10.4 Payload store

Use a separate payload store / arena for source-specific payloads.

Do not put large payloads directly into ring entries.


11. Outbox, senders, and transports

11.1 Outbox queue

Use a bounded in-memory queue of event references.

Recommended outbox item:

OutboxItem
----------
seq_no: uint64
event_id: uint64
priority: uint8
enqueue_mono_ns: uint64
deadline_mono_ns: uint64
attempt_no: uint16

Outbox is the single internal source for all outbound delivery.

Senders read messages from outbox and send them outside the application, or emulate successful delivery depending on configured sender/transport type.

11.2 Sender types

The application must support multiple sender modes while preserving one common pipeline.

none

A stub sender that emulates successful delivery without performing real outbound transmission.

Use cases:

  • preserve full application pipeline when real delivery is not required;
  • functional testing of collectors, director, cache, outbox, batching, and command-result delivery;
  • dry-run and lab operation.

Behavior:

  • reads items from outbox;
  • marks them as successfully handled;
  • does not perform real network output.

strict_priority

A sender that attempts to send messages immediately after they appear in outbox, without intentional buffering delay.

Use cases:

  • minimum outbound latency;
  • alarms, failures, urgent operational events, urgent command-result events.

Behavior:

  • consumes outbox items as soon as possible;
  • may batch only minimally if implementation requires transport framing;
  • prioritizes immediate forwarding.

buffered

A sender that accumulates messages and sends them in batches when a configured periodic timer expires.

Use cases:

  • reduce network overhead;
  • reduce webhook request rate;
  • improve efficiency on constrained systems.

Behavior:

  • accumulates outbox items up to time and/or size limits;
  • emits batched delivery when flush timer expires;
  • may also flush earlier on max batch size.

11.3 Sender transports

Sender behavior must be separated from transport implementation.

At minimum the application must support the following transports.

drop

A transport that simply removes outbound messages and reports successful delivery.

Use cases:

  • synthetic pipeline completion;
  • tests and benchmarks;
  • operation where full pipeline semantics are required but actual delivery is intentionally suppressed.

Behavior:

  • receives sender output;
  • discards payload;
  • reports success.

webhook

A transport that sends outbound data using HTTP POST with configured request parameters.

Use cases:

  • integration with remote systems;
  • event export;
  • alert forwarding.

Behavior:

  • serializes batch payload as configured format;
  • executes HTTP POST;
  • supports timeout, headers, authentication, and other configured request parameters;
  • returns success/failure to sender retry logic.

11.4 Sender + transport model

Recommended composition model:

  • sender type controls when and how outbox items are drained;
  • transport controls where and by what protocol payload is delivered.

Examples:

  • none sender + drop transport
  • strict_priority sender + webhook transport
  • buffered sender + webhook transport

The default v1 operational path should keep this separation explicit in code and config.

11.5 Sender behavior

General sender loop:

  1. collect OutboxItems according to sender type policy;
  2. resolve current events from cache;
  3. materialize protobuf envelopes or JSON projection;
  4. pass prepared payload to selected transport;
  5. on success: ack and drop batch items;
  6. on failure: retry with bounded backoff or drop on expiry.

11.6 Delivery mode

Recommended default:

  • at-least-once from in-memory outbox while agent is alive;
  • no persistence across restart in v1.

11.7 Webhook payloads

Webhook outbound payload may include:

  • collector-generated raw events;
  • derivator-generated derived events;
  • executor-generated command-result events.

12. CLI

The application must expose CLI for control and inspection.

Recommended top-level commands:

agent run
agent config check
agent status
agent stats
agent collectors list
agent collectors show <name>
agent cache head
agent cache tail
agent cache find --type ... --iface ... --ssid ...
agent outbox show
agent outbox stats
agent sender test
agent sender flush
agent derivator status
agent proto dump-sample
agent cmd wpa status --iface ...
agent cmd wpa signal-poll --iface ...
agent cmd wpa scan --iface ...
agent cmd wpa deassociate --iface ...
agent cmd system set-regdomain --country ...
agent tasks list
agent tasks show <name>
agent tasks run-once <name>
agent tasks enable <name>
agent tasks disable <name>
agent tasks stats

CLI requirements

  • human-readable text output by default;
  • optional JSON output for automation;
  • no heavy TUI in v1.

13. Configuration model

13.1 .env

Use .env for environment-specific variables.

Examples:

AGENT_ENV=dev
AGENT_LOG_LEVEL=INFO
AGENT_CONFIG_PATH=./config/agent.toml
WEBHOOK_URL=https://example.local/webhook
WEBHOOK_TOKEN=secret-token
HOST_ID=robot-17
SITE_ID=warehouse-a

13.2 TOML config

Use TOML for collectors, filters, sender, transport, cache, derivator, commands, executors, tasks, and CLI defaults.

Example structure

[agent]
name = "wifi-event-agent"
log_level = "INFO"

[cache]
capacity_events = 50000
payload_arena_bytes = 67108864

[outbox]
capacity_items = 5000

[sender]
type = "buffered" # none | strict_priority | buffered

[sender.buffered]
batch_max_events = 200
batch_flush_ms = 1000
retry_base_ms = 500
retry_max_ms = 10000

[transport]
type = "webhook" # drop | webhook

[transport.webhook]
url = "${WEBHOOK_URL}"
timeout_ms = 3000
format = "json"
auth_mode = "bearer"
token = "${WEBHOOK_TOKEN}"

[commands]
queue_capacity = 1000

[coordinator]
default_priority_operator = 100
default_priority_derivator = 70
default_priority_scheduler = 50

[executors.wpa_ctrl]
enabled = true
interface = "wlp3s0"
ctrl_path = "/run/wpa_supplicant"

[executors.system]
enabled = true
allow_set_regdomain = true

[collectors.journal]
enabled = true
mode = "tail"

[[collectors.journal.filters]]
field = "_SYSTEMD_UNIT"
op = "in"
value = ["wpa_supplicant.service", "NetworkManager.service"]

[[collectors.journal.filters]]
field = "PRIORITY"
op = "lte"
value = 4

[[collectors.journal.marks]]
when.field = "_SYSTEMD_UNIT"
when.op = "eq"
when.value = "wpa_supplicant.service"
add.workflow_tags = ["wifi", "roaming"]
add.labels.site = "warehouse-a"

[collectors.dbus]
enabled = true
bus = "system"

[[collectors.dbus.subscriptions]]
service = "fi.w1.wpa_supplicant1"
path = "/fi/w1/wpa_supplicant1"
interface = "org.freedesktop.DBus.Properties"
member = "PropertiesChanged"

[collectors.wpa_ctrl]
enabled = true
interface = "wlp3s0"
ctrl_path = "/run/wpa_supplicant"

[[collectors.wpa_ctrl.filters]]
event = "CTRL-EVENT-DISCONNECTED"
action = "keep"

[[collectors.wpa_ctrl.filters]]
event = "CTRL-EVENT-SCAN-RESULTS"
action = "keep"

[collectors.navigation]
enabled = false
adapter = "stub"

[derivator]
enabled = true
poll_interval_ms = 500
allow_command_initiation = true

[[derivator.workflows]]
name = "wifi_scan_summary"
match_tags = ["wifi"]
window_ms = 5000

[tasks]
enabled = true

[[tasks.jobs]]
name = "wpa-status"
enabled = true
type = "interval"
interval_ms = 10000
executor = "wpa_ctrl"
command = "status"
target = "wlp3s0"

[[tasks.jobs]]
name = "wifi-active-scan"
enabled = true
type = "interval"
interval_ms = 30000
executor = "wpa_ctrl"
command = "scan"
target = "wlp3s0"

[tasks.jobs.args]
mode = "active"
freq = [5180, 5200, 5220, 5240]

14. Protobuf v1 examples

14.1 proto/common.proto

syntax = "proto3";
package agent.proto.v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";

message StringList {
  repeated string values = 1;
}

message AttributeMap {
  map<string, string> labels = 1;
}

enum EventKind {
  EVENT_KIND_UNSPECIFIED = 0;
  EVENT_KIND_RAW = 1;
  EVENT_KIND_DERIVED = 2;
}

enum SourceKind {
  SOURCE_KIND_UNSPECIFIED = 0;
  SOURCE_KIND_JOURNAL = 1;
  SOURCE_KIND_DBUS = 2;
  SOURCE_KIND_WPA_CTRL = 3;
  SOURCE_KIND_NAVIGATION = 4;
  SOURCE_KIND_APPLICATION = 5;
  SOURCE_KIND_CONTROL = 6;
}

enum Severity {
  SEVERITY_UNSPECIFIED = 0;
  SEVERITY_TRACE = 1;
  SEVERITY_DEBUG = 2;
  SEVERITY_INFO = 3;
  SEVERITY_WARNING = 4;
  SEVERITY_ERROR = 5;
  SEVERITY_CRITICAL = 6;
}

14.2 proto/events.proto

syntax = "proto3";
package agent.proto.v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
import "proto/common.proto";

message TraceContext {
  string correlation_id = 1;
  string causation_id = 2;
  repeated string parent_event_ids = 3;
  repeated string workflow_tags = 4;
}

message HostContext {
  string host_id = 1;
  string hostname = 2;
}

message NetworkContext {
  string interface_name = 1;
  string phy_name = 2;
  string regulatory_domain = 3;
}

message RoutingDirectives {
  bool cache_enabled = 1;
  bool outbox_enabled = 2;
  uint32 priority = 3;
  string partition_key = 4;
}

message EventEnvelope {
  string id = 1;
  string source = 2;
  string type = 3;
  string subject = 4;
  google.protobuf.Timestamp time = 5;
  string dataschema = 6;
  string datacontenttype = 7;
  string specversion = 8;

  EventKind event_kind = 20;
  SourceKind source_kind = 21;
  Severity severity = 22;
  uint32 schema_version = 23;

  HostContext host = 30;
  NetworkContext network = 31;
  TraceContext trace = 32;
  RoutingDirectives routing = 33;
  AttributeMap attributes = 34;

  string normalized_ssid = 40;
  string normalized_bssid = 41;
  uint32 normalized_freq_mhz = 42;
  sint32 normalized_rssi_dbm = 43;
  string normalized_event_code = 44;
  string normalized_reason = 45;

  oneof payload {
    RawJournalPayload raw_journal = 100;
    RawDbusPayload raw_dbus = 101;
    RawWpaPayload raw_wpa = 102;
    NavigationPayload navigation = 103;
    DerivedEventPayload derived = 104;
    CommandResultPayload command_result = 105;
  }
}

message RawJournalPayload {
  string cursor = 1;
  string message = 2;
  string unit = 3;
  string comm = 4;
  string exe = 5;
  map<string, string> fields = 10;
}

message RawDbusPayload {
  string bus_type = 1;
  string bus_name = 2;
  string object_path = 3;
  string interface = 4;
  string member = 5;
  map<string, string> headers = 10;
  repeated string args_json = 11;
}

message RawWpaPayload {
  string interface_name = 1;
  string event_line = 2;
  string event_name = 3;
  map<string, string> key_values = 10;
}

message NavigationPayload {
  string robot_id = 1;
  string mission_id = 2;
  double x = 3;
  double y = 4;
  double z = 5;
  double yaw = 6;
  string frame_id = 7;
}

message DerivedEventPayload {
  string derivation_name = 1;
  string workflow_name = 2;
  string summary = 3;
  double confidence = 4;
  google.protobuf.Struct details = 10;
}

message CommandResultPayload {
  string command_id = 1;
  string command_type = 2;
  string origin_kind = 3;
  string target_kind = 4;
  string target_id = 5;
  string result_state = 6;
  string message = 7;
  google.protobuf.Struct details = 10;
}

message BatchEnvelope {
  string batch_id = 1;
  google.protobuf.Timestamp created_at = 2;
  repeated EventEnvelope events = 10;
}

15. Project structure

agent/
  pyproject.toml
  README.md
  .env.example
  config/
    agent.toml

  proto/
    common.proto
    events.proto

  src/agent/
    __init__.py
    app.py
    cli.py
    env.py
    settings.py

    core/
      types.py
      enums.py
      ids.py
      intern.py
      clock.py
      metrics.py

    collectors/
      __init__.py
      base.py
      supervisor.py
      pipeline.py
      prefilter.py
      validation.py
      normalizer.py
      marking.py
      journal.py
      dbus.py
      wpa_ctrl.py
      navigation.py

    commands/
      __init__.py
      models.py
      coordinator.py
      policy.py
      queue.py
      results.py

    executors/
      __init__.py
      base.py
      router.py
      wpa_ctrl.py
      dbus.py
      system.py
      navigation.py

    scheduler/
      __init__.py
      models.py
      scheduler.py
      registry.py

    director/
      __init__.py
      director.py
      routing.py
      policies.py

    cache/
      __init__.py
      ring_buffer.py
      payload_store.py
      indexes.py
      cache_api.py
      snapshot.py

    derivator/
      __init__.py
      base.py
      worker.py
      workflows.py
      wifi_scan_summary.py

    sender/
      __init__.py
      outbox.py
      batcher.py
      sender_types.py
      retry.py
      transports/
        __init__.py
        drop.py
        webhook.py

    proto_generated/
      # generated python protobuf code

    observability/
      __init__.py
      logging.py
      stats.py
      health.py

    utils/
      __init__.py
      toml_loader.py
      json_output.py
      time.py

  tests/
    unit/
    integration/
    fixtures/

16. CLI details

Example agent status

Should show:

  • process uptime;
  • collector states;
  • coordinator state;
  • cache fill ratio;
  • outbox queue depth;
  • derivator lag;
  • sender last success/failure;
  • webhook endpoint mode;
  • config path.

Example agent stats

Should show counters:

  • events_received_total{collector}
  • events_prefilter_dropped_total{collector}
  • events_validation_failed_total{collector}
  • events_normalized_total{collector}
  • events_marked_total{collector}
  • events_cached_total
  • events_outbox_enqueued_total
  • cache_overwrite_total
  • derived_events_total
  • commands_received_total{origin}
  • commands_rejected_total{reason}
  • commands_executed_total{executor}
  • webhook_sent_total
  • webhook_send_failed_total

Example agent cache tail --limit 20

Should print recent events with minimal fields:

  • seq_no
  • time
  • collector
  • type
  • iface
  • ssid
  • event_code
  • severity

Example agent outbox show --limit 20

Should print:

  • seq_no
  • event_id
  • priority
  • attempt_no
  • age_ms

Example command CLI

agent cmd wpa status --iface wlp3s0
agent cmd wpa signal-poll --iface wlp3s0
agent cmd wpa scan --iface wlp3s0 --mode active
agent cmd wpa deassociate --iface wlp3s0
agent cmd system set-regdomain --country US

Example task CLI

agent tasks list
agent tasks run-once wifi-active-scan
agent tasks enable wpa-status
agent tasks disable wifi-active-scan

17. Libraries and stack

Recommended stack:

  • Python 3.11+
  • protobuf
  • python-dotenv
  • tomli / stdlib TOML depending on target Python version
  • httpx
  • dbus-next
  • systemd journal Python bindings or equivalent
  • standard library asyncio
  • typer or argparse for CLI

Linux-specific assumptions:

  • systemd present for journal access;
  • unix sockets available for wpa_supplicant ctrl_iface;
  • .env file loaded at startup;
  • TOML file read at process start.

Storage/runtime assumptions for v1:

  • no SQL database in the hot operational path;
  • no SQLite requirement for cache or outbox;
  • cache implemented as bounded in-memory ring buffer;
  • outbox implemented as bounded in-memory queue;
  • optional persistent spill-to-disk remains a future extension, not part of the base design.

18. Implementation constraints

Must-have constraints

  • bounded memory use;
  • no unbounded queues;
  • explicit overflow policies;
  • low CPU overhead;
  • reconnect logic in all collectors;
  • normalized protobuf envelope from all collectors;
  • CLI introspection built in;
  • all outbound delivery must go through outbox;
  • senders must read only from outbox;
  • sender type and transport type must be configurable independently;
  • all commands must go through CommandCoordinator;
  • periodic tasks and ad-hoc commands must share the same execution path;
  • derivator-initiated commands must go through the same coordinator path as CLI and scheduler commands.

Anti-goals for v1

  • no historical durable storage;
  • no distributed message bus;
  • no heavy database;
  • no SQL dependency in the hot path;
  • no web UI;
  • no plugin framework beyond simple source adapter abstraction.

19. Codex-ready implementation plan

Below is a phased implementation plan. Each step is intended to map to exactly one commit.

Each step contains:

  • Goal
  • Scope
  • Result
  • Depends on
  • Commit
  • Status

Status for all steps initially: TODO.


Phase 0. Repository bootstrap and standards

Step 0.1

Goal

Create project skeleton, Python packaging, base directories, and developer tooling baseline.

Scope

  • create repository structure;
  • add pyproject.toml;
  • add README.md;
  • add .gitignore;
  • create src/agent/... package skeleton;
  • create proto/ folder;
  • create tests/ skeleton.

Result

A buildable Python project skeleton for Linux agent development.

Depends on

  • none

Commit

chore: bootstrap repository structure for linux event agent

Status

TODO

Step 0.2

Goal

Add environment and config loading foundations.

Scope

  • add .env.example;
  • implement env.py;
  • implement TOML config loader;
  • define settings.py bootstrap structure;
  • support config path from environment.

Result

Application can load .env and TOML config deterministically.

Depends on

  • Step 0.1

Commit

feat: add dotenv and toml configuration loading foundation

Status

TODO

Step 0.3

Goal

Add CLI entrypoint and base command tree.

Scope

  • create cli.py;
  • implement commands:
    • run
    • config check
    • status
    • stats
  • wire package console script.

Result

CLI boots and can validate config loading.

Depends on

  • Step 0.2

Commit

feat: add base cli entrypoint and config check command

Status

TODO


Phase 1. Protobuf schema and internal core types

Step 1.1

Goal

Define protobuf v1 common schema.

Scope

  • create proto/common.proto;
  • define enums and shared message primitives;
  • add generation command scaffolding.

Result

Common proto definitions exist and compile.

Depends on

  • Step 0.1

Commit

feat: add common protobuf v1 schema

Status

TODO

Step 1.2

Goal

Define protobuf v1 event schema.

Scope

  • create proto/events.proto;
  • define:
    • EventEnvelope
    • RawJournalPayload
    • RawDbusPayload
    • RawWpaPayload
    • NavigationPayload
    • DerivedEventPayload
    • CommandResultPayload
    • BatchEnvelope

Result

Canonical v1 event schema exists.

Depends on

  • Step 1.1

Commit

feat: add protobuf v1 event envelope and payload schema

Status

TODO

Step 1.3

Goal

Generate Python protobuf bindings and wrap usage.

Scope

  • add code generation script/target;
  • generate python protobuf files;
  • add thin adapter helpers for envelope creation.

Result

Python code can instantiate and serialize v1 protobuf messages.

Depends on

  • Step 1.2

Commit

feat: generate python bindings for protobuf v1 schema

Status

TODO

Step 1.4

Goal

Implement internal core runtime types for hot path.

Scope

  • create runtime enums and typed ids;
  • implement EventRecord runtime model;
  • implement string interning table;
  • add helper converters between proto and runtime model.

Result

Core runtime event representation is available.

Depends on

  • Step 1.3

Commit

feat: add runtime event core types and interning tables

Status

TODO


Phase 2. Cache core and in-memory indexes

Step 2.1

Goal

Implement bounded ring buffer.

Scope

  • create ring_buffer.py;
  • fixed-capacity append/overwrite logic;
  • monotonic seq_no allocation;
  • safe slot overwrite semantics.

Result

Core event cache buffer works in memory with bounded size.

Depends on

  • Step 1.4

Commit

feat: implement bounded in-memory ring buffer for event cache

Status

TODO

Step 2.2

Goal

Implement payload store for source-specific payloads.

Scope

  • create payload_store.py;
  • implement bounded payload arena/slab;
  • support payload reference attachment from EventRecord.

Result

Large payload data is separated from ring entries.

Depends on

  • Step 2.1

Commit

feat: add bounded payload store for event cache

Status

TODO

Step 2.3

Goal

Implement secondary indexes.

Scope

  • create indexes.py;
  • implement indexes:
    • by interface
    • by event type
    • by source kind
    • by ssid
  • implement lazy stale-reference cleanup.

Result

Derivator-friendly low-overhead indexes exist.

Depends on

  • Step 2.2

Commit

feat: add in-memory secondary indexes for event cache

Status

TODO

Step 2.4

Goal

Expose cache inspection API and snapshots for CLI.

Scope

  • create cache_api.py and snapshot.py;
  • implement recent-head/tail reads;
  • implement filtered lookups for CLI.

Result

CLI can inspect cache contents safely.

Depends on

  • Step 2.3

Commit

feat: add cache inspection api for cli and diagnostics

Status

TODO


Phase 3. Collector framework

Step 3.1

Goal

Implement collector base abstractions.

Scope

  • add collectors/base.py;
  • define collector lifecycle and interfaces;
  • define common stats/health/state models.

Result

All collectors can implement a common contract.

Depends on

  • Step 0.3

Commit

feat: add base collector interfaces and lifecycle states

Status

TODO

Step 3.2

Goal

Implement collector pipeline primitives.

Scope

  • add:
    • pipeline.py
    • prefilter.py
    • validation.py
    • normalizer.py
    • marking.py
  • implement rule engine skeleton for TOML-driven filters and marks.

Result

Collector pipeline stages exist and can be configured.

Depends on

  • Step 3.1

Commit

feat: add configurable collector pipeline stages

Status

TODO

Step 3.3

Goal

Implement collector supervisor.

Scope

  • add supervisor.py;
  • start/stop enabled collectors;
  • collect health/stats;
  • expose supervisor state to app/cli.

Result

Application can manage multiple collectors uniformly.

Depends on

  • Step 3.2

Commit

feat: add collector supervisor and health aggregation

Status

TODO


Phase 4. Commands, coordinator, executors, and scheduler

Step 4.1

Goal

Implement command models.

Scope

  • add commands/models.py;
  • define CommandRequest and supporting enums/types;
  • define CommandResult internal model.

Result

The control plane has explicit typed command objects.

Depends on

  • Step 1.4

Commit

feat: add typed command request and result models

Status

TODO

Step 4.2

Goal

Implement command coordinator queue and policy layer.

Scope

  • add commands/queue.py;
  • add commands/policy.py;
  • add coordinator acceptance/rejection rules;
  • implement priority, exclusivity, dedup, and cooldown checks.

Result

A single arbitration point exists for all command origins.

Depends on

  • Step 4.1

Commit

feat: add command coordinator queue and policy engine

Status

TODO

Step 4.3

Goal

Implement command coordinator runtime.

Scope

  • add commands/coordinator.py;
  • accept commands from CLI, scheduler, and derivator;
  • dispatch accepted commands to executor router;
  • emit command lifecycle result objects.

Result

All command origins share the same coordinated control path.

Depends on

  • Step 4.2

Commit

feat: implement command coordinator runtime

Status

TODO

Step 4.4

Goal

Implement executor base abstractions and router.

Scope

  • add executors/base.py;
  • add executors/router.py;
  • define executor interface;
  • map command types to executor backends.

Result

Executors can be addressed through one stable routing layer.

Depends on

  • Step 4.3

Commit

feat: add executor interfaces and command router

Status

TODO

Step 4.5

Goal

Implement scheduler models and runtime.

Scope

  • add scheduler/models.py;
  • add scheduler/registry.py;
  • add scheduler/scheduler.py;
  • generate CommandRequest from interval and one-shot jobs.

Result

Periodic and one-shot tasks are expressed through the same control path as CLI commands.

Depends on

  • Step 4.3

Commit

feat: add scheduler for periodic and one-shot command generation

Status

TODO


Phase 5. Director and outbox core

Step 5.1

Goal

Implement director routing engine.

Scope

  • add director.py, routing.py, policies.py;
  • implement route decisions:
    • cache
    • outbox
    • derivator-interest
  • use normalized envelope fields and marks only.

Result

Director can route collector, derivator, and command-result events correctly.

Depends on

  • Step 2.4
  • Step 3.3
  • Step 4.3

Commit

feat: implement director routing engine for canonical events

Status

TODO

Step 5.2

Goal

Implement outbox queue.

Scope

  • add sender/outbox.py;
  • implement bounded in-memory queue for OutboxItem;
  • add overflow policy and counters;
  • ensure outbox is the single source for outbound senders.

Result

Events can be enqueued for outbound delivery without persistence.

Depends on

  • Step 5.1

Commit

feat: add bounded outbox queue for outbound delivery

Status

TODO

Step 5.3

Goal

Implement sender type framework and transport abstraction.

Scope

  • add sender types:
    • none
    • strict_priority
    • buffered
  • add transport abstractions:
    • drop
    • webhook
  • define composition rules between sender types and transports.

Result

Outbound delivery architecture supports configurable sender strategy and transport backend.

Depends on

  • Step 5.2

Commit

feat: add sender type framework and outbound transport abstraction

Status

TODO

Step 5.4

Goal

Implement batch builder.

Scope

  • add sender/batcher.py;
  • materialize protobuf BatchEnvelope from outbox refs;
  • support JSON projection option.

Result

Senders can build outbound payload batches from in-memory state.

Depends on

  • Step 5.3

Commit

feat: add batch builder for protobuf and json outbound payloads

Status

TODO


Phase 6. Concrete collectors

Step 6.1

Goal

Implement JournalCollector.

Scope

  • add collectors/journal.py;
  • connect to systemd journal;
  • implement configurable prefilter, validation, normalization, marking;
  • emit canonical events to director.

Result

Journal events flow through full collector pipeline.

Depends on

  • Step 3.3
  • Step 5.1

Commit

feat: implement journal collector with pipeline integration

Status

TODO

Step 6.2

Goal

Implement DbusCollector.

Scope

  • add collectors/dbus.py;
  • connect to system bus;
  • implement subscriptions from TOML;
  • implement pipeline integration and reconnect logic.

Result

D-Bus signals flow through canonical collector pipeline.

Depends on

  • Step 6.1

Commit

feat: implement dbus collector with configurable subscriptions

Status

TODO

Step 6.3

Goal

Implement WpaCtrlCollector.

Scope

  • add collectors/wpa_ctrl.py;
  • connect to wpa_supplicant ctrl_iface;
  • attach to unsolicited events;
  • normalize and mark wpa events.

Result

wpa_supplicant ctrl events flow into director.

Depends on

  • Step 6.2

Commit

feat: implement wpa ctrl iface collector and normalization

Status

TODO

Step 6.4

Goal

Implement NavigationCollector stub and adapter interface.

Scope

  • add collectors/navigation.py;
  • define navigation adapter contract;
  • implement stub collector for tests and future integration.

Result

Architecture supports future navigation source integration cleanly.

Depends on

  • Step 6.3

Commit

feat: add navigation collector adapter interface and stub implementation

Status

TODO


Phase 7. Executors, transports, and sender loops

Step 7.1

Goal

Implement WpaCtrlExecutor.

Scope

  • add executors/wpa_ctrl.py;
  • support commands:
    • status
    • signal_poll
    • scan
    • scan_results
    • deassociate
    • add_network
    • set_network
    • enable_network
    • remove_network
  • emit command-result payloads.

Result

Control commands for wpa_supplicant can be executed through the unified control plane.

Depends on

  • Step 4.4
  • Step 5.1

Commit

feat: implement wpa ctrl executor and command result emission

Status

TODO

Step 7.2

Goal

Implement SystemExecutor.

Scope

  • add executors/system.py;
  • support system.set_regdomain and future system-scoped actions;
  • emit command-result payloads.

Result

System-level commands are supported through the unified control plane.

Depends on

  • Step 7.1

Commit

feat: implement system executor for regdomain and system actions

Status

TODO

Step 7.3

Goal

Implement transport layer for drop and webhook.

Scope

  • add sender/transports/drop.py;
  • add sender/transports/webhook.py;
  • implement HTTP POST transport with timeout, auth, and headers;
  • implement successful discard transport.

Result

Transport backends exist for synthetic and real outbound delivery.

Depends on

  • Step 5.4

Commit

feat: implement drop and webhook sender transports

Status

TODO

Step 7.4

Goal

Implement sender loops for none, strict_priority, and buffered.

Scope

  • add sender loop implementations;
  • implement immediate drain for strict_priority;
  • implement timer-based batch flush for buffered;
  • implement pipeline-preserving success emulation for none.

Result

Application supports multiple sender strategies over the same outbox model.

Depends on

  • Step 7.3

Commit

feat: implement none strict-priority and buffered sender loops

Status

TODO

Step 7.5

Goal

Implement retry policy and bounded backoff.

Scope

  • add sender/retry.py;
  • implement bounded retry with deadline/expiry;
  • add metrics for failure/drop.

Result

Sender failure handling is deterministic and bounded.

Depends on

  • Step 7.4

Commit

feat: add bounded retry policy for outbound senders

Status

TODO


Phase 8. Derivator

Step 8.1

Goal

Implement derivator base worker.

Scope

  • add derivator/base.py, worker.py;
  • implement watermark processing from cache;
  • support periodic polling over new seq_no range.

Result

Derivator can consume recent cache windows.

Depends on

  • Step 2.4
  • Step 5.1

Commit

feat: implement derivator worker over bounded cache windows

Status

TODO

Step 8.2

Goal

Implement first workflow example.

Scope

  • add wifi_scan_summary.py;
  • derive simple summary event from recent wifi-related events;
  • emit derived EventEnvelope back into director.

Result

The end-to-end raw -> derived -> routed flow is proven.

Depends on

  • Step 8.1

Commit

feat: add first derivator workflow for wifi scan summary

Status

TODO

Step 8.3

Goal

Implement derivator-initiated command path.

Scope

  • allow derivator workflows to create CommandRequest objects;
  • submit them to CommandCoordinator;
  • enforce coordinator policy for derivator-origin commands.

Result

Derivator can initiate permitted actions without bypassing control-plane coordination.

Depends on

  • Step 8.2
  • Step 4.3

Commit

feat: route derivator-initiated commands through command coordinator

Status

TODO


Phase 9. CLI inspection and operations

Step 9.1

Goal

Implement status and stats CLI commands fully.

Scope

  • wire runtime app state into CLI;
  • implement:
    • status
    • stats
    • collectors list
    • collectors show

Result

Operators can inspect collector and pipeline state.

Depends on

  • Step 7.4

Commit

feat: add cli status and collector inspection commands

Status

TODO

Step 9.2

Goal

Implement cache inspection CLI commands.

Scope

  • implement:
    • cache head
    • cache tail
    • cache find
  • support text and JSON output.

Result

Operators can inspect recent cache contents safely.

Depends on

  • Step 9.1

Commit

feat: add cli cache inspection commands

Status

TODO

Step 9.3

Goal

Implement outbox and sender CLI commands.

Scope

  • implement:
    • outbox show
    • outbox stats
    • sender test
    • sender flush
  • expose sender type, transport type, retry state, and queue depth.

Result

Operators can inspect and control outbound delivery path.

Depends on

  • Step 9.2

Commit

feat: add cli outbox sender and transport operational commands

Status

TODO

Step 9.4

Goal

Implement derivator CLI commands.

Scope

  • implement:
    • derivator status
    • optional derivator run-once
  • print lag, workflow state, recent derived counts.

Result

Operators can inspect derivator health and lag.

Depends on

  • Step 9.3

Commit

feat: add cli derivator status and control commands

Status

TODO

Step 9.5

Goal

Implement command and task CLI commands.

Scope

  • implement:
    • cmd ...
    • tasks list
    • tasks show
    • tasks run-once
    • tasks enable
    • tasks disable
    • tasks stats
  • route command execution through CommandCoordinator only.

Result

Operators can issue ad-hoc commands and inspect scheduled jobs through one consistent control path.

Depends on

  • Step 9.4
  • Step 4.5

Commit

feat: add cli command execution and task management commands

Status

TODO


Phase 10. Observability, health, and tests

Step 10.1

Goal

Add counters, watermarks, and health reporting.

Scope

  • implement observability metrics and health summaries;
  • include:
    • cache fill ratio
    • cache overwrite count
    • outbox depth
    • sender failure count
    • derivator lag
    • per-collector pipeline counters
    • command coordinator counters
    • executor counters
    • scheduler counters.

Result

Runtime behavior is measurable and operable.

Depends on

  • Step 9.5

Commit

feat: add observability counters watermarks and health reporting

Status

TODO

Step 10.2

Goal

Add unit tests for core, collector pipeline, and control plane.

Scope

  • test ring buffer overwrite semantics;
  • test indexes stale cleanup;
  • test prefilter/validation/marking rules;
  • test envelope normalization;
  • test coordinator arbitration and dedup;
  • test scheduler job-to-command conversion.

Result

Core runtime invariants are covered by tests.

Depends on

  • Step 10.1

Commit

test: add unit coverage for cache collectors and control plane

Status

TODO

Step 10.3

Goal

Add integration tests for end-to-end flow.

Scope

  • collector fixture events -> director -> cache -> outbox -> sender;
  • command CLI -> coordinator -> executor -> result event -> director;
  • scheduler -> command -> executor -> result event;
  • derivator loop integration;
  • CLI smoke tests.

Result

Main application workflows are covered end-to-end.

Depends on

  • Step 10.2

Commit

test: add integration coverage for ingestion control sender and derivator flows

Status

TODO


Phase 11. Packaging and runtime hardening

Step 11.1

Goal

Add production Linux runtime files.

Scope

  • add systemd unit example;
  • add sample .env and TOML configs;
  • document Linux runtime assumptions.

Result

Agent can be deployed on Linux hosts consistently.

Depends on

  • Step 10.3

Commit

chore: add linux deployment examples and sample configs

Status

TODO

Step 11.2

Goal

Finalize operator documentation.

Scope

  • document collector model;
  • document command/coordinator/executor/scheduler model;
  • document CLI usage;
  • document config model;
  • document protobuf contract and event flow.

Result

Repository is usable by implementers and operators.

Depends on

  • Step 11.1

Commit

docs: finalize operator and developer documentation for linux event agent

Status

TODO


20. Definition of done

The implementation is complete when:

  • all enabled collectors can connect, reconnect, and report health;
  • every collector runs the required pipeline:
    • prefilter,
    • validation,
    • normalization to protobuf v1,
    • marking;
  • all commands from CLI, scheduler, and derivator go through CommandCoordinator;
  • executors emit command-result events into director;
  • director routes events correctly to cache and outbox;
  • cache uses bounded in-memory ring buffer with defined overflow behavior;
  • outbox uses bounded in-memory queue with defined overflow behavior;
  • sender types none, strict_priority, and buffered work as configured;
  • transports drop and webhook work as configured;
  • CLI can report status, stats, cache contents, outbox contents, command execution, and task state;
  • .env and TOML config are both active and documented;
  • at least one derivator workflow works end-to-end;
  • derivator-initiated commands work through coordinator policy;
  • unit and integration tests cover the core runtime invariants.

21. Immediate implementation order recommendation

If you want the most practical first slice, implement in this exact order:

  1. Phase 0
  2. Phase 1
  3. Phase 2
  4. Phase 3
  5. Phase 4
  6. Phase 5
  7. Phase 6.1 and 6.2
  8. Phase 7.1 and 7.2
  9. Phase 7.3 to 7.5
  10. Phase 9.1 to 9.3
  11. Phase 8
  12. Phase 9.4 and 9.5
  13. Phase 10
  14. Phase 11

That order gives the fastest path to a usable minimal agent with journal + D-Bus + command coordination + webhook, while leaving wpa_ctrl, scheduling, and derivation as controlled extensions.