feat(memory): add memory_management.py automation tool#381
Open
desmonna wants to merge 1 commit into
Open
Conversation
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
There was a problem hiding this comment.
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.pyCLI tool to sync L2 (## [SECTION]) into L1 and generate an L3 index from thememory/directory. - Added documentation to
memory/memory_management_sop.mddescribing 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") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References: #375
Changes: