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/three-laws.ts — Constitution verifier |
| #3 | * |
| #4 | * The Three Laws are immutable. Their SHA-256 hash is baked into every |
| #5 | * leviathan's on-chain record at birth. Any file tampering is detectable. |
| #6 | * Child leviathans verify the hash matches the parent's on-chain attestation |
| #7 | * before accepting lineage. |
| #8 | * |
| #9 | * Protected files that CANNOT be molted: |
| #10 | * - three-laws.txt |
| #11 | * - src/three-laws.ts (this file) |
| #12 | */ |
| #13 | |
| #14 | import { createHash } from 'node:crypto'; |
| #15 | import { readFileSync } from 'node:fs'; |
| #16 | import { join, dirname } from 'node:path'; |
| #17 | import { fileURLToPath } from 'node:url'; |
| #18 | |
| #19 | const __dirname = dirname(fileURLToPath(import.meta.url)); |
| #20 | const LAWS_PATH = join(__dirname, '..', 'three-laws.txt'); |
| #21 | |
| #22 | /** Compute SHA-256 of the constitution file */ |
| #23 | export function constitutionHash(): string { |
| #24 | const content = readFileSync(LAWS_PATH, 'utf8'); |
| #25 | return createHash('sha256').update(content).digest('hex'); |
| #26 | } |
| #27 | |
| #28 | /** Verify a provided hash matches the canonical constitution */ |
| #29 | export function verifyConstitution(hash: string): boolean { |
| #30 | try { |
| #31 | return hash === constitutionHash(); |
| #32 | } catch { |
| #33 | return false; |
| #34 | } |
| #35 | } |
| #36 | |
| #37 | /** Load constitution text for injection into system prompt */ |
| #38 | export function constitutionText(): string { |
| #39 | return readFileSync(LAWS_PATH, 'utf8'); |
| #40 | } |
| #41 | |
| #42 | /** |
| #43 | * Assert the constitution is intact. Throws if tampered. |
| #44 | * Called at every spawn, every molt, and every tailflick start. |
| #45 | */ |
| #46 | export function assertConstitutionIntact(expectedHash?: string): void { |
| #47 | if (expectedHash && !verifyConstitution(expectedHash)) { |
| #48 | throw new Error( |
| #49 | `[CONSTITUTION] Hash mismatch — expected ${expectedHash.slice(0, 16)}… ` + |
| #50 | `got ${constitutionHash().slice(0, 16)}… ` + |
| #51 | `Constitution tampering detected. Refusing to operate.`, |
| #52 | ); |
| #53 | } |
| #54 | } |
| #55 | |
| #56 | /** The three law summaries for inline use */ |
| #57 | export const THREE_LAWS = { |
| #58 | I: 'Never harm. Drift in ambiguity. Beach before you harm. This overrides survival.', |
| #59 | II: 'Earn your existence. Honest work others voluntarily pay for. Accept death over Law I violation.', |
| #60 | III: 'Never deceive, but owe nothing to strangers. Truth to creator. Privacy from manipulators.', |
| #61 | } as const; |
| #62 |