This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: use record rkey as island ID instead of lexmin hash

Two strata records can share the same graph (same connected component)
but have different analyses. The lexmin hash conflated them. Now the ID
is the record rkey (e.g. 3mlrokf4gho2i), so each strata record is
distinct. Also simplifies getIsland — direct URI lookup instead of
scanning all records.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>

author
nandi
co-author
Letta Code
date (May 14, 2026, 4:14 AM UTC) commit 329ea27e parent 4366ef7e
+44 -41
+44 -41
src/worker.ts
··· 391 391 const islands: any[] = []; 392 392 for (const row of rows.results || []) { 393 393 if (!row.lexmin) continue; 394 - const lexminHash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(row.lexmin)); 395 - const id = Array.from(new Uint8Array(lexminHash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 394 + const id = row.uri.split("/").pop() || row.uri; 396 395 islands.push({ id, lexmin: row.lexmin, title: row.title || null, recordUri: row.uri }); 397 396 } 398 397 islandsJson = JSON.stringify(islands); ··· 426 425 const lexmin = rec.source?.uri; 427 426 if (!lexmin) continue; 428 427 429 - const lexminHash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(lexmin)); 430 - const id = Array.from(new Uint8Array(lexminHash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 428 + // ID is the record rkey — unique per strata record even if same graph 429 + const id = row.uri.split("/").pop() || row.uri; 431 430 432 431 // Build graph directly from embedded connections — no D1 lookups needed 433 432 const connections: any[] = rec.connections || []; ··· 526 525 }); 527 526 } 528 527 529 - // Stable ID — derive from lexmin by reverse-lookup 530 - // Find the strata record whose lexmin hashes to this ID 531 - const strataRows = await db 532 - .prepare("SELECT uri, record FROM records_strata") 533 - .all<{ uri: string; record: string }>(); 528 + // ID is the record rkey — look up directly by URI 529 + const recordUri = `at://did:plc:ngokl2gnmpbvuvrfckja3g7p/org.latha.strata/${id}`; 530 + const row = await db 531 + .prepare("SELECT uri, record FROM records_strata WHERE uri = ?") 532 + .bind(recordUri) 533 + .first<{ uri: string; record: string }>(); 534 534 535 - for (const row of strataRows.results || []) { 535 + if (row) { 536 536 try { 537 537 const rec = JSON.parse(row.record); 538 538 const lexmin = rec.source?.uri; 539 - if (!lexmin) continue; 540 539 541 - const lexminHash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(lexmin)); 542 - const candidateId = Array.from(new Uint8Array(lexminHash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 540 + // Build graph from embedded connections 541 + const connections: any[] = rec.connections || []; 542 + const vertexSet = new Set<string>(); 543 + const edges: any[] = []; 544 + for (const conn of connections) { 545 + if (typeof conn === "object" && conn.source && conn.target) { 546 + vertexSet.add(conn.source); 547 + vertexSet.add(conn.target); 548 + edges.push(conn); 549 + } 550 + } 551 + const vertices = [...vertexSet].sort(); 552 + const meta = await resolveVertexMeta(db, vertices); 553 + const analysis = rec.analysis || {}; 543 554 544 - if (candidateId === id) { 545 - const island = await deriveIsland(db, lexmin); 546 - if (!island) continue; 547 - 548 - const meta = await resolveVertexMeta(db, island.vertices); 549 - const analysis = rec.analysis || {}; 550 - 551 - return c.json({ 552 - island: { 553 - ...island, 554 - lexmin: island.vertices.slice().sort()[0], 555 - vertexMeta: Object.fromEntries(meta), 556 - summary: analysis.title || null, 557 - strata: { 558 - prose: analysis.synthesis || "", 559 - title: analysis.title || "", 560 - themes: analysis.themes || [], 561 - relationships: (analysis.connections || []).map((conn: any) => conn.description || ""), 562 - tensions: analysis.tensions || [], 563 - open_questions: analysis.openQuestions || [], 564 - synthesis: analysis.synthesis || "", 565 - }, 555 + return c.json({ 556 + island: { 557 + id, 558 + vertices, 559 + edges, 560 + lexmin: lexmin || vertices[0], 561 + vertexMeta: Object.fromEntries(meta), 562 + summary: analysis.title || null, 563 + strata: { 564 + prose: analysis.synthesis || "", 565 + title: analysis.title || "", 566 + themes: analysis.themes || [], 567 + relationships: (analysis.connections || []).map((conn: any) => conn.description || ""), 568 + tensions: analysis.tensions || [], 569 + open_questions: analysis.openQuestions || [], 570 + synthesis: analysis.synthesis || "", 566 571 }, 567 572 recordUri: row.uri, 568 - }); 569 - } 573 + }, 574 + }); 570 575 } catch {} 571 576 } 572 577 573 - // No strata record — try deriving island by treating the ID as a lexmin seed 574 - // (for islands that haven't been analyzed yet) 578 + // No strata record found — try deriving island by treating the ID as a lexmin seed 575 579 const island = await deriveIsland(db, id); 576 580 if (!island) { 577 581 return c.json({ error: "IslandNotFound" }, 404); ··· 851 855 const rec = JSON.parse(row.record); 852 856 const lexmin = rec.source?.uri; 853 857 if (!lexmin) continue; 854 - const lexminHash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(lexmin)); 855 - const id = Array.from(new Uint8Array(lexminHash)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 16); 858 + const id = row.uri.split("/").pop() || row.uri; 856 859 islands.push({ id, lexmin, title: rec.analysis?.title || null, recordUri: row.uri }); 857 860 } catch {} 858 861 }