MINDS EYE FABRIC

Published: (December 13, 2025 at 03:26 AM EST)
5 min read
Source: Dev.to

Source: Dev.to

Phase 1 — C++ Sovereign Kernel Skeleton (Daemon‑First)

Goal – ship a running C++ daemon that can:

  • accept events
  • maintain a capability graph (endpoints + edges)
  • run a minimal state kernel (deterministic transitions)
  • write an append‑only ledger (provenance + replay‑ready)
  • execute a first “hunt” (graph search over reachability)

Non‑goals (Phase 1)

  • LLM integration
  • MindScript parsing/compilation
  • Distributed multi‑node consensus
  • Fancy persistence engines (storage will be clean + swappable)

Core Concepts

ComponentDescription
ledger / Append‑only logImmutable entries, file‑backed
stateDeterministic state machine + transition rules
graphEndpoints, capabilities, reachability computation
eventsIn‑process pub/sub bus (daemon’s nervous system)
huntsPlanner that searches reachable endpoints under constraints
daemonMain loop + API surface (HTTP/gRPC later; Phase 1 uses HTTP)

In Phase 1, collapse = atomic commit:

  1. receive input (event / command)
  2. validate
  3. compute consequences (state + graph updates)
  4. write one ledger entry (append‑only)
  5. emit internal events

No mutation occurs without a ledger commit.


Project Structure

mindseye-fabric/
├─ README.md
├─ LICENSE
├─ CMakeLists.txt
├─ docs/
│  └─ 01_phase1_kernel.md
├─ src/
│  ├─ main.cpp
│  ├─ daemon/
│  │  ├─ server.hpp
│  │  ├─ server.cpp
│  │  ├─ routes.hpp
│  │  └─ routes.cpp
│  ├─ core/
│  │  ├─ types.hpp
│  │  ├─ time.hpp
│  │  └─ result.hpp
│  ├─ ledger/
│  │  ├─ ledger.hpp
│  │  ├─ ledger.cpp
│  │  └─ entry.hpp
│  ├─ state/
│  │  ├─ state.hpp
│  │  ├─ state.cpp
│  │  └─ transitions.hpp
│  ├─ graph/
│  │  ├─ graph.hpp
│  │  ├─ graph.cpp
│  │  ├─ endpoint.hpp
│  │  └─ capability.hpp
│  ├─ events/
│  │  ├─ bus.hpp
│  │  └─ bus.cpp
│  └─ hunts/
│     ├─ hunt.hpp
│     └─ hunt.cpp
├─ third_party/
│  └─ httplib.h
└─ tests/
   └─ test_smoke.cpp

Each folder is a kernel “organ”; there are no mixed‑purpose “utils” directories.


CMake Configuration

cmake_minimum_required(VERSION 3.20)
project(mindseye_fabric LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(mindseye_fabric
  src/main.cpp
  src/daemon/server.cpp
  src/daemon/routes.cpp
  src/events/bus.cpp
  src/ledger/ledger.cpp
  src/state/state.cpp
  src/graph/graph.cpp
  src/hunts/hunt.cpp
)

target_include_directories(mindseye_fabric PRIVATE
  src
  third_party
)

# Good defaults
if(MSVC)
  target_compile_options(mindseye_fabric PRIVATE /W4)
else()
  target_compile_options(mindseye_fabric PRIVATE -Wall -Wextra -Wpedantic)
endif()

Core Types (src/core/types.hpp)

#pragma once
#include 
#include 
#include 
#include 
#include 
#include 
#include 

namespace me {

using u64 = std::uint64_t;
using i64 = std::int64_t;

struct Error {
  std::string code;
  std::string message;
};

template 
using Result = std::variant;

inline bool ok(const auto& r) {
  return std::holds_alternative(r))>>(r);
}

} // namespace me

Core Time (src/core/time.hpp)

#pragma once
#include 
#include "core/types.hpp"

namespace me {

inline u64 now_ms() {
  using namespace std::chrono;
  return static_cast(duration_cast(system_clock::now().time_since_epoch()).count());
}

} // namespace me

Ledger Entry Format

An entry is a single JSON line (NDJSON), easy to tail and replay.

FieldDescription
idMonotonic integer
ts_msTimestamp (milliseconds)
kind"event"
payloadJSON object (stringified for Phase 1)
prev_hashHash of the previous entry
hashHash of this entry (integrity chain)

