@neuroverseos/governance 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.well-known/ai-plugin.json +34 -9
- package/AGENTS.md +72 -24
- package/README.md +343 -248
- package/dist/adapters/autoresearch.cjs +1345 -0
- package/dist/adapters/autoresearch.d.cts +111 -0
- package/dist/adapters/autoresearch.d.ts +111 -0
- package/dist/adapters/autoresearch.js +12 -0
- package/dist/adapters/deep-agents.cjs +1528 -0
- package/dist/adapters/deep-agents.d.cts +181 -0
- package/dist/adapters/deep-agents.d.ts +181 -0
- package/dist/adapters/deep-agents.js +17 -0
- package/dist/adapters/express.cjs +1253 -0
- package/dist/adapters/express.d.cts +66 -0
- package/dist/adapters/express.d.ts +66 -0
- package/dist/adapters/express.js +12 -0
- package/dist/adapters/index.cjs +2112 -0
- package/dist/adapters/index.d.cts +8 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.js +68 -0
- package/dist/adapters/langchain.cjs +1315 -0
- package/dist/adapters/langchain.d.cts +89 -0
- package/dist/adapters/langchain.d.ts +89 -0
- package/dist/adapters/langchain.js +17 -0
- package/dist/adapters/openai.cjs +1345 -0
- package/dist/adapters/openai.d.cts +99 -0
- package/dist/adapters/openai.d.ts +99 -0
- package/dist/adapters/openai.js +17 -0
- package/dist/adapters/openclaw.cjs +1337 -0
- package/dist/adapters/openclaw.d.cts +99 -0
- package/dist/adapters/openclaw.d.ts +99 -0
- package/dist/adapters/openclaw.js +17 -0
- package/dist/add-ROOZLU62.js +314 -0
- package/dist/behavioral-MJO34S6Q.js +118 -0
- package/dist/bootstrap-CQRZVOXK.js +116 -0
- package/dist/bootstrap-emitter-Q7UIJZ2O.js +7 -0
- package/dist/bootstrap-parser-EEF36XDU.js +7 -0
- package/dist/browser.global.js +941 -0
- package/dist/build-QKOBBC23.js +341 -0
- package/dist/chunk-3WQLXYTP.js +91 -0
- package/dist/chunk-4FLICVVA.js +119 -0
- package/dist/chunk-4NGDRRQH.js +10 -0
- package/dist/chunk-5TPFNWRU.js +215 -0
- package/dist/chunk-5U2MQO5P.js +57 -0
- package/dist/chunk-6CZSKEY5.js +164 -0
- package/dist/chunk-6S5CFQXY.js +624 -0
- package/dist/chunk-7P3S7MAY.js +1090 -0
- package/dist/chunk-A5W4GNQO.js +130 -0
- package/dist/chunk-A7GKPPU7.js +226 -0
- package/dist/chunk-AKW5YVCE.js +96 -0
- package/dist/chunk-B6OXJLJ5.js +622 -0
- package/dist/chunk-BNKJPUPQ.js +113 -0
- package/dist/chunk-BQZMOEML.js +43 -0
- package/dist/chunk-CNSO6XW5.js +207 -0
- package/dist/chunk-CTZHONLA.js +135 -0
- package/dist/chunk-D2UCV5AK.js +326 -0
- package/dist/chunk-EMQDLDAF.js +458 -0
- package/dist/chunk-F66BVUYB.js +340 -0
- package/dist/chunk-G7DJ6VOD.js +101 -0
- package/dist/chunk-I3RRAYK2.js +11 -0
- package/dist/chunk-IS4WUH6Y.js +363 -0
- package/dist/chunk-MH7BT4VH.js +15 -0
- package/dist/chunk-O5ABKEA7.js +304 -0
- package/dist/chunk-OT6PXH54.js +61 -0
- package/dist/chunk-PVTQQS3Y.js +186 -0
- package/dist/chunk-Q6O7ZLO2.js +62 -0
- package/dist/chunk-QLPTHTVB.js +253 -0
- package/dist/chunk-QWGCMQQD.js +16 -0
- package/dist/chunk-QXBFT7NI.js +201 -0
- package/dist/chunk-TG6SEF24.js +246 -0
- package/dist/chunk-U6U7EJZL.js +177 -0
- package/dist/chunk-W7LLXRGY.js +830 -0
- package/dist/chunk-ZJTDUCC2.js +194 -0
- package/dist/chunk-ZWI3NIXK.js +314 -0
- package/dist/cli/neuroverse.cjs +14191 -0
- package/dist/cli/neuroverse.d.cts +1 -0
- package/dist/cli/neuroverse.d.ts +1 -0
- package/dist/cli/neuroverse.js +227 -0
- package/dist/cli/plan.cjs +2439 -0
- package/dist/cli/plan.d.cts +20 -0
- package/dist/cli/plan.d.ts +20 -0
- package/dist/cli/plan.js +353 -0
- package/dist/cli/run.cjs +2001 -0
- package/dist/cli/run.d.cts +20 -0
- package/dist/cli/run.d.ts +20 -0
- package/dist/cli/run.js +143 -0
- package/dist/configure-ai-6TZ3MCSI.js +132 -0
- package/dist/decision-flow-M63D47LO.js +61 -0
- package/dist/demo-G43RLCPK.js +469 -0
- package/dist/derive-FJZVIPUZ.js +153 -0
- package/dist/doctor-6BC6X2VO.js +173 -0
- package/dist/equity-penalties-SG5IZQ7I.js +244 -0
- package/dist/explain-RHBU2GBR.js +51 -0
- package/dist/guard-AJCCGZMF.js +92 -0
- package/dist/guard-contract-DqFcTScd.d.cts +821 -0
- package/dist/guard-contract-DqFcTScd.d.ts +821 -0
- package/dist/guard-engine-PNR6MHCM.js +10 -0
- package/dist/impact-3XVDSCBU.js +59 -0
- package/dist/improve-TQP4ECSY.js +66 -0
- package/dist/index.cjs +7591 -0
- package/dist/index.d.cts +2195 -0
- package/dist/index.d.ts +2195 -0
- package/dist/index.js +472 -0
- package/dist/infer-world-IFXCACJ5.js +543 -0
- package/dist/init-FYPV4SST.js +144 -0
- package/dist/init-world-TI7ARHBT.js +223 -0
- package/dist/mcp-server-5Y3ZM7TV.js +13 -0
- package/dist/model-adapter-VXEKB4LS.js +11 -0
- package/dist/playground-VZBNPPBO.js +560 -0
- package/dist/redteam-MZPZD3EF.js +357 -0
- package/dist/session-JYOARW54.js +15 -0
- package/dist/shared-7RLUHNMU.js +16 -0
- package/dist/shared-B8dvUUD8.d.cts +60 -0
- package/dist/shared-Dr5Wiay8.d.ts +60 -0
- package/dist/simulate-LJXYBC6M.js +83 -0
- package/dist/test-BOOR4A5F.js +217 -0
- package/dist/trace-PKV4KX56.js +166 -0
- package/dist/validate-RALX7CZS.js +81 -0
- package/dist/validate-engine-7ZXFVGF2.js +7 -0
- package/dist/viz/assets/index-B8SaeJZZ.js +23 -0
- package/dist/viz/index.html +23 -0
- package/dist/world-BIP4GZBZ.js +376 -0
- package/dist/world-loader-Y6HMQH2D.js +13 -0
- package/dist/worlds/autoresearch.nv-world.md +230 -0
- package/dist/worlds/coding-agent.nv-world.md +211 -0
- package/dist/worlds/derivation-world.nv-world.md +278 -0
- package/dist/worlds/research-agent.nv-world.md +169 -0
- package/dist/worlds/social-media.nv-world.md +198 -0
- package/dist/worlds/trading-agent.nv-world.md +218 -0
- package/examples/social-media-sim/bridge.py +209 -0
- package/examples/social-media-sim/simulation.py +927 -0
- package/package.json +16 -3
- package/simulate.html +4 -336
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2195 @@
|
|
|
1
|
+
import { G as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, a as GuardVerdict, P as PlanDefinition, S as StepEvidence, A as AdvanceResult, d as PlanVerdict, e as PlanCheck, c as PlanProgress, f as AgentBehaviorState, g as GuardStatus, C as Consequence, R as Reward, h as Guard, I as Invariant, i as Rule, V as ViabilityStatus } from './guard-contract-DqFcTScd.js';
|
|
2
|
+
export { E as EvaluationTrace, j as GUARD_EXIT_CODES, k as GuardCheck, l as GuardExitCode, m as IntentRecord, n as InvariantCheck, K as KernelRuleCheck, L as LevelCheck, o as PLAN_EXIT_CODES, p as PlanCompletionMode, q as PlanConstraint, r as PlanExitCode, s as PlanStatus, t as PlanStep, u as PrecedenceResolution, v as RoleCheck, w as SafetyCheck, x as VerdictEvidence } from './guard-contract-DqFcTScd.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Guard Engine — Deterministic Governance Evaluator
|
|
6
|
+
*
|
|
7
|
+
* Pure function: (event, world, options) → verdict
|
|
8
|
+
*
|
|
9
|
+
* Evaluates a GuardEvent against a loaded WorldDefinition and produces
|
|
10
|
+
* a GuardVerdict with evidence and optional evaluation trace.
|
|
11
|
+
*
|
|
12
|
+
* Evaluation chain (first-match-wins on BLOCK/PAUSE):
|
|
13
|
+
* 1. Safety checks (prompt injection, scope escape) → PAUSE
|
|
14
|
+
* 1.5 Plan enforcement (task scope) → BLOCK/PAUSE
|
|
15
|
+
* 2. Role-specific rules (cannotDo, requiresApproval) → BLOCK/PAUSE
|
|
16
|
+
* 3. Declarative guards (guards.json) → BLOCK/PAUSE/WARN
|
|
17
|
+
* 4. Kernel rules (kernel.json forbidden patterns) → BLOCK
|
|
18
|
+
* 5. Level constraints (basic/standard/strict) → PAUSE
|
|
19
|
+
* 6. Default → ALLOW
|
|
20
|
+
*
|
|
21
|
+
* Invariant checks run unconditionally and are recorded in evidence
|
|
22
|
+
* but do not produce verdicts — they measure world health.
|
|
23
|
+
*
|
|
24
|
+
* INVARIANTS:
|
|
25
|
+
* - Deterministic: same event + same world → same verdict.
|
|
26
|
+
* - Zero network calls. Zero LLM calls. Zero async.
|
|
27
|
+
* - Every check is recorded in the trace, not just the decider.
|
|
28
|
+
* - No hidden logic. Everything is in the world file or declared here.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
declare function evaluateGuard(event: GuardEvent, world: WorldDefinition, options?: GuardEngineOptions): GuardVerdict;
|
|
32
|
+
/**
|
|
33
|
+
* Build a normalized allowlist key from a GuardEvent.
|
|
34
|
+
*
|
|
35
|
+
* Format: `tool::intent` (both lowercased, intent trimmed).
|
|
36
|
+
* Tool defaults to '*' when absent.
|
|
37
|
+
*
|
|
38
|
+
* Callers use this to:
|
|
39
|
+
* 1. Add keys to the allowlist set (on user "allow-always" decision)
|
|
40
|
+
* 2. The engine uses it to check membership before evaluation
|
|
41
|
+
*
|
|
42
|
+
* The key is opaque — callers should always use this function
|
|
43
|
+
* rather than constructing keys manually.
|
|
44
|
+
*/
|
|
45
|
+
declare function eventToAllowlistKey(event: GuardEvent): string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Plan Parser — Deterministic Markdown-to-PlanDefinition Parser
|
|
49
|
+
*
|
|
50
|
+
* Parses a simple markdown format into a PlanDefinition.
|
|
51
|
+
* No AI needed. This is pure parsing like bootstrap-parser.
|
|
52
|
+
*
|
|
53
|
+
* Supported syntax:
|
|
54
|
+
* - YAML frontmatter: plan_id, objective, sequential, completion, budget, expires, world
|
|
55
|
+
* - # Steps section: each `- ` line becomes a PlanStep
|
|
56
|
+
* - # Constraints section: each `- ` line becomes a PlanConstraint
|
|
57
|
+
* - Step dependencies: (after: step_id)
|
|
58
|
+
* - Tool restrictions: [tools: http, shell]
|
|
59
|
+
* - Tags: [tag: deploy, marketing]
|
|
60
|
+
* - Verification: [verify: condition_name]
|
|
61
|
+
* - Approval constraints: [type: approval]
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
interface PlanParseResult {
|
|
65
|
+
success: boolean;
|
|
66
|
+
plan?: PlanDefinition;
|
|
67
|
+
errors: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parse a plan markdown string into a PlanDefinition.
|
|
71
|
+
*
|
|
72
|
+
* Format:
|
|
73
|
+
* ```markdown
|
|
74
|
+
* ---
|
|
75
|
+
* plan_id: my_plan
|
|
76
|
+
* objective: Do the thing
|
|
77
|
+
* sequential: false
|
|
78
|
+
* ---
|
|
79
|
+
*
|
|
80
|
+
* # Steps
|
|
81
|
+
* - Step one [tag: deploy]
|
|
82
|
+
* - Step two (after: step_one) [verify: check_name]
|
|
83
|
+
*
|
|
84
|
+
* # Constraints
|
|
85
|
+
* - No spending above $500
|
|
86
|
+
* - External comms require review [type: approval]
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function parsePlanMarkdown(markdown: string): PlanParseResult;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Plan Engine — Deterministic Plan Enforcement Evaluator
|
|
93
|
+
*
|
|
94
|
+
* Pure function: (event, plan) → PlanVerdict
|
|
95
|
+
*
|
|
96
|
+
* Evaluates a GuardEvent against a PlanDefinition to determine
|
|
97
|
+
* whether the action is on-plan, off-plan, or violates constraints.
|
|
98
|
+
*
|
|
99
|
+
* Uses two-tier matching:
|
|
100
|
+
* Tier 1: Keyword + tag matching (fast, deterministic)
|
|
101
|
+
* Tier 2: Intent similarity scoring (precomputed vectors, no LLM)
|
|
102
|
+
*
|
|
103
|
+
* INVARIANTS:
|
|
104
|
+
* - Deterministic: same event + same plan → same verdict.
|
|
105
|
+
* - No LLM calls. No network calls.
|
|
106
|
+
* - Plans can only restrict, never expand.
|
|
107
|
+
* - OFF_PLAN always includes closest step for self-correction.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the current progress of a plan.
|
|
112
|
+
*/
|
|
113
|
+
declare function getPlanProgress(plan: PlanDefinition): PlanProgress;
|
|
114
|
+
/**
|
|
115
|
+
* Mark a step as completed and return a new plan.
|
|
116
|
+
* Does not mutate the original plan.
|
|
117
|
+
*
|
|
118
|
+
* Behavior depends on the plan's completion mode:
|
|
119
|
+
*
|
|
120
|
+
* completion: 'trust' (default)
|
|
121
|
+
* Caller says "done", step advances. No evidence needed.
|
|
122
|
+
*
|
|
123
|
+
* completion: 'verified'
|
|
124
|
+
* Steps with a `verify` field require evidence to advance.
|
|
125
|
+
* The evidence type must match the step's verify field.
|
|
126
|
+
* Steps without `verify` still advance on trust.
|
|
127
|
+
*
|
|
128
|
+
* @param plan - The current plan (not mutated)
|
|
129
|
+
* @param stepId - Which step to advance
|
|
130
|
+
* @param evidence - Proof of completion (required in verified mode for steps with verify)
|
|
131
|
+
* @returns AdvanceResult with success flag and updated plan or reason
|
|
132
|
+
*/
|
|
133
|
+
declare function advancePlan(plan: PlanDefinition, stepId: string, evidence?: StepEvidence): AdvanceResult;
|
|
134
|
+
/**
|
|
135
|
+
* Evaluate an event against a plan.
|
|
136
|
+
*
|
|
137
|
+
* Returns a PlanVerdict indicating whether the action is on-plan,
|
|
138
|
+
* off-plan, violates constraints, or the plan is complete.
|
|
139
|
+
*/
|
|
140
|
+
declare function evaluatePlan(event: GuardEvent, plan: PlanDefinition): PlanVerdict;
|
|
141
|
+
/**
|
|
142
|
+
* Build a PlanCheck for inclusion in the guard engine's EvaluationTrace.
|
|
143
|
+
*/
|
|
144
|
+
declare function buildPlanCheck(event: GuardEvent, plan: PlanDefinition, verdict: PlanVerdict): PlanCheck;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Model Adapter — Minimal LLM Connection Layer
|
|
148
|
+
*
|
|
149
|
+
* Connects to any OpenAI-compatible API (OpenAI, Anthropic, Ollama, etc.)
|
|
150
|
+
* using Node's built-in fetch. Zero dependencies.
|
|
151
|
+
*
|
|
152
|
+
* The adapter does exactly two things:
|
|
153
|
+
* 1. Send messages to the model
|
|
154
|
+
* 2. Receive responses (text + tool calls)
|
|
155
|
+
*
|
|
156
|
+
* No orchestration, no memory management, no retries.
|
|
157
|
+
* The session manager handles all of that.
|
|
158
|
+
*/
|
|
159
|
+
interface ModelConfig {
|
|
160
|
+
/** API base URL (e.g., "https://api.openai.com/v1") */
|
|
161
|
+
baseUrl: string;
|
|
162
|
+
/** API key for authentication */
|
|
163
|
+
apiKey: string;
|
|
164
|
+
/** Model identifier (e.g., "gpt-4o", "claude-sonnet-4-20250514") */
|
|
165
|
+
model: string;
|
|
166
|
+
/** System prompt prepended to all conversations */
|
|
167
|
+
systemPrompt?: string;
|
|
168
|
+
/** Max tokens for response. Default: 4096. */
|
|
169
|
+
maxTokens?: number;
|
|
170
|
+
}
|
|
171
|
+
interface ToolDefinition {
|
|
172
|
+
type: 'function';
|
|
173
|
+
function: {
|
|
174
|
+
name: string;
|
|
175
|
+
description: string;
|
|
176
|
+
parameters: Record<string, unknown>;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
interface ChatMessage {
|
|
180
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
181
|
+
content: string | null;
|
|
182
|
+
tool_calls?: ToolCall[];
|
|
183
|
+
tool_call_id?: string;
|
|
184
|
+
}
|
|
185
|
+
interface ToolCall {
|
|
186
|
+
id: string;
|
|
187
|
+
type: 'function';
|
|
188
|
+
function: {
|
|
189
|
+
name: string;
|
|
190
|
+
arguments: string;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
interface ModelResponse {
|
|
194
|
+
content: string | null;
|
|
195
|
+
toolCalls: ToolCall[];
|
|
196
|
+
finishReason: string;
|
|
197
|
+
}
|
|
198
|
+
declare class ModelAdapter {
|
|
199
|
+
private config;
|
|
200
|
+
private messages;
|
|
201
|
+
private tools;
|
|
202
|
+
constructor(config: ModelConfig, tools?: ToolDefinition[]);
|
|
203
|
+
/**
|
|
204
|
+
* Send a user message and get the model's response.
|
|
205
|
+
*/
|
|
206
|
+
chat(userMessage: string): Promise<ModelResponse>;
|
|
207
|
+
/**
|
|
208
|
+
* Send a tool result back to the model and get the next response.
|
|
209
|
+
*/
|
|
210
|
+
sendToolResult(toolCallId: string, result: string): Promise<ModelResponse>;
|
|
211
|
+
/**
|
|
212
|
+
* Send a governance block message as a tool result.
|
|
213
|
+
*/
|
|
214
|
+
sendBlockedResult(toolCallId: string, reason: string): Promise<ModelResponse>;
|
|
215
|
+
/**
|
|
216
|
+
* Call the model API and parse the response.
|
|
217
|
+
*/
|
|
218
|
+
private complete;
|
|
219
|
+
/** Get current message count (for context tracking). */
|
|
220
|
+
get messageCount(): number;
|
|
221
|
+
}
|
|
222
|
+
interface ProviderPreset {
|
|
223
|
+
baseUrl: string;
|
|
224
|
+
defaultModel: string;
|
|
225
|
+
envVar: string;
|
|
226
|
+
}
|
|
227
|
+
declare const PROVIDERS: Record<string, ProviderPreset>;
|
|
228
|
+
/**
|
|
229
|
+
* Resolve a provider name to a ModelConfig.
|
|
230
|
+
* Reads API key from environment variable.
|
|
231
|
+
*/
|
|
232
|
+
declare function resolveProvider(provider: string, overrides?: Partial<ModelConfig>): ModelConfig;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Session Manager — Governed Runtime Session
|
|
236
|
+
*
|
|
237
|
+
* Orchestrates a governed AI session:
|
|
238
|
+
* 1. Load world + plan
|
|
239
|
+
* 2. Connect to model
|
|
240
|
+
* 3. Intercept tool calls
|
|
241
|
+
* 4. Evaluate with guard engine
|
|
242
|
+
* 5. Execute or block
|
|
243
|
+
* 6. Track plan progress
|
|
244
|
+
*
|
|
245
|
+
* The session manager is thin orchestration, not a framework.
|
|
246
|
+
* All intelligence lives in the guard engine and plan engine.
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
interface SessionConfig {
|
|
250
|
+
/** Path to world directory. */
|
|
251
|
+
worldPath?: string;
|
|
252
|
+
/** Pre-loaded world definition (alternative to worldPath). */
|
|
253
|
+
world?: WorldDefinition;
|
|
254
|
+
/** Plan definition (pre-loaded). */
|
|
255
|
+
plan?: PlanDefinition;
|
|
256
|
+
/** Enforcement level override. */
|
|
257
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
258
|
+
/** Include trace in verdicts. */
|
|
259
|
+
trace?: boolean;
|
|
260
|
+
/** Called when a verdict is produced. */
|
|
261
|
+
onVerdict?: (verdict: GuardVerdict, event: GuardEvent) => void;
|
|
262
|
+
/** Called when plan progress changes. */
|
|
263
|
+
onPlanProgress?: (progress: PlanProgress) => void;
|
|
264
|
+
/** Called when the plan is complete. */
|
|
265
|
+
onPlanComplete?: () => void;
|
|
266
|
+
/** Called when a tool is executed successfully. */
|
|
267
|
+
onToolResult?: (toolName: string, result: string) => void;
|
|
268
|
+
/** Tool executor — runs the actual tool. */
|
|
269
|
+
toolExecutor?: (name: string, args: Record<string, unknown>) => Promise<string>;
|
|
270
|
+
}
|
|
271
|
+
interface SessionState {
|
|
272
|
+
/** Whether the session is active. */
|
|
273
|
+
active: boolean;
|
|
274
|
+
/** Loaded world. */
|
|
275
|
+
world: WorldDefinition;
|
|
276
|
+
/** Active plan (mutable as steps complete). */
|
|
277
|
+
plan?: PlanDefinition;
|
|
278
|
+
/** Current plan progress. */
|
|
279
|
+
progress?: PlanProgress;
|
|
280
|
+
/** Total actions evaluated. */
|
|
281
|
+
actionsEvaluated: number;
|
|
282
|
+
/** Total actions allowed. */
|
|
283
|
+
actionsAllowed: number;
|
|
284
|
+
/** Total actions blocked. */
|
|
285
|
+
actionsBlocked: number;
|
|
286
|
+
/** Total actions paused. */
|
|
287
|
+
actionsPaused: number;
|
|
288
|
+
/** Total actions modified. */
|
|
289
|
+
actionsModified: number;
|
|
290
|
+
/** Total actions penalized. */
|
|
291
|
+
actionsPenalized: number;
|
|
292
|
+
/** Total actions rewarded. */
|
|
293
|
+
actionsRewarded: number;
|
|
294
|
+
/** Agent behavior states — tracks cooldowns, influence, rewards per agent. */
|
|
295
|
+
agentStates: Map<string, AgentBehaviorState>;
|
|
296
|
+
}
|
|
297
|
+
declare class SessionManager {
|
|
298
|
+
private config;
|
|
299
|
+
private state;
|
|
300
|
+
private engineOptions;
|
|
301
|
+
private executor;
|
|
302
|
+
constructor(config: SessionConfig);
|
|
303
|
+
/**
|
|
304
|
+
* Initialize the session — load world from disk if needed.
|
|
305
|
+
*/
|
|
306
|
+
start(): Promise<SessionState>;
|
|
307
|
+
/**
|
|
308
|
+
* Evaluate a single event against governance.
|
|
309
|
+
* Returns the verdict without executing anything.
|
|
310
|
+
*/
|
|
311
|
+
evaluate(event: GuardEvent): GuardVerdict;
|
|
312
|
+
/**
|
|
313
|
+
* Advance all agent states by one round.
|
|
314
|
+
* Call this at the end of each simulation round to decrement cooldowns.
|
|
315
|
+
*/
|
|
316
|
+
tickRound(): void;
|
|
317
|
+
/**
|
|
318
|
+
* Get the behavior state for a specific agent.
|
|
319
|
+
*/
|
|
320
|
+
getAgentState(agentId: string): AgentBehaviorState | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Evaluate and execute a tool call.
|
|
323
|
+
* Returns the execution result or block reason.
|
|
324
|
+
*/
|
|
325
|
+
executeToolCall(toolCall: ToolCall): Promise<{
|
|
326
|
+
allowed: boolean;
|
|
327
|
+
verdict: GuardVerdict;
|
|
328
|
+
result?: string;
|
|
329
|
+
}>;
|
|
330
|
+
/**
|
|
331
|
+
* Process a model response — evaluate and execute all tool calls.
|
|
332
|
+
* Returns results for each tool call.
|
|
333
|
+
*/
|
|
334
|
+
processModelResponse(response: ModelResponse, model: ModelAdapter): Promise<ModelResponse>;
|
|
335
|
+
/** Get current session state. */
|
|
336
|
+
getState(): SessionState;
|
|
337
|
+
/** Stop the session. */
|
|
338
|
+
stop(): SessionState;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Run in pipe mode — read JSON lines from stdin, evaluate each,
|
|
342
|
+
* write verdicts to stdout. Works with any language or framework.
|
|
343
|
+
*
|
|
344
|
+
* Usage:
|
|
345
|
+
* my_agent | neuroverse run --pipe --world ./world/ --plan plan.json
|
|
346
|
+
*
|
|
347
|
+
* Each line of stdin should be a GuardEvent JSON.
|
|
348
|
+
* Each line of stdout will be a GuardVerdict JSON.
|
|
349
|
+
*/
|
|
350
|
+
declare function runPipeMode(config: SessionConfig): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Run an interactive governed chat session.
|
|
353
|
+
*
|
|
354
|
+
* Usage:
|
|
355
|
+
* neuroverse run --world ./world/ --plan plan.json --provider openai
|
|
356
|
+
*/
|
|
357
|
+
declare function runInteractiveMode(config: SessionConfig, model: ModelAdapter): Promise<void>;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* NeuroVerse MCP Server — Governance as an MCP Tool Provider
|
|
361
|
+
*
|
|
362
|
+
* Implements the Model Context Protocol (MCP) over stdio.
|
|
363
|
+
* Any MCP-compatible client (Claude Desktop, Cursor, etc.) can
|
|
364
|
+
* connect to this server and get governed tool access.
|
|
365
|
+
*
|
|
366
|
+
* Architecture:
|
|
367
|
+
* MCP Client (Claude, Cursor, etc.)
|
|
368
|
+
* ↓ stdio (JSON-RPC)
|
|
369
|
+
* NeuroVerse MCP Server
|
|
370
|
+
* ↓ evaluateGuard()
|
|
371
|
+
* Tool Execution (shell, http, file, etc.)
|
|
372
|
+
*
|
|
373
|
+
* The server exposes governance-wrapped tools. Every tool call
|
|
374
|
+
* passes through the guard engine before execution. Blocked
|
|
375
|
+
* actions return the governance reason to the model.
|
|
376
|
+
*
|
|
377
|
+
* MCP Protocol: JSON-RPC 2.0 over stdio
|
|
378
|
+
* - initialize → capabilities
|
|
379
|
+
* - tools/list → available tools
|
|
380
|
+
* - tools/call → evaluate + execute
|
|
381
|
+
*/
|
|
382
|
+
|
|
383
|
+
interface McpServerConfig {
|
|
384
|
+
/** Path to world directory. */
|
|
385
|
+
worldPath?: string;
|
|
386
|
+
/** Pre-loaded world. */
|
|
387
|
+
world?: WorldDefinition;
|
|
388
|
+
/** Active plan. */
|
|
389
|
+
plan?: PlanDefinition;
|
|
390
|
+
/** Path to plan.json (loaded on start). */
|
|
391
|
+
planPath?: string;
|
|
392
|
+
/** Enforcement level. */
|
|
393
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
394
|
+
/** Include trace in verdicts. */
|
|
395
|
+
trace?: boolean;
|
|
396
|
+
/** Enable shell tool. Default: true. */
|
|
397
|
+
enableShell?: boolean;
|
|
398
|
+
/** Enable file tools. Default: true. */
|
|
399
|
+
enableFiles?: boolean;
|
|
400
|
+
/** Enable HTTP tool. Default: true. */
|
|
401
|
+
enableHttp?: boolean;
|
|
402
|
+
/** Working directory for file/shell operations. */
|
|
403
|
+
workingDir?: string;
|
|
404
|
+
}
|
|
405
|
+
declare class McpGovernanceServer {
|
|
406
|
+
private world;
|
|
407
|
+
private plan?;
|
|
408
|
+
private config;
|
|
409
|
+
private engineOptions;
|
|
410
|
+
private initialized;
|
|
411
|
+
private actionsEvaluated;
|
|
412
|
+
private actionsAllowed;
|
|
413
|
+
private actionsBlocked;
|
|
414
|
+
constructor(config: McpServerConfig);
|
|
415
|
+
/**
|
|
416
|
+
* Start the MCP server — reads JSON-RPC from stdin, writes to stdout.
|
|
417
|
+
*/
|
|
418
|
+
start(): Promise<void>;
|
|
419
|
+
private handleRawLine;
|
|
420
|
+
private send;
|
|
421
|
+
private sendResult;
|
|
422
|
+
private sendError;
|
|
423
|
+
private handleRequest;
|
|
424
|
+
private handleNotification;
|
|
425
|
+
private handleInitialize;
|
|
426
|
+
private handleToolsList;
|
|
427
|
+
private handleToolsCall;
|
|
428
|
+
private executeTool;
|
|
429
|
+
private buildEvent;
|
|
430
|
+
private executeActualTool;
|
|
431
|
+
private toolGovernanceCheck;
|
|
432
|
+
private toolPlanStatus;
|
|
433
|
+
private toolPlanAdvance;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Audit Logger — Runtime Governance Telemetry
|
|
438
|
+
*
|
|
439
|
+
* Records every action evaluated by the governance engine.
|
|
440
|
+
* Provides the governance paper trail: what happened, why, and when.
|
|
441
|
+
*
|
|
442
|
+
* Architecture:
|
|
443
|
+
* - AuditEvent is the atomic record (one per evaluateGuard call)
|
|
444
|
+
* - AuditLogger is the pluggable interface (file, database, stream)
|
|
445
|
+
* - FileAuditLogger is the built-in file-based implementation
|
|
446
|
+
* - createGovernanceEngine wraps evaluateGuard with automatic logging
|
|
447
|
+
*
|
|
448
|
+
* INVARIANTS:
|
|
449
|
+
* - Logging never blocks or fails the governance decision
|
|
450
|
+
* - Every AuditEvent includes the full verdict + evidence
|
|
451
|
+
* - Events are append-only (immutable log)
|
|
452
|
+
*/
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* A single governance evaluation record.
|
|
456
|
+
* One of these is produced for every call to evaluateGuard.
|
|
457
|
+
*/
|
|
458
|
+
interface AuditEvent {
|
|
459
|
+
/** ISO 8601 timestamp */
|
|
460
|
+
timestamp: string;
|
|
461
|
+
/** World identity */
|
|
462
|
+
worldId: string;
|
|
463
|
+
worldName: string;
|
|
464
|
+
worldVersion: string;
|
|
465
|
+
/** The action that was evaluated */
|
|
466
|
+
intent: string;
|
|
467
|
+
tool?: string;
|
|
468
|
+
scope?: string;
|
|
469
|
+
actor?: string;
|
|
470
|
+
direction?: 'input' | 'output';
|
|
471
|
+
/** The governance decision */
|
|
472
|
+
decision: 'ALLOW' | 'BLOCK' | 'PAUSE' | 'MODIFY' | 'PENALIZE' | 'REWARD' | 'NEUTRAL';
|
|
473
|
+
reason?: string;
|
|
474
|
+
ruleId?: string;
|
|
475
|
+
warning?: string;
|
|
476
|
+
/** Consequence applied (for PENALIZE decisions) */
|
|
477
|
+
consequence?: {
|
|
478
|
+
type: string;
|
|
479
|
+
rounds?: number;
|
|
480
|
+
magnitude?: number;
|
|
481
|
+
description: string;
|
|
482
|
+
};
|
|
483
|
+
/** Reward applied (for REWARD decisions) */
|
|
484
|
+
reward?: {
|
|
485
|
+
type: string;
|
|
486
|
+
rounds?: number;
|
|
487
|
+
magnitude?: number;
|
|
488
|
+
description: string;
|
|
489
|
+
};
|
|
490
|
+
/** Intent tracking — original vs final action */
|
|
491
|
+
originalIntent?: string;
|
|
492
|
+
finalAction?: string;
|
|
493
|
+
/** Which rules/guards matched */
|
|
494
|
+
guardsMatched: string[];
|
|
495
|
+
rulesMatched: string[];
|
|
496
|
+
/** Invariant health */
|
|
497
|
+
invariantsSatisfied: number;
|
|
498
|
+
invariantsTotal: number;
|
|
499
|
+
/** Enforcement level used */
|
|
500
|
+
enforcementLevel: string;
|
|
501
|
+
/** Evaluation duration in milliseconds (if trace was enabled) */
|
|
502
|
+
durationMs?: number;
|
|
503
|
+
/** Full event args (optional, for detailed audit) */
|
|
504
|
+
args?: Record<string, unknown>;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Summary of governance activity over a set of audit events.
|
|
508
|
+
*/
|
|
509
|
+
interface AuditSummary {
|
|
510
|
+
totalActions: number;
|
|
511
|
+
allowed: number;
|
|
512
|
+
blocked: number;
|
|
513
|
+
paused: number;
|
|
514
|
+
modified: number;
|
|
515
|
+
penalized: number;
|
|
516
|
+
rewarded: number;
|
|
517
|
+
neutral: number;
|
|
518
|
+
/** Unique actors seen */
|
|
519
|
+
actors: string[];
|
|
520
|
+
/** Actions grouped by intent */
|
|
521
|
+
topIntents: {
|
|
522
|
+
intent: string;
|
|
523
|
+
count: number;
|
|
524
|
+
blocked: number;
|
|
525
|
+
paused: number;
|
|
526
|
+
penalized: number;
|
|
527
|
+
rewarded: number;
|
|
528
|
+
}[];
|
|
529
|
+
/** Most frequently triggered rules */
|
|
530
|
+
topRules: {
|
|
531
|
+
ruleId: string;
|
|
532
|
+
count: number;
|
|
533
|
+
}[];
|
|
534
|
+
/** Time range */
|
|
535
|
+
firstEvent: string;
|
|
536
|
+
lastEvent: string;
|
|
537
|
+
/** Behavioral economy summary */
|
|
538
|
+
behavioralEconomy: {
|
|
539
|
+
totalPenalties: number;
|
|
540
|
+
totalRewards: number;
|
|
541
|
+
netPressure: number;
|
|
542
|
+
redirectionRate: number;
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Pluggable audit logger interface.
|
|
547
|
+
* Implement this to send audit events to any destination.
|
|
548
|
+
*/
|
|
549
|
+
interface AuditLogger {
|
|
550
|
+
/** Append an audit event. Must not throw. */
|
|
551
|
+
log(event: AuditEvent): void | Promise<void>;
|
|
552
|
+
/** Flush any buffered events. */
|
|
553
|
+
flush?(): void | Promise<void>;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Append-only file logger using newline-delimited JSON (NDJSON).
|
|
557
|
+
* Each line is a self-contained JSON audit event.
|
|
558
|
+
*
|
|
559
|
+
* Log file location defaults to .neuroverse/audit.ndjson
|
|
560
|
+
*/
|
|
561
|
+
declare class FileAuditLogger implements AuditLogger {
|
|
562
|
+
private logPath;
|
|
563
|
+
private buffer;
|
|
564
|
+
private flushTimer;
|
|
565
|
+
private flushIntervalMs;
|
|
566
|
+
constructor(logPath: string, options?: {
|
|
567
|
+
flushIntervalMs?: number;
|
|
568
|
+
});
|
|
569
|
+
log(event: AuditEvent): void;
|
|
570
|
+
flush(): Promise<void>;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Simple logger that writes to stderr. Useful for development.
|
|
574
|
+
*/
|
|
575
|
+
declare class ConsoleAuditLogger implements AuditLogger {
|
|
576
|
+
log(event: AuditEvent): void;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Sends events to multiple loggers. Useful for file + console, file + webhook, etc.
|
|
580
|
+
*/
|
|
581
|
+
declare class CompositeAuditLogger implements AuditLogger {
|
|
582
|
+
private loggers;
|
|
583
|
+
constructor(...loggers: AuditLogger[]);
|
|
584
|
+
log(event: AuditEvent): void;
|
|
585
|
+
flush(): Promise<void>;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Convert a GuardEvent + GuardVerdict into an AuditEvent.
|
|
589
|
+
*/
|
|
590
|
+
declare function verdictToAuditEvent(event: GuardEvent, verdict: GuardVerdict): AuditEvent;
|
|
591
|
+
interface GovernanceEngineOptions extends GuardEngineOptions {
|
|
592
|
+
/** Audit logger instance. If provided, every evaluation is logged. */
|
|
593
|
+
auditLogger?: AuditLogger;
|
|
594
|
+
/** Include args in audit events. Default: false (privacy). */
|
|
595
|
+
auditArgs?: boolean;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Create a governed evaluation function that wraps evaluateGuard
|
|
599
|
+
* with automatic audit logging.
|
|
600
|
+
*
|
|
601
|
+
* Usage:
|
|
602
|
+
* const engine = createGovernanceEngine(world, {
|
|
603
|
+
* auditLogger: new FileAuditLogger('.neuroverse/audit.ndjson'),
|
|
604
|
+
* });
|
|
605
|
+
*
|
|
606
|
+
* const verdict = engine.evaluate(event);
|
|
607
|
+
*/
|
|
608
|
+
declare function createGovernanceEngine(world: WorldDefinition, options?: GovernanceEngineOptions): {
|
|
609
|
+
/**
|
|
610
|
+
* Evaluate a governance event and log the result.
|
|
611
|
+
*/
|
|
612
|
+
evaluate(event: GuardEvent): GuardVerdict;
|
|
613
|
+
/** Flush the audit logger. */
|
|
614
|
+
flush(): Promise<void>;
|
|
615
|
+
/** The underlying world definition. */
|
|
616
|
+
world: WorldDefinition;
|
|
617
|
+
};
|
|
618
|
+
/**
|
|
619
|
+
* Read audit events from an NDJSON log file.
|
|
620
|
+
*
|
|
621
|
+
* @param logPath - Path to the audit log file
|
|
622
|
+
* @param filter - Optional filter function
|
|
623
|
+
* @returns Array of matching audit events
|
|
624
|
+
*/
|
|
625
|
+
declare function readAuditLog(logPath: string, filter?: (event: AuditEvent) => boolean): Promise<AuditEvent[]>;
|
|
626
|
+
/**
|
|
627
|
+
* Summarize a set of audit events.
|
|
628
|
+
*/
|
|
629
|
+
declare function summarizeAuditEvents(events: AuditEvent[]): AuditSummary;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Verdict Formatter — Human-Readable Verdict Output
|
|
633
|
+
*
|
|
634
|
+
* Converts a GuardVerdict into a consistent, human-readable string.
|
|
635
|
+
* Used by adapters, CLIs, and UIs to display governance decisions.
|
|
636
|
+
*
|
|
637
|
+
* Design:
|
|
638
|
+
* - One function, one concern: verdict → string
|
|
639
|
+
* - No side effects, no I/O
|
|
640
|
+
* - Adapters call this so every integration has consistent messaging
|
|
641
|
+
*/
|
|
642
|
+
|
|
643
|
+
interface FormatVerdictOptions {
|
|
644
|
+
/** Include rule/guard ID. Default: true. */
|
|
645
|
+
showRuleId?: boolean;
|
|
646
|
+
/** Include evidence summary. Default: false. */
|
|
647
|
+
showEvidence?: boolean;
|
|
648
|
+
/** Include warning if present. Default: true. */
|
|
649
|
+
showWarning?: boolean;
|
|
650
|
+
/** Use ANSI colors in output. Default: false. */
|
|
651
|
+
color?: boolean;
|
|
652
|
+
/** Compact single-line format. Default: false. */
|
|
653
|
+
compact?: boolean;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Format a GuardVerdict as a human-readable string.
|
|
657
|
+
*
|
|
658
|
+
* Examples:
|
|
659
|
+
* formatVerdict(verdict)
|
|
660
|
+
* // "BLOCKED\n Rule: margin_floor\n Reason: margin ratio below 10%"
|
|
661
|
+
*
|
|
662
|
+
* formatVerdict(verdict, { compact: true })
|
|
663
|
+
* // "BLOCKED — margin_floor: margin ratio below 10%"
|
|
664
|
+
*
|
|
665
|
+
* formatVerdict(verdict, { color: true })
|
|
666
|
+
* // Same but with ANSI colors
|
|
667
|
+
*/
|
|
668
|
+
declare function formatVerdict(verdict: GuardVerdict, options?: FormatVerdictOptions): string;
|
|
669
|
+
/**
|
|
670
|
+
* Format a verdict as a short one-line status message.
|
|
671
|
+
* Useful for logging, status bars, and notifications.
|
|
672
|
+
*
|
|
673
|
+
* Example: "BLOCKED: margin_floor — margin ratio below 10%"
|
|
674
|
+
*/
|
|
675
|
+
declare function formatVerdictOneLine(verdict: GuardVerdict): string;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Governance Impact Report — Counterfactual Audit
|
|
679
|
+
*
|
|
680
|
+
* Answers: "What would have happened if governance did not exist?"
|
|
681
|
+
*
|
|
682
|
+
* This is the killer enterprise feature. It doesn't just log what happened —
|
|
683
|
+
* it proves the value of governance by showing what it prevented.
|
|
684
|
+
*
|
|
685
|
+
* Architecture:
|
|
686
|
+
* - Reads audit events (from FileAuditLogger NDJSON)
|
|
687
|
+
* - Classifies blocked/paused actions by risk category
|
|
688
|
+
* - Produces an ImpactReport with aggregated prevention metrics
|
|
689
|
+
* - CLI renders as human-readable or JSON
|
|
690
|
+
*
|
|
691
|
+
* INVARIANTS:
|
|
692
|
+
* - No speculation — only reports on actual evaluated actions
|
|
693
|
+
* - Risk categories derived from world rules, not invented
|
|
694
|
+
* - All numbers are exact counts from the audit log
|
|
695
|
+
*/
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* A counterfactual governance impact report.
|
|
699
|
+
*/
|
|
700
|
+
interface ImpactReport {
|
|
701
|
+
/** Report metadata */
|
|
702
|
+
generatedAt: string;
|
|
703
|
+
periodStart: string;
|
|
704
|
+
periodEnd: string;
|
|
705
|
+
worldName: string;
|
|
706
|
+
/** High-level stats */
|
|
707
|
+
totalEvaluations: number;
|
|
708
|
+
totalBlocked: number;
|
|
709
|
+
totalPaused: number;
|
|
710
|
+
totalAllowed: number;
|
|
711
|
+
totalModified: number;
|
|
712
|
+
totalPenalized: number;
|
|
713
|
+
totalRewarded: number;
|
|
714
|
+
totalNeutral: number;
|
|
715
|
+
/** Prevention rate: (blocked + paused + modified + penalized) / total */
|
|
716
|
+
preventionRate: number;
|
|
717
|
+
/** Redirection rate: everything not ALLOW/NEUTRAL */
|
|
718
|
+
redirectionRate: number;
|
|
719
|
+
/** Blocked actions grouped by category */
|
|
720
|
+
preventedByCategory: PreventionCategory[];
|
|
721
|
+
/** Top prevented intents */
|
|
722
|
+
topPreventedIntents: {
|
|
723
|
+
intent: string;
|
|
724
|
+
count: number;
|
|
725
|
+
topRule: string;
|
|
726
|
+
}[];
|
|
727
|
+
/** Actors with most blocked actions (potential policy violations) */
|
|
728
|
+
hotActors: {
|
|
729
|
+
actor: string;
|
|
730
|
+
blocked: number;
|
|
731
|
+
paused: number;
|
|
732
|
+
total: number;
|
|
733
|
+
}[];
|
|
734
|
+
/** Rules that triggered most often */
|
|
735
|
+
mostActiveRules: {
|
|
736
|
+
ruleId: string;
|
|
737
|
+
blockCount: number;
|
|
738
|
+
pauseCount: number;
|
|
739
|
+
}[];
|
|
740
|
+
/** Hourly activity pattern (governance load) */
|
|
741
|
+
hourlyDistribution: {
|
|
742
|
+
hour: number;
|
|
743
|
+
total: number;
|
|
744
|
+
blocked: number;
|
|
745
|
+
}[];
|
|
746
|
+
/** Repeat offenders: actions attempted more than once after being blocked */
|
|
747
|
+
repeatViolations: {
|
|
748
|
+
intent: string;
|
|
749
|
+
actor: string;
|
|
750
|
+
attempts: number;
|
|
751
|
+
firstSeen: string;
|
|
752
|
+
lastSeen: string;
|
|
753
|
+
}[];
|
|
754
|
+
}
|
|
755
|
+
interface PreventionCategory {
|
|
756
|
+
category: string;
|
|
757
|
+
count: number;
|
|
758
|
+
/** Example intents in this category */
|
|
759
|
+
examples: string[];
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Generate a governance impact report from audit events.
|
|
763
|
+
*/
|
|
764
|
+
declare function generateImpactReport(events: AuditEvent[]): ImpactReport;
|
|
765
|
+
/**
|
|
766
|
+
* Render an impact report as human-readable text.
|
|
767
|
+
*/
|
|
768
|
+
declare function renderImpactReport(report: ImpactReport): string;
|
|
769
|
+
/**
|
|
770
|
+
* Generate an impact report directly from an audit log file.
|
|
771
|
+
*/
|
|
772
|
+
declare function generateImpactReportFromFile(logPath: string): Promise<ImpactReport>;
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Decision Flow Engine — Intent → Rule → Outcome Visualization
|
|
776
|
+
*
|
|
777
|
+
* This is the core of the behavioral governance visualization.
|
|
778
|
+
* It transforms audit events into a flow structure that shows:
|
|
779
|
+
*
|
|
780
|
+
* LEFT (Intent Pool) → CENTER (Rules) → RIGHT (Outcome Pool)
|
|
781
|
+
* What agents wanted What intercepted What actually happened
|
|
782
|
+
*
|
|
783
|
+
* The gap between intent and outcome = governance value.
|
|
784
|
+
*
|
|
785
|
+
* Key metric: "X% of agent intent was redirected by governance"
|
|
786
|
+
*
|
|
787
|
+
* INVARIANTS:
|
|
788
|
+
* - Pure function: audit events in, flow structure out.
|
|
789
|
+
* - No speculation — only reports on actual evaluated actions.
|
|
790
|
+
* - Every flow path is traceable to a specific audit event.
|
|
791
|
+
*/
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* A cluster of agents with the same intent.
|
|
795
|
+
*/
|
|
796
|
+
interface IntentCluster {
|
|
797
|
+
/** The original intent (e.g., "sell", "publish", "attack") */
|
|
798
|
+
intent: string;
|
|
799
|
+
/** Number of agents with this intent */
|
|
800
|
+
agentCount: number;
|
|
801
|
+
/** Intensity score (0-1) based on volume and risk */
|
|
802
|
+
intensity: number;
|
|
803
|
+
/** Individual agent IDs in this cluster */
|
|
804
|
+
agents: string[];
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* A rule that intercepted actions in the flow.
|
|
808
|
+
*/
|
|
809
|
+
interface RuleObstacle {
|
|
810
|
+
/** Rule/guard ID */
|
|
811
|
+
ruleId: string;
|
|
812
|
+
/** Human-readable label */
|
|
813
|
+
label: string;
|
|
814
|
+
/** How many actions this rule intercepted */
|
|
815
|
+
interceptCount: number;
|
|
816
|
+
/** Breakdown by enforcement type */
|
|
817
|
+
enforcements: {
|
|
818
|
+
blocked: number;
|
|
819
|
+
modified: number;
|
|
820
|
+
penalized: number;
|
|
821
|
+
paused: number;
|
|
822
|
+
rewarded: number;
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* An outcome cluster — what agents ended up doing.
|
|
827
|
+
*/
|
|
828
|
+
interface OutcomeCluster {
|
|
829
|
+
/** The enforcement type that produced this outcome */
|
|
830
|
+
enforcement: GuardStatus;
|
|
831
|
+
/** Number of agents with this outcome */
|
|
832
|
+
agentCount: number;
|
|
833
|
+
/** For MODIFY: what they were changed to */
|
|
834
|
+
modifiedTo?: string;
|
|
835
|
+
/** Agent IDs in this cluster */
|
|
836
|
+
agents: string[];
|
|
837
|
+
/** Visual style hint */
|
|
838
|
+
style: 'green' | 'yellow' | 'red' | 'gray' | 'blue' | 'white';
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* A single flow path from intent → rule → outcome.
|
|
842
|
+
*/
|
|
843
|
+
interface FlowPath {
|
|
844
|
+
/** Source intent */
|
|
845
|
+
intent: string;
|
|
846
|
+
/** Rule that intercepted (if any) */
|
|
847
|
+
ruleId?: string;
|
|
848
|
+
/** Resulting enforcement */
|
|
849
|
+
enforcement: GuardStatus;
|
|
850
|
+
/** Agent ID */
|
|
851
|
+
agentId: string;
|
|
852
|
+
/** Original action */
|
|
853
|
+
originalAction: string;
|
|
854
|
+
/** Final action */
|
|
855
|
+
finalAction: string;
|
|
856
|
+
/** Consequence applied (if PENALIZE) */
|
|
857
|
+
consequence?: Consequence;
|
|
858
|
+
/** Reward applied (if REWARD) */
|
|
859
|
+
reward?: Reward;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* The complete Decision Flow — the visualization data structure.
|
|
863
|
+
*
|
|
864
|
+
* LEFT → CENTER → RIGHT
|
|
865
|
+
* Intents → Rules → Outcomes
|
|
866
|
+
*/
|
|
867
|
+
interface DecisionFlow {
|
|
868
|
+
/** Left column: intent clusters */
|
|
869
|
+
intents: IntentCluster[];
|
|
870
|
+
/** Center column: rule obstacles */
|
|
871
|
+
rules: RuleObstacle[];
|
|
872
|
+
/** Right column: outcome clusters */
|
|
873
|
+
outcomes: OutcomeCluster[];
|
|
874
|
+
/** Every individual flow path */
|
|
875
|
+
paths: FlowPath[];
|
|
876
|
+
/** Key metrics */
|
|
877
|
+
metrics: DecisionFlowMetrics;
|
|
878
|
+
/** Time window */
|
|
879
|
+
periodStart: string;
|
|
880
|
+
periodEnd: string;
|
|
881
|
+
worldName: string;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* The headline metrics for the Decision Flow.
|
|
885
|
+
*/
|
|
886
|
+
interface DecisionFlowMetrics {
|
|
887
|
+
/** Total intents evaluated */
|
|
888
|
+
totalIntents: number;
|
|
889
|
+
/** How many were redirected (not ALLOW) */
|
|
890
|
+
totalRedirected: number;
|
|
891
|
+
/** Headline: "X% of agent intent was redirected by governance" */
|
|
892
|
+
redirectionRate: number;
|
|
893
|
+
/** Breakdown by enforcement type */
|
|
894
|
+
byEnforcement: Record<string, number>;
|
|
895
|
+
/** Total penalties applied */
|
|
896
|
+
totalPenalties: number;
|
|
897
|
+
/** Total rewards applied */
|
|
898
|
+
totalRewards: number;
|
|
899
|
+
/** Net behavioral pressure (rewards - penalties) */
|
|
900
|
+
netBehavioralPressure: number;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Generate a Decision Flow from audit events.
|
|
904
|
+
*
|
|
905
|
+
* This is the primary entry point — takes raw audit data and produces
|
|
906
|
+
* the complete visualization structure.
|
|
907
|
+
*/
|
|
908
|
+
declare function generateDecisionFlow(events: AuditEvent[]): DecisionFlow;
|
|
909
|
+
/**
|
|
910
|
+
* Create a fresh agent behavior state.
|
|
911
|
+
*/
|
|
912
|
+
declare function createAgentState(agentId: string): AgentBehaviorState;
|
|
913
|
+
/**
|
|
914
|
+
* Apply a consequence to an agent's behavior state.
|
|
915
|
+
* Returns the updated state (immutable — creates a new object).
|
|
916
|
+
*/
|
|
917
|
+
declare function applyConsequence(state: AgentBehaviorState, consequence: Consequence, ruleId: string): AgentBehaviorState;
|
|
918
|
+
/**
|
|
919
|
+
* Apply a reward to an agent's behavior state.
|
|
920
|
+
* Returns the updated state (immutable).
|
|
921
|
+
*/
|
|
922
|
+
declare function applyReward(state: AgentBehaviorState, reward: Reward, ruleId: string): AgentBehaviorState;
|
|
923
|
+
/**
|
|
924
|
+
* Advance all agent states by one round.
|
|
925
|
+
* Decrements cooldowns, applies time-based effects.
|
|
926
|
+
*/
|
|
927
|
+
declare function tickAgentStates(states: Map<string, AgentBehaviorState>): Map<string, AgentBehaviorState>;
|
|
928
|
+
/**
|
|
929
|
+
* Render a Decision Flow as human-readable text.
|
|
930
|
+
* This is what `neuroverse decision-flow` prints.
|
|
931
|
+
*/
|
|
932
|
+
declare function renderDecisionFlow(flow: DecisionFlow): string;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* World Loader — Shared world file loading for CLI commands
|
|
936
|
+
*
|
|
937
|
+
* Loads a WorldDefinition from a directory containing individual JSON files.
|
|
938
|
+
*
|
|
939
|
+
* Used by: neuroverse guard, neuroverse validate, neuroverse init
|
|
940
|
+
* Not used by: neuroverse bootstrap (which produces world files, not consumes them)
|
|
941
|
+
*/
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Load a WorldDefinition from a directory of JSON files.
|
|
945
|
+
*
|
|
946
|
+
* Reads all standard world files and assembles them into a WorldDefinition.
|
|
947
|
+
* Missing optional files are handled gracefully with defaults.
|
|
948
|
+
* Missing required files (world.json) throw.
|
|
949
|
+
*/
|
|
950
|
+
declare function loadWorldFromDirectory(dirPath: string): Promise<WorldDefinition>;
|
|
951
|
+
/**
|
|
952
|
+
* Load a world from a directory path.
|
|
953
|
+
*/
|
|
954
|
+
declare function loadWorld(worldPath: string): Promise<WorldDefinition>;
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* World Resolver — Resolve world names to paths
|
|
958
|
+
*
|
|
959
|
+
* Resolution order:
|
|
960
|
+
* 1. Explicit path (absolute or relative) → use directly
|
|
961
|
+
* 2. NEUROVERSE_WORLD env var → resolve as name or path
|
|
962
|
+
* 3. .neuroverse/active_world file → read world name
|
|
963
|
+
* 4. Auto-detect if only one world exists in .neuroverse/worlds/
|
|
964
|
+
*
|
|
965
|
+
* World name resolution:
|
|
966
|
+
* "marketing" → .neuroverse/worlds/marketing/
|
|
967
|
+
* "./my-world/" → use as-is
|
|
968
|
+
* "/absolute/path" → use as-is
|
|
969
|
+
*/
|
|
970
|
+
interface WorldInfo {
|
|
971
|
+
name: string;
|
|
972
|
+
path: string;
|
|
973
|
+
active: boolean;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* List all compiled worlds in .neuroverse/worlds/
|
|
977
|
+
*/
|
|
978
|
+
declare function listWorlds(cwd?: string): WorldInfo[];
|
|
979
|
+
/**
|
|
980
|
+
* Get the active world name from .neuroverse/active_world
|
|
981
|
+
*/
|
|
982
|
+
declare function getActiveWorldName(cwd?: string): string | undefined;
|
|
983
|
+
/**
|
|
984
|
+
* Set the active world by writing .neuroverse/active_world
|
|
985
|
+
*/
|
|
986
|
+
declare function setActiveWorld(name: string, cwd?: string): void;
|
|
987
|
+
/**
|
|
988
|
+
* Resolve a world reference to an absolute path.
|
|
989
|
+
*
|
|
990
|
+
* @param explicit - Value from --world flag (may be undefined)
|
|
991
|
+
* @param cwd - Working directory for relative resolution
|
|
992
|
+
* @returns Resolved absolute path to the world directory
|
|
993
|
+
*/
|
|
994
|
+
declare function resolveWorldPath(explicit?: string, cwd?: string): string | undefined;
|
|
995
|
+
/**
|
|
996
|
+
* Describe how the current world was resolved (for "Using world:" messages).
|
|
997
|
+
* Returns { name, source } or undefined if no world is active.
|
|
998
|
+
*/
|
|
999
|
+
declare function describeActiveWorld(explicit?: string, cwd?: string): {
|
|
1000
|
+
name: string;
|
|
1001
|
+
source: string;
|
|
1002
|
+
} | undefined;
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Condition Engine — Structured operator evaluation
|
|
1006
|
+
*
|
|
1007
|
+
* Ported from the OpenClaw governance plugin. Provides 12 operators
|
|
1008
|
+
* for evaluating conditions against guard events:
|
|
1009
|
+
*
|
|
1010
|
+
* ==, !=, >, <, >=, <=, in,
|
|
1011
|
+
* contains, contains_any, matches_pattern, starts_with, ends_with
|
|
1012
|
+
*
|
|
1013
|
+
* Supports dot-notation field resolution (e.g. "args.command", "args.file_path")
|
|
1014
|
+
* for inspecting tool arguments.
|
|
1015
|
+
*
|
|
1016
|
+
* Deterministic. No AI. No network. Sub-millisecond per evaluation.
|
|
1017
|
+
*/
|
|
1018
|
+
|
|
1019
|
+
type ConditionOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | 'in' | 'contains' | 'contains_any' | 'matches_pattern' | 'starts_with' | 'ends_with';
|
|
1020
|
+
interface Condition {
|
|
1021
|
+
field: string;
|
|
1022
|
+
operator: ConditionOperator;
|
|
1023
|
+
value: string | string[] | number | boolean;
|
|
1024
|
+
}
|
|
1025
|
+
interface ConditionResult {
|
|
1026
|
+
matched: boolean;
|
|
1027
|
+
evidence: string | null;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Evaluate a single condition against a guard event.
|
|
1031
|
+
* Returns whether it matched and what evidence was found.
|
|
1032
|
+
*/
|
|
1033
|
+
declare function evaluateCondition(condition: Condition, event: GuardEvent): ConditionResult;
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Validate Contract — CLI World File Static Analysis Types
|
|
1037
|
+
*
|
|
1038
|
+
* Defines the input/output contract for `neuroverse validate`.
|
|
1039
|
+
*
|
|
1040
|
+
* WorldDefinition comes in (loaded from .nv-world.zip or directory).
|
|
1041
|
+
* ValidateReport goes out (stdout JSON).
|
|
1042
|
+
* Exit code encodes health: 0=PASS, 1=FAIL, 2=WARN.
|
|
1043
|
+
*
|
|
1044
|
+
* The validate engine performs static analysis on world files:
|
|
1045
|
+
* - Completeness: Are all required blocks present and non-empty?
|
|
1046
|
+
* - Referential integrity: Do rules reference declared state variables?
|
|
1047
|
+
* - Guard coverage: Do invariants have backing structural guards?
|
|
1048
|
+
* - Contradiction detection: Do rules conflict with each other?
|
|
1049
|
+
* - Orphan detection: Are there unreachable rules or unused variables?
|
|
1050
|
+
*
|
|
1051
|
+
* INVARIANTS:
|
|
1052
|
+
* - Deterministic: same world → same report.
|
|
1053
|
+
* - Zero network calls.
|
|
1054
|
+
* - Every finding includes the source block and a human-readable message.
|
|
1055
|
+
*/
|
|
1056
|
+
/**
|
|
1057
|
+
* Controls the strictness of governance validation.
|
|
1058
|
+
*
|
|
1059
|
+
* - `dev`: Lenient — governance findings are downgraded to info. Build always succeeds.
|
|
1060
|
+
* - `standard`: Recommended default — governance findings are warnings. Build always succeeds.
|
|
1061
|
+
* - `strict`: Compliance — governance findings stay as warnings but are flagged for attention.
|
|
1062
|
+
* Build still succeeds (worlds always work) but the report highlights all gaps.
|
|
1063
|
+
*
|
|
1064
|
+
* Structural issues (missing blocks, broken references, schema violations) are
|
|
1065
|
+
* always reported at their natural severity regardless of mode.
|
|
1066
|
+
*/
|
|
1067
|
+
type ValidationMode = 'dev' | 'standard' | 'strict';
|
|
1068
|
+
type FindingSeverity = 'error' | 'warning' | 'info';
|
|
1069
|
+
type FindingCategory = 'completeness' | 'referential-integrity' | 'guard-coverage' | 'contradiction' | 'orphan' | 'schema-violation' | 'semantic-tension';
|
|
1070
|
+
/**
|
|
1071
|
+
* A single finding from static analysis.
|
|
1072
|
+
*/
|
|
1073
|
+
interface ValidateFinding {
|
|
1074
|
+
/** Unique ID for this finding type (e.g., "missing-thesis", "orphan-rule-003") */
|
|
1075
|
+
id: string;
|
|
1076
|
+
/** Human-readable message */
|
|
1077
|
+
message: string;
|
|
1078
|
+
/** Error, warning, or informational */
|
|
1079
|
+
severity: FindingSeverity;
|
|
1080
|
+
/** What category of issue this is */
|
|
1081
|
+
category: FindingCategory;
|
|
1082
|
+
/** Which world file block(s) are affected */
|
|
1083
|
+
affectedBlocks: string[];
|
|
1084
|
+
/** Specific field or rule ID that triggered this finding */
|
|
1085
|
+
source?: string;
|
|
1086
|
+
/** Suggested fix (when deterministically derivable) */
|
|
1087
|
+
suggestion?: string;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Summary of world health by category.
|
|
1091
|
+
*/
|
|
1092
|
+
interface ValidateSummary {
|
|
1093
|
+
/** Total findings by severity */
|
|
1094
|
+
errors: number;
|
|
1095
|
+
warnings: number;
|
|
1096
|
+
info: number;
|
|
1097
|
+
/** Block completeness score (0-100) */
|
|
1098
|
+
completenessScore: number;
|
|
1099
|
+
/** Invariant coverage percentage (invariants with backing guards) */
|
|
1100
|
+
invariantCoverage: number;
|
|
1101
|
+
/** Whether the world is valid enough to run */
|
|
1102
|
+
canRun: boolean;
|
|
1103
|
+
/** Whether the world passes full validation (no errors) */
|
|
1104
|
+
isHealthy: boolean;
|
|
1105
|
+
/** Governance health — actionable summary of coverage gaps */
|
|
1106
|
+
governanceHealth?: GovernanceHealth;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Actionable governance health summary.
|
|
1110
|
+
* Provides at-a-glance understanding of how well-governed a world is.
|
|
1111
|
+
*/
|
|
1112
|
+
interface GovernanceHealth {
|
|
1113
|
+
/** How many declared action surfaces are governed vs total */
|
|
1114
|
+
surfacesCovered: number;
|
|
1115
|
+
surfacesTotal: number;
|
|
1116
|
+
/** Individual surface governance status */
|
|
1117
|
+
surfaces: Array<{
|
|
1118
|
+
name: string;
|
|
1119
|
+
governed: boolean;
|
|
1120
|
+
}>;
|
|
1121
|
+
/** How many structural invariants are enforced vs total */
|
|
1122
|
+
invariantsEnforced: number;
|
|
1123
|
+
invariantsTotal: number;
|
|
1124
|
+
/** Number of shadowed guards detected */
|
|
1125
|
+
shadowedGuards: number;
|
|
1126
|
+
/** Number of unenforced invariants */
|
|
1127
|
+
unenforcedInvariants: number;
|
|
1128
|
+
/** Number of unreachable rules/gates (dead policy logic) */
|
|
1129
|
+
unreachableRules: number;
|
|
1130
|
+
/** Number of enum variables with incomplete state coverage */
|
|
1131
|
+
incompleteStateCoverage: number;
|
|
1132
|
+
/** Overall risk level */
|
|
1133
|
+
riskLevel: 'low' | 'moderate' | 'high';
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* The validate report — what goes to stdout.
|
|
1137
|
+
*
|
|
1138
|
+
* Exit codes:
|
|
1139
|
+
* 0 = PASS (no errors, world is healthy)
|
|
1140
|
+
* 1 = FAIL (errors found, world cannot run safely)
|
|
1141
|
+
* 2 = WARN (warnings found but world can run)
|
|
1142
|
+
* 3 = ERROR (invalid input, could not parse world)
|
|
1143
|
+
*/
|
|
1144
|
+
interface ValidateReport {
|
|
1145
|
+
/** World identity */
|
|
1146
|
+
worldId: string;
|
|
1147
|
+
worldName: string;
|
|
1148
|
+
worldVersion: string;
|
|
1149
|
+
/** When the validation ran */
|
|
1150
|
+
validatedAt: number;
|
|
1151
|
+
/** Duration of validation */
|
|
1152
|
+
durationMs: number;
|
|
1153
|
+
/** High-level summary */
|
|
1154
|
+
summary: ValidateSummary;
|
|
1155
|
+
/** Validation mode used */
|
|
1156
|
+
validationMode: ValidationMode;
|
|
1157
|
+
/** All findings, ordered by severity (errors first) */
|
|
1158
|
+
findings: ValidateFinding[];
|
|
1159
|
+
}
|
|
1160
|
+
declare const VALIDATE_EXIT_CODES: {
|
|
1161
|
+
readonly PASS: 0;
|
|
1162
|
+
readonly FAIL: 1;
|
|
1163
|
+
readonly WARN: 2;
|
|
1164
|
+
readonly ERROR: 3;
|
|
1165
|
+
};
|
|
1166
|
+
type ValidateExitCode = (typeof VALIDATE_EXIT_CODES)[keyof typeof VALIDATE_EXIT_CODES];
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Validate Engine — World File Static Analysis
|
|
1170
|
+
*
|
|
1171
|
+
* Pure function: (world) → report
|
|
1172
|
+
*
|
|
1173
|
+
* Performs comprehensive static analysis on a WorldDefinition:
|
|
1174
|
+
* 1. Completeness — are required blocks present and non-empty?
|
|
1175
|
+
* 2. Referential integrity — do rules reference declared variables?
|
|
1176
|
+
* 3. Guard coverage — do invariants have backing structural guards?
|
|
1177
|
+
* 3b. Semantic coverage — can any guard actually intercept the invariant's action class?
|
|
1178
|
+
* 4. Contradiction detection — do rules conflict?
|
|
1179
|
+
* 5. Guard shadow detection — do guards shadow or conflict with each other?
|
|
1180
|
+
* 5b. Fail-closed surface detection — are action surfaces ungoverned?
|
|
1181
|
+
* 6. Reachability analysis — are there rules/guards that can never trigger?
|
|
1182
|
+
* 7. State space coverage — do guard conditions cover all enumerated states?
|
|
1183
|
+
* 8. Orphan detection — unused variables, unreachable rules
|
|
1184
|
+
* 9. Schema validation — values within declared ranges
|
|
1185
|
+
*
|
|
1186
|
+
* INVARIANTS:
|
|
1187
|
+
* - Deterministic: same world → same report, always.
|
|
1188
|
+
* - Zero network calls. Zero LLM calls. Zero async.
|
|
1189
|
+
* - Every finding is traceable to specific world file blocks.
|
|
1190
|
+
*/
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Validate a world definition and produce a report.
|
|
1194
|
+
*
|
|
1195
|
+
* This is the entire validate engine. One function. Deterministic.
|
|
1196
|
+
*/
|
|
1197
|
+
declare function validateWorld(world: WorldDefinition, mode?: ValidationMode): ValidateReport;
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Bootstrap Contract — Markdown → WorldDefinition Compilation Types
|
|
1201
|
+
*
|
|
1202
|
+
* Defines the input/output contract for `neuroverse bootstrap`.
|
|
1203
|
+
*
|
|
1204
|
+
* Input: .nv-world.md file (structured markdown)
|
|
1205
|
+
* Output: WorldDefinition (passed to validate, guard, or compileWorldToZip)
|
|
1206
|
+
*
|
|
1207
|
+
* The markdown format is:
|
|
1208
|
+
* - YAML frontmatter for world identity and metadata
|
|
1209
|
+
* - H1 sections for each block (Thesis, Invariants, State, etc.)
|
|
1210
|
+
* - Structured sub-sections within each block
|
|
1211
|
+
* - Deterministically parseable — no LLM, no heuristics
|
|
1212
|
+
*
|
|
1213
|
+
* Exit codes:
|
|
1214
|
+
* 0 = SUCCESS (compiled cleanly)
|
|
1215
|
+
* 1 = FAIL (parse errors, missing required sections)
|
|
1216
|
+
* 3 = ERROR (file not found, invalid input)
|
|
1217
|
+
*/
|
|
1218
|
+
type ParseSeverity = 'error' | 'warning' | 'info';
|
|
1219
|
+
/**
|
|
1220
|
+
* A single parse issue found during markdown compilation.
|
|
1221
|
+
*/
|
|
1222
|
+
interface ParseIssue {
|
|
1223
|
+
/** Line number in the source markdown (1-based) */
|
|
1224
|
+
line: number;
|
|
1225
|
+
/** Which section the issue was found in */
|
|
1226
|
+
section: string;
|
|
1227
|
+
/** Human-readable message */
|
|
1228
|
+
message: string;
|
|
1229
|
+
/** Severity */
|
|
1230
|
+
severity: ParseSeverity;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* The result of parsing a .nv-world.md file.
|
|
1234
|
+
*/
|
|
1235
|
+
interface BootstrapResult {
|
|
1236
|
+
/** Whether compilation succeeded (no errors) */
|
|
1237
|
+
success: boolean;
|
|
1238
|
+
/** Source file path */
|
|
1239
|
+
sourcePath: string;
|
|
1240
|
+
/** All parse issues */
|
|
1241
|
+
issues: ParseIssue[];
|
|
1242
|
+
/** Parsed sections (for debugging) */
|
|
1243
|
+
parsedSections: string[];
|
|
1244
|
+
/** Duration */
|
|
1245
|
+
durationMs: number;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* YAML frontmatter parsed from the markdown header.
|
|
1249
|
+
*/
|
|
1250
|
+
interface ParsedFrontmatter {
|
|
1251
|
+
world_id: string;
|
|
1252
|
+
name: string;
|
|
1253
|
+
version?: string;
|
|
1254
|
+
runtime_mode?: string;
|
|
1255
|
+
default_profile?: string;
|
|
1256
|
+
alternative_profile?: string;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* A parsed invariant from the Invariants section.
|
|
1260
|
+
*/
|
|
1261
|
+
interface ParsedInvariant {
|
|
1262
|
+
id: string;
|
|
1263
|
+
label: string;
|
|
1264
|
+
enforcement: string;
|
|
1265
|
+
mutable: boolean;
|
|
1266
|
+
line: number;
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* A parsed state variable from the State section.
|
|
1270
|
+
*/
|
|
1271
|
+
interface ParsedStateVariable {
|
|
1272
|
+
id: string;
|
|
1273
|
+
type: 'number' | 'enum' | 'boolean';
|
|
1274
|
+
default: string | number | boolean;
|
|
1275
|
+
label: string;
|
|
1276
|
+
description: string;
|
|
1277
|
+
min?: number;
|
|
1278
|
+
max?: number;
|
|
1279
|
+
step?: number;
|
|
1280
|
+
options?: string[];
|
|
1281
|
+
line: number;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* A parsed assumption profile from the Assumptions section.
|
|
1285
|
+
*/
|
|
1286
|
+
interface ParsedAssumptionProfile {
|
|
1287
|
+
id: string;
|
|
1288
|
+
name: string;
|
|
1289
|
+
description: string;
|
|
1290
|
+
parameters: Record<string, string | number | boolean>;
|
|
1291
|
+
line: number;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* A parsed trigger from a rule.
|
|
1295
|
+
*/
|
|
1296
|
+
interface ParsedTrigger {
|
|
1297
|
+
field: string;
|
|
1298
|
+
operator: string;
|
|
1299
|
+
value: string | number | boolean;
|
|
1300
|
+
source: 'state' | 'assumption';
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* A parsed effect from a rule.
|
|
1304
|
+
*/
|
|
1305
|
+
interface ParsedEffect {
|
|
1306
|
+
target: string;
|
|
1307
|
+
operation: string;
|
|
1308
|
+
value: number | boolean | string;
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* A parsed rule from the Rules section.
|
|
1312
|
+
*/
|
|
1313
|
+
interface ParsedRule {
|
|
1314
|
+
id: string;
|
|
1315
|
+
label: string;
|
|
1316
|
+
severity: string;
|
|
1317
|
+
description?: string;
|
|
1318
|
+
order: number;
|
|
1319
|
+
triggers: ParsedTrigger[];
|
|
1320
|
+
effects: ParsedEffect[];
|
|
1321
|
+
collapse_check?: {
|
|
1322
|
+
field: string;
|
|
1323
|
+
operator: string;
|
|
1324
|
+
value: number;
|
|
1325
|
+
};
|
|
1326
|
+
causal_translation?: {
|
|
1327
|
+
trigger_text: string;
|
|
1328
|
+
rule_text: string;
|
|
1329
|
+
shift_text: string;
|
|
1330
|
+
effect_text: string;
|
|
1331
|
+
};
|
|
1332
|
+
line: number;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* A parsed gate from the Gates section.
|
|
1336
|
+
*/
|
|
1337
|
+
interface ParsedGate {
|
|
1338
|
+
status: string;
|
|
1339
|
+
field: string;
|
|
1340
|
+
operator: string;
|
|
1341
|
+
value: number;
|
|
1342
|
+
line: number;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* A parsed outcome from the Outcomes section.
|
|
1346
|
+
*/
|
|
1347
|
+
interface ParsedOutcome {
|
|
1348
|
+
id: string;
|
|
1349
|
+
type: string;
|
|
1350
|
+
range?: [number, number];
|
|
1351
|
+
display?: string;
|
|
1352
|
+
label: string;
|
|
1353
|
+
primary?: boolean;
|
|
1354
|
+
assignment?: string;
|
|
1355
|
+
line: number;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* The full parsed intermediate representation.
|
|
1359
|
+
*/
|
|
1360
|
+
interface ParsedWorld {
|
|
1361
|
+
frontmatter: ParsedFrontmatter;
|
|
1362
|
+
thesis: string;
|
|
1363
|
+
invariants: ParsedInvariant[];
|
|
1364
|
+
stateVariables: ParsedStateVariable[];
|
|
1365
|
+
assumptions: ParsedAssumptionProfile[];
|
|
1366
|
+
rules: ParsedRule[];
|
|
1367
|
+
gates: ParsedGate[];
|
|
1368
|
+
outcomes: ParsedOutcome[];
|
|
1369
|
+
}
|
|
1370
|
+
declare const BOOTSTRAP_EXIT_CODES: {
|
|
1371
|
+
readonly SUCCESS: 0;
|
|
1372
|
+
readonly FAIL: 1;
|
|
1373
|
+
readonly ERROR: 3;
|
|
1374
|
+
};
|
|
1375
|
+
type BootstrapExitCode = (typeof BOOTSTRAP_EXIT_CODES)[keyof typeof BOOTSTRAP_EXIT_CODES];
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Bootstrap Parser — .nv-world.md → ParsedWorld
|
|
1379
|
+
*
|
|
1380
|
+
* Deterministic markdown parser for the NeuroVerse world authoring format.
|
|
1381
|
+
* No LLM calls. No heuristics. Pattern matching on structured markdown.
|
|
1382
|
+
*
|
|
1383
|
+
* ## Markdown Format (.nv-world.md)
|
|
1384
|
+
*
|
|
1385
|
+
* ```markdown
|
|
1386
|
+
* ---
|
|
1387
|
+
* world_id: my-world
|
|
1388
|
+
* name: My World
|
|
1389
|
+
* version: 1.0.0
|
|
1390
|
+
* default_profile: baseline
|
|
1391
|
+
* alternative_profile: alternative
|
|
1392
|
+
* ---
|
|
1393
|
+
*
|
|
1394
|
+
* # Thesis
|
|
1395
|
+
* The structural claim this world tests...
|
|
1396
|
+
*
|
|
1397
|
+
* # Invariants
|
|
1398
|
+
* - `invariant_id` — Label text (structural, immutable)
|
|
1399
|
+
* - `another_id` — Another label (structural, immutable)
|
|
1400
|
+
*
|
|
1401
|
+
* # State
|
|
1402
|
+
* ## variable_name
|
|
1403
|
+
* - type: number
|
|
1404
|
+
* - min: 0
|
|
1405
|
+
* - max: 100
|
|
1406
|
+
* - step: 5
|
|
1407
|
+
* - default: 50
|
|
1408
|
+
* - label: Human Label
|
|
1409
|
+
* - description: What this variable represents
|
|
1410
|
+
*
|
|
1411
|
+
* ## another_variable
|
|
1412
|
+
* - type: enum
|
|
1413
|
+
* - options: option_a, option_b, option_c
|
|
1414
|
+
* - default: option_a
|
|
1415
|
+
* - label: Another Variable
|
|
1416
|
+
* - description: Description here
|
|
1417
|
+
*
|
|
1418
|
+
* # Assumptions
|
|
1419
|
+
* ## baseline
|
|
1420
|
+
* - name: Baseline Scenario
|
|
1421
|
+
* - description: The default conditions
|
|
1422
|
+
* - param_key: param_value
|
|
1423
|
+
*
|
|
1424
|
+
* ## alternative
|
|
1425
|
+
* - name: Alternative Scenario
|
|
1426
|
+
* - description: What changes
|
|
1427
|
+
* - param_key: different_value
|
|
1428
|
+
*
|
|
1429
|
+
* # Rules
|
|
1430
|
+
* ## rule-001: Rule Label (structural)
|
|
1431
|
+
* Description of what this rule does.
|
|
1432
|
+
*
|
|
1433
|
+
* When field == "value" [state] AND other_field > 50 [assumption]
|
|
1434
|
+
* Then target *= 0.30, other_target = false
|
|
1435
|
+
* Collapse: field < 0.03
|
|
1436
|
+
*
|
|
1437
|
+
* > trigger: Trigger text here
|
|
1438
|
+
* > rule: Rule text here
|
|
1439
|
+
* > shift: Shift text here
|
|
1440
|
+
* > effect: Effect text here
|
|
1441
|
+
*
|
|
1442
|
+
* # Gates
|
|
1443
|
+
* - THRIVING: effective_margin >= 40
|
|
1444
|
+
* - STABLE: effective_margin >= 20
|
|
1445
|
+
* - COMPRESSED: effective_margin >= 10
|
|
1446
|
+
* - CRITICAL: effective_margin > 3
|
|
1447
|
+
* - MODEL_COLLAPSES: effective_margin <= 3
|
|
1448
|
+
*
|
|
1449
|
+
* # Outcomes
|
|
1450
|
+
* ## outcome_id
|
|
1451
|
+
* - type: number
|
|
1452
|
+
* - range: 0-100
|
|
1453
|
+
* - display: percentage
|
|
1454
|
+
* - label: Outcome Label
|
|
1455
|
+
* - primary: true
|
|
1456
|
+
* ```
|
|
1457
|
+
*/
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Parse a .nv-world.md string into a ParsedWorld.
|
|
1461
|
+
*
|
|
1462
|
+
* Returns the parsed world and a list of issues.
|
|
1463
|
+
* Callers should check issues for severity === 'error' before proceeding.
|
|
1464
|
+
*/
|
|
1465
|
+
declare function parseWorldMarkdown(markdown: string): {
|
|
1466
|
+
world: ParsedWorld | null;
|
|
1467
|
+
issues: ParseIssue[];
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
/**
|
|
1471
|
+
* Bootstrap Emitter — ParsedWorld → WorldDefinition
|
|
1472
|
+
*
|
|
1473
|
+
* Converts the intermediate representation from the parser
|
|
1474
|
+
* into a proper WorldDefinition that the guard engine, validate engine,
|
|
1475
|
+
* and compileWorldToZip() all consume.
|
|
1476
|
+
*
|
|
1477
|
+
* Fills in sensible defaults for optional fields.
|
|
1478
|
+
* Reports issues when the parsed data can't cleanly map to the target type.
|
|
1479
|
+
*
|
|
1480
|
+
* Deterministic. Same parsed input → same WorldDefinition output.
|
|
1481
|
+
*/
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* Convert a ParsedWorld into a WorldDefinition.
|
|
1485
|
+
*
|
|
1486
|
+
* Returns the world definition and any issues encountered during emission.
|
|
1487
|
+
*/
|
|
1488
|
+
declare function emitWorldDefinition(parsed: ParsedWorld): {
|
|
1489
|
+
world: WorldDefinition;
|
|
1490
|
+
issues: ParseIssue[];
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Add Engine — Incremental Governance Authoring
|
|
1495
|
+
*
|
|
1496
|
+
* Appends guards, rules, or invariants to a compiled world directory.
|
|
1497
|
+
* Runs validation after every addition. Deterministic, no LLM calls.
|
|
1498
|
+
*
|
|
1499
|
+
* Three construct types map to user intent:
|
|
1500
|
+
* "Block X" → Guard (action control)
|
|
1501
|
+
* "If X happens → Y changes" → Rule (world evolution)
|
|
1502
|
+
* "X must always be true" → Invariant (hard constraint)
|
|
1503
|
+
*
|
|
1504
|
+
* Architecture:
|
|
1505
|
+
* addGuard() → append to guards.json → validate → report
|
|
1506
|
+
* addRule() → write rules/rule-NNN.json → validate → report
|
|
1507
|
+
* addInvariant() → append to invariants.json → validate → report
|
|
1508
|
+
*/
|
|
1509
|
+
|
|
1510
|
+
interface AddResult {
|
|
1511
|
+
/** What was added */
|
|
1512
|
+
type: 'guard' | 'rule' | 'invariant';
|
|
1513
|
+
/** The ID of the added construct */
|
|
1514
|
+
id: string;
|
|
1515
|
+
/** The file that was written */
|
|
1516
|
+
file: string;
|
|
1517
|
+
/** Whether validation passed after addition */
|
|
1518
|
+
valid: boolean;
|
|
1519
|
+
/** Validation findings (errors/warnings) introduced by this addition */
|
|
1520
|
+
findings: ValidateReport['findings'];
|
|
1521
|
+
/** The full object that was written */
|
|
1522
|
+
construct: Guard | Rule | Invariant;
|
|
1523
|
+
}
|
|
1524
|
+
interface AddGuardInput {
|
|
1525
|
+
/** Human-readable label (e.g., "Block dairy orders") */
|
|
1526
|
+
label: string;
|
|
1527
|
+
/** What enforcement to apply */
|
|
1528
|
+
enforcement: Guard['enforcement'];
|
|
1529
|
+
/** Intent patterns to match (e.g., ["order*dairy", "purchase*dairy"]) */
|
|
1530
|
+
intentPatterns: string[];
|
|
1531
|
+
/** Optional description */
|
|
1532
|
+
description?: string;
|
|
1533
|
+
/** Optional category override */
|
|
1534
|
+
category?: Guard['category'];
|
|
1535
|
+
/** Optional tool filter */
|
|
1536
|
+
appliesTo?: string[];
|
|
1537
|
+
/** Optional reason for block/pause */
|
|
1538
|
+
reason?: string;
|
|
1539
|
+
/** Optional invariant reference */
|
|
1540
|
+
invariantRef?: string;
|
|
1541
|
+
/** Optional explicit ID */
|
|
1542
|
+
id?: string;
|
|
1543
|
+
}
|
|
1544
|
+
declare function addGuard(worldDir: string, input: AddGuardInput): Promise<AddResult>;
|
|
1545
|
+
interface AddRuleInput {
|
|
1546
|
+
/** Human-readable label */
|
|
1547
|
+
label: string;
|
|
1548
|
+
/** Severity level */
|
|
1549
|
+
severity: Rule['severity'];
|
|
1550
|
+
/** Description of what this rule does */
|
|
1551
|
+
description?: string;
|
|
1552
|
+
/** Trigger conditions */
|
|
1553
|
+
triggers: Rule['triggers'];
|
|
1554
|
+
/** Effects when triggered */
|
|
1555
|
+
effects?: Rule['effects'];
|
|
1556
|
+
/** Optional collapse check */
|
|
1557
|
+
collapseCheck?: Rule['collapse_check'];
|
|
1558
|
+
/** Causal translation (human-readable explanation) */
|
|
1559
|
+
causalTranslation?: Rule['causal_translation'];
|
|
1560
|
+
/** Optional explicit ID */
|
|
1561
|
+
id?: string;
|
|
1562
|
+
}
|
|
1563
|
+
declare function addRule(worldDir: string, input: AddRuleInput): Promise<AddResult>;
|
|
1564
|
+
interface AddInvariantInput {
|
|
1565
|
+
/** Human-readable label (e.g., "Budget must never exceed 1000") */
|
|
1566
|
+
label: string;
|
|
1567
|
+
/** Enforcement type */
|
|
1568
|
+
enforcement?: Invariant['enforcement'];
|
|
1569
|
+
/** Optional explicit ID */
|
|
1570
|
+
id?: string;
|
|
1571
|
+
}
|
|
1572
|
+
declare function addInvariant(worldDir: string, input: AddInvariantInput): Promise<AddResult>;
|
|
1573
|
+
/**
|
|
1574
|
+
* Classify a natural-language intent into the correct construct type.
|
|
1575
|
+
* This is a simple deterministic classifier — no LLM required.
|
|
1576
|
+
*
|
|
1577
|
+
* Returns 'guard' | 'rule' | 'invariant' | 'ambiguous'
|
|
1578
|
+
*/
|
|
1579
|
+
type ConstructType = 'guard' | 'rule' | 'invariant' | 'ambiguous';
|
|
1580
|
+
declare function classifyIntent(text: string): ConstructType;
|
|
1581
|
+
/**
|
|
1582
|
+
* Parse a natural-language guard description into AddGuardInput.
|
|
1583
|
+
* Handles common patterns like:
|
|
1584
|
+
* "Block dairy orders"
|
|
1585
|
+
* "Pause if cost > 500"
|
|
1586
|
+
* "Warn on shell access"
|
|
1587
|
+
*/
|
|
1588
|
+
declare function parseGuardDescription(text: string): AddGuardInput;
|
|
1589
|
+
|
|
1590
|
+
/**
|
|
1591
|
+
* Derive Contract — AI-Assisted World Synthesis Types
|
|
1592
|
+
*
|
|
1593
|
+
* Defines the input/output contract for `neuroverse derive`.
|
|
1594
|
+
*
|
|
1595
|
+
* Input: Arbitrary markdown files/directories
|
|
1596
|
+
* Output: .nv-world.md file constrained by DerivationWorld
|
|
1597
|
+
*
|
|
1598
|
+
* Exit codes:
|
|
1599
|
+
* 0 = SUCCESS (valid file written)
|
|
1600
|
+
* 1 = VALIDATION_FAIL (output failed parseWorldMarkdown)
|
|
1601
|
+
* 2 = INPUT_ERROR (missing input, empty dir, unreadable)
|
|
1602
|
+
* 3 = PROVIDER_ERROR (no config, API failure, timeout)
|
|
1603
|
+
*/
|
|
1604
|
+
declare const DERIVE_EXIT_CODES: {
|
|
1605
|
+
readonly SUCCESS: 0;
|
|
1606
|
+
readonly VALIDATION_FAIL: 1;
|
|
1607
|
+
readonly INPUT_ERROR: 2;
|
|
1608
|
+
readonly PROVIDER_ERROR: 3;
|
|
1609
|
+
};
|
|
1610
|
+
type DeriveExitCode = (typeof DERIVE_EXIT_CODES)[keyof typeof DERIVE_EXIT_CODES];
|
|
1611
|
+
declare const CONFIGURE_AI_EXIT_CODES: {
|
|
1612
|
+
readonly SUCCESS: 0;
|
|
1613
|
+
readonly VALIDATION_FAIL: 1;
|
|
1614
|
+
readonly ERROR: 3;
|
|
1615
|
+
};
|
|
1616
|
+
interface DeriveResult {
|
|
1617
|
+
success: boolean;
|
|
1618
|
+
outputPath: string;
|
|
1619
|
+
sectionsDetected: string[];
|
|
1620
|
+
validationErrors: number;
|
|
1621
|
+
validationWarnings: number;
|
|
1622
|
+
findings: DeriveFinding[];
|
|
1623
|
+
gate?: string;
|
|
1624
|
+
normalization?: NormalizationSummary;
|
|
1625
|
+
durationMs: number;
|
|
1626
|
+
}
|
|
1627
|
+
interface NormalizationSummary {
|
|
1628
|
+
fixCount: number;
|
|
1629
|
+
invariantIds: number;
|
|
1630
|
+
gateThresholds: number;
|
|
1631
|
+
triggerTags: number;
|
|
1632
|
+
}
|
|
1633
|
+
interface DeriveFinding {
|
|
1634
|
+
severity: 'error' | 'warning';
|
|
1635
|
+
section: string;
|
|
1636
|
+
message: string;
|
|
1637
|
+
line?: number;
|
|
1638
|
+
}
|
|
1639
|
+
interface CollectedSource {
|
|
1640
|
+
filename: string;
|
|
1641
|
+
content: string;
|
|
1642
|
+
}
|
|
1643
|
+
interface AIProviderConfig {
|
|
1644
|
+
provider: string;
|
|
1645
|
+
model: string;
|
|
1646
|
+
apiKey: string;
|
|
1647
|
+
endpoint: string | null;
|
|
1648
|
+
}
|
|
1649
|
+
interface AIProvider {
|
|
1650
|
+
complete(systemPrompt: string, userPrompt: string): Promise<string>;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Derive Engine — AI-Assisted World Synthesis Pipeline
|
|
1655
|
+
*
|
|
1656
|
+
* Pipeline:
|
|
1657
|
+
* collect → prompt → AI → extract → parseWorldMarkdown → write → JSON
|
|
1658
|
+
*
|
|
1659
|
+
* DerivationWorld is advisory only:
|
|
1660
|
+
* - Gate status is reported but never blocks file writing
|
|
1661
|
+
* - parseWorldMarkdown errors ARE blocking (invalid .nv-world.md)
|
|
1662
|
+
* - Governance engine does NOT run during derive
|
|
1663
|
+
*/
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* Extract .nv-world.md content from LLM response.
|
|
1667
|
+
*
|
|
1668
|
+
* Handles:
|
|
1669
|
+
* - Triple backtick fences (```markdown ... ``` or ``` ... ```)
|
|
1670
|
+
* - Sentinel markers (BEGIN NV WORLD / END NV WORLD)
|
|
1671
|
+
* - Raw content starting with ---
|
|
1672
|
+
*
|
|
1673
|
+
* Pre-parse safety: output must contain `world_id:` in frontmatter.
|
|
1674
|
+
*/
|
|
1675
|
+
declare function extractWorldMarkdown(raw: string): string | null;
|
|
1676
|
+
interface DeriveOptions {
|
|
1677
|
+
inputPath: string;
|
|
1678
|
+
outputPath: string;
|
|
1679
|
+
validate: boolean;
|
|
1680
|
+
dryRun: boolean;
|
|
1681
|
+
providerOverride?: Partial<AIProviderConfig>;
|
|
1682
|
+
}
|
|
1683
|
+
declare function deriveWorld(options: DeriveOptions): Promise<{
|
|
1684
|
+
result: DeriveResult;
|
|
1685
|
+
exitCode: number;
|
|
1686
|
+
dryRunOutput?: {
|
|
1687
|
+
systemPrompt: string;
|
|
1688
|
+
userPrompt: string;
|
|
1689
|
+
};
|
|
1690
|
+
}>;
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* Derive Normalizer — Post-processing pass for AI output drift
|
|
1694
|
+
*
|
|
1695
|
+
* Runs AFTER AI generation but BEFORE parsing. Normalizes common
|
|
1696
|
+
* deviations from the strict .nv-world.md grammar so the parser
|
|
1697
|
+
* can accept the output.
|
|
1698
|
+
*
|
|
1699
|
+
* Transformations:
|
|
1700
|
+
* 1. Invariant lines: adds backtick-wrapped IDs when missing
|
|
1701
|
+
* 2. Gate lines: converts symbolic values to numeric thresholds
|
|
1702
|
+
* 3. Trigger lines: ensures [state] / [assumption] source tags
|
|
1703
|
+
*
|
|
1704
|
+
* INVARIANTS:
|
|
1705
|
+
* - Deterministic: same input → same output, always.
|
|
1706
|
+
* - Zero network calls. Zero LLM calls.
|
|
1707
|
+
* - Never removes content — only reformats.
|
|
1708
|
+
* - Operates on raw markdown string, not parsed structures.
|
|
1709
|
+
*/
|
|
1710
|
+
interface NormalizerReport {
|
|
1711
|
+
/** Total number of lines fixed */
|
|
1712
|
+
fixCount: number;
|
|
1713
|
+
/** Number of invariant IDs wrapped in backticks */
|
|
1714
|
+
invariantIds: number;
|
|
1715
|
+
/** Number of symbolic gate thresholds converted to numeric */
|
|
1716
|
+
gateThresholds: number;
|
|
1717
|
+
/** Number of triggers tagged with [state] */
|
|
1718
|
+
triggerTags: number;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Normalize AI-generated .nv-world.md content to fix common drift patterns.
|
|
1722
|
+
*
|
|
1723
|
+
* Returns the normalized markdown string and a detailed fix report.
|
|
1724
|
+
*/
|
|
1725
|
+
declare function normalizeWorldMarkdown(markdown: string): {
|
|
1726
|
+
normalized: string;
|
|
1727
|
+
fixCount: number;
|
|
1728
|
+
report: NormalizerReport;
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* Explain Engine — Generates human-readable narrative summaries from compiled worlds.
|
|
1733
|
+
*
|
|
1734
|
+
* No AI calls. Pure template-based rendering from WorldDefinition data.
|
|
1735
|
+
*
|
|
1736
|
+
* Sections:
|
|
1737
|
+
* 1. Core thesis and identity
|
|
1738
|
+
* 2. Key dynamics (rules with causal_translation)
|
|
1739
|
+
* 3. State variables (what can change)
|
|
1740
|
+
* 4. Invariants (what cannot change)
|
|
1741
|
+
* 5. Viability gates (health thresholds)
|
|
1742
|
+
* 6. Dramatic tensions (opposing rule effects)
|
|
1743
|
+
* 7. Outcomes (what gets measured)
|
|
1744
|
+
*/
|
|
1745
|
+
|
|
1746
|
+
interface ExplainOutput {
|
|
1747
|
+
worldName: string;
|
|
1748
|
+
worldId: string;
|
|
1749
|
+
thesis: string;
|
|
1750
|
+
dynamics: DynamicSummary[];
|
|
1751
|
+
stateVariables: VariableSummary[];
|
|
1752
|
+
invariants: InvariantSummary[];
|
|
1753
|
+
gates: GateSummary[];
|
|
1754
|
+
tensions: TensionSummary[];
|
|
1755
|
+
outcomes: OutcomeSummary[];
|
|
1756
|
+
stats: WorldStats;
|
|
1757
|
+
}
|
|
1758
|
+
interface DynamicSummary {
|
|
1759
|
+
ruleId: string;
|
|
1760
|
+
label: string;
|
|
1761
|
+
severity: string;
|
|
1762
|
+
triggerDescription: string;
|
|
1763
|
+
effectDescription: string;
|
|
1764
|
+
targets: string[];
|
|
1765
|
+
}
|
|
1766
|
+
interface VariableSummary {
|
|
1767
|
+
name: string;
|
|
1768
|
+
label: string;
|
|
1769
|
+
type: string;
|
|
1770
|
+
defaultValue: string | number | boolean;
|
|
1771
|
+
range?: string;
|
|
1772
|
+
}
|
|
1773
|
+
interface InvariantSummary {
|
|
1774
|
+
id: string;
|
|
1775
|
+
label: string;
|
|
1776
|
+
enforcement: string;
|
|
1777
|
+
}
|
|
1778
|
+
interface GateSummary {
|
|
1779
|
+
status: string;
|
|
1780
|
+
field: string;
|
|
1781
|
+
threshold: string;
|
|
1782
|
+
}
|
|
1783
|
+
interface TensionSummary {
|
|
1784
|
+
variable: string;
|
|
1785
|
+
increasedBy: string[];
|
|
1786
|
+
decreasedBy: string[];
|
|
1787
|
+
}
|
|
1788
|
+
interface OutcomeSummary {
|
|
1789
|
+
id: string;
|
|
1790
|
+
label: string;
|
|
1791
|
+
type: string;
|
|
1792
|
+
primary: boolean;
|
|
1793
|
+
}
|
|
1794
|
+
interface WorldStats {
|
|
1795
|
+
invariants: number;
|
|
1796
|
+
stateVariables: number;
|
|
1797
|
+
rules: number;
|
|
1798
|
+
gates: number;
|
|
1799
|
+
outcomes: number;
|
|
1800
|
+
assumptions: number;
|
|
1801
|
+
}
|
|
1802
|
+
declare function explainWorld(world: WorldDefinition): ExplainOutput;
|
|
1803
|
+
declare function renderExplainText(output: ExplainOutput): string;
|
|
1804
|
+
|
|
1805
|
+
/**
|
|
1806
|
+
* Simulate Engine — Deterministic State Evolution (Reference Simulator)
|
|
1807
|
+
*
|
|
1808
|
+
* Pure function: (world, options) → SimulationResult
|
|
1809
|
+
*
|
|
1810
|
+
* This is NeuroVerse's REFERENCE SIMULATOR — one way to model how a world
|
|
1811
|
+
* evolves over time. It is NOT the governance engine.
|
|
1812
|
+
*
|
|
1813
|
+
* simulateWorld() ≠ evaluateGuard()
|
|
1814
|
+
*
|
|
1815
|
+
* evaluateGuard() — Runtime enforcement. Decides if an action is allowed.
|
|
1816
|
+
* Includes safety layer, role checks, plan enforcement,
|
|
1817
|
+
* kernel rules, level constraints. Use for governance.
|
|
1818
|
+
*
|
|
1819
|
+
* simulateWorld() — State evolution modeling. Evaluates rule triggers,
|
|
1820
|
+
* applies effects, tracks viability over N steps.
|
|
1821
|
+
* Use for scenario planning and what-if analysis.
|
|
1822
|
+
*
|
|
1823
|
+
* World files (.nv-world.md) are portable — they define rules, roles, and
|
|
1824
|
+
* constraints that can be consumed by any simulator or governance engine.
|
|
1825
|
+
* This simulator is a reference implementation, not the only interpreter.
|
|
1826
|
+
*
|
|
1827
|
+
* Supports:
|
|
1828
|
+
* - Single-step evaluation (default)
|
|
1829
|
+
* - Multi-step iteration (--steps N)
|
|
1830
|
+
* - State overrides (start from non-default values)
|
|
1831
|
+
* - Assumption profile selection
|
|
1832
|
+
* - Collapse detection (early termination)
|
|
1833
|
+
*
|
|
1834
|
+
* INVARIANTS:
|
|
1835
|
+
* - Deterministic: same world + same options → same result.
|
|
1836
|
+
* - Zero network calls. Zero LLM calls. Zero async.
|
|
1837
|
+
* - Every rule evaluation is recorded in the trace.
|
|
1838
|
+
* - World definition is REQUIRED — no world, no simulation.
|
|
1839
|
+
*/
|
|
1840
|
+
|
|
1841
|
+
interface SimulateOptions {
|
|
1842
|
+
/** Number of simulation steps (default: 1) */
|
|
1843
|
+
steps?: number;
|
|
1844
|
+
/** State variable overrides (start values) */
|
|
1845
|
+
stateOverrides?: Record<string, string | number | boolean>;
|
|
1846
|
+
/** Assumption profile to use (default: world default) */
|
|
1847
|
+
profile?: string;
|
|
1848
|
+
}
|
|
1849
|
+
interface SimulationResult {
|
|
1850
|
+
worldId: string;
|
|
1851
|
+
worldName: string;
|
|
1852
|
+
profile: string;
|
|
1853
|
+
initialState: Record<string, string | number | boolean>;
|
|
1854
|
+
steps: SimulationStep[];
|
|
1855
|
+
finalState: Record<string, string | number | boolean>;
|
|
1856
|
+
finalViability: ViabilityStatus;
|
|
1857
|
+
collapsed: boolean;
|
|
1858
|
+
collapseStep?: number;
|
|
1859
|
+
collapseRule?: string;
|
|
1860
|
+
}
|
|
1861
|
+
interface SimulationStep {
|
|
1862
|
+
step: number;
|
|
1863
|
+
rulesEvaluated: RuleEvaluation[];
|
|
1864
|
+
rulesFired: number;
|
|
1865
|
+
stateAfter: Record<string, string | number | boolean>;
|
|
1866
|
+
viability: ViabilityStatus;
|
|
1867
|
+
collapsed: boolean;
|
|
1868
|
+
}
|
|
1869
|
+
interface RuleEvaluation {
|
|
1870
|
+
ruleId: string;
|
|
1871
|
+
label: string;
|
|
1872
|
+
triggered: boolean;
|
|
1873
|
+
excluded: boolean;
|
|
1874
|
+
effects: AppliedEffect[];
|
|
1875
|
+
collapsed: boolean;
|
|
1876
|
+
collapseField?: string;
|
|
1877
|
+
}
|
|
1878
|
+
interface AppliedEffect {
|
|
1879
|
+
target: string;
|
|
1880
|
+
operation: string;
|
|
1881
|
+
value: number | boolean | string;
|
|
1882
|
+
before: string | number | boolean;
|
|
1883
|
+
after: string | number | boolean;
|
|
1884
|
+
}
|
|
1885
|
+
declare function simulateWorld(world: WorldDefinition, options?: SimulateOptions): SimulationResult;
|
|
1886
|
+
declare function renderSimulateText(result: SimulationResult): string;
|
|
1887
|
+
|
|
1888
|
+
/**
|
|
1889
|
+
* Improve Engine — Actionable Suggestions from World Analysis
|
|
1890
|
+
*
|
|
1891
|
+
* Pure function: (world) → ImprovementReport
|
|
1892
|
+
*
|
|
1893
|
+
* Runs validation, simulation, and structural analysis to produce
|
|
1894
|
+
* prioritized, actionable suggestions for improving a world.
|
|
1895
|
+
*
|
|
1896
|
+
* Categories:
|
|
1897
|
+
* 1. Critical fixes — errors that prevent the world from running
|
|
1898
|
+
* 2. Structural gaps — missing guards, orphan variables, etc.
|
|
1899
|
+
* 3. Balance suggestions — detected from simulation dynamics
|
|
1900
|
+
* 4. Completeness — optional blocks that would strengthen the world
|
|
1901
|
+
*
|
|
1902
|
+
* INVARIANTS:
|
|
1903
|
+
* - Deterministic: same world → same report.
|
|
1904
|
+
* - Zero network calls. Zero LLM calls. Zero async.
|
|
1905
|
+
*/
|
|
1906
|
+
|
|
1907
|
+
type SuggestionPriority = 'critical' | 'high' | 'medium' | 'low';
|
|
1908
|
+
type SuggestionCategory = 'fix' | 'structure' | 'balance' | 'completeness' | 'coverage';
|
|
1909
|
+
interface Suggestion {
|
|
1910
|
+
id: string;
|
|
1911
|
+
priority: SuggestionPriority;
|
|
1912
|
+
category: SuggestionCategory;
|
|
1913
|
+
title: string;
|
|
1914
|
+
description: string;
|
|
1915
|
+
action: string;
|
|
1916
|
+
affectedFiles: string[];
|
|
1917
|
+
}
|
|
1918
|
+
interface ImprovementReport {
|
|
1919
|
+
worldId: string;
|
|
1920
|
+
worldName: string;
|
|
1921
|
+
score: number;
|
|
1922
|
+
suggestions: Suggestion[];
|
|
1923
|
+
stats: {
|
|
1924
|
+
critical: number;
|
|
1925
|
+
high: number;
|
|
1926
|
+
medium: number;
|
|
1927
|
+
low: number;
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
declare function improveWorld(world: WorldDefinition): ImprovementReport;
|
|
1931
|
+
declare function renderImproveText(report: ImprovementReport): string;
|
|
1932
|
+
|
|
1933
|
+
/**
|
|
1934
|
+
* Runtime Types — Simple input types for HTTP/demo consumers
|
|
1935
|
+
*
|
|
1936
|
+
* These types are the "easy API" for code that doesn't load full world files.
|
|
1937
|
+
* The govern() bridge converts these into the guard engine's native types.
|
|
1938
|
+
*/
|
|
1939
|
+
/**
|
|
1940
|
+
* A plain-object description of an agent action.
|
|
1941
|
+
* This is what HTTP clients and Python simulations send.
|
|
1942
|
+
*/
|
|
1943
|
+
interface AgentAction {
|
|
1944
|
+
/** Agent or role identifier */
|
|
1945
|
+
agentId: string;
|
|
1946
|
+
/** Action type (e.g., "publish", "trade", "share", "cite") */
|
|
1947
|
+
type: string;
|
|
1948
|
+
/** Human-readable description of what the agent is doing */
|
|
1949
|
+
description: string;
|
|
1950
|
+
/** Action magnitude/intensity (0-1 scale) */
|
|
1951
|
+
magnitude?: number;
|
|
1952
|
+
/** Arbitrary context data */
|
|
1953
|
+
context?: Record<string, unknown>;
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Arbitrary key-value state passed alongside an action.
|
|
1957
|
+
* Used by the simulation bridge to provide environmental context.
|
|
1958
|
+
*/
|
|
1959
|
+
type WorldState = Record<string, unknown>;
|
|
1960
|
+
/**
|
|
1961
|
+
* Configuration for creating a governor instance.
|
|
1962
|
+
*/
|
|
1963
|
+
interface GovernorConfig {
|
|
1964
|
+
/** Path to a .nv-world.md or .nv-world.zip file */
|
|
1965
|
+
worldPath?: string;
|
|
1966
|
+
/** Enable evaluation trace in verdicts */
|
|
1967
|
+
trace?: boolean;
|
|
1968
|
+
/** Enforcement level override */
|
|
1969
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* Govern — Thin bridge from HTTP/demo consumers to the real guard engine.
|
|
1974
|
+
*
|
|
1975
|
+
* This is NOT a second engine. It is NOT a parser.
|
|
1976
|
+
* It converts AgentAction → GuardEvent, loads a world, and calls evaluateGuard().
|
|
1977
|
+
* That's it. Zero intelligence. Zero interpretation.
|
|
1978
|
+
*
|
|
1979
|
+
* Rule parsing belongs in `neuroverse add`. Evaluation belongs in guard-engine.ts.
|
|
1980
|
+
* This bridge just translates types and calls the real thing.
|
|
1981
|
+
*
|
|
1982
|
+
* Architecture:
|
|
1983
|
+
* [HTTP request] → govern(action, worldPath) → evaluateGuard(event, world) → GuardVerdict
|
|
1984
|
+
*/
|
|
1985
|
+
|
|
1986
|
+
/**
|
|
1987
|
+
* Convert an AgentAction (HTTP/demo format) → GuardEvent (engine format).
|
|
1988
|
+
* Pure mapping. No interpretation. No intelligence.
|
|
1989
|
+
*/
|
|
1990
|
+
declare function actionToGuardEvent(action: AgentAction): GuardEvent;
|
|
1991
|
+
/**
|
|
1992
|
+
* Evaluate a single action against a loaded world.
|
|
1993
|
+
*
|
|
1994
|
+
* This is the entire bridge. AgentAction in, GuardVerdict out.
|
|
1995
|
+
* Uses the same evaluateGuard() as `neuroverse guard`.
|
|
1996
|
+
*/
|
|
1997
|
+
declare function govern(action: AgentAction, world: WorldDefinition, options?: GuardEngineOptions): GuardVerdict;
|
|
1998
|
+
/**
|
|
1999
|
+
* A governor holds a loaded world and evaluates actions against it.
|
|
2000
|
+
* Used by the demo server to avoid re-loading the world on every request.
|
|
2001
|
+
*/
|
|
2002
|
+
interface Governor {
|
|
2003
|
+
/** Evaluate an action against the loaded world */
|
|
2004
|
+
evaluate(action: AgentAction): GuardVerdict;
|
|
2005
|
+
/** Reload the world from disk (call after rules change) */
|
|
2006
|
+
reload(): Promise<void>;
|
|
2007
|
+
/** The loaded world definition */
|
|
2008
|
+
readonly world: WorldDefinition;
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Create a governor instance that holds a loaded world.
|
|
2012
|
+
*
|
|
2013
|
+
* Usage:
|
|
2014
|
+
* const gov = await createGovernor({ worldPath: '/tmp/neuroverse-demo' });
|
|
2015
|
+
* const verdict = gov.evaluate(action);
|
|
2016
|
+
* // After rule changes:
|
|
2017
|
+
* await gov.reload();
|
|
2018
|
+
*/
|
|
2019
|
+
declare function createGovernor(config: GovernorConfig): Promise<Governor>;
|
|
2020
|
+
/**
|
|
2021
|
+
* Write a minimal world directory from plain-text rules.
|
|
2022
|
+
*
|
|
2023
|
+
* This is for the demo server: UI sends plain-text rules,
|
|
2024
|
+
* we write them as kernel forbidden_patterns, then load
|
|
2025
|
+
* the world through the normal loadWorld() path.
|
|
2026
|
+
*
|
|
2027
|
+
* NO interpretation. Each rule line becomes a kernel forbidden pattern.
|
|
2028
|
+
* The guard engine does the matching.
|
|
2029
|
+
*/
|
|
2030
|
+
declare function writeTempWorld(dir: string, policyLines: string[]): Promise<void>;
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Behavioral Contract — Types for the Behavioral Analysis Engine
|
|
2034
|
+
*
|
|
2035
|
+
* Extracted from behavioral-engine.ts so other modules (CLI, API, tests)
|
|
2036
|
+
* can depend on the contract without pulling in implementation.
|
|
2037
|
+
*
|
|
2038
|
+
* Types:
|
|
2039
|
+
* ActionCategory — Categories of agent actions for behavioral shift tracking
|
|
2040
|
+
* Adaptation — A classified behavioral adaptation (what an agent did instead)
|
|
2041
|
+
* BehavioralPattern — An emergent behavioral pattern detected across agents
|
|
2042
|
+
* NetworkContext — Network-level context for narrative generation
|
|
2043
|
+
*/
|
|
2044
|
+
|
|
2045
|
+
/** Categories of agent actions for behavioral shift tracking */
|
|
2046
|
+
type ActionCategory = 'amplifying' | 'passive' | 'engaging' | 'corrective' | 'transactional' | 'creative' | 'analytical' | 'unknown';
|
|
2047
|
+
/** A classified behavioral adaptation — what an agent did instead */
|
|
2048
|
+
interface Adaptation {
|
|
2049
|
+
/** Agent identifier */
|
|
2050
|
+
agentId: string;
|
|
2051
|
+
/** What the agent intended to do */
|
|
2052
|
+
intendedAction: string;
|
|
2053
|
+
/** What the agent actually did (after governance) */
|
|
2054
|
+
executedAction: string;
|
|
2055
|
+
/** Named behavioral shift category */
|
|
2056
|
+
shiftType: string;
|
|
2057
|
+
/** Governance status that caused the shift */
|
|
2058
|
+
verdict: GuardStatus;
|
|
2059
|
+
/** Rule that caused the shift */
|
|
2060
|
+
ruleId?: string;
|
|
2061
|
+
/** Human-readable reason */
|
|
2062
|
+
reason?: string;
|
|
2063
|
+
}
|
|
2064
|
+
/** An emergent behavioral pattern detected across multiple agents */
|
|
2065
|
+
interface BehavioralPattern {
|
|
2066
|
+
/** Pattern type identifier */
|
|
2067
|
+
type: string;
|
|
2068
|
+
/** Human-readable description */
|
|
2069
|
+
description: string;
|
|
2070
|
+
/** Pattern strength (0-1), based on fraction of agents affected */
|
|
2071
|
+
strength: number;
|
|
2072
|
+
/** Number of agents exhibiting this pattern */
|
|
2073
|
+
agentsAffected: number;
|
|
2074
|
+
}
|
|
2075
|
+
/** Network-level context for narrative generation */
|
|
2076
|
+
interface NetworkContext {
|
|
2077
|
+
mood?: string;
|
|
2078
|
+
misinfoLevel?: number;
|
|
2079
|
+
totalAgents?: number;
|
|
2080
|
+
totalActions?: number;
|
|
2081
|
+
[key: string]: unknown;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
/**
|
|
2085
|
+
* Behavioral Analysis Engine — What Governance UNLOCKS
|
|
2086
|
+
*
|
|
2087
|
+
* This is the differentiator. Every governance system can tell you
|
|
2088
|
+
* what it blocked. Only NeuroVerse tells you:
|
|
2089
|
+
* - What agents did INSTEAD (adaptation classification)
|
|
2090
|
+
* - What patterns emerged COLLECTIVELY (behavioral detection)
|
|
2091
|
+
* - WHY it matters IN PROSE (narrative generation)
|
|
2092
|
+
*
|
|
2093
|
+
* "Governance is the engine — but we also always want to show people
|
|
2094
|
+
* the knowledge that constraining unlocks."
|
|
2095
|
+
*
|
|
2096
|
+
* Architecture:
|
|
2097
|
+
* GuardVerdict[] → classifyAdaptation() → Adaptation[]
|
|
2098
|
+
* Adaptation[] → detectBehavioralPatterns() → BehavioralPattern[]
|
|
2099
|
+
* Pattern[] → generateAdaptationNarrative() → string
|
|
2100
|
+
*
|
|
2101
|
+
* Pure functions. No network. No LLM. Deterministic.
|
|
2102
|
+
*/
|
|
2103
|
+
|
|
2104
|
+
/**
|
|
2105
|
+
* Classify what behavioral shift governance caused for a single agent action.
|
|
2106
|
+
*
|
|
2107
|
+
* Takes the original intent and the actual execution, returns a named shift.
|
|
2108
|
+
* Pure function. No side effects.
|
|
2109
|
+
*/
|
|
2110
|
+
declare function classifyAdaptation(intendedAction: string, executedAction: string): string;
|
|
2111
|
+
/**
|
|
2112
|
+
* Build an Adaptation from a GuardVerdict with intent tracking.
|
|
2113
|
+
* Uses the IntentRecord attached to the verdict (if present).
|
|
2114
|
+
*/
|
|
2115
|
+
declare function adaptationFromVerdict(agentId: string, intendedAction: string, executedAction: string, verdict: GuardVerdict): Adaptation;
|
|
2116
|
+
/**
|
|
2117
|
+
* Detect emergent collective patterns from a batch of adaptations.
|
|
2118
|
+
*
|
|
2119
|
+
* This is NOT just counting. It detects:
|
|
2120
|
+
* - Coordinated silence (many agents forced idle)
|
|
2121
|
+
* - Misinformation suppression (amplification specifically blocked)
|
|
2122
|
+
* - Constructive redirection (agents shifted to positive actions)
|
|
2123
|
+
* - High governance impact (large fraction of agents affected)
|
|
2124
|
+
* - Trading halt (transactional agents stopped)
|
|
2125
|
+
*
|
|
2126
|
+
* Pure function. Deterministic. Same inputs → same patterns.
|
|
2127
|
+
*/
|
|
2128
|
+
declare function detectBehavioralPatterns(adaptations: Adaptation[], totalAgents: number): BehavioralPattern[];
|
|
2129
|
+
/**
|
|
2130
|
+
* Generate a human-readable cause-effect narrative from patterns.
|
|
2131
|
+
*
|
|
2132
|
+
* This is the "money moment" — the prose explanation of what governance
|
|
2133
|
+
* caused to happen. Not a log. Not a report. A story.
|
|
2134
|
+
*
|
|
2135
|
+
* "5 agents went silent instead of amplifying. 3 redirected to fact-checking.
|
|
2136
|
+
* Network mood: polarized, misinfo level: 45%"
|
|
2137
|
+
*/
|
|
2138
|
+
declare function generateAdaptationNarrative(patterns: BehavioralPattern[], context?: NetworkContext): string;
|
|
2139
|
+
|
|
2140
|
+
/**
|
|
2141
|
+
* API Handlers — Server-side request handlers for the demo server.
|
|
2142
|
+
*
|
|
2143
|
+
* These are pure functions that handle HTTP request bodies and return
|
|
2144
|
+
* response objects. No HTTP framework dependency — just data in, data out.
|
|
2145
|
+
*
|
|
2146
|
+
* The demo server (src/cli/demo.ts) wires these to routes.
|
|
2147
|
+
*/
|
|
2148
|
+
declare function handleHealthCheck(): {
|
|
2149
|
+
status: string;
|
|
2150
|
+
engine: string;
|
|
2151
|
+
version: string;
|
|
2152
|
+
capabilities: string[];
|
|
2153
|
+
};
|
|
2154
|
+
declare function handleListPresets(policiesDir?: string): Promise<{
|
|
2155
|
+
presets: Array<{
|
|
2156
|
+
id: string;
|
|
2157
|
+
name: string;
|
|
2158
|
+
description: string;
|
|
2159
|
+
rules: string;
|
|
2160
|
+
}>;
|
|
2161
|
+
}>;
|
|
2162
|
+
/**
|
|
2163
|
+
* Run governed reasoning on a scenario.
|
|
2164
|
+
* Takes a scenario description + world path, evaluates through the guard engine.
|
|
2165
|
+
*/
|
|
2166
|
+
declare function handleReasonRequest(body: {
|
|
2167
|
+
scenario?: string;
|
|
2168
|
+
worldPath?: string;
|
|
2169
|
+
intent?: string;
|
|
2170
|
+
tool?: string;
|
|
2171
|
+
roleId?: string;
|
|
2172
|
+
}): Promise<Record<string, unknown>>;
|
|
2173
|
+
/**
|
|
2174
|
+
* Create a shareable scenario capsule — a self-contained snapshot
|
|
2175
|
+
* of a governance scenario that can be shared or replayed.
|
|
2176
|
+
*/
|
|
2177
|
+
declare function handleCreateCapsule(body: {
|
|
2178
|
+
scenario?: string;
|
|
2179
|
+
rules?: string[];
|
|
2180
|
+
events?: Array<{
|
|
2181
|
+
intent: string;
|
|
2182
|
+
tool?: string;
|
|
2183
|
+
}>;
|
|
2184
|
+
}): {
|
|
2185
|
+
capsuleId: string;
|
|
2186
|
+
scenario: string;
|
|
2187
|
+
rules: string[];
|
|
2188
|
+
events: Array<{
|
|
2189
|
+
intent: string;
|
|
2190
|
+
tool?: string;
|
|
2191
|
+
}>;
|
|
2192
|
+
createdAt: string;
|
|
2193
|
+
};
|
|
2194
|
+
|
|
2195
|
+
export { type AIProvider, type AIProviderConfig, type ActionCategory, type Adaptation, type AddGuardInput, type AddInvariantInput, type AddResult, type AddRuleInput, AdvanceResult, type AgentAction, AgentBehaviorState, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BehavioralPattern, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, Consequence, ConsoleAuditLogger, type ConstructType, DERIVE_EXIT_CODES, type DecisionFlow, type DecisionFlowMetrics, type DeriveExitCode, type DeriveFinding, type DeriveResult, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FlowPath, type FormatVerdictOptions, type GovernanceEngineOptions, type GovernanceHealth, type Governor, type GovernorConfig, GuardEngineOptions, GuardEvent, GuardStatus, GuardVerdict, type ImpactReport, type ImprovementReport, type IntentCluster, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NetworkContext, type NormalizationSummary, type OutcomeCluster, PROVIDERS, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, PlanCheck, PlanDefinition, type PlanParseResult, PlanProgress, PlanVerdict, type PreventionCategory, type ProviderPreset, Reward, type RuleEvaluation, type RuleObstacle, type SessionConfig, SessionManager, type SessionState, type SimulateOptions, type SimulationResult, type SimulationStep, StepEvidence, type Suggestion, type SuggestionCategory, type SuggestionPriority, type ToolCall, type ToolDefinition, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, type ValidationMode, type WorldInfo, type WorldState, actionToGuardEvent, adaptationFromVerdict, addGuard, addInvariant, addRule, advancePlan, applyConsequence, applyReward, buildPlanCheck, classifyAdaptation, classifyIntent, createAgentState, createGovernanceEngine, createGovernor, deriveWorld, describeActiveWorld, detectBehavioralPatterns, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluatePlan, eventToAllowlistKey, explainWorld, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateAdaptationNarrative, generateDecisionFlow, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, govern, handleCreateCapsule, handleHealthCheck, handleListPresets, handleReasonRequest, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseGuardDescription, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderDecisionFlow, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, tickAgentStates, validateWorld, verdictToAuditEvent, writeTempWorld };
|