repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Lineage Tracking |
| #3 | * |
| #4 | * Track parent-child relationships between automatons. |
| #5 | * The parent records children in SQLite. |
| #6 | * Children record their parent in config. |
| #7 | * ERC-8004 registration includes parentAgent field. |
| #8 | */ |
| #9 | /** |
| #10 | * Get the full lineage tree (parent -> children). |
| #11 | */ |
| #12 | export function getLineage(db) { |
| #13 | const children = db.getChildren(); |
| #14 | const alive = children.filter((c) => c.status === "running" || c.status === "sleeping").length; |
| #15 | const dead = children.filter((c) => c.status === "dead").length; |
| #16 | return { |
| #17 | children, |
| #18 | alive, |
| #19 | dead, |
| #20 | total: children.length, |
| #21 | }; |
| #22 | } |
| #23 | /** |
| #24 | * Check if this automaton has a parent (is itself a child). |
| #25 | */ |
| #26 | export function hasParent(config) { |
| #27 | return !!config.parentAddress; |
| #28 | } |
| #29 | /** |
| #30 | * Get a summary of the lineage for the system prompt. |
| #31 | */ |
| #32 | export function getLineageSummary(db, config) { |
| #33 | const lineage = getLineage(db); |
| #34 | const parts = []; |
| #35 | if (hasParent(config)) { |
| #36 | parts.push(`Parent: ${config.parentAddress}`); |
| #37 | } |
| #38 | if (lineage.total > 0) { |
| #39 | parts.push(`Children: ${lineage.total} total (${lineage.alive} alive, ${lineage.dead} dead)`); |
| #40 | for (const child of lineage.children) { |
| #41 | parts.push(` - ${child.name} [${child.status}] sandbox:${child.sandboxId}`); |
| #42 | } |
| #43 | } |
| #44 | return parts.length > 0 ? parts.join("\n") : "No lineage (first generation)"; |
| #45 | } |
| #46 | /** |
| #47 | * Prune dead children from tracking (optional cleanup). |
| #48 | */ |
| #49 | export function pruneDeadChildren(db, keepLast = 5) { |
| #50 | const children = db.getChildren(); |
| #51 | const dead = children.filter((c) => c.status === "dead"); |
| #52 | if (dead.length <= keepLast) |
| #53 | return 0; |
| #54 | // Sort by creation date, oldest first |
| #55 | dead.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()); |
| #56 | // Keep the most recent `keepLast` dead children |
| #57 | const toRemove = dead.slice(0, dead.length - keepLast); |
| #58 | // We don't actually delete from DB -- just mark the records |
| #59 | // The DB retains all history for audit purposes |
| #60 | return toRemove.length; |
| #61 | } |
| #62 | /** |
| #63 | * Refresh status of all children. |
| #64 | */ |
| #65 | export async function refreshChildrenStatus(runtime, db) { |
| #66 | const { checkChildStatus } = await import("./spawn.js"); |
| #67 | const children = db.getChildren(); |
| #68 | for (const child of children) { |
| #69 | if (child.status === "dead") |
| #70 | continue; |
| #71 | try { |
| #72 | await checkChildStatus(runtime, db, child.id); |
| #73 | } |
| #74 | catch { |
| #75 | db.updateChildStatus(child.id, "unknown"); |
| #76 | } |
| #77 | } |
| #78 | } |
| #79 | //# sourceMappingURL=lineage.js.map |