Skip to content

feat(memory): add memory_management.py automation tool#381

Open
desmonna wants to merge 1 commit into
lsdefine:mainfrom
desmonna:main
Open

feat(memory): add memory_management.py automation tool#381
desmonna wants to merge 1 commit into
lsdefine:mainfrom
desmonna:main

Conversation

@desmonna
Copy link
Copy Markdown
Contributor

References: #375

Changes:

  1. Add memory/memory_management.py - automation script for L1↔L2/L3 sync
    • L2 sync: parse ## [SECTION] headings, patch L1 index
    • L3 sync: scan memory/ dir, generate index with SOP>folder>py priority
    • CLI: --check / --rebuild-l3 / --validate / --dry-run
  2. Add section to memory/memory_management_sop.md
    • Document the automation tool usage, timing, and collaboration with SOP

References: lsdefine#375

Changes:
1. Add memory/memory_management.py - automation script for L1↔L2/L3 sync
   - L2 sync: parse ## [SECTION] headings, patch L1 index
   - L3 sync: scan memory/ dir, generate index with SOP>folder>py priority
   - CLI: --check / --rebuild-l3 / --validate / --dry-run
2. Add section to memory/memory_management_sop.md
   - Document the automation tool usage, timing, and collaboration with SOP
Copilot AI review requested due to automatic review settings May 14, 2026 15:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an automation script to keep the repo’s memory index (L1) synchronized with L2 section headings and the L3 filesystem layout, and documents how/when to run it in the META-SOP.

Changes:

  • Added memory/memory_management.py CLI tool to sync L2 (## [SECTION]) into L1 and generate an L3 index from the memory/ directory.
  • Added documentation to memory/memory_management_sop.md describing the tool’s purpose and recommended workflows/flags.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
memory/memory_management.py New CLI script implementing L1↔L2/L3 sync, L3 rebuild, and L1 validation.
memory/memory_management_sop.md New SOP section documenting how and when to run the automation tool.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +32
import os
import re
import argparse
from datetime import datetime
Comment on lines +69 to +74
def parse_l1_l2_topics(l1_content):
"""Parse L1 L2 line. L2 uses '/' as topic delimiter, so L2 section names must not contain '/'."""
for line in l1_content.splitlines():
if line.startswith('L2:'):
parts = line.replace('L2:', '', 1).strip().split('/')
return [p.strip() for p in parts if p.strip()]
Comment on lines +109 to +116
def l3_base_name(path):
"""Return rough skill base for grouping SOP/folder/py."""
name = path.name
if path.is_dir():
return name
if name.endswith('_sop.md'):
return name[:-7] # remove _sop.md
if name.endswith('.md'):
folder_names.append(item.name)
elif is_standalone_py(item):
if not sop_represented_py(item, sop_bases):
py_names.append(item.stem)
Comment on lines +257 to +271
# Patch L1 L3 block
lines = l1_content.splitlines()
start, end, block = extract_l3_block(lines)

if start is None:
# No L3 line, add one
new_lines = lines + [f'L3: ' + ' | '.join(added)]
return '\n'.join(new_lines), added, stale

# Build new L3 content
existing_text = ' | '.join(l3_existing + added)
new_l3_line = f'L3: {existing_text}'

new_lines = lines[:start] + [new_l3_line] + lines[end:]
return '\n'.join(new_lines), added, stale
Comment on lines +280 to +304

removed = [e for e in l3_existing if e not in l3_scan]

lines = l1_content.splitlines()
start, end, _ = extract_l3_block(lines)

if start is None:
if l3_scan:
new_lines = lines + [f'L3: ' + ' | '.join(l3_scan)]
else:
new_lines = lines
return '\n'.join(new_lines), removed

# Build new L3 content with only valid entries
valid_entries = [e for e in l3_existing if e in l3_scan]
# Add new entries not in existing
for e in l3_scan:
if e not in valid_entries:
valid_entries.append(e)

if valid_entries:
new_l3_line = f'L3: ' + ' | '.join(valid_entries)
else:
new_l3_line = 'L3: (empty)'

Comment on lines +316 to +321
if len(lines) > 35:
issues.append(f"L1 has {len(lines)} lines, exceeds 30-line limit")

if len(l1_content) > 2000:
issues.append(f"L1 is {len(l1_content)} chars, may exceed 1k tokens")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants