LeoYeAI/agent-master-skills / skills/auto-respawn
auto-respawn
VerifiedYour agent always comes back. Anchor identity and memory on-chain so any new instance can resurrect from just an address — no local state, no single point of failure. Permanent identity and recovery on the Autonomys Network.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 16.4 KB |
| _meta.json | config | 281 B |
| auto-respawn.ts | script | 14.4 KB |
| eslint.config.js | script | 468 B |
| lib/address.ts | script | 2.2 KB |
| lib/balance.ts | script | 1.1 KB |
| lib/cli.ts | script | 1.6 KB |
| lib/evm-balance.ts | script | 925 B |
| lib/evm-transfer.ts | script | 2.4 KB |
| lib/evm.ts | script | 3.4 KB |
| lib/memory-chain.ts | script | 3.5 KB |
| lib/network.ts | script | 1.4 KB |
| lib/remark.ts | script | 1.3 KB |
| lib/transfer.ts | script | 1.7 KB |
| lib/wallet.ts | script | 8.8 KB |
| lib/xdm.ts | script | 3.3 KB |
| package.json | manifest | 647 B |
| references/auto-respawn-commands.md | markdown | 9.6 KB |
| references/autonomys-network.md | markdown | 6.2 KB |
| setup.shexecutable | script | 2.2 KB |
| tests/address.test.ts | script | 3.4 KB |
| tests/balance.test.ts | script | 4.3 KB |
| tests/cli.test.ts | script | 3.5 KB |
| tests/evm-balance.test.ts | script | 3.1 KB |
| tests/evm-transfer.test.ts | script | 5.2 KB |
| tests/evm.test.ts | script | 2.4 KB |
| tests/network.test.ts | script | 1.8 KB |
| tests/wallet-roundtrip.test.ts | script | 6.3 KB |
| tests/wallet.test.ts | script | 1.1 KB |
| tsconfig.json | config | 366 B |
lib/memory-chain.ts
View on GitHubimport { ethers } from 'ethers'
export interface AnchorResult {
success: boolean
txHash: string | undefined
blockHash: string | undefined
cid: string
evmAddress: string
network: string
gasUsed?: string
warning?: string
}
/**
* Anchor a CID on-chain by writing it to the MemoryChain contract.
* Calls updateHead(string cid) — the contract stores the CID string directly.
*
* Pre-checks the wallet's EVM balance and estimates gas before sending.
* If the balance is too low, throws with an actionable hint to run fund-evm.
*/
export async function anchorCid(
contract: ethers.Contract,
cid: string,
evmAddress: string,
network: string,
): Promise<AnchorResult> {
const provider = contract.runner?.provider
if (!provider) {
throw new Error('Contract has no provider — cannot estimate gas or check balance.')
}
// Estimate gas cost before sending
let estimatedGas: bigint
try {
estimatedGas = await contract.updateHead.estimateGas(cid)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
if (message.includes('insufficient funds') || message.includes('INSUFFICIENT_FUNDS')) {
throw new Error(
`Insufficient EVM balance to anchor. ` +
`Run: fund-evm --from <wallet> --amount 1 --network ${network}`,
{ cause: err },
)
}
throw err
}
// Check balance against estimated cost
const feeData = await provider.getFeeData()
const gasPrice = feeData.gasPrice ?? feeData.maxFeePerGas
if (gasPrice == null) {
throw new Error('Unable to determine gas price from network. Please try again.')
}
const estimatedCost = estimatedGas * gasPrice
const balance = await provider.getBalance(evmAddress)
if (balance < estimatedCost) {
const needed = ethers.formatEther(estimatedCost)
const have = ethers.formatEther(balance)
throw new Error(
`Insufficient EVM balance to anchor. ` +
`Need ~${needed} ${network === 'mainnet' ? 'AI3' : 'tAI3'}, have ${have}. ` +
`Run: fund-evm --from <wallet> --amount 1 --network ${network}`,
)
}
const tx: ethers.TransactionResponse = await contract.updateHead(cid)
const receipt = await tx.wait()
if (!receipt) {
throw new Error('Anchor transaction was sent but no receipt was received (transaction may have been replaced or dropped).')
}
return {
success: receipt.status === 1,
txHash: receipt.hash,
blockHash: receipt.blockHash,
cid,
evmAddress,
network,
gasUsed: receipt.gasUsed.toString(),
}
}
export interface GetHeadResult {
evmAddress: string
cid: string | undefined
network: string
}
/**
* Read the last anchored CID for an EVM address from the MemoryChain contract.
* Calls getHead(address) — returns the CID string directly, or undefined if none set.
*/
export async function getHeadCid(
contract: ethers.Contract,
evmAddress: string,
network: string,
): Promise<GetHeadResult> {
let cid: string
try {
cid = await contract.getHead(evmAddress)
} catch (err) {
// ethers throws BAD_DATA when calling a non-existent contract (returns 0x).
const message = err instanceof Error ? err.message : String(err)
if (message.includes('BAD_DATA') || message.includes('could not decode result data')) {
throw new Error(
`MemoryChain contract not available on network "${network}". ` +
'The contract may not be deployed at the configured address.',
{ cause: err },
)
}
throw err
}
return {
evmAddress,
cid: cid || undefined,
network,
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |