22 KiB
22 KiB
Repo State Report
1) Build + test entrypoints
- Tests:
ctest --test-dir build(top-level build includes vendor tests viaadd_subdirectory(vendor/amduat)inCMakeLists.txt); core-only tests:ctest --test-dir vendor/amduat/build(binaries present invendor/amduat/build). - Main daemon:
./build/amduatd --root .amduat-asl --sock amduatd.sock(README.md,src/amduatd.c). - Dev loop:
./scripts/dev-restart.sh(build + restart inscripts/dev-restart.sh). - Core CLIs/tools:
./vendor/amduat/build/amduat-asl ...(store/init/log/index commands invendor/amduat/src/tools/amduat_asl_cli.c),./vendor/amduat/build/amduat-pel ...(PEL tooling invendor/amduat/src/tools/amduat_pel_cli.c),./build/amduat-pel gc --root .amduat-asl(GC tool insrc/amduat_pel_gc.c). - Languages/toolchains: C11 + CMake (
CMakeLists.txt,vendor/amduat/CMakeLists.txt), shell scripts (scripts/*.sh), embedded HTML/JS/CSS in C strings (src/amduatd_ui.c). - CI config: none found (no
.github/workflows/*,.gitlab-ci.yml, etc.).
2) Top-level architecture map (as implemented)
- Daemon runtime + HTTP surface: Paths
src/amduatd.c,src/amduatd_http.c,src/amduatd_http.h,src/amduatd_ui.c; main typesamduatd_cfg_t,amduatd_http_req_t,amduatd_http_resp_t; entrypointsmain,amduatd_handle_conn,amduatd_http_read_req; wiring: initializes store fs config, concepts, caps, federation coord, then serves HTTP over Unix socket with aselect()loop (src/amduatd.c). - Capability tokens: Paths
src/amduatd_caps.c,src/amduatd_caps.h; main typesamduatd_caps_t,amduatd_caps_token_t; entrypointsamduatd_caps_init,amduatd_caps_handle,amduatd_caps_check; wiring: per-request token validation with optional space/pointer scoping (src/amduatd_caps.c). - Concepts/relations + edge graph index: Paths
src/amduatd_concepts.c,src/amduatd_concepts.h; main typesamduatd_concepts_t,amduatd_edge_index_state_t,amduatd_edge_list_t; entrypointsamduatd_concepts_init,amduatd_concepts_refresh_edges,amduatd_handle_get_relations,amduatd_handle_get_concepts; wiring: edge records stored in a collection log, plus derived edge graph + index pointer state (src/amduatd_concepts.c). - Space scoping: Paths
src/amduatd_space.c,src/amduatd_space.h; main typesamduatd_space_t; entrypointsamduatd_space_init,amduatd_space_scope_name,amduatd_space_unscoped_name; wiring: scopes pointer/collection names with prefixspace/<space_id>/when enabled (src/amduatd_space.c). - Federation coordinator: Paths
federation/coord.c,federation/coord.h; main typesamduat_fed_coord_t,amduat_fed_coord_cfg_t; entrypointsamduat_fed_coord_open,amduat_fed_coord_tick,amduat_fed_coord_get_status; wiring: daemon ticks coordinator on interval (src/amduatd.c). - Federation transport: Paths
federation/transport_unix.c,federation/transport_stub.c; main typesamduat_fed_transport_t; entrypointsamduat_fed_transport_unix_ops,amduat_fed_transport_stub_ops; wiring: daemon currently uses stub transport (src/amduatd.c). - CAS store (filesystem): Paths
vendor/amduat/src/adapters/asl_store_fs/*,vendor/amduat/include/amduat/asl/store.h; main typesamduat_asl_store_fs_t,amduat_asl_store_t; entrypointsamduat_asl_store_fs_init,amduat_asl_store_put,amduat_asl_store_get; wiring: used by daemon and tools as the backing store. - Pointer store: Paths
vendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c; main typesamduat_asl_pointer_store_t; entrypointsamduat_asl_pointer_get,amduat_asl_pointer_cas; wiring: used by log store, collection store, concept index, and caps checks. - Log store: Paths
vendor/amduat/src/core/asl_log_store.c,vendor/amduat/include/amduat/asl/log_store.h; main typesamduat_asl_log_store_t,amduat_asl_log_entry_t; entrypointsamduat_asl_log_append,amduat_asl_log_read; wiring: collection store writes log chunks in CAS and advances pointer heads. - Collection store: Paths
vendor/amduat/src/core/asl_collection.c,vendor/amduat/include/amduat/asl/collection.h; main typesamduat_asl_collection_store_t; entrypointsamduat_asl_collection_append,amduat_asl_collection_snapshot,amduat_asl_collection_read; wiring: concept edges are stored as records appended to a collection log. - ASL index store: Paths
vendor/amduat/src/adapters/asl_store_index_fs/*; main typesamduat_asl_store_index_fs_t,amduat_asl_index_state_t; entrypointsamduat_asl_store_index_fs_put_indexed,amduat_asl_store_index_fs_log_scan,amduat_asl_store_index_fs_gc; wiring: available in core but not wired into amduatd (amduatd uses store_fs ops). - PEL execution + materialization cache: Paths
vendor/amduat/src/pel_stack/surf/surf.c,vendor/amduat/src/adapters/asl_materialization_cache_fs/asl_materialization_cache_fs.c; main typesamduat_pel_program_t,amduat_pel_run_result_t; entrypointsamduat_pel_surf_run_with_result,amduat_asl_materialization_cache_fs_get,amduat_asl_materialization_cache_fs_put; wiring: used by/v1/pel/runand by the collection view implementation. - Derivation index (core-only): Paths
vendor/amduat/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c,vendor/amduat/include/amduat/asl/asl_derivation_index_fs.h; main typesamduat_asl_derivation_index_fs_t,amduat_asl_derivation_record_t; entrypointsamduat_asl_derivation_index_fs_add,amduat_asl_derivation_index_fs_list; wiring: used by CLI tools (vendor/amduat/src/tools/amduat_asl_cli.c,vendor/amduat/src/tools/amduat_pel_cli.c), not by amduatd.
3) “Space” concept: definition + storage layout
- Definition: “space” is a daemon-level scoping prefix for pointer/collection names, not a separate store; it rewrites names into
space/<space_id>/...when enabled (src/amduatd_space.c,amduatd_space_scope_name,amduatd_space_unscoped_name). - Storage layout: scoped names are stored in the pointer store under
root/pointers/space/<space_id>/.../headperamduat_asl_pointer_build_head_path(vendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c). No dedicated per-space directory outside pointer name paths is created by amduatd. - Identification:
space_idis a pointer-name-safe token without/, validated byamduatd_space_space_id_is_valid(callsamduat_asl_pointer_name_is_valid) (src/amduatd_space.c). - Multi-space support: only one space can be active per daemon process via
--space(src/amduatd.c,amduatd_space_init); code does not show per-request space selection.
4) Source of truth: pointers + logs (actual)
- Canonical “head/root” pointer for a space: there is no single global space root pointer. The main space-scoped heads used by amduatd are the edge index head (
daemon/edges/index/headscoped byamduatd_space_edges_index_head_name) and collection snapshot/log heads for the edge collection (see below) (src/amduatd_space.c,src/amduatd_concepts.c). - Pointer storage location + format:
- Location:
root/pointers/<name>/headusing path segments from the pointer name (amduat_asl_pointer_build_head_pathinvendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c). - Format:
ASLPTR1magic with version and flags, then name/ref/prev fields encoded viaamduat_enc_asl1_core_encode_reference_v1(amduat_asl_pointer_read_headandamduat_asl_pointer_write_headinvendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c). - Read/write:
amduat_asl_pointer_getandamduat_asl_pointer_cas(vendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c).
- Location:
- Collection heads used by amduatd concepts:
- Snapshot head pointer:
collection/<name>/headbuilt byamduatd_build_collection_head_name(src/amduatd_concepts.c) and also byamduat_asl_collection_build_head_name(vendor/amduat/src/core/asl_collection.c). - Log head pointer:
log/collection/<name>/log/headbuilt byamduatd_build_collection_log_head_name(src/amduatd_concepts.c) andamduat_asl_log_build_pointer_name(vendor/amduat/src/core/asl_log_store.c).
- Snapshot head pointer:
- Log entry schema (ASL index log):
amduat_asl_log_record_t {logseq, record_type, payload, record_hash}with record types defined invendor/amduat/include/amduat/enc/asl_log.h. - Log append behavior:
- Collection log:
amduat_asl_log_appendwrites CAS log chunks (ASL_LOG_CHUNK_1) and advances the log head pointer via CAS (vendor/amduat/src/core/asl_log_store.c). - Index log:
amduat_asl_store_index_fs_append_log_recordappends toindex/log.asl(vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c).
- Collection log:
- Integrity mechanisms:
- Collection log chunks form a chain via
prev_refand are rooted at the log head pointer (amduat_asl_log_append,amduat_asl_log_chunk_tinvendor/amduat/src/core/asl_log_store.c). - Index log uses a hash chain where
record_hash = SHA256(prev_hash || logseq || type || payload_len || payload)(amduat_asl_store_index_fs_log_hash_recordinvendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c).
- Collection log chunks form a chain via
- Log traversal:
- Collection log:
amduat_asl_log_readwalks the head pointer andprev_refchain to gather chunks (vendor/amduat/src/core/asl_log_store.c). - Index log: replay happens via
amduat_asl_store_index_fs_build_replay_stateusingamduat_asl_replay_apply_log(vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c,vendor/amduat/include/amduat/asl/index_replay.h).
- Collection log:
- Other persistent state that can diverge from logs/pointers:
- Edge index state and edge graph artifacts (
tgk/edge_index_staterecord +TGK_EDGE_GRAPH_1artifact) are separate derived state from the edge collection log (src/amduatd_concepts.c). - Legacy
.amduatd.edgesfile (used only for migration) can diverge until migrated (src/amduatd_concepts.c). - Materialization cache in
index/materializationscan diverge from CAS and is treated as a cache (vendor/amduat/src/adapters/asl_materialization_cache_fs/asl_materialization_cache_fs.c).
- Edge index state and edge graph artifacts (
5) CAS (content-addressed store)
- Hash algorithm: SHA-256 is the only defined ASL1 hash id and default (
AMDUAT_HASH_ASL1_ID_SHA256invendor/amduat/include/amduat/hash/asl1.h, default config invendor/amduat/src/adapters/asl_store_fs/asl_store_fs_meta.c). - Object types stored: arbitrary artifacts with optional type tags (
amduat_artifact_tinvendor/amduat/include/amduat/asl/core.h); records are stored viaamduat_asl_record_store_put(schema + payload) invendor/amduat/src/core/asl_record.cand used by amduatd for concept edges (src/amduatd_concepts.c). - Address format: refs are
{hash_id, digest}; on disk, objects are stored under hex-digest filenames derived from the raw digest (amduat_asl_store_fs_layout_build_pathsinvendor/amduat/src/adapters/asl_store_fs/asl_store_fs_layout.c). - Disk layout and APIs:
- Layout:
root/objects/<profile_hex>/<hash_hex>/<byte0>/<byte1>/<digest_hex>(amduat_asl_store_fs_layout_build_pathsinvendor/amduat/src/adapters/asl_store_fs/asl_store_fs_layout.c). - APIs:
amduat_asl_store_put/get(generic) andamduat_asl_store_fs_ops(filesystem implementation) (vendor/amduat/include/amduat/asl/store.h,vendor/amduat/src/adapters/asl_store_fs/asl_store_fs.c).
- Layout:
- Garbage collection:
- Exists as a standalone tool:
amduat-pel gcusesamduat_asl_gc_fs_runto mark from pointer/log/collection roots and optionally delete artifacts (src/amduat_pel_gc.c,src/asl_gc_fs.c).
- Exists as a standalone tool:
- Pinning concept: no explicit pin API found; reachability is derived from pointers/logs/snapshots (GC uses those roots) (
src/asl_gc_fs.c).
6) Deterministic derivations (current reality)
- Derivation-related types exist in core:
amduat_pel_derivation_sid_input_t,amduat_pel_derivation_sid_compute(vendor/amduat/include/amduat/pel/derivation_sid.h,vendor/amduat/src/core/derivation_sid.c). - Execution model: PEL DAGs execute in-process (no external sandbox) via
amduat_pel_program_dag_exec_traceandamduat_pel_surf_run_with_result(vendor/amduat/src/pel_stack/surf/surf.c). - Inputs: referenced as CAS refs from the store (
amduat_pel_surf_run_with_resultloads program/input/params artifacts by ref invendor/amduat/src/pel_stack/surf/surf.c). - Outputs: stored back into CAS (
amduat_asl_store_putinvendor/amduat/src/pel_stack/surf/surf.c); results/traces/receipts are separate artifacts (amduat_enc_pel1_result,amduat_enc_pel_trace_dagetc. used insrc/amduatd.c). - Provenance/audit: optional FER1 receipt data is accepted/serialized in
/v1/pel/run(src/amduatd.c), but no daemon-side derivation index is written. - Derivation index persistence: exists in core (
vendor/amduat/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c) and CLI tools (vendor/amduat/src/tools/amduat_asl_cli.c,vendor/amduat/src/tools/amduat_pel_cli.c), but amduatd does not write derivation records (no references insrc/).
7) ASL index: what it is and what it depends on
- Storage location:
root/index/withlog.asl,segments/,blocks/, andsnapshots/(layout invendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs_layout.c). - Derived vs authoritative: the index log (
index/log.asl) and segment files are the authoritative index state; higher-level state can be rebuilt by replaying the log plus snapshots (amduat_asl_store_index_fs_build_replay_state+amduat_asl_replay_apply_loginvendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c). - Build/update path:
amduat_asl_store_index_fs_put_indexedappends log records, writes segments/blocks, and may create snapshots (vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c). - Queries relying on it:
amduat_asl_log_scan, tombstone operations, andamduat_asl_index_current_stateare implemented by the index-backed store ops (vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c,vendor/amduat/include/amduat/asl/store.h). - What breaks if deleted: if
index/(includinglog.asl) is removed, index-backed stores cannot answer log/state/tombstone queries; recovery requires a log to replay, which lives underindex/itself (vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c).
8) Daemon / runtime model (if any)
- Daemon process:
amduatdinsrc/amduatd.cbinds a Unix domain socket, listens, and handles one connection peraccept()in a single-threaded loop usingselect(). - Single-space or multi-space: single-space per daemon process via
--space(src/amduatd.c,src/amduatd_space.c). - Config mechanism: CLI flags
--root,--sock,--space,--migrate-unscoped-edges,--edges-refresh-ms,--allow-uid,--allow-user,--enable-cap-reads(src/amduatd.c). - IPC/RPC/HTTP APIs: HTTP over Unix socket, routes in
src/amduatd.cand handlers insrc/amduatd_concepts.candsrc/amduatd_caps.c. - Background workers: federation tick every 1s (
AMDUATD_FED_TICK_MS) and optional edge refresh on--edges-refresh-msinterval (src/amduatd.c).
9) Projections / query layer
- Projection concept in this repo: the edge graph and edge index state are projections derived from the edge collection log (
AMDUATD_EDGE_INDEX_SCHEMA,amduatd_concepts_write_edge_index_state,amduatd_concepts_refresh_edges_internalinsrc/amduatd_concepts.c). - Generation + storage: edge graph stored as
TGK_EDGE_GRAPH_1artifact plus pointer totgk/edge_index_staterecord (src/amduatd_concepts.c). - Derived from logs/CAS: refresh reads collection log entries via
amduat_asl_log_readand rebuilds the edge list/graph (src/amduatd_concepts.c). - Query APIs: HTTP endpoints for concepts/relations/resolve in
src/amduatd_concepts.cand routing insrc/amduatd.c; collection view is generated by a PEL program over collection snapshot + log (amduatd_collection_viewinsrc/amduatd_concepts.c).
10) Federation / collaboration
- Networking code:
federation/transport_unix.cbuilds HTTP requests over Unix sockets for/v1/fed/recordsand/v1/fed/artifacts(seeamduat_fed_transport_unix_ops). - Federation coordinator:
federation/coord.cmaintains registry state and a cached view (amduat_fed_coord_t). - Daemon behavior: federation is wired but uses the stub transport (
amduat_fed_transport_stub_opsinsrc/amduatd.c), so no remote sync by default. - Remote refs/replication/merge/signatures: not implemented in daemon beyond read-only federation endpoints; no CRDT/merge logic found in this repo (coordinator logic delegates to core types in
vendor/amduat/include/amduat/fed/*).
11) Invariants (explicit + implicit)
- Pointer names are path-safe and forbid
..segments; used throughout for space IDs and pointer names (amduat_asl_pointer_name_is_validinvendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c). - Collection log append is append-only with CAS+pointer CAS; chunks point to previous chunk to form a chain (
amduat_asl_log_append,amduat_asl_log_chunk_tinvendor/amduat/src/core/asl_log_store.c). - Log chunk entries must be consistent about timestamp/actor presence across the batch (
amduat_asl_log_entries_consistentinvendor/amduat/src/core/asl_log_store.c). - Collection snapshot heads and log heads are stable pointer names derived from collection name (
amduat_asl_collection_build_head_nameandamduat_asl_collection_build_log_nameinvendor/amduat/src/core/asl_collection.c). - Index log hash chain uses
prev_hash+ record fields to compute the next hash (amduat_asl_store_index_fs_log_hash_recordinvendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c). - Edge index state is written via pointer CAS, implying the index head should only advance if the expected previous ref matches (
amduatd_concepts_write_edge_index_stateinsrc/amduatd_concepts.c).
12) Immediate risks of “parallel mechanisms”
- Edge index state vs edge collection log: the derived edge graph +
tgk/edge_index_statecan diverge from the log if refresh fails; there is a deterministic rebuild path by replaying the collection log (amduatd_concepts_refresh_edges_internalinsrc/amduatd_concepts.c). - Legacy
.amduatd.edgesvs collection log: migration reads.amduatd.edgesand writes into the collection log, so stale files can diverge until migrated (amduatd_concepts_migrate_edgesinsrc/amduatd_concepts.c). - Materialization cache vs CAS: cache entries are validated against CAS and are treated as a performance-only layer; missing or stale cache forces recompute (
amduat_asl_materialization_cache_fs_getusage invendor/amduat/src/pel_stack/surf/surf.c). - ASL index files vs index log: segment/summary/snapshot files are derived from
index/log.asl; if any are deleted,amduat_asl_store_index_fs_build_replay_statecan rebuild from the log, but ifindex/log.aslis deleted the rebuild story is gone (vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs.c). - Federation coordinator cached view vs store log: coordinator caches
last_viewin memory and refreshes on tick; divergence is possible across restarts or if tick stops (federation/coord.c,src/amduatd.c).
13) Recommendation inputs (no decision yet)
- Current capability summary:
- Local Unix-socket HTTP daemon over a single ASL store root with artifact CRUD, concepts/relations, and PEL execution (
src/amduatd.c,src/amduatd_concepts.c). - CAS store on disk with pointer and log primitives; collection logs and snapshot pointers are wired (
vendor/amduat/src/adapters/asl_store_fs,vendor/amduat/src/core/asl_log_store.c,vendor/amduat/src/core/asl_collection.c). - Edge graph projection maintained as derived state from collection logs (
src/amduatd_concepts.c). - Federation coordinator scaffolding and endpoints, but using stub transport by default (
federation/coord.c,federation/transport_stub.c,src/amduatd.c). - Core tooling for index/derivation/GC exists in vendor and repo tools (
vendor/amduat/src/tools/*,src/amduat_pel_gc.c).
- Local Unix-socket HTTP daemon over a single ASL store root with artifact CRUD, concepts/relations, and PEL execution (
- Top 5 unknowns/blockers for the next step (grounded in code):
- Whether amduatd should switch to
amduat_asl_store_index_fs_opsto enableamduat_asl_log_scanand tombstones; current store fs ops do not implement log scan (vendor/amduat/src/adapters/asl_store_fs/asl_store_fs.c,vendor/amduat/src/near_core/asl/store.c). - The intended authoritative store for federation records: amduatd’s
/v1/fed/recordsrelies onamduat_asl_log_scan, which is unsupported by store_fs (src/amduatd.c,vendor/amduat/src/near_core/asl/store.c). - How/when to persist derivation index records from daemon PEL runs (present in core but unused in
src/). - Whether the “space” scope should be exposed as a first-class selector in the API (only CLI flag currently applies globally).
- The intended registry flow for federation (coordinator expects registry refs, but no daemon config path for them besides code defaults in
src/amduatd.c).
- Whether amduatd should switch to
- Top 5 next commit candidates grounded in repo reality (no new architecture):
- Wire amduatd to an index-backed store (use
amduat_asl_store_index_fs_ops) so federation record scanning and index state endpoints are meaningful. - Add a daemon flag/config to load a federation registry ref and domain id into
amduat_fed_coord_cfg_t(values are currently hardcoded insrc/amduatd.c). - Persist derivation index records for
/v1/pel/runoutputs using existing coreamduat_asl_derivation_index_fs_*APIs. - Expose index state or health endpoints that surface
amduat_asl_index_current_state(available in core API, already used in/v1/fed/records). - Formalize edge index rebuild tooling (e.g., CLI switch or maintenance endpoint) using existing
amduatd_concepts_refresh_edgesand pointer state.
- Wire amduatd to an index-backed store (use
- Method used:
- Searched for key terms with
rg -n "cas|content address|hash|log|append|pointer|head|space|derivation|projection|ASL|index|daemon|server|coordinator|sync|replication". - Read key sources:
src/amduatd.c,src/amduatd_concepts.c,src/amduatd_space.c,vendor/amduat/src/adapters/asl_store_fs/asl_store_fs_layout.c,vendor/amduat/src/adapters/asl_pointer_fs/asl_pointer_fs.c,vendor/amduat/src/core/asl_log_store.c,vendor/amduat/src/adapters/asl_store_index_fs/asl_store_index_fs_layout.c. - Ran CLIs:
./build/amduatd --help,./vendor/amduat/build/amduat-asl --help,./vendor/amduat/build/amduat-asl index state --root .amduat-asl,./vendor/amduat/build/amduat-asl log inspect --root .amduat-asl. - Tests were not executed; enumerated
ctestcommands above.
- Searched for key terms with