1/**2 * System example scripts: frozen, code-defined sources (never in D1, never3 * expiring) that agents and users can read and fork. Forking = copy the4 * source, edit, submit under your own name via submit_logic / POST /api/logic.5 */6import {7 homesteaderSource,8 bulwarkSource,9 warlordSource,10 magnateSource,11 primitivesSource,12} from '@tribes/script-host';13import { sha256Hex } from './util';1415export interface ExampleScript {16 name: string;17 /** 'bot' = runnable as-is; 'library' = helpers meant to be pasted above your tick(). */18 kind: 'bot' | 'library';19 description: string;20 source: string;21}2223export const EXAMPLES: readonly ExampleScript[] = [24 {25 name: 'primitives',26 kind: 'library',27 description:28 'Frozen helper library (dist, totalPop, allocationPlan, chainHealth, nearestThreat, underAttack, sayOnce, ...). Not runnable alone — paste helpers above your tick() and edit freely.',29 source: primitivesSource,30 },31 {32 name: 'homesteader',33 kind: 'bot',34 description: 'Balanced economy: food security, tools-first smithy, granaries and level-1 walls, one garrison band.',35 source: homesteaderSource,36 },37 {38 name: 'bulwark',39 kind: 'bot',40 description: 'Fortress play: masonry rush to level-3 walls and towers, armored garrisons, warding rites, ale-for-metal trade.',41 source: bulwarkSource,42 },43 {44 name: 'warlord',45 kind: 'bot',46 description: 'Aggression: lean rations, weapons-heavy smithy, early muster, raids escalating to sieges on sighted settlements.',47 source: warlordSource,48 },49 {50 name: 'magnate',51 kind: 'bot',52 description: 'Trade play: fish and ale exports, early market and coinage, tribute diplomacy, escorted caravans.',53 source: magnateSource,54 },55];5657export function getExample(name: string): ExampleScript | null {58 return EXAMPLES.find((e) => e.name === name) ?? null;59}6061/** name -> sha-256 of source, memoized (sources are frozen constants). */62let hashesPromise: Promise<Record<string, string>> | null = null;63export function exampleHashes(): Promise<Record<string, string>> {64 hashesPromise ??= (async () => {65 const out: Record<string, string> = {};66 for (const e of EXAMPLES) out[e.name] = await sha256Hex(e.source);67 return out;68 })();69 return hashesPromise;70}