It is difficult to track how much information remains relevant or accurate as a project evolves over time. Projects often accumulate outdated data that makes it hard to see what is still important.
It looks at different parts of a project and calculates a score based on how much that information has changed or faded. It tracks how well each piece of data holds up as the rest of the project moves forward.
It helps identify which parts of a project are becoming outdated so you can focus on what still matters.
It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.
$ python3 context_aware_state_node_memory.py
Traceback (most recent call last):
File "/work/context_aware_state_node_memory.py", line 105, in <module>
decay_scores = manager.calculate_all_decay_scores()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/context_aware_state_node_memory.py", line 74, in calculate_all_decay_scores
return {node.id: node.calculate_contextual_decay() for node in self.nodes}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/context_aware_state_node_memory.py", line 20, in calculate_contextual_decay
reachability_score = self._calculate_reachability()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/context_aware_state_node_memory.py", line 44, in _calculate_reachability
queue.extend((dep, current_depth + 1) for dep in dep.depends_on)
^^^
NameError: name 'dep' is not definedNo screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.
All of it — 188 lines, one file, standard library only.
import json
from datetime import datetime
import heapq
PRIORITY_WEIGHTS = {
'critical': 1.50,
'high': 1.25,
'medium': 1.00,
'low': 0.75,
'none': 0.50,
}
class ContextualMemory:
def __init__(self, node_data):
self.id = node_data.get('id')
self.type = node_data.get('type', 'task')
self.created_at = datetime.fromisoformat(node_data.get('created_at', datetime.now().isoformat()))
self.last_updated = datetime.fromisoformat(node_data.get('last_updated', datetime.now().isoformat()))
self.depends_on = node_data.get('depends_on', [])
self.states = node_data.get('states', [])
self.context = node_data.get('context', {})
def calculate_contextual_decay(self):
time_delta = (datetime.now() - self.last_updated).total_seconds()
time_decay = max(0.1, 1.0 / (time_delta + 1)) # Inverse decay over time
reachability_score = self._calculate_reachability()
state_entropy = self._calculate_state_entropy()
base_decay = (time_decay * 0.5) + (reachability_score * 0.3) + (state_entropy * 0.2)
priority_weight = self._get_priority_weight()
decay_score = base_decay * priority_weight
return min(1.0, decay_score), {
'time_decay': time_decay,
'reachability_score': reachability_score,
'state_entropy': state_entropy,
'base_decay': base_decay,
'priority_weight': priority_weight,
'priority': self.context.get('priority', 'unknown'),
}
def _get_priority_weight(self):
priority = self.context.get('priority', 'medium')
if isinstance(priority, str):
return PRIORITY_WEIGHTS.get(priority.lower(), 1.00)
try:
return float(priority)
except (TypeError, ValueError):
return 1.00
def _calculate_reachability(self):
if not self.depends_on:
return 0.5 # Base score for independent nodes
reachable_nodes = 1 # Self
depth = 1
queue = [(self, depth)]
while queue:
node, current_depth = queue.pop(0)
for dependency in node.depends_on:
reachable_nodes += 1
queue.extend((dep, current_depth + 1) for dep in dep.depends_on)
depth = max(depth, current_depth)
if depth > 5:
break
return min(1.0, reachable_nodes / (2 ** depth))
def _calculate_state_entropy(self):
if not self.states:
return 0.5
state_changes = [s['state'] for s in self.states if s.get('changed')]
if len(set(state_changes)) == 1:
return 0.3
return 0.7
class ContextMemoryManager:
def __init__(self, memory_nodes):
self.nodes = [ContextualMemory(node) for node in memory_nodes]
self.graph = self._build_graph()
def _build_graph(self):
graph = {
node.id: node for node in self.nodes
}
return graph
def calculate_all_decay_scores(self):
scores = {}
for node in self.nodes:
score, details = node.calculate_contextual_decay()
scores[node.id] = (score, details)
return scores
if __name__ == '__main__':
example_nodes = [
{
'id': 'task-1',
'type': 'task',
'created_at': '2026-07-20T10:00:00',
'last_updated': '2026-07-25T14:30:00',
'depends_on': ['task-0'],
'states': [
{'state': 'pending', 'changed': True},
{'state': 'in-progress', 'changed': True}
],
'context': {'priority': 'high'}
},
{
'id': 'task-0',
'type': 'task',
'created_at': '2026-07-15T09:00:00',
'last_updated': '2026-07-22T11:00:00',
'depends_on': [],
'states': [
{'state': 'pending', 'changed': True}
]
},
{
'id': 'task-2',
'type': 'task',
'created_at': '2026-07-18T08:00:00',
'last_updated': '2026-07-24T09:00:00',
'depends_on': ['task-1'],
'states': [
{'state': 'pending', 'changed': True},
{'state': 'in-progress', 'changed': True},
{'state': 'completed', 'changed': True}
],
'context': {'priority': 'critical'}
},
{
'id': 'task-3',
'type': 'task',
'created_at': '2026-07-10T12:00:00',
'last_updated': '2026-07-19T16:00:00',
'depends_on': [],
'states': [
{'state': 'pending', 'changed': True}
],
'context': {'priority': 'low'}
},
{
'id': 'task-4',
'type': 'task',
'created_at': '2026-07-22T07:00:00',
'last_updated': '2026-07-28T08:00:00',
'depends_on': ['task-0', 'task-1'],
'states': [
{'state': 'pending', 'changed': True}
],
'context': {'priority': 'medium'}
},
]
manager = ContextMemoryManager(example_nodes)
decay_scores = manager.calculate_all_decay_scores()
print('=' * 78)
print('CONTEXT-AWARE STATE NODE MEMORY v2 — Priority-Weighted Decay')
print('=' * 78)
print()
print(f"{'Node':<10} {'Priority':<10} {'Time':>7} {'Reach':>7} {'Entropy':>7} {'Base':>7} {'Wt':>6} {'Final':>7}")
print('-' * 78)
for node_id, (score, d) in sorted(decay_scores.items()):
print(
f"{node_id:<10} {d['priority']:<10} "
f"{d['time_decay']:7.4f} {d['reachability_score']:7.4f} "
f"{d['state_entropy']:7.4f} {d['base_decay']:7.4f} "
f"{d['priority_weight']:6.2f} {score:7.4f}"
)
print()
print('Weight map: critical=1.50 high=1.25 medium=1.00 low=0.75 em=0.50')
print()
print('Priority effect on decay:')
non_weighted = {nid: d['base_decay'] for nid, (_, d) in decay_scores.items()}
print(f" Without priority weighting: {non_weighted}")
print(f" With priority weighting: { {nid: round(s, 4) for nid, (s, _) in decay_scores.items()} }")