src/ledger/entry.hpp

#pragma once
#include 
#include "core/types.hpp"

namespace me {

struct LedgerEntry {
  u64 id = 0;
  u64 ts_ms = 0;
  std::string kind;
  std::string payload_json;
  std::string prev_hash;
  std::string hash;
};

} // namespace me

Ledger Implementation (src/ledger/ledger.hpp / .cpp)

#pragma once
#include 
#include 
#include 
#include "ledger/entry.hpp"
#include "core/types.hpp"

namespace me {

class Ledger {
public:
  explicit Ledger(std::string path);

  Result append(std::string kind, std::string payload_json);

  std::optional last() const;
  u64 next_id() const;

private:
  std::string path_;
  mutable std::mutex mu_;
  u64 next_id_{1};
  std::optional last_;

  static std::string sha256_hex(std::string_view data); // stub for Phase 1
  static std::string compute_hash(const LedgerEntry& e);
};

} // namespace me

Source

#include "ledger/ledger.hpp"
#include "core/time.hpp"
#include 

namespace me {

static std::string fake_hash(std::string_view s) {
  // Phase 1 placeholder – replace with real SHA‑256 later.
  std::hash h;
  return std::to_string(h(s));
}

Ledger::Ledger(std::string path) : path_(std::move(path)) {
  // Start fresh if the file does not exist.
  std::ifstream in(path_);
  if (!in.good()) return;

  // Minimal restore: read the last line only (fast path).
  std::string line, last_line;
  while (std::getline(in, line))
    if (!line.empty()) last_line = line;

  // Phase 1: keep next_id_ conservative.
  if (!last_line.empty()) next_id_ = 1000; // placeholder
}

std::optional Ledger::last() const {
  std::scoped_lock lk(mu_);
  return last_;
}

u64 Ledger::next_id() const {
  std::scoped_lock lk(mu_);
  return next_id_;
}

std::string Ledger::sha256_hex(std::string_view data) {
  return fake_hash(data);
}

std::string Ledger::compute_hash(const LedgerEntry& e) {
  std::ostringstream ss;
  ss  Ledger::append(std::string kind, std::string payload_json) {
  std::scoped_lock lk(mu_);
  LedgerEntry e;
  e.id = next_id_++;
  e.ts_ms = now_ms();
  e.kind = std::move(kind);
  e.payload_json = std::move(payload_json);
  e.prev_hash = last_ ? last_->hash : "GENESIS";
  e.hash = compute_hash(e);

  std::ofstream out(path_, std::ios::app);
  if (!out.good())
    return Error{"LEDGER_IO", "Failed to open ledger file for append"};

  // NDJSON line
  out 

State Header (src/state/state.hpp)

#include "core/types.hpp"

namespace me {

enum class State : u64 {
  PAUSE = 0,
  STRESS = 1,
  LOOP = 2,
  TRANSMIT = 3,
  COLLAPSE = 4
};

inline std::string to_string(State s) {
  switch (s) {
    case State::PAUSE:    return "PAUSE";
    case State::STRESS:   return "STRESS";
    case State::LOOP:     return "LOOP";
    case State::TRANSMIT: return "TRANSMIT";
    case State::COLLAPSE: return "COLLAPSE";
  }
  return "UNKNOWN";
}

struct Transition {
  State from;
  State to;
  std::string reason;
};

class StateKernel {
public:
  State current() const { return current_; }

  // Phase 1: simple rule set. Later: constraints + costs + guards.
  Transition apply_event(std::string_view event_type);

private:
  State current_{State::PAUSE};
};

} // namespace me

Source (src/state/state.cpp)

#include "state/state.hpp"

namespace me {

Transition StateKernel::apply_event(std::string_view event_type) {
  // Deterministic, minimal mapping for Phase 1.
  if (event_type == "ingest") {
    State prev = current_;
    current_ = State::LOOP;
    return {prev, current_, "ingest -> LOOP"};
  }
  if (event_type == "pressure") {
    State prev = current_;
    current_ = State::STRESS;
    return {prev, current_, "pressure -> STRESS"};
  }
  // Default: no state change.
  return {current_, current_, "no transition"};
}

} // namespace me

The remaining modules (graph, events, hunts, daemon server, routes, etc.) follow the same clean‑code conventions and will be expanded in later phases.

Back to Blog

Related posts

Read more »