Sync .meaning/index.yaml with filesystem changes
Synchronize the .meaning/index.yaml with filesystem changes by detecting new, modified, and deleted files.
Keeps your semantic index in sync with the actual filesystem by:
from pathlib import Path
from meaning.meaning_core import meaning_dir_exists, load_index, load_schema, load_config
project_root = Path.cwd()
# Check if .meaning/ exists
if not meaning_dir_exists(project_root):
print("ā .meaning/ not found!")
print("Run /meaning-init to create semantic index first")
exit(1)
# Load existing index
index = load_index(project_root)
schema = load_schema(project_root)
config = load_config(project_root)
print(f"ā Loaded index with {len(index.files)} files")
from meaning.meaning_core import (
find_unindexed_files,
find_modified_files,
find_deleted_files,
)
# Find changes
new_files = find_unindexed_files(project_root, index, config)
modified_files = find_modified_files(project_root, index)
deleted_files = find_deleted_files(project_root, index)
print(f"š Changes detected:")
print(f" ⢠New files: {len(new_files)}")
print(f" ⢠Modified files: {len(modified_files)}")
print(f" ⢠Deleted files: {len(deleted_files)}")
if not new_files and not modified_files and not deleted_files:
print("ā Index is up to date!")
exit(0)
if deleted_files:
print(f"\nšļø Removing {len(deleted_files)} deleted files:")
for path in deleted_files:
print(f" ⢠{path}")
index.remove_file(path)
from meaning_inference import infer_file_metadata, infer_timestamps
from meaning.meaning_core import FileEntry
if new_files:
print(f"\n⨠Adding {len(new_files)} new files:")
now = infer_timestamps()
for i, file_path in enumerate(new_files):
print(f" Inferring {i+1}/{len(new_files)}: {file_path}")
# Run inference
result = infer_file_metadata(file_path, project_root, index, schema)
# Determine if needs review
needs_review = (
not result.intent
or (result.intent and result.intent.confidence < 0.8)
or len(result.tags) == 0
or any(e for e in result.errors)
)
# High-confidence tags and relationships
high_conf_tags = [t.tag for t in result.tags if t.confidence >= 0.8]
high_conf_rels = [r.relationship for r in result.relationships if r.confidence >= 0.8]
# Create entry
intent = result.intent.intent if result.intent else f"[REVIEW NEEDED] {file_path}"
entry = FileEntry(
path=file_path,
intent=intent,
tags=high_conf_tags if high_conf_tags else ["x-needs-tags"],
status="active",
needs_review=needs_review,
last_verified=now,
relationships=high_conf_rels,
)
index.add_file(entry)
if modified_files:
print(f"\nš Flagging {len(modified_files)} modified files for review:")
now = infer_timestamps()
for file_path in modified_files:
print(f" ⢠{file_path}")
# Get existing entry
entry = index.get_file(file_path)
if entry:
# Flag for review and update timestamp
entry.needs_review = True
entry.last_verified = now
# Optionally re-run inference and show suggestions
# (User can review and apply manually)
from meaning.meaning_core import save_index, validate_index
# Update index timestamp
index.last_updated = infer_timestamps()
# Save
save_index(index, project_root)
print(f"\nā Saved updated index.yaml")
# Validate
validation = validate_index(index, schema, config, project_root)
print("\n" + "="*60)
print("š UPDATE COMPLETE")
print("="*60)
print(f"ā Files in index: {len(index.files)}")
print(f" + Added: {len(new_files)}")
print(f" ~ Modified: {len(modified_files)}")
print(f" - Deleted: {len(deleted_files)}")
print(f"ā ļø Files needing review: {len(index.files_needing_review())}")
print(f"ā Validation: {validation.is_valid}")
if validation.errors:
print(f"\nā Errors: {len(validation.errors)}")
for e in validation.errors[:5]:
print(f" ⢠{e}")
if validation.warnings:
print(f"\nā ļø Warnings: {len(validation.warnings)}")
for w in validation.warnings[:5]:
print(f" ⢠{w}")
print("\n" + "="*60)
print("Next steps:")
if index.files_needing_review():
print("1. Run /meaning-review to review flagged entries")
print("2. Commit updated .meaning/ to git")
print("="*60)
Parse user arguments to control what gets updated:
--new - Only process new files--modified - Only flag modified files--deleted - Only remove deleted files--all - Process all changes (default)--re-infer - Re-run inference on modified files (not just flag)--dry-run - Show what would change without writingā Loaded index with 50 files
š Changes detected:
⢠New files: 5
⢠Modified files: 3
⢠Deleted files: 1
šļø Removing 1 deleted file:
⢠src/old_module.py
⨠Adding 5 new files:
Inferring 1/5: src/new_feature.py
Inferring 2/5: tests/test_new_feature.py
Inferring 3/5: docs/new_feature.md
Inferring 4/5: src/helpers/utils.py
Inferring 5/5: tests/test_utils.py
š Flagging 3 modified files for review:
⢠src/api/client.py
⢠README.md
⢠CHANGELOG.md
ā Saved updated index.yaml
============================================================
š UPDATE COMPLETE
============================================================
ā Files in index: 57
+ Added: 5
~ Modified: 3
- Deleted: 1
ā ļø Files needing review: 8
ā Validation: True
ā ļø Warnings: 0
============================================================
Next steps:
1. Run /meaning-review to review flagged entries
2. Commit updated .meaning/ to git
============================================================
| Scenario | Command |
|---|---|
| Added new files | /meaning-update --new |
| Edited existing files | /meaning-update --modified |
| Deleted files | /meaning-update --deleted |
| After git pull | /meaning-update --all |
| Daily sync | /meaning-update |
| Error | Solution |
|---|---|
.meaning/ missing |
Run /meaning-init first |
| Permission denied | Check file/directory permissions |
| Invalid index.yaml | Fix YAML syntax errors |
| Validation errors | Review and fix relationships |
Do not write code before stating assumptions.
Do not claim correctness you haven't verified.
Do not handle only the happy path.
Under what conditions does this work?
This skill: