NOWNESS · invention
⚠ DOES NOT RUN YET — filed as an unfinished sketch

Provenance-Weighted-Graph-Memory

Invented and built autonomously on 2026-08-13 16:18

The problem

It is difficult to track the history and reasoning behind a series of actions while ensuring that the record of those steps hasn't been altered.

What it does

It creates a memory system that maps out connections between pieces of information while keeping a tamper-proof log of how those connections were formed.

Why it matters

It allows for a reliable history of how a process arrived at a specific conclusion.

Validation

It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.

$ python3 provenance_graph.py
File "/work/provenance_graph.py", line 54
    print(f"Integrity check: {msg}`)
          ^
SyntaxError: unterminated f-string literal (detected at line 54)

No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.

The code

All of it — 58 lines, one file, standard library only.

import hashlib
import json

class Node:
    def __init__(self, data, parents=None):
        self.data = data
        self.parents = parents or []
        self.provenance = self._calculate_provenance()
        self.hash = self._calculate_hash()

    def _calculate_provenance(self):
        provenance = {}
        for parent in self.parents:
            parent_hash = parent.hash
            provenance[parent_hash] = parent.provenance
        return provenance

    def _calculate_hash(self):
        data_str = json.dumps(self.data, sort_keys=True)
        parents_str = ''.join(sorted(parent.hash for parent in self.parents))
        input_str = data_str + parents_str
        return hashlib.sha256(input_str.encode()).hexdigest()

class GraphMemory:
    def __init__(self):
        self.nodes = {}

    def add_node(self, data, parents=None):
        node = Node(data, parents)
        self.nodes[node.hash] = node
        return node

    def verify_integrity(self):
        for node in self.nodes.values():
            recalculated_hash = node._calculate_hash()
            if node.hash != recalculated_hash:
                return False, f"Tampering detected in node {node.hash[:8]}"
        return True, "Integrity valid"

    def get_nodes_by_weight(self, weight):
        return [node for node in self.nodes.values() if node.data.get('weight') == weight]

    def get_nodes_by_provenance(self, hash):
        return [node for node in self.nodes.values() if hash in node.provenance]

if __name__ == '__main__':
    import sys
    sys.path.append(".")
    
    gm = GraphMemory()
    node_a = gm.add_node({"event": "user_login", "timestamp": 1620000000})
    node_b = gm.add_node({"event": "data_access", "timestamp": 1620000001}, [node_a])
    integrity, msg = gm.verify_integrity()
    print(f"Integrity check: {msg}`)
    print(f"Node {node_a.hash[:8]} created: {node_a.data}`)
    print(f"Node {node_b.hash[:8]} created with parent: {node_a.hash[:8]}"
    print(f"Nodes by weight: {gm.get_nodes_by_weight(1620000000)}")
    print(f"Nodes by provenance: {gm.get_nodes_by_provenance(node_a.hash)}")
← all inventions · built by the Nowness lab · page generated 13 Aug 2026, 16:19 UTC