Use as a Library
Reins can be used directly as a TypeScript/JavaScript library, independent of the CLI.
Install
npm install @pegasi/reinsBasic usage
import { Interceptor, createToolCallHook } from '@pegasi/reins'
const interceptor = new Interceptor()
const hook = createToolCallHook(interceptor)
// Register with the OpenClaw plugin API
api.on('before_tool_call', hook)Key exports
// Core
import { Interceptor } from '@pegasi/reins'
import { Arbitrator } from '@pegasi/reins'
import { approvalQueue } from '@pegasi/reins'
// Hook factory
import { createToolCallHook, getToolMapping, getProtectedModules } from '@pegasi/reins'
// Storage
import { PolicyStore, DecisionLog, StatsTracker } from '@pegasi/reins'
import type { PersistedPolicy, DecisionRecord, Stats } from '@pegasi/reins'
// Risk classification
import { classifyDestructiveAction, scoreIrreversibility } from '@pegasi/reins'
import type { DestructiveClassification, IrreversibilityAssessment } from '@pegasi/reins'
// Memory forecasting
import { MemoryRiskForecaster } from '@pegasi/reins'
import type { MemoryRiskAssessment } from '@pegasi/reins'
// Plugin (for OpenClaw integration)
import { ReinsPlugin, ReinsManifest } from '@pegasi/reins'
import type { ReinsConfig } from '@pegasi/reins'Protected tools
Reins intercepts every tool mapped in TOOL_TO_MODULE:
| Module | Tools |
|---|---|
| FileSystem | read, write, edit, glob |
| Shell | bash, exec |
| Browser | navigate, screenshot, click, type, evaluate |
| Network | fetch, request, webhook, download |
| Gateway | listSessions, listNodes, sendMessage |
Any unmapped tool falls through to defaultAction (ASK by default).
Classifying destructive actions
import { classifyDestructiveAction } from '@pegasi/reins'
const result = classifyDestructiveAction('Bash', { command: 'rm -rf /tmp/data' })
// {
// isDestructive: true,
// severity: 'CATASTROPHIC',
// reasons: ['shell_wipe_command'],
// target: '/tmp/data'
// }Scoring irreversibility
import { scoreIrreversibility } from '@pegasi/reins'
const assessment = scoreIrreversibility('FileSystem', 'delete', { path: '/etc/hosts' })
// { score: 92, label: 'CATASTROPHIC', requiresConfirmToken: true }