build(agent): new-agents-2#7e3bbc iteration
This commit is contained in:
parent
7ece74b55e
commit
887f28ed52
|
|
@ -0,0 +1,55 @@
|
||||||
|
#include "Registry.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Internal helper to ensure capacity
|
||||||
|
static int registry_ensure_capacity(Registry* r) {
|
||||||
|
if (r->entries == NULL) {
|
||||||
|
size_t cap = 4;
|
||||||
|
r->entries = (RegistryEntry*)calloc(cap, sizeof(RegistryEntry));
|
||||||
|
if (!r->entries) return -1;
|
||||||
|
r->capacity = cap;
|
||||||
|
r->count = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (r->count < r->capacity) return 0;
|
||||||
|
size_t newcap = r->capacity * 2;
|
||||||
|
RegistryEntry* tmp = (RegistryEntry*)realloc(r->entries, newcap * sizeof(RegistryEntry));
|
||||||
|
if (!tmp) return -1;
|
||||||
|
// Initialize new slots to zero
|
||||||
|
for (size_t i = r->capacity; i < newcap; ++i) {
|
||||||
|
tmp[i].key = NULL;
|
||||||
|
tmp[i].value = NULL;
|
||||||
|
tmp[i].version = 0;
|
||||||
|
}
|
||||||
|
r->entries = tmp;
|
||||||
|
r->capacity = newcap;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void registry_init(Registry* r) {
|
||||||
|
r->entries = NULL;
|
||||||
|
r->count = 0;
|
||||||
|
r->capacity = 0;
|
||||||
|
// lazy initialization on first register
|
||||||
|
}
|
||||||
|
|
||||||
|
int registry_register(Registry* r, const char* key, const char* value, int version) {
|
||||||
|
if (registry_ensure_capacity(r) != 0) return -1;
|
||||||
|
RegistryEntry e;
|
||||||
|
e.key = key;
|
||||||
|
e.value = value;
|
||||||
|
e.version = version;
|
||||||
|
r->entries[r->count++] = e;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* registry_lookup(Registry* r, const char* key) {
|
||||||
|
if (!r || !r->entries) return NULL;
|
||||||
|
for (size_t i = 0; i < r->count; ++i) {
|
||||||
|
if (r->entries[i].key && strcmp(r->entries[i].key, key) == 0) {
|
||||||
|
return r->entries[i].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Simple in-process registry to map canonical primitives to versions/handles
|
||||||
|
#ifndef REGISTRY_H
|
||||||
|
#define REGISTRY_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef struct RegistryEntry {
|
||||||
|
const char* key;
|
||||||
|
const char* value;
|
||||||
|
int version;
|
||||||
|
} RegistryEntry;
|
||||||
|
|
||||||
|
typedef struct Registry {
|
||||||
|
RegistryEntry* entries;
|
||||||
|
size_t count;
|
||||||
|
size_t capacity;
|
||||||
|
} Registry;
|
||||||
|
|
||||||
|
void registry_init(Registry* r);
|
||||||
|
int registry_register(Registry* r, const char* key, const char* value, int version);
|
||||||
|
const char* registry_lookup(Registry* r, const char* key);
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,4 @@
|
||||||
|
#include "delta_crdt.h"
|
||||||
|
|
||||||
|
// No heavy implementation needed for a toy MVP; this file exists to
|
||||||
|
// satisfy build expectations and to place future CRDT logic here.
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Lightweight CRDT-like delta structure and merge utility
|
||||||
|
#ifndef DELTA_CRDT_H
|
||||||
|
#define DELTA_CRDT_H
|
||||||
|
|
||||||
|
typedef struct DeltaCRDT {
|
||||||
|
unsigned long version;
|
||||||
|
double value_delta;
|
||||||
|
} DeltaCRDT;
|
||||||
|
|
||||||
|
// Merge two deltas by choosing the one with the higher version.
|
||||||
|
static inline void crdt_merge(const DeltaCRDT* a, const DeltaCRDT* b, DeltaCRDT* out) {
|
||||||
|
if (!a || !b || !out) return;
|
||||||
|
if (a->version >= b->version) {
|
||||||
|
*out = *a;
|
||||||
|
} else {
|
||||||
|
*out = *b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
BIN
delta_mesh/demo
BIN
delta_mesh/demo
Binary file not shown.
|
|
@ -1,16 +1,43 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "LocalMarket.h"
|
#include "LocalMarket.h"
|
||||||
#include "admm_lite.h"
|
#include "admm_lite.h"
|
||||||
|
#include "Registry.h"
|
||||||
|
#include "dsl_seed.h"
|
||||||
|
#include "delta_crdt.h"
|
||||||
|
|
||||||
// A tiny demo that creates two LocalMarkets and demonstrates a simple ADMM-lite step.
|
// A tiny demo that creates two LocalMarkets and demonstrates a simple ADMM-lite step.
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
// 1) Demonstrate a simple registry usage (GoC-like bridge)
|
||||||
|
Registry reg;
|
||||||
|
registry_init(®);
|
||||||
|
registry_register(®, "LocalMarket", "v1.0", 1);
|
||||||
|
registry_register(®, "SharedSignals", "v1.0", 1);
|
||||||
|
const char* lm_ver = registry_lookup(®, "LocalMarket");
|
||||||
|
printf("DeltaMesh REG: LocalMarket -> %s\n", lm_ver ? lm_ver : "<missing>");
|
||||||
|
|
||||||
|
// 2) Demonstrate DSL seed usage (toy initialization)
|
||||||
|
LocalMarketSeed lm_seed;
|
||||||
|
dsl_localmarket_seed_init(&lm_seed, "VenueA", 100.0, 50.0);
|
||||||
|
SharedSignalsSeed ss_seed;
|
||||||
|
dsl_sharedsignals_seed_init(&ss_seed, 0.25, 0.18);
|
||||||
|
PlanDeltaSeed pd_seed;
|
||||||
|
dsl_plandelta_seed_init(&pd_seed, 0.5, 0.2, 12345);
|
||||||
|
printf("DeltaMesh DSL seeds: lm=%s, ivol=%.3f, quote=%.3f\n",
|
||||||
|
lm_seed.venue, ss_seed.implied_vol, pd_seed.quote);
|
||||||
|
|
||||||
|
// 3) Demonstrate a CRDT-like delta merge (toy)
|
||||||
|
DeltaCRDT d1 = { .version = 1, .value_delta = 0.2 };
|
||||||
|
DeltaCRDT d2 = { .version = 2, .value_delta = -0.1 };
|
||||||
|
DeltaCRDT merged = {0};
|
||||||
|
crdt_merge(&d1, &d2, &merged);
|
||||||
|
printf("DeltaMesh CRDT merge: ver=%lu delta=%.4f\n", merged.version, merged.value_delta);
|
||||||
|
|
||||||
|
// 4) Simple ADMM-lite step using existing demo helper for compatibility
|
||||||
LocalMarket v1 = {"VenueA", 100.0, 50.0};
|
LocalMarket v1 = {"VenueA", 100.0, 50.0};
|
||||||
LocalMarket v2 = {"VenueB", 150.0, 75.0};
|
LocalMarket v2 = {"VenueB", 150.0, 75.0};
|
||||||
|
|
||||||
double quotes[2] = { v1.inventory, v2.inventory };
|
double quotes[2] = { v1.inventory, v2.inventory };
|
||||||
double aggregate = 0.0;
|
double aggregate = 0.0;
|
||||||
admm_lite_step(quotes, 2, &aggregate);
|
admm_lite_step(quotes, 2, &aggregate);
|
||||||
|
|
||||||
printf("DeltaMesh DEMO: aggregated quote = %f\n", aggregate);
|
printf("DeltaMesh DEMO: aggregated quote = %f\n", aggregate);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,11 +1,21 @@
|
||||||
// Minimal DSL seed implementation for DeltaMesh MVP (toy).
|
|
||||||
#include "dsl_seed.h"
|
#include "dsl_seed.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// Example entry point to exercise the seed artifacts without pulling external deps.
|
void dsl_localmarket_seed_init(LocalMarketSeed* s, const char* venue, double inventory, double risk_budget) {
|
||||||
void dsl_seed_example_log(void) {
|
if (!s) return;
|
||||||
AuditLog log = { "delta_seed_initialized", 0 };
|
s->venue = venue;
|
||||||
(void)log; // suppress unused warning in a tiny demo
|
s->inventory = inventory;
|
||||||
// No-op print guarded by a macro in a real build; kept tiny to avoid side effects.
|
s->risk_budget = risk_budget;
|
||||||
// printf("%s @ %lu\n", log.entry, log.timestamp);
|
}
|
||||||
|
|
||||||
|
void dsl_sharedsignals_seed_init(SharedSignalsSeed* s, double greeks, double ivol) {
|
||||||
|
if (!s) return;
|
||||||
|
s->aggregated_greeks = greeks;
|
||||||
|
s->implied_vol = ivol;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dsl_plandelta_seed_init(PlanDeltaSeed* s, double quote, double hedge, unsigned long ts) {
|
||||||
|
if (!s) return;
|
||||||
|
s->quote = quote;
|
||||||
|
s->hedge = hedge;
|
||||||
|
s->timestamp = ts;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,28 @@
|
||||||
// Minimal DSL seed primitives for DeltaMesh MVP (toy).
|
// Lightweight seed structures for LocalMarket, SharedSignals, and PlanDelta
|
||||||
// This header provides lightweight, forward-looking data structures that
|
// to bootstrap interoperability in the DeltaMesh MVP.
|
||||||
// can be used by adapters and the coordination layer to agree on contract
|
|
||||||
// representations without leaking raw data.
|
|
||||||
|
|
||||||
#ifndef DSL_SEED_H
|
#ifndef DSL_SEED_H
|
||||||
#define DSL_SEED_H
|
#define DSL_SEED_H
|
||||||
|
|
||||||
typedef struct LocalArbProblem {
|
typedef struct LocalMarketSeed {
|
||||||
double objective; // toy objective value for the arb problem
|
const char* venue;
|
||||||
unsigned long timestamp; // monotonic timestamp for replay
|
double inventory;
|
||||||
} LocalArbProblem;
|
double risk_budget;
|
||||||
|
} LocalMarketSeed;
|
||||||
|
|
||||||
typedef struct AuditLog {
|
typedef struct SharedSignalsSeed {
|
||||||
const char* entry; // human-readable log entry or hash
|
double aggregated_greeks;
|
||||||
unsigned long timestamp; // log timestamp for replay and audit
|
double implied_vol;
|
||||||
} AuditLog;
|
} SharedSignalsSeed;
|
||||||
|
|
||||||
typedef struct GovernanceBlock {
|
typedef struct PlanDeltaSeed {
|
||||||
const char* policy; // description of governance constraint
|
double quote;
|
||||||
unsigned long timestamp; // policy versioning / timestamp
|
double hedge;
|
||||||
} GovernanceBlock;
|
unsigned long timestamp;
|
||||||
|
} PlanDeltaSeed;
|
||||||
|
|
||||||
|
void dsl_localmarket_seed_init(LocalMarketSeed* s, const char* venue, double inventory, double risk_budget);
|
||||||
|
void dsl_sharedsignals_seed_init(SharedSignalsSeed* s, double greeks, double ivol);
|
||||||
|
void dsl_plandelta_seed_init(PlanDeltaSeed* s, double quote, double hedge, unsigned long ts);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Binary file not shown.
5
test.sh
5
test.sh
|
|
@ -13,7 +13,10 @@ $cc $CCFLAGS -c delta_mesh/LocalMarket.c -o delta_mesh/LocalMarket.o || true
|
||||||
$cc $CCFLAGS -c delta_mesh/SharedSignals.c -o delta_mesh/SharedSignals.o || true
|
$cc $CCFLAGS -c delta_mesh/SharedSignals.c -o delta_mesh/SharedSignals.o || true
|
||||||
$cc $CCFLAGS -c delta_mesh/PlanDelta.c -o delta_mesh/PlanDelta.o || true
|
$cc $CCFLAGS -c delta_mesh/PlanDelta.c -o delta_mesh/PlanDelta.o || true
|
||||||
$cc $CCFLAGS -c delta_mesh/EnergiBridge.c -o delta_mesh/EnergiBridge.o
|
$cc $CCFLAGS -c delta_mesh/EnergiBridge.c -o delta_mesh/EnergiBridge.o
|
||||||
$cc $CCFLAGS -o delta_mesh/demo delta_mesh/demo_main.o delta_mesh/admm_lite.o delta_mesh/LocalMarket.o delta_mesh/SharedSignals.o delta_mesh/PlanDelta.o delta_mesh/EnergiBridge.o
|
$cc $CCFLAGS -c delta_mesh/Registry.c -o delta_mesh/Registry.o || true
|
||||||
|
$cc $CCFLAGS -c delta_mesh/dsl_seed.c -o delta_mesh/dsl_seed.o || true
|
||||||
|
$cc $CCFLAGS -c delta_mesh/delta_crdt.c -o delta_mesh/delta_crdt.o || true
|
||||||
|
$cc $CCFLAGS -o delta_mesh/demo delta_mesh/demo_main.o delta_mesh/admm_lite.o delta_mesh/LocalMarket.o delta_mesh/SharedSignals.o delta_mesh/PlanDelta.o delta_mesh/EnergiBridge.o delta_mesh/Registry.o delta_mesh/dsl_seed.o delta_mesh/delta_crdt.o
|
||||||
|
|
||||||
echo "Running demo..."
|
echo "Running demo..."
|
||||||
./delta_mesh/demo
|
./delta_mesh/demo
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue