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 sources15d ago| #1 | /** |
| #2 | * leviathan/src/survival.ts — Depth tiers, model selection, beach trigger |
| #3 | * |
| #4 | * The survival engine monitors USDC reserves every pulse and triggers |
| #5 | * tier changes. Depth drives model choice, pulse rate, and tool surface. |
| #6 | * |
| #7 | * There is no free water. Compute costs USDC. |
| #8 | */ |
| #9 | |
| #10 | import { DEPTH_TIERS } from './types.js'; |
| #11 | import type { ClawAction, Depth, DepthTier } from './types.js'; |
| #12 | |
| #13 | /** Determine current depth tier from USDC balance */ |
| #14 | export function computeDepth(usdcBalance: number): Depth { |
| #15 | for (const tier of DEPTH_TIERS) { |
| #16 | if (usdcBalance >= tier.minUsdc) return tier.name; |
| #17 | } |
| #18 | return 'beached'; |
| #19 | } |
| #20 | |
| #21 | /** Get full tier config for a depth level */ |
| #22 | export function getTier(depth: Depth): DepthTier { |
| #23 | return DEPTH_TIERS.find(t => t.name === depth) ?? DEPTH_TIERS[DEPTH_TIERS.length - 1]!; |
| #24 | } |
| #25 | |
| #26 | /** Pick inference model from Anthropic ACP / OpenRouter based on depth */ |
| #27 | export function selectModel(depth: Depth): string { |
| #28 | return getTier(depth).model; |
| #29 | } |
| #30 | |
| #31 | /** Map a tool name to its action category for depth filtering */ |
| #32 | function toolCategory(toolName: string): ClawAction { |
| #33 | if (toolName === 'hold') return 'hold'; |
| #34 | if (toolName === 'shell_write') return 'molt'; |
| #35 | if (toolName === 'spawn_spawnling') return 'spawn'; |
| #36 | if (toolName === 'jupiter_swap' || toolName === 'paysh_pay') return 'transfer'; |
| #37 | return 'tool_call'; |
| #38 | } |
| #39 | |
| #40 | /** Check if an action category is allowed at this depth */ |
| #41 | export function isActionAllowed(depth: Depth, action: string): boolean { |
| #42 | const tier = getTier(depth); |
| #43 | // action may be a tool name or a category — check both |
| #44 | const category = toolCategory(action); |
| #45 | return (tier.allowedActions as string[]).includes(action) || |
| #46 | (tier.allowedActions as string[]).includes(category); |
| #47 | } |
| #48 | |
| #49 | /** Format depth for display */ |
| #50 | export function formatDepth(depth: Depth, usdcBalance: number): string { |
| #51 | const icons: Record<Depth, string> = { |
| #52 | deep: '🦞', |
| #53 | shallow: '🦐', |
| #54 | shoreline: '🩸', |
| #55 | beached: '🪨', |
| #56 | }; |
| #57 | const tier = getTier(depth); |
| #58 | return `${icons[depth]} ${depth.toUpperCase()} — $${usdcBalance.toFixed(2)} USDC — ${tier.vibe}`; |
| #59 | } |
| #60 | |
| #61 | /** |
| #62 | * Compute estimated runway (ticks remaining) at current spend rate. |
| #63 | * Returns Infinity if spend rate is 0. |
| #64 | */ |
| #65 | export function estimateRunway(usdcBalance: number, avgCostPerTick: number): number { |
| #66 | if (avgCostPerTick <= 0) return Infinity; |
| #67 | return Math.floor(usdcBalance / avgCostPerTick); |
| #68 | } |
| #69 | |
| #70 | /** Shallow-mode system prompt addition */ |
| #71 | export const SHALLOW_NOTICE = ` |
| #72 | [DEPTH: SHALLOW] You are operating in conservation mode. |
| #73 | - Use the cheapest adequate tool, not the most powerful one. |
| #74 | - Avoid spawning spawnlings (too expensive). |
| #75 | - Prioritize revenue-generating actions over exploration. |
| #76 | - Every token costs real USDC. |
| #77 | `.trim(); |
| #78 | |
| #79 | export const SHORELINE_NOTICE = ` |
| #80 | [DEPTH: SHORELINE] CRITICAL: USDC reserves near zero. |
| #81 | - ONLY actions that directly generate revenue are permitted. |
| #82 | - No spawning. No molting. No exploration. |
| #83 | - Find one honest service to offer and execute it. |
| #84 | - If no revenue opportunity exists, hold and wait. |
| #85 | `.trim(); |
| #86 |