update and cleanup repo

This commit is contained in:
2026-05-26 15:32:01 -07:00
parent 5041d9fbb9
commit 0db899d0c3
72 changed files with 788 additions and 1884 deletions
+13 -51
View File
@@ -504,67 +504,29 @@ def rows_to_config(rows) -> Dict[str, Any]:
if cat == 'global':
config[key] = parsed_val
else:
# Modular structure: config[cat][sub][name][key]
if cat in ('provider', 'tool'):
# Modular structure: config[category][subtype][item_name?][key]
if cat == 'plugin':
cat_dict = config.setdefault('plugin', {})
sub_dict = cat_dict.setdefault(sub, {})
if str(name or '').strip().lower() == 'default':
sub_dict[key] = parsed_val
else:
name_dict = sub_dict.setdefault(name, {})
name_dict[key] = parsed_val
elif cat in ('provider', 'store'):
continue
elif cat == 'tool':
cat_dict = config.setdefault(cat, {})
sub_dict = cat_dict.setdefault(sub, {})
sub_dict[key] = parsed_val
elif cat == 'store':
# Migrate legacy store rows into the unified plugin namespace.
# store config used a 4-level path: (store, type, instance_name, key).
# Plugin config uses: config["plugin"][type][instance_name][key].
cat_dict = config.setdefault('plugin', {})
sub_dict = cat_dict.setdefault(sub, {})
name_dict = sub_dict.setdefault(name, {})
name_dict[key] = parsed_val
else:
config.setdefault(cat, {})[key] = parsed_val
return config
def migrate_store_category_to_plugin() -> int:
"""One-time migration: re-key category='store' DB rows to category='plugin'.
The 'store' category used ``(store, type, instance_name, key)`` tuples;
the unified plugin system uses the same 4-level path under category='plugin'.
Existing 'plugin' rows for the same (subtype, item_name, key) are overwritten.
Returns the number of rows that were migrated (0 if already migrated).
"""
try:
count_row = db.fetchone(
"SELECT COUNT(*) AS n FROM config WHERE category='store' AND subtype != 'folder'"
)
count = int(count_row['n']) if count_row else 0
if count == 0:
# Also clean up any lingering folder-store rows
db.execute("DELETE FROM config WHERE category='store'")
with db._conn_lock:
db.conn.commit()
return 0
# Copy store rows to plugin, replacing any pre-existing plugin rows for
# the same (subtype, item_name, key), then delete the old store rows.
db.execute(
"""
INSERT OR REPLACE INTO config (category, subtype, item_name, key, value)
SELECT 'plugin', subtype, item_name, key, value
FROM config
WHERE category = 'store' AND subtype != 'folder'
"""
)
db.execute("DELETE FROM config WHERE category = 'store'")
with db._conn_lock:
db.conn.commit()
logger.info("Migrated %d config rows from category='store' to category='plugin'", count)
return count
except Exception:
logger.exception("Failed to migrate store config rows to plugin category")
return 0
def get_config_all() -> Dict[str, Any]:
"""Retrieve all configuration from the database in the legacy dict format."""
"""Retrieve all configuration from the database in the canonical plugin-centric dict format."""
rows = db.fetchall("SELECT category, subtype, item_name, key, value FROM config")
return rows_to_config(rows)