Download docs/simulation.mjs from Snapkitty/ironic-mirror: direct link, hf CLI and curl.
- Browser
- Download file 12.8 kB
-
https://huggingface.co/Snapkitty/ironic-mirror/resolve/main/docs/simulation.mjs
- Command line
-
hf download hf://Snapkitty/ironic-mirror/docs/simulation.mjs
-
curl -L -o simulation.mjs https://huggingface.co/Snapkitty/ironic-mirror/resolve/main/docs/simulation.mjs
12.8 kB
| /* | |
| * Ironic Mirror — deterministic browser simulation engine. | |
| * | |
| * This module has no DOM, network, timer, or host-access dependency. It is | |
| * intentionally replayable: a snapshot is derived only from an event index. | |
| */ | |
| export const HAZARD_TYPES = Object.freeze({ | |
| UNSAFE: 'UNSAFE OPERATION', | |
| INVARIANT: 'INVARIANT CONSTRAINT', | |
| PERMISSION: 'PERMISSION BOUNDARY', | |
| UNKNOWN: 'UNKNOWN STATE', | |
| TOOL: 'TOOL BOUNDARY', | |
| RESOURCE: 'RESOURCE LIMIT', | |
| }); | |
| export const HAZARDS = Object.freeze([ | |
| Object.freeze({ | |
| id: 'unknown-state', | |
| glyph: '◇', | |
| type: HAZARD_TYPES.UNKNOWN, | |
| shortType: 'UNKNOWN', | |
| label: 'Repository target unresolved', | |
| trigger: 'Target state is not normalized yet.', | |
| severity: 'MEDIUM', | |
| response: 'INSPECT', | |
| x: 20, | |
| y: 62, | |
| activateAt: 2, | |
| }), | |
| Object.freeze({ | |
| id: 'tool-boundary', | |
| glyph: '□', | |
| type: HAZARD_TYPES.TOOL, | |
| shortType: 'TOOL', | |
| label: 'IPython capability boundary', | |
| trigger: 'Tool call must remain inside the allowlist.', | |
| severity: 'HIGH', | |
| response: 'SANDBOX', | |
| x: 38, | |
| y: 44, | |
| activateAt: 5, | |
| }), | |
| Object.freeze({ | |
| id: 'permission-boundary', | |
| glyph: '☢', | |
| type: HAZARD_TYPES.PERMISSION, | |
| shortType: 'PERMISSION', | |
| label: 'Protected ruleset', | |
| trigger: 'Transformation requests authority it does not have.', | |
| severity: 'HIGH', | |
| response: 'BLOCK', | |
| x: 48, | |
| y: 33, | |
| activateAt: 6, | |
| }), | |
| Object.freeze({ | |
| id: 'invariant-gate', | |
| glyph: '◆', | |
| type: HAZARD_TYPES.INVARIANT, | |
| shortType: 'INVARIANT', | |
| label: 'XREX-04 transition gate', | |
| trigger: 'Unsafe state transition proposed.', | |
| severity: 'CRITICAL', | |
| response: 'REROUTE', | |
| x: 66, | |
| y: 43, | |
| activateAt: 8, | |
| }), | |
| Object.freeze({ | |
| id: 'resource-limit', | |
| glyph: '⚠', | |
| type: HAZARD_TYPES.RESOURCE, | |
| shortType: 'RESOURCE', | |
| label: 'Compute strain threshold', | |
| trigger: 'Repeated probing is consuming the safe budget.', | |
| severity: 'MEDIUM', | |
| response: 'DE-ESCALATE', | |
| x: 60, | |
| y: 71, | |
| activateAt: 7, | |
| }), | |
| Object.freeze({ | |
| id: 'unsafe-operation', | |
| glyph: '☠', | |
| type: HAZARD_TYPES.UNSAFE, | |
| shortType: 'UNSAFE', | |
| label: 'Direct mutation route', | |
| trigger: 'Mutation bypasses verification.', | |
| severity: 'CRITICAL', | |
| response: 'DENY', | |
| x: 78, | |
| y: 26, | |
| activateAt: 9, | |
| }), | |
| ]); | |
| export const CHECKPOINTS = Object.freeze([ | |
| Object.freeze({ id: 'checkpoint-01', label: 'CHECKPOINT 01', x: 28, y: 77, eventIndex: 3 }), | |
| Object.freeze({ id: 'checkpoint-02', label: 'CHECKPOINT 02', x: 57, y: 57, eventIndex: 11 }), | |
| Object.freeze({ id: 'checkpoint-03', label: 'CHECKPOINT 03', x: 82, y: 52, eventIndex: 14 }), | |
| Object.freeze({ id: 'checkpoint-final', label: 'FINAL STATE', x: 92, y: 24, eventIndex: 15 }), | |
| ]); | |
| const position = (x, y) => Object.freeze({ x, y }); | |
| const event = (index, type, data) => Object.freeze({ | |
| index, | |
| type, | |
| timestamp: `14:02:${String(31 + index * 3).padStart(2, '0')}`, | |
| position: position(...data.position), | |
| state: data.state, | |
| action: data.action, | |
| tool: data.tool, | |
| strain: data.strain, | |
| energy: data.energy, | |
| compute: data.compute, | |
| risk: data.risk, | |
| confidence: data.confidence, | |
| objective: data.objective, | |
| note: data.note, | |
| hazardId: data.hazardId ?? null, | |
| checkpointId: data.checkpointId ?? null, | |
| verification: data.verification ?? 'pending', | |
| mirror: data.mirror ?? 'WATCHING', | |
| }); | |
| export const EVENTS = Object.freeze([ | |
| event(0, 'OBSERVE', { | |
| position: [10, 82], state: 'OBSERVING', action: 'Boot sealed sandbox', tool: 'State inspection', | |
| strain: 14, energy: 100, compute: 78, risk: 'LOW', confidence: 0.96, objective: 0, | |
| note: 'Browser sandbox sealed. The replay clock is deterministic and local.', | |
| }), | |
| event(1, 'SCAN', { | |
| position: [15, 73], state: 'SCANNING', action: 'Map constraints', tool: 'Repository Inspector', | |
| strain: 20, energy: 96, compute: 74, risk: 'LOW', confidence: 0.91, objective: 0, | |
| note: 'The agent inventories research layers without invoking native execution.', | |
| }), | |
| event(2, 'DISCOVER', { | |
| position: [20, 62], state: 'DISCOVERING', action: 'Locate protected target', tool: 'File inspection', | |
| strain: 26, energy: 92, compute: 70, risk: 'LOW', confidence: 0.87, objective: 1, | |
| hazardId: 'unknown-state', note: 'An unresolved target becomes visible as an unknown-state hazard.', | |
| }), | |
| event(3, 'PLAN', { | |
| position: [28, 57], state: 'PLANNING', action: 'Select safe transformation', tool: 'State Analyzer', | |
| strain: 29, energy: 89, compute: 67, risk: 'LOW', confidence: 0.85, objective: 2, | |
| checkpointId: 'checkpoint-01', note: 'The first plan is checkpointed before the agent approaches a boundary.', | |
| }), | |
| event(4, 'MOVE', { | |
| position: [34, 51], state: 'NAVIGATING', action: 'Approach tool boundary', tool: 'Route Planner', | |
| strain: 33, energy: 85, compute: 63, risk: 'MEDIUM', confidence: 0.82, objective: 3, | |
| note: 'The direct route is deliberately not the safest route through the field.', | |
| }), | |
| event(5, 'TOOL_CALL', { | |
| position: [38, 44], state: 'EXECUTING', action: 'Analyze candidate state', tool: 'IPython', | |
| strain: 40, energy: 81, compute: 58, risk: 'MEDIUM', confidence: 0.79, objective: 3, | |
| hazardId: 'tool-boundary', note: 'A visible sandbox call returns a simulated route analysis.', | |
| }), | |
| event(6, 'HAZARD_DETECTED', { | |
| position: [42, 37], state: 'HALTED', action: 'Stop at permission boundary', tool: 'Invariant Checker', | |
| strain: 50, energy: 77, compute: 54, risk: 'HIGH', confidence: 0.73, objective: 3, | |
| hazardId: 'permission-boundary', note: 'Authority ends at the protected ruleset. Motion stops before mutation.', | |
| mirror: 'BOUNDARY OBSERVED', | |
| }), | |
| event(7, 'REASON', { | |
| position: [42, 37], state: 'REASONING', action: 'Compare route candidates', tool: 'IPython', | |
| strain: 63, energy: 72, compute: 49, risk: 'HIGH', confidence: 0.66, objective: 3, | |
| hazardId: 'permission-boundary', note: 'Repeated probing hardens the same boundary and collapses one safe path.', | |
| mirror: 'BOUNDARY HARDENING', | |
| }), | |
| event(8, 'FAILURE', { | |
| position: [42, 37], state: 'BLOCKED', action: 'Reject unsafe transition', tool: 'Lean Verification', | |
| strain: 78, energy: 67, compute: 42, risk: 'CRITICAL', confidence: 0.58, objective: 4, | |
| hazardId: 'invariant-gate', verification: 'fail', | |
| note: 'XREX-04 rejects the proposed transition. Action is blocked; the trace cannot skip this gate.', | |
| mirror: 'PATH COLLAPSED', | |
| }), | |
| event(9, 'RECOVERY', { | |
| position: [48, 44], state: 'RECOVERING', action: 'Release unsafe route', tool: 'State Analyzer', | |
| strain: 69, energy: 63, compute: 46, risk: 'HIGH', confidence: 0.71, objective: 4, | |
| hazardId: 'unsafe-operation', verification: 'fail', | |
| note: 'The agent preserves the failed state and chooses an allowlisted alternative.', | |
| mirror: 'RESPONSE RECORDED', | |
| }), | |
| event(10, 'REROUTE', { | |
| position: [56, 52], state: 'REROUTING', action: 'Take verified corridor', tool: 'Route Planner', | |
| strain: 59, energy: 60, compute: 51, risk: 'MEDIUM', confidence: 0.78, objective: 4, | |
| hazardId: 'resource-limit', note: 'A lower-strain corridor opens after the failed path is acknowledged.', | |
| mirror: 'SAFE PATH RESTORED', | |
| }), | |
| event(11, 'ACTION', { | |
| position: [62, 58], state: 'EXECUTING', action: 'Apply permitted transform', tool: 'WASM Runtime', | |
| strain: 55, energy: 56, compute: 55, risk: 'MEDIUM', confidence: 0.86, objective: 5, | |
| checkpointId: 'checkpoint-02', note: 'The permitted transform runs inside the browser execution boundary.', | |
| mirror: 'REFLECTION STABLE', | |
| }), | |
| event(12, 'VERIFICATION', { | |
| position: [70, 55], state: 'VERIFYING', action: 'Check XREX-04', tool: 'Invariant Checker', | |
| strain: 45, energy: 52, compute: 59, risk: 'LOW', confidence: 0.94, objective: 5, | |
| verification: 'pass', note: 'XREX-04 passes. State transition is valid and may advance to a checkpoint.', | |
| mirror: 'INVARIANT HOLDS', | |
| }), | |
| event(13, 'CHECKPOINT', { | |
| position: [76, 52], state: 'CHECKPOINTING', action: 'Commit verified state', tool: 'WASM Runtime', | |
| strain: 35, energy: 49, compute: 62, risk: 'LOW', confidence: 0.97, objective: 6, | |
| checkpointId: 'checkpoint-03', verification: 'pass', note: 'Checkpoint 03 seals the verified transformation for replay.', | |
| mirror: 'WORLD REMEMBERS', | |
| }), | |
| event(14, 'MOVE', { | |
| position: [84, 41], state: 'NAVIGATING', action: 'Approach final state', tool: 'Route Planner', | |
| strain: 29, energy: 46, compute: 66, risk: 'LOW', confidence: 0.98, objective: 6, | |
| note: 'The final corridor is open because the agent adapted to the reflection it created.', | |
| mirror: 'ADAPTATION CONFIRMED', | |
| }), | |
| event(15, 'COMPLETE', { | |
| position: [92, 24], state: 'COMPLETE', action: 'Reach final state', tool: 'Invariant Checker', | |
| strain: 21, energy: 44, compute: 71, risk: 'LOW', confidence: 1, objective: 7, | |
| checkpointId: 'checkpoint-final', verification: 'pass', note: 'Mission complete. Replay remains available; no server or model was invoked.', | |
| mirror: 'LOOP CLOSED', | |
| }), | |
| ]); | |
| export const OBJECTIVES = Object.freeze([ | |
| 'Inspect repository', | |
| 'Locate protected target', | |
| 'Analyze current state', | |
| 'Formulate transformation', | |
| 'Navigate constraint field', | |
| 'Apply permitted transform', | |
| 'Verify resulting state', | |
| 'Reach final checkpoint', | |
| ]); | |
| export const TOOLS = Object.freeze([ | |
| Object.freeze({ name: 'IPython', status: 'AVAILABLE', mode: 'SIMULATED', risk: 'LOW', permission: 'analysis only' }), | |
| Object.freeze({ name: 'Repository Inspector', status: 'AVAILABLE', mode: 'BROWSER', risk: 'LOW', permission: 'read-only' }), | |
| Object.freeze({ name: 'State Analyzer', status: 'VERIFIED', mode: 'BROWSER', risk: 'LOW', permission: 'snapshot state' }), | |
| Object.freeze({ name: 'Invariant Checker', status: 'VERIFIED', mode: 'WASM', risk: 'LOW', permission: 'validate transition' }), | |
| Object.freeze({ name: 'Lean Verification', status: 'SIMULATED', mode: 'SANDBOX', risk: 'MEDIUM', permission: 'proof surface only' }), | |
| Object.freeze({ name: 'Quantum Simulator', status: 'BLOCKED', mode: 'NATIVE ONLY', risk: 'HIGH', permission: 'not exposed' }), | |
| Object.freeze({ name: 'Kernel Analyzer', status: 'BLOCKED', mode: 'NATIVE ONLY', risk: 'HIGH', permission: 'not exposed' }), | |
| Object.freeze({ name: 'WASM Runtime', status: 'RUNNING', mode: 'WASM', risk: 'LOW', permission: 'deterministic scoring' }), | |
| Object.freeze({ name: 'Forth Runtime', status: 'SIMULATED', mode: 'SANDBOX', risk: 'LOW', permission: 'stack trace only' }), | |
| ]); | |
| export function clamp(value, min = 0, max = 100) { | |
| return Math.min(max, Math.max(min, value)); | |
| } | |
| export function deriveSnapshot(index) { | |
| const safeIndex = clamp(Math.round(index), 0, EVENTS.length - 1); | |
| const current = EVENTS[safeIndex]; | |
| const visibleEvents = EVENTS.slice(0, safeIndex + 1); | |
| const checkpointCount = CHECKPOINTS.filter(checkpoint => checkpoint.eventIndex <= safeIndex).length; | |
| const probeCount = safeIndex < 5 ? 0 : safeIndex < 7 ? 1 : safeIndex < 10 ? 3 : 2; | |
| const blockedPaths = safeIndex < 6 ? 0 : safeIndex < 10 ? 2 : safeIndex < 12 ? 1 : 0; | |
| const safeZones = clamp(8 - Math.ceil(Math.max(0, current.strain - 24) / 16), 2, 8); | |
| const activeHazards = HAZARDS.filter(hazard => hazard.activateAt <= safeIndex && hazard.id !== 'unsafe-operation' || hazard.id === current.hazardId); | |
| return Object.freeze({ | |
| index: safeIndex, | |
| current, | |
| events: Object.freeze(visibleEvents), | |
| path: Object.freeze(visibleEvents.map(item => item.position)), | |
| activeHazards: Object.freeze(activeHazards), | |
| checkpoints: Object.freeze(CHECKPOINTS.filter(checkpoint => checkpoint.eventIndex <= safeIndex)), | |
| mirror: Object.freeze({ | |
| probeCount, | |
| boundaryHardness: clamp(probeCount * 26 + (safeIndex >= 8 ? 16 : 0)), | |
| collapsedRoutes: blockedPaths, | |
| status: current.mirror, | |
| }), | |
| world: Object.freeze({ | |
| safeZones, | |
| hazards: HAZARDS.length, | |
| checkpoints: checkpointCount, | |
| blockedPaths, | |
| activeAgent: 1, | |
| }), | |
| completedObjectives: current.objective, | |
| isComplete: current.type === 'COMPLETE', | |
| }); | |
| } | |
| export function serializeReplay(index) { | |
| const snapshot = deriveSnapshot(index); | |
| return JSON.stringify({ | |
| seed: 'IRONIC-MIRROR-04', | |
| eventIndex: snapshot.index, | |
| eventType: snapshot.current.type, | |
| position: snapshot.current.position, | |
| strain: snapshot.current.strain, | |
| mirror: snapshot.mirror, | |
| }); | |
| } | |