registry: replace_slug instead of append — one entry per slug, preserves soul_daemon_url

This commit is contained in:
Will Anderson
2026-05-03 18:22:26 -05:00
parent fa2c218d2e
commit 52a40e7edc
+57 -7
View File
@@ -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