replace state.json cache with bincode state.bin
Faster serialization/deserialization, smaller on disk (4.2MB vs 5.9MB). Automatic migration from state.json on first load — reads the JSON, writes state.bin, deletes the old file. Added list-keys, list-edges, dump-json commands so Python scripts no longer need to parse the cache directly. Updated bulk-categorize.py and consolidation-loop.py to use the new CLI commands.
This commit is contained in:
parent
c4d1675128
commit
4b0bba7c56
6 changed files with 88 additions and 24 deletions
|
|
@ -50,13 +50,12 @@ def call_sonnet(prompt: str, timeout: int = 300) -> str:
|
|||
|
||||
|
||||
def get_all_keys() -> list[str]:
|
||||
"""Get all node keys from state.json."""
|
||||
state_path = MEMORY_DIR / "state.json"
|
||||
if not state_path.exists():
|
||||
"""Get all node keys via poc-memory list-keys."""
|
||||
r = subprocess.run(["poc-memory", "list-keys"],
|
||||
capture_output=True, text=True, timeout=30)
|
||||
if r.returncode != 0:
|
||||
return []
|
||||
content = state_path.read_text()
|
||||
keys = re.findall(r'"key":\s*"([^"]*)"', content)
|
||||
return sorted(set(keys))
|
||||
return [k for k in r.stdout.strip().split('\n') if k]
|
||||
|
||||
|
||||
def get_unique_files(keys: list[str]) -> list[str]:
|
||||
|
|
|
|||
|
|
@ -167,16 +167,17 @@ def build_triangle_prompt(round_num: int) -> str:
|
|||
graph = get_graph_structure()
|
||||
status = get_status()
|
||||
|
||||
# Get some node pairs that share neighbors
|
||||
state_path = MEMORY_DIR / "state.json"
|
||||
if state_path.exists():
|
||||
state = state_path.read_text()
|
||||
# Extract some relations
|
||||
relations = re.findall(r'"source_key":\s*"([^"]*)".*?"target_key":\s*"([^"]*)"', state[:20000])
|
||||
else:
|
||||
relations = []
|
||||
# Get edges via CLI
|
||||
r = subprocess.run(["poc-memory", "list-edges"],
|
||||
capture_output=True, text=True, timeout=30)
|
||||
relations = []
|
||||
if r.returncode == 0:
|
||||
for line in r.stdout.strip().split('\n')[:100]:
|
||||
parts = line.split('\t')
|
||||
if len(parts) >= 2:
|
||||
relations.append((parts[0], parts[1]))
|
||||
|
||||
rel_sample = '\n'.join(f" {s} → {t}" for s, t in relations[:100])
|
||||
rel_sample = '\n'.join(f" {s} → {t}" for s, t in relations)
|
||||
|
||||
return f"""You are a triangle-closing agent (round {round_num}).
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue