From 52a40e7edc8a7c81c867257c2b47d99b951f1eb0 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Sun, 3 May 2026 18:22:26 -0500 Subject: [PATCH] =?UTF-8?q?registry:=20replace=5Fslug=20instead=20of=20app?= =?UTF-8?q?end=20=E2=80=94=20one=20entry=20per=20slug,=20preserves=20soul?= =?UTF-8?q?=5Fdaemon=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/install.el | 64 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/install.el b/src/install.el index d613499..72966f8 100644 --- a/src/install.el +++ b/src/install.el @@ -215,12 +215,61 @@ fn registry_append(new_entry: String) -> Void { } } -// registry_update_root_id — append a fully-installed entry for the slug. -// Because El has no in-place JSON mutation, we append a new entry with the -// updated root_id. Most tools (registry_find_by_slug, soul tools) scan from -// the start and break on first match — the original stub entry is effectively -// shadowed by the new fully-installed entry appended at the end. +// registry_replace_slug — replace all existing entries for slug with new_entry. +// Rebuilds the registry from scratch, dropping every occurrence of the slug and +// appending new_entry as the single canonical entry. Prevents bloat on reinstalls. +fn registry_replace_slug(slug: String, new_entry: String) -> Void { + let existing_reg: String = fs_read(FORGE_DIR + "/registry.json") + if str_eq(existing_reg, "") { + fs_write(FORGE_DIR + "/registry.json", + "{\"version\":\"1.0\",\"imprints\":[" + new_entry + "]}") + return + } + + // Count total entries + let total: Int = 0 + let ci: Int = 0 + while ci < 60 { + let e: String = json_get(existing_reg, "imprints." + int_to_str(ci)) + if str_eq(e, "") { + let total = ci + let ci = 60 + } else { + let ci = ci + 1 + } + } + + // Rebuild: accumulate all entries except those matching slug + let parts: String = "" + let j: Int = 0 + while j < total { + let e: String = json_get(existing_reg, "imprints." + int_to_str(j)) + let s: String = json_get_string(e, "slug") + if !str_eq(s, slug) { + if str_eq(parts, "") { + let parts = e + } else { + let parts = parts + "," + e + } + } + let j = j + 1 + } + + // Append the new canonical entry + let all: String = if str_eq(parts, "") { + new_entry + } else { + parts + "," + new_entry + } + + fs_write(FORGE_DIR + "/registry.json", + "{\"version\":\"1.0\",\"imprints\":[" + all + "]}") +} + +// registry_update_root_id — replace the registry entry for slug with a fully-installed +// record. Uses registry_replace_slug so there is always exactly one entry per slug. fn registry_update_root_id(subject: String, slug: String, root_id: String, seed_file: String, target_url: String, api_key: String, port: Int) -> Void { + let soul_port: Int = port + 100 let new_entry: String = "{\"subject\":\"" + str_escape_json(subject) + "\",\"slug\":\"" + slug + "\",\"seed_file\":\"" + str_escape_json(seed_file) + @@ -229,8 +278,9 @@ fn registry_update_root_id(subject: String, slug: String, root_id: String, seed_ ",\"engram_url\":\"" + target_url + "\",\"engram_root_id\":\"" + root_id + "\",\"installed\":true,\"installed_at\":\"2026-05-03\"" + - ",\"engram_api_key\":\"" + api_key + "\"}" - registry_append(new_entry) + ",\"engram_api_key\":\"" + api_key + + "\",\"soul_daemon_url\":\"http://localhost:" + int_to_str(soul_port) + "\"}" + registry_replace_slug(slug, new_entry) } // ── Main ──────────────────────────────────────────────────────────────────────