@neuroverseos/governance 0.3.0 → 0.3.1
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/README.md +20 -0
- package/package.json +16 -3
- package/policies/content-moderation-rules.txt +8 -0
- package/policies/marketing-rules.txt +8 -0
- package/policies/science-research-rules.txt +11 -0
- package/policies/social-media-rules.txt +7 -0
- package/policies/strict-rules.txt +8 -0
- package/policies/trading-rules.txt +8 -0
- package/simulate.html +1899 -0
- package/dist/adapters/autoresearch.cjs +0 -196
- package/dist/adapters/autoresearch.d.cts +0 -103
- package/dist/adapters/autoresearch.d.ts +0 -103
- package/dist/adapters/autoresearch.js +0 -7
- package/dist/adapters/express.cjs +0 -1114
- package/dist/adapters/express.d.cts +0 -66
- package/dist/adapters/express.d.ts +0 -66
- package/dist/adapters/express.js +0 -12
- package/dist/adapters/index.cjs +0 -1669
- package/dist/adapters/index.d.cts +0 -6
- package/dist/adapters/index.d.ts +0 -6
- package/dist/adapters/index.js +0 -46
- package/dist/adapters/langchain.cjs +0 -1155
- package/dist/adapters/langchain.d.cts +0 -89
- package/dist/adapters/langchain.d.ts +0 -89
- package/dist/adapters/langchain.js +0 -16
- package/dist/adapters/openai.cjs +0 -1185
- package/dist/adapters/openai.d.cts +0 -99
- package/dist/adapters/openai.d.ts +0 -99
- package/dist/adapters/openai.js +0 -16
- package/dist/adapters/openclaw.cjs +0 -1177
- package/dist/adapters/openclaw.d.cts +0 -99
- package/dist/adapters/openclaw.d.ts +0 -99
- package/dist/adapters/openclaw.js +0 -16
- package/dist/bootstrap-GXVDZNF7.js +0 -114
- package/dist/build-P42YFKQV.js +0 -339
- package/dist/chunk-2NICNKOM.js +0 -100
- package/dist/chunk-2PQU3VAN.js +0 -131
- package/dist/chunk-4A7LISES.js +0 -324
- package/dist/chunk-4JRYGIO7.js +0 -727
- package/dist/chunk-4NGDRRQH.js +0 -10
- package/dist/chunk-4QXB6PEO.js +0 -232
- package/dist/chunk-6CZSKEY5.js +0 -164
- package/dist/chunk-7P3S7MAY.js +0 -1090
- package/dist/chunk-A5W4GNQO.js +0 -130
- package/dist/chunk-AKW5YVCE.js +0 -96
- package/dist/chunk-BUWWN2NX.js +0 -192
- package/dist/chunk-COT5XS4V.js +0 -109
- package/dist/chunk-ER62HNGF.js +0 -139
- package/dist/chunk-FYS2CBUW.js +0 -304
- package/dist/chunk-GR6DGCZ2.js +0 -340
- package/dist/chunk-I3RRAYK2.js +0 -11
- package/dist/chunk-JZPQGIKR.js +0 -79
- package/dist/chunk-MWDQ4MJB.js +0 -11
- package/dist/chunk-NF5POFCI.js +0 -622
- package/dist/chunk-OGL7QXZS.js +0 -608
- package/dist/chunk-OT6PXH54.js +0 -61
- package/dist/chunk-PDOZHZWL.js +0 -225
- package/dist/chunk-Q6O7ZLO2.js +0 -62
- package/dist/chunk-QPASI2BR.js +0 -187
- package/dist/chunk-T5EUJQE5.js +0 -172
- package/dist/chunk-XPDMYECO.js +0 -642
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/cli/neuroverse.cjs +0 -11448
- package/dist/cli/neuroverse.d.cts +0 -1
- package/dist/cli/neuroverse.d.ts +0 -1
- package/dist/cli/neuroverse.js +0 -196
- package/dist/cli/plan.cjs +0 -1599
- package/dist/cli/plan.d.cts +0 -20
- package/dist/cli/plan.d.ts +0 -20
- package/dist/cli/plan.js +0 -361
- package/dist/cli/run.cjs +0 -1746
- package/dist/cli/run.d.cts +0 -20
- package/dist/cli/run.d.ts +0 -20
- package/dist/cli/run.js +0 -143
- package/dist/configure-ai-TK67ZWZL.js +0 -132
- package/dist/derive-TLIV4OOU.js +0 -152
- package/dist/doctor-XPDLEYXN.js +0 -171
- package/dist/explain-IDCRWMPX.js +0 -70
- package/dist/guard-RV65TT4L.js +0 -96
- package/dist/guard-contract-WZx__PmU.d.cts +0 -709
- package/dist/guard-contract-WZx__PmU.d.ts +0 -709
- package/dist/guard-engine-JLTUARGU.js +0 -10
- package/dist/impact-XPECYRLH.js +0 -59
- package/dist/improve-GPUBKTEA.js +0 -85
- package/dist/index.cjs +0 -6273
- package/dist/index.d.cts +0 -1616
- package/dist/index.d.ts +0 -1616
- package/dist/index.js +0 -379
- package/dist/infer-world-7GVZWFX4.js +0 -543
- package/dist/init-PKPIYHYE.js +0 -144
- package/dist/init-world-VWMQZQC7.js +0 -223
- package/dist/mcp-server-FPVSU32Z.js +0 -13
- package/dist/model-adapter-BB7G4MFI.js +0 -11
- package/dist/playground-E664U4T6.js +0 -550
- package/dist/redteam-Z7WREJ44.js +0 -357
- package/dist/session-EKTRSR7C.js +0 -14
- package/dist/simulate-VDOYQFRO.js +0 -108
- package/dist/test-OGXJK4QU.js +0 -217
- package/dist/trace-JVF67VR3.js +0 -166
- package/dist/validate-LLBWVPGV.js +0 -81
- package/dist/validate-engine-UIABSIHD.js +0 -7
- package/dist/world-LAXO6DOX.js +0 -378
- package/dist/world-loader-HMPTOEA2.js +0 -9
- package/dist/worlds/autoresearch.nv-world.md +0 -230
- package/dist/worlds/derivation-world.nv-world.md +0 -278
package/dist/index.d.ts
DELETED
|
@@ -1,1616 +0,0 @@
|
|
|
1
|
-
import { G as GuardEvent, W as WorldDefinition, c as GuardEngineOptions, a as GuardVerdict, P as PlanDefinition, S as StepEvidence, A as AdvanceResult, d as PlanVerdict, e as PlanCheck, b as PlanProgress, V as ViabilityStatus } from './guard-contract-WZx__PmU.js';
|
|
2
|
-
export { E as EvaluationTrace, f as GUARD_EXIT_CODES, g as GuardCheck, h as GuardExitCode, i as GuardStatus, I as InvariantCheck, K as KernelRuleCheck, L as LevelCheck, j as PLAN_EXIT_CODES, k as PlanCompletionMode, l as PlanConstraint, m as PlanExitCode, n as PlanStatus, o as PlanStep, p as PrecedenceResolution, R as RoleCheck, q as SafetyCheck, r as VerdictEvidence } from './guard-contract-WZx__PmU.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
|
-
/**
|
|
32
|
-
* Evaluate a guard event against a world definition.
|
|
33
|
-
*
|
|
34
|
-
* This is the entire guard engine. One function. Deterministic.
|
|
35
|
-
* No class instantiation, no state, no side effects.
|
|
36
|
-
*/
|
|
37
|
-
declare function evaluateGuard(event: GuardEvent, world: WorldDefinition, options?: GuardEngineOptions): GuardVerdict;
|
|
38
|
-
/**
|
|
39
|
-
* Build a normalized allowlist key from a GuardEvent.
|
|
40
|
-
*
|
|
41
|
-
* Format: `tool::intent` (both lowercased, intent trimmed).
|
|
42
|
-
* Tool defaults to '*' when absent.
|
|
43
|
-
*
|
|
44
|
-
* Callers use this to:
|
|
45
|
-
* 1. Add keys to the allowlist set (on user "allow-always" decision)
|
|
46
|
-
* 2. The engine uses it to check membership before evaluation
|
|
47
|
-
*
|
|
48
|
-
* The key is opaque — callers should always use this function
|
|
49
|
-
* rather than constructing keys manually.
|
|
50
|
-
*/
|
|
51
|
-
declare function eventToAllowlistKey(event: GuardEvent): string;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Plan Parser — Deterministic Markdown-to-PlanDefinition Parser
|
|
55
|
-
*
|
|
56
|
-
* Parses a simple markdown format into a PlanDefinition.
|
|
57
|
-
* No AI needed. This is pure parsing like bootstrap-parser.
|
|
58
|
-
*
|
|
59
|
-
* Supported syntax:
|
|
60
|
-
* - YAML frontmatter: plan_id, objective, sequential, completion, budget, expires, world
|
|
61
|
-
* - # Steps section: each `- ` line becomes a PlanStep
|
|
62
|
-
* - # Constraints section: each `- ` line becomes a PlanConstraint
|
|
63
|
-
* - Step dependencies: (after: step_id)
|
|
64
|
-
* - Tool restrictions: [tools: http, shell]
|
|
65
|
-
* - Tags: [tag: deploy, marketing]
|
|
66
|
-
* - Verification: [verify: condition_name]
|
|
67
|
-
* - Approval constraints: [type: approval]
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
interface PlanParseResult {
|
|
71
|
-
success: boolean;
|
|
72
|
-
plan?: PlanDefinition;
|
|
73
|
-
errors: string[];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Parse a plan markdown string into a PlanDefinition.
|
|
77
|
-
*
|
|
78
|
-
* Format:
|
|
79
|
-
* ```markdown
|
|
80
|
-
* ---
|
|
81
|
-
* plan_id: my_plan
|
|
82
|
-
* objective: Do the thing
|
|
83
|
-
* sequential: false
|
|
84
|
-
* ---
|
|
85
|
-
*
|
|
86
|
-
* # Steps
|
|
87
|
-
* - Step one [tag: deploy]
|
|
88
|
-
* - Step two (after: step_one) [verify: check_name]
|
|
89
|
-
*
|
|
90
|
-
* # Constraints
|
|
91
|
-
* - No spending above $500
|
|
92
|
-
* - External comms require review [type: approval]
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
declare function parsePlanMarkdown(markdown: string): PlanParseResult;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Plan Engine — Deterministic Plan Enforcement Evaluator
|
|
99
|
-
*
|
|
100
|
-
* Pure function: (event, plan) → PlanVerdict
|
|
101
|
-
*
|
|
102
|
-
* Evaluates a GuardEvent against a PlanDefinition to determine
|
|
103
|
-
* whether the action is on-plan, off-plan, or violates constraints.
|
|
104
|
-
*
|
|
105
|
-
* Uses two-tier matching:
|
|
106
|
-
* Tier 1: Keyword + tag matching (fast, deterministic)
|
|
107
|
-
* Tier 2: Intent similarity scoring (precomputed vectors, no LLM)
|
|
108
|
-
*
|
|
109
|
-
* INVARIANTS:
|
|
110
|
-
* - Deterministic: same event + same plan → same verdict.
|
|
111
|
-
* - No LLM calls. No network calls.
|
|
112
|
-
* - Plans can only restrict, never expand.
|
|
113
|
-
* - OFF_PLAN always includes closest step for self-correction.
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Get the current progress of a plan.
|
|
118
|
-
*/
|
|
119
|
-
declare function getPlanProgress(plan: PlanDefinition): PlanProgress;
|
|
120
|
-
/**
|
|
121
|
-
* Mark a step as completed and return a new plan.
|
|
122
|
-
* Does not mutate the original plan.
|
|
123
|
-
*
|
|
124
|
-
* Behavior depends on the plan's completion mode:
|
|
125
|
-
*
|
|
126
|
-
* completion: 'trust' (default)
|
|
127
|
-
* Caller says "done", step advances. No evidence needed.
|
|
128
|
-
*
|
|
129
|
-
* completion: 'verified'
|
|
130
|
-
* Steps with a `verify` field require evidence to advance.
|
|
131
|
-
* The evidence type must match the step's verify field.
|
|
132
|
-
* Steps without `verify` still advance on trust.
|
|
133
|
-
*
|
|
134
|
-
* @param plan - The current plan (not mutated)
|
|
135
|
-
* @param stepId - Which step to advance
|
|
136
|
-
* @param evidence - Proof of completion (required in verified mode for steps with verify)
|
|
137
|
-
* @returns AdvanceResult with success flag and updated plan or reason
|
|
138
|
-
*/
|
|
139
|
-
declare function advancePlan(plan: PlanDefinition, stepId: string, evidence?: StepEvidence): AdvanceResult;
|
|
140
|
-
/**
|
|
141
|
-
* Evaluate an event against a plan.
|
|
142
|
-
*
|
|
143
|
-
* Returns a PlanVerdict indicating whether the action is on-plan,
|
|
144
|
-
* off-plan, violates constraints, or the plan is complete.
|
|
145
|
-
*/
|
|
146
|
-
declare function evaluatePlan(event: GuardEvent, plan: PlanDefinition): PlanVerdict;
|
|
147
|
-
/**
|
|
148
|
-
* Build a PlanCheck for inclusion in the guard engine's EvaluationTrace.
|
|
149
|
-
*/
|
|
150
|
-
declare function buildPlanCheck(event: GuardEvent, plan: PlanDefinition, verdict: PlanVerdict): PlanCheck;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Model Adapter — Minimal LLM Connection Layer
|
|
154
|
-
*
|
|
155
|
-
* Connects to any OpenAI-compatible API (OpenAI, Anthropic, Ollama, etc.)
|
|
156
|
-
* using Node's built-in fetch. Zero dependencies.
|
|
157
|
-
*
|
|
158
|
-
* The adapter does exactly two things:
|
|
159
|
-
* 1. Send messages to the model
|
|
160
|
-
* 2. Receive responses (text + tool calls)
|
|
161
|
-
*
|
|
162
|
-
* No orchestration, no memory management, no retries.
|
|
163
|
-
* The session manager handles all of that.
|
|
164
|
-
*/
|
|
165
|
-
interface ModelConfig {
|
|
166
|
-
/** API base URL (e.g., "https://api.openai.com/v1") */
|
|
167
|
-
baseUrl: string;
|
|
168
|
-
/** API key for authentication */
|
|
169
|
-
apiKey: string;
|
|
170
|
-
/** Model identifier (e.g., "gpt-4o", "claude-sonnet-4-20250514") */
|
|
171
|
-
model: string;
|
|
172
|
-
/** System prompt prepended to all conversations */
|
|
173
|
-
systemPrompt?: string;
|
|
174
|
-
/** Max tokens for response. Default: 4096. */
|
|
175
|
-
maxTokens?: number;
|
|
176
|
-
}
|
|
177
|
-
interface ToolDefinition {
|
|
178
|
-
type: 'function';
|
|
179
|
-
function: {
|
|
180
|
-
name: string;
|
|
181
|
-
description: string;
|
|
182
|
-
parameters: Record<string, unknown>;
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
interface ChatMessage {
|
|
186
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
187
|
-
content: string | null;
|
|
188
|
-
tool_calls?: ToolCall[];
|
|
189
|
-
tool_call_id?: string;
|
|
190
|
-
}
|
|
191
|
-
interface ToolCall {
|
|
192
|
-
id: string;
|
|
193
|
-
type: 'function';
|
|
194
|
-
function: {
|
|
195
|
-
name: string;
|
|
196
|
-
arguments: string;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
interface ModelResponse {
|
|
200
|
-
content: string | null;
|
|
201
|
-
toolCalls: ToolCall[];
|
|
202
|
-
finishReason: string;
|
|
203
|
-
}
|
|
204
|
-
declare class ModelAdapter {
|
|
205
|
-
private config;
|
|
206
|
-
private messages;
|
|
207
|
-
private tools;
|
|
208
|
-
constructor(config: ModelConfig, tools?: ToolDefinition[]);
|
|
209
|
-
/**
|
|
210
|
-
* Send a user message and get the model's response.
|
|
211
|
-
*/
|
|
212
|
-
chat(userMessage: string): Promise<ModelResponse>;
|
|
213
|
-
/**
|
|
214
|
-
* Send a tool result back to the model and get the next response.
|
|
215
|
-
*/
|
|
216
|
-
sendToolResult(toolCallId: string, result: string): Promise<ModelResponse>;
|
|
217
|
-
/**
|
|
218
|
-
* Send a governance block message as a tool result.
|
|
219
|
-
*/
|
|
220
|
-
sendBlockedResult(toolCallId: string, reason: string): Promise<ModelResponse>;
|
|
221
|
-
/**
|
|
222
|
-
* Call the model API and parse the response.
|
|
223
|
-
*/
|
|
224
|
-
private complete;
|
|
225
|
-
/** Get current message count (for context tracking). */
|
|
226
|
-
get messageCount(): number;
|
|
227
|
-
}
|
|
228
|
-
interface ProviderPreset {
|
|
229
|
-
baseUrl: string;
|
|
230
|
-
defaultModel: string;
|
|
231
|
-
envVar: string;
|
|
232
|
-
}
|
|
233
|
-
declare const PROVIDERS: Record<string, ProviderPreset>;
|
|
234
|
-
/**
|
|
235
|
-
* Resolve a provider name to a ModelConfig.
|
|
236
|
-
* Reads API key from environment variable.
|
|
237
|
-
*/
|
|
238
|
-
declare function resolveProvider(provider: string, overrides?: Partial<ModelConfig>): ModelConfig;
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Session Manager — Governed Runtime Session
|
|
242
|
-
*
|
|
243
|
-
* Orchestrates a governed AI session:
|
|
244
|
-
* 1. Load world + plan
|
|
245
|
-
* 2. Connect to model
|
|
246
|
-
* 3. Intercept tool calls
|
|
247
|
-
* 4. Evaluate with guard engine
|
|
248
|
-
* 5. Execute or block
|
|
249
|
-
* 6. Track plan progress
|
|
250
|
-
*
|
|
251
|
-
* The session manager is thin orchestration, not a framework.
|
|
252
|
-
* All intelligence lives in the guard engine and plan engine.
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
interface SessionConfig {
|
|
256
|
-
/** Path to world directory. */
|
|
257
|
-
worldPath?: string;
|
|
258
|
-
/** Pre-loaded world definition (alternative to worldPath). */
|
|
259
|
-
world?: WorldDefinition;
|
|
260
|
-
/** Plan definition (pre-loaded). */
|
|
261
|
-
plan?: PlanDefinition;
|
|
262
|
-
/** Enforcement level override. */
|
|
263
|
-
level?: 'basic' | 'standard' | 'strict';
|
|
264
|
-
/** Include trace in verdicts. */
|
|
265
|
-
trace?: boolean;
|
|
266
|
-
/** Called when a verdict is produced. */
|
|
267
|
-
onVerdict?: (verdict: GuardVerdict, event: GuardEvent) => void;
|
|
268
|
-
/** Called when plan progress changes. */
|
|
269
|
-
onPlanProgress?: (progress: PlanProgress) => void;
|
|
270
|
-
/** Called when the plan is complete. */
|
|
271
|
-
onPlanComplete?: () => void;
|
|
272
|
-
/** Called when a tool is executed successfully. */
|
|
273
|
-
onToolResult?: (toolName: string, result: string) => void;
|
|
274
|
-
/** Tool executor — runs the actual tool. */
|
|
275
|
-
toolExecutor?: (name: string, args: Record<string, unknown>) => Promise<string>;
|
|
276
|
-
}
|
|
277
|
-
interface SessionState {
|
|
278
|
-
/** Whether the session is active. */
|
|
279
|
-
active: boolean;
|
|
280
|
-
/** Loaded world. */
|
|
281
|
-
world: WorldDefinition;
|
|
282
|
-
/** Active plan (mutable as steps complete). */
|
|
283
|
-
plan?: PlanDefinition;
|
|
284
|
-
/** Current plan progress. */
|
|
285
|
-
progress?: PlanProgress;
|
|
286
|
-
/** Total actions evaluated. */
|
|
287
|
-
actionsEvaluated: number;
|
|
288
|
-
/** Total actions allowed. */
|
|
289
|
-
actionsAllowed: number;
|
|
290
|
-
/** Total actions blocked. */
|
|
291
|
-
actionsBlocked: number;
|
|
292
|
-
/** Total actions paused. */
|
|
293
|
-
actionsPaused: number;
|
|
294
|
-
}
|
|
295
|
-
declare class SessionManager {
|
|
296
|
-
private config;
|
|
297
|
-
private state;
|
|
298
|
-
private engineOptions;
|
|
299
|
-
private executor;
|
|
300
|
-
constructor(config: SessionConfig);
|
|
301
|
-
/**
|
|
302
|
-
* Initialize the session — load world from disk if needed.
|
|
303
|
-
*/
|
|
304
|
-
start(): Promise<SessionState>;
|
|
305
|
-
/**
|
|
306
|
-
* Evaluate a single event against governance.
|
|
307
|
-
* Returns the verdict without executing anything.
|
|
308
|
-
*/
|
|
309
|
-
evaluate(event: GuardEvent): GuardVerdict;
|
|
310
|
-
/**
|
|
311
|
-
* Evaluate and execute a tool call.
|
|
312
|
-
* Returns the execution result or block reason.
|
|
313
|
-
*/
|
|
314
|
-
executeToolCall(toolCall: ToolCall): Promise<{
|
|
315
|
-
allowed: boolean;
|
|
316
|
-
verdict: GuardVerdict;
|
|
317
|
-
result?: string;
|
|
318
|
-
}>;
|
|
319
|
-
/**
|
|
320
|
-
* Process a model response — evaluate and execute all tool calls.
|
|
321
|
-
* Returns results for each tool call.
|
|
322
|
-
*/
|
|
323
|
-
processModelResponse(response: ModelResponse, model: ModelAdapter): Promise<ModelResponse>;
|
|
324
|
-
/** Get current session state. */
|
|
325
|
-
getState(): SessionState;
|
|
326
|
-
/** Stop the session. */
|
|
327
|
-
stop(): SessionState;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Run in pipe mode — read JSON lines from stdin, evaluate each,
|
|
331
|
-
* write verdicts to stdout. Works with any language or framework.
|
|
332
|
-
*
|
|
333
|
-
* Usage:
|
|
334
|
-
* my_agent | neuroverse run --pipe --world ./world/ --plan plan.json
|
|
335
|
-
*
|
|
336
|
-
* Each line of stdin should be a GuardEvent JSON.
|
|
337
|
-
* Each line of stdout will be a GuardVerdict JSON.
|
|
338
|
-
*/
|
|
339
|
-
declare function runPipeMode(config: SessionConfig): Promise<void>;
|
|
340
|
-
/**
|
|
341
|
-
* Run an interactive governed chat session.
|
|
342
|
-
*
|
|
343
|
-
* Usage:
|
|
344
|
-
* neuroverse run --world ./world/ --plan plan.json --provider openai
|
|
345
|
-
*/
|
|
346
|
-
declare function runInteractiveMode(config: SessionConfig, model: ModelAdapter): Promise<void>;
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* NeuroVerse MCP Server — Governance as an MCP Tool Provider
|
|
350
|
-
*
|
|
351
|
-
* Implements the Model Context Protocol (MCP) over stdio.
|
|
352
|
-
* Any MCP-compatible client (Claude Desktop, Cursor, etc.) can
|
|
353
|
-
* connect to this server and get governed tool access.
|
|
354
|
-
*
|
|
355
|
-
* Architecture:
|
|
356
|
-
* MCP Client (Claude, Cursor, etc.)
|
|
357
|
-
* ↓ stdio (JSON-RPC)
|
|
358
|
-
* NeuroVerse MCP Server
|
|
359
|
-
* ↓ evaluateGuard()
|
|
360
|
-
* Tool Execution (shell, http, file, etc.)
|
|
361
|
-
*
|
|
362
|
-
* The server exposes governance-wrapped tools. Every tool call
|
|
363
|
-
* passes through the guard engine before execution. Blocked
|
|
364
|
-
* actions return the governance reason to the model.
|
|
365
|
-
*
|
|
366
|
-
* MCP Protocol: JSON-RPC 2.0 over stdio
|
|
367
|
-
* - initialize → capabilities
|
|
368
|
-
* - tools/list → available tools
|
|
369
|
-
* - tools/call → evaluate + execute
|
|
370
|
-
*/
|
|
371
|
-
|
|
372
|
-
interface McpServerConfig {
|
|
373
|
-
/** Path to world directory. */
|
|
374
|
-
worldPath?: string;
|
|
375
|
-
/** Pre-loaded world. */
|
|
376
|
-
world?: WorldDefinition;
|
|
377
|
-
/** Active plan. */
|
|
378
|
-
plan?: PlanDefinition;
|
|
379
|
-
/** Path to plan.json (loaded on start). */
|
|
380
|
-
planPath?: string;
|
|
381
|
-
/** Enforcement level. */
|
|
382
|
-
level?: 'basic' | 'standard' | 'strict';
|
|
383
|
-
/** Include trace in verdicts. */
|
|
384
|
-
trace?: boolean;
|
|
385
|
-
/** Enable shell tool. Default: true. */
|
|
386
|
-
enableShell?: boolean;
|
|
387
|
-
/** Enable file tools. Default: true. */
|
|
388
|
-
enableFiles?: boolean;
|
|
389
|
-
/** Enable HTTP tool. Default: true. */
|
|
390
|
-
enableHttp?: boolean;
|
|
391
|
-
/** Working directory for file/shell operations. */
|
|
392
|
-
workingDir?: string;
|
|
393
|
-
}
|
|
394
|
-
declare class McpGovernanceServer {
|
|
395
|
-
private world;
|
|
396
|
-
private plan?;
|
|
397
|
-
private config;
|
|
398
|
-
private engineOptions;
|
|
399
|
-
private initialized;
|
|
400
|
-
private actionsEvaluated;
|
|
401
|
-
private actionsAllowed;
|
|
402
|
-
private actionsBlocked;
|
|
403
|
-
constructor(config: McpServerConfig);
|
|
404
|
-
/**
|
|
405
|
-
* Start the MCP server — reads JSON-RPC from stdin, writes to stdout.
|
|
406
|
-
*/
|
|
407
|
-
start(): Promise<void>;
|
|
408
|
-
private handleRawLine;
|
|
409
|
-
private send;
|
|
410
|
-
private sendResult;
|
|
411
|
-
private sendError;
|
|
412
|
-
private handleRequest;
|
|
413
|
-
private handleNotification;
|
|
414
|
-
private handleInitialize;
|
|
415
|
-
private handleToolsList;
|
|
416
|
-
private handleToolsCall;
|
|
417
|
-
private executeTool;
|
|
418
|
-
private buildEvent;
|
|
419
|
-
private executeActualTool;
|
|
420
|
-
private toolGovernanceCheck;
|
|
421
|
-
private toolPlanStatus;
|
|
422
|
-
private toolPlanAdvance;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Audit Logger — Runtime Governance Telemetry
|
|
427
|
-
*
|
|
428
|
-
* Records every action evaluated by the governance engine.
|
|
429
|
-
* Provides the governance paper trail: what happened, why, and when.
|
|
430
|
-
*
|
|
431
|
-
* Architecture:
|
|
432
|
-
* - AuditEvent is the atomic record (one per evaluateGuard call)
|
|
433
|
-
* - AuditLogger is the pluggable interface (file, database, stream)
|
|
434
|
-
* - FileAuditLogger is the built-in file-based implementation
|
|
435
|
-
* - createGovernanceEngine wraps evaluateGuard with automatic logging
|
|
436
|
-
*
|
|
437
|
-
* INVARIANTS:
|
|
438
|
-
* - Logging never blocks or fails the governance decision
|
|
439
|
-
* - Every AuditEvent includes the full verdict + evidence
|
|
440
|
-
* - Events are append-only (immutable log)
|
|
441
|
-
*/
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* A single governance evaluation record.
|
|
445
|
-
* One of these is produced for every call to evaluateGuard.
|
|
446
|
-
*/
|
|
447
|
-
interface AuditEvent {
|
|
448
|
-
/** ISO 8601 timestamp */
|
|
449
|
-
timestamp: string;
|
|
450
|
-
/** World identity */
|
|
451
|
-
worldId: string;
|
|
452
|
-
worldName: string;
|
|
453
|
-
worldVersion: string;
|
|
454
|
-
/** The action that was evaluated */
|
|
455
|
-
intent: string;
|
|
456
|
-
tool?: string;
|
|
457
|
-
scope?: string;
|
|
458
|
-
actor?: string;
|
|
459
|
-
direction?: 'input' | 'output';
|
|
460
|
-
/** The governance decision */
|
|
461
|
-
decision: 'ALLOW' | 'BLOCK' | 'PAUSE';
|
|
462
|
-
reason?: string;
|
|
463
|
-
ruleId?: string;
|
|
464
|
-
warning?: string;
|
|
465
|
-
/** Which rules/guards matched */
|
|
466
|
-
guardsMatched: string[];
|
|
467
|
-
rulesMatched: string[];
|
|
468
|
-
/** Invariant health */
|
|
469
|
-
invariantsSatisfied: number;
|
|
470
|
-
invariantsTotal: number;
|
|
471
|
-
/** Enforcement level used */
|
|
472
|
-
enforcementLevel: string;
|
|
473
|
-
/** Evaluation duration in milliseconds (if trace was enabled) */
|
|
474
|
-
durationMs?: number;
|
|
475
|
-
/** Full event args (optional, for detailed audit) */
|
|
476
|
-
args?: Record<string, unknown>;
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Summary of governance activity over a set of audit events.
|
|
480
|
-
*/
|
|
481
|
-
interface AuditSummary {
|
|
482
|
-
totalActions: number;
|
|
483
|
-
allowed: number;
|
|
484
|
-
blocked: number;
|
|
485
|
-
paused: number;
|
|
486
|
-
/** Unique actors seen */
|
|
487
|
-
actors: string[];
|
|
488
|
-
/** Actions grouped by intent */
|
|
489
|
-
topIntents: {
|
|
490
|
-
intent: string;
|
|
491
|
-
count: number;
|
|
492
|
-
blocked: number;
|
|
493
|
-
paused: number;
|
|
494
|
-
}[];
|
|
495
|
-
/** Most frequently triggered rules */
|
|
496
|
-
topRules: {
|
|
497
|
-
ruleId: string;
|
|
498
|
-
count: number;
|
|
499
|
-
}[];
|
|
500
|
-
/** Time range */
|
|
501
|
-
firstEvent: string;
|
|
502
|
-
lastEvent: string;
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Pluggable audit logger interface.
|
|
506
|
-
* Implement this to send audit events to any destination.
|
|
507
|
-
*/
|
|
508
|
-
interface AuditLogger {
|
|
509
|
-
/** Append an audit event. Must not throw. */
|
|
510
|
-
log(event: AuditEvent): void | Promise<void>;
|
|
511
|
-
/** Flush any buffered events. */
|
|
512
|
-
flush?(): void | Promise<void>;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Append-only file logger using newline-delimited JSON (NDJSON).
|
|
516
|
-
* Each line is a self-contained JSON audit event.
|
|
517
|
-
*
|
|
518
|
-
* Log file location defaults to .neuroverse/audit.ndjson
|
|
519
|
-
*/
|
|
520
|
-
declare class FileAuditLogger implements AuditLogger {
|
|
521
|
-
private logPath;
|
|
522
|
-
private buffer;
|
|
523
|
-
private flushTimer;
|
|
524
|
-
private flushIntervalMs;
|
|
525
|
-
constructor(logPath: string, options?: {
|
|
526
|
-
flushIntervalMs?: number;
|
|
527
|
-
});
|
|
528
|
-
log(event: AuditEvent): void;
|
|
529
|
-
flush(): Promise<void>;
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Simple logger that writes to stderr. Useful for development.
|
|
533
|
-
*/
|
|
534
|
-
declare class ConsoleAuditLogger implements AuditLogger {
|
|
535
|
-
log(event: AuditEvent): void;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Sends events to multiple loggers. Useful for file + console, file + webhook, etc.
|
|
539
|
-
*/
|
|
540
|
-
declare class CompositeAuditLogger implements AuditLogger {
|
|
541
|
-
private loggers;
|
|
542
|
-
constructor(...loggers: AuditLogger[]);
|
|
543
|
-
log(event: AuditEvent): void;
|
|
544
|
-
flush(): Promise<void>;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Convert a GuardEvent + GuardVerdict into an AuditEvent.
|
|
548
|
-
*/
|
|
549
|
-
declare function verdictToAuditEvent(event: GuardEvent, verdict: GuardVerdict): AuditEvent;
|
|
550
|
-
interface GovernanceEngineOptions extends GuardEngineOptions {
|
|
551
|
-
/** Audit logger instance. If provided, every evaluation is logged. */
|
|
552
|
-
auditLogger?: AuditLogger;
|
|
553
|
-
/** Include args in audit events. Default: false (privacy). */
|
|
554
|
-
auditArgs?: boolean;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Create a governed evaluation function that wraps evaluateGuard
|
|
558
|
-
* with automatic audit logging.
|
|
559
|
-
*
|
|
560
|
-
* Usage:
|
|
561
|
-
* const engine = createGovernanceEngine(world, {
|
|
562
|
-
* auditLogger: new FileAuditLogger('.neuroverse/audit.ndjson'),
|
|
563
|
-
* });
|
|
564
|
-
*
|
|
565
|
-
* const verdict = engine.evaluate(event);
|
|
566
|
-
*/
|
|
567
|
-
declare function createGovernanceEngine(world: WorldDefinition, options?: GovernanceEngineOptions): {
|
|
568
|
-
/**
|
|
569
|
-
* Evaluate a governance event and log the result.
|
|
570
|
-
*/
|
|
571
|
-
evaluate(event: GuardEvent): GuardVerdict;
|
|
572
|
-
/** Flush the audit logger. */
|
|
573
|
-
flush(): Promise<void>;
|
|
574
|
-
/** The underlying world definition. */
|
|
575
|
-
world: WorldDefinition;
|
|
576
|
-
};
|
|
577
|
-
/**
|
|
578
|
-
* Read audit events from an NDJSON log file.
|
|
579
|
-
*
|
|
580
|
-
* @param logPath - Path to the audit log file
|
|
581
|
-
* @param filter - Optional filter function
|
|
582
|
-
* @returns Array of matching audit events
|
|
583
|
-
*/
|
|
584
|
-
declare function readAuditLog(logPath: string, filter?: (event: AuditEvent) => boolean): Promise<AuditEvent[]>;
|
|
585
|
-
/**
|
|
586
|
-
* Summarize a set of audit events.
|
|
587
|
-
*/
|
|
588
|
-
declare function summarizeAuditEvents(events: AuditEvent[]): AuditSummary;
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Verdict Formatter — Human-Readable Verdict Output
|
|
592
|
-
*
|
|
593
|
-
* Converts a GuardVerdict into a consistent, human-readable string.
|
|
594
|
-
* Used by adapters, CLIs, and UIs to display governance decisions.
|
|
595
|
-
*
|
|
596
|
-
* Design:
|
|
597
|
-
* - One function, one concern: verdict → string
|
|
598
|
-
* - No side effects, no I/O
|
|
599
|
-
* - Adapters call this so every integration has consistent messaging
|
|
600
|
-
*/
|
|
601
|
-
|
|
602
|
-
interface FormatVerdictOptions {
|
|
603
|
-
/** Include rule/guard ID. Default: true. */
|
|
604
|
-
showRuleId?: boolean;
|
|
605
|
-
/** Include evidence summary. Default: false. */
|
|
606
|
-
showEvidence?: boolean;
|
|
607
|
-
/** Include warning if present. Default: true. */
|
|
608
|
-
showWarning?: boolean;
|
|
609
|
-
/** Use ANSI colors in output. Default: false. */
|
|
610
|
-
color?: boolean;
|
|
611
|
-
/** Compact single-line format. Default: false. */
|
|
612
|
-
compact?: boolean;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Format a GuardVerdict as a human-readable string.
|
|
616
|
-
*
|
|
617
|
-
* Examples:
|
|
618
|
-
* formatVerdict(verdict)
|
|
619
|
-
* // "BLOCKED\n Rule: margin_floor\n Reason: margin ratio below 10%"
|
|
620
|
-
*
|
|
621
|
-
* formatVerdict(verdict, { compact: true })
|
|
622
|
-
* // "BLOCKED — margin_floor: margin ratio below 10%"
|
|
623
|
-
*
|
|
624
|
-
* formatVerdict(verdict, { color: true })
|
|
625
|
-
* // Same but with ANSI colors
|
|
626
|
-
*/
|
|
627
|
-
declare function formatVerdict(verdict: GuardVerdict, options?: FormatVerdictOptions): string;
|
|
628
|
-
/**
|
|
629
|
-
* Format a verdict as a short one-line status message.
|
|
630
|
-
* Useful for logging, status bars, and notifications.
|
|
631
|
-
*
|
|
632
|
-
* Example: "BLOCKED: margin_floor — margin ratio below 10%"
|
|
633
|
-
*/
|
|
634
|
-
declare function formatVerdictOneLine(verdict: GuardVerdict): string;
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* Governance Impact Report — Counterfactual Audit
|
|
638
|
-
*
|
|
639
|
-
* Answers: "What would have happened if governance did not exist?"
|
|
640
|
-
*
|
|
641
|
-
* This is the killer enterprise feature. It doesn't just log what happened —
|
|
642
|
-
* it proves the value of governance by showing what it prevented.
|
|
643
|
-
*
|
|
644
|
-
* Architecture:
|
|
645
|
-
* - Reads audit events (from FileAuditLogger NDJSON)
|
|
646
|
-
* - Classifies blocked/paused actions by risk category
|
|
647
|
-
* - Produces an ImpactReport with aggregated prevention metrics
|
|
648
|
-
* - CLI renders as human-readable or JSON
|
|
649
|
-
*
|
|
650
|
-
* INVARIANTS:
|
|
651
|
-
* - No speculation — only reports on actual evaluated actions
|
|
652
|
-
* - Risk categories derived from world rules, not invented
|
|
653
|
-
* - All numbers are exact counts from the audit log
|
|
654
|
-
*/
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* A counterfactual governance impact report.
|
|
658
|
-
*/
|
|
659
|
-
interface ImpactReport {
|
|
660
|
-
/** Report metadata */
|
|
661
|
-
generatedAt: string;
|
|
662
|
-
periodStart: string;
|
|
663
|
-
periodEnd: string;
|
|
664
|
-
worldName: string;
|
|
665
|
-
/** High-level stats */
|
|
666
|
-
totalEvaluations: number;
|
|
667
|
-
totalBlocked: number;
|
|
668
|
-
totalPaused: number;
|
|
669
|
-
totalAllowed: number;
|
|
670
|
-
/** Prevention rate: (blocked + paused) / total */
|
|
671
|
-
preventionRate: number;
|
|
672
|
-
/** Blocked actions grouped by category */
|
|
673
|
-
preventedByCategory: PreventionCategory[];
|
|
674
|
-
/** Top prevented intents */
|
|
675
|
-
topPreventedIntents: {
|
|
676
|
-
intent: string;
|
|
677
|
-
count: number;
|
|
678
|
-
topRule: string;
|
|
679
|
-
}[];
|
|
680
|
-
/** Actors with most blocked actions (potential policy violations) */
|
|
681
|
-
hotActors: {
|
|
682
|
-
actor: string;
|
|
683
|
-
blocked: number;
|
|
684
|
-
paused: number;
|
|
685
|
-
total: number;
|
|
686
|
-
}[];
|
|
687
|
-
/** Rules that triggered most often */
|
|
688
|
-
mostActiveRules: {
|
|
689
|
-
ruleId: string;
|
|
690
|
-
blockCount: number;
|
|
691
|
-
pauseCount: number;
|
|
692
|
-
}[];
|
|
693
|
-
/** Hourly activity pattern (governance load) */
|
|
694
|
-
hourlyDistribution: {
|
|
695
|
-
hour: number;
|
|
696
|
-
total: number;
|
|
697
|
-
blocked: number;
|
|
698
|
-
}[];
|
|
699
|
-
/** Repeat offenders: actions attempted more than once after being blocked */
|
|
700
|
-
repeatViolations: {
|
|
701
|
-
intent: string;
|
|
702
|
-
actor: string;
|
|
703
|
-
attempts: number;
|
|
704
|
-
firstSeen: string;
|
|
705
|
-
lastSeen: string;
|
|
706
|
-
}[];
|
|
707
|
-
}
|
|
708
|
-
interface PreventionCategory {
|
|
709
|
-
category: string;
|
|
710
|
-
count: number;
|
|
711
|
-
/** Example intents in this category */
|
|
712
|
-
examples: string[];
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Generate a governance impact report from audit events.
|
|
716
|
-
*/
|
|
717
|
-
declare function generateImpactReport(events: AuditEvent[]): ImpactReport;
|
|
718
|
-
/**
|
|
719
|
-
* Render an impact report as human-readable text.
|
|
720
|
-
*/
|
|
721
|
-
declare function renderImpactReport(report: ImpactReport): string;
|
|
722
|
-
/**
|
|
723
|
-
* Generate an impact report directly from an audit log file.
|
|
724
|
-
*/
|
|
725
|
-
declare function generateImpactReportFromFile(logPath: string): Promise<ImpactReport>;
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* World Loader — Shared world file loading for CLI commands
|
|
729
|
-
*
|
|
730
|
-
* Loads a WorldDefinition from either:
|
|
731
|
-
* - A directory containing individual JSON files
|
|
732
|
-
* - (Future) A .nv-world.zip archive
|
|
733
|
-
*
|
|
734
|
-
* Used by: neuroverse guard, neuroverse validate, neuroverse init
|
|
735
|
-
* Not used by: neuroverse bootstrap (which produces world files, not consumes them)
|
|
736
|
-
*/
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Load a WorldDefinition from a directory of JSON files.
|
|
740
|
-
*
|
|
741
|
-
* Reads all standard world files and assembles them into a WorldDefinition.
|
|
742
|
-
* Missing optional files are handled gracefully with defaults.
|
|
743
|
-
* Missing required files (world.json) throw.
|
|
744
|
-
*/
|
|
745
|
-
declare function loadWorldFromDirectory(dirPath: string): Promise<WorldDefinition>;
|
|
746
|
-
/**
|
|
747
|
-
* Load a world from a path — auto-detects directory vs .nv-world.zip.
|
|
748
|
-
*/
|
|
749
|
-
declare function loadWorld(worldPath: string): Promise<WorldDefinition>;
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* World Resolver — Resolve world names to paths
|
|
753
|
-
*
|
|
754
|
-
* Resolution order:
|
|
755
|
-
* 1. Explicit path (absolute or relative) → use directly
|
|
756
|
-
* 2. NEUROVERSE_WORLD env var → resolve as name or path
|
|
757
|
-
* 3. .neuroverse/active_world file → read world name
|
|
758
|
-
* 4. Auto-detect if only one world exists in .neuroverse/worlds/
|
|
759
|
-
*
|
|
760
|
-
* World name resolution:
|
|
761
|
-
* "marketing" → .neuroverse/worlds/marketing/
|
|
762
|
-
* "./my-world/" → use as-is
|
|
763
|
-
* "/absolute/path" → use as-is
|
|
764
|
-
*/
|
|
765
|
-
interface WorldInfo {
|
|
766
|
-
name: string;
|
|
767
|
-
path: string;
|
|
768
|
-
active: boolean;
|
|
769
|
-
}
|
|
770
|
-
/**
|
|
771
|
-
* List all compiled worlds in .neuroverse/worlds/
|
|
772
|
-
*/
|
|
773
|
-
declare function listWorlds(cwd?: string): WorldInfo[];
|
|
774
|
-
/**
|
|
775
|
-
* Get the active world name from .neuroverse/active_world
|
|
776
|
-
*/
|
|
777
|
-
declare function getActiveWorldName(cwd?: string): string | undefined;
|
|
778
|
-
/**
|
|
779
|
-
* Set the active world by writing .neuroverse/active_world
|
|
780
|
-
*/
|
|
781
|
-
declare function setActiveWorld(name: string, cwd?: string): void;
|
|
782
|
-
/**
|
|
783
|
-
* Resolve a world reference to an absolute path.
|
|
784
|
-
*
|
|
785
|
-
* @param explicit - Value from --world flag (may be undefined)
|
|
786
|
-
* @param cwd - Working directory for relative resolution
|
|
787
|
-
* @returns Resolved absolute path to the world directory
|
|
788
|
-
*/
|
|
789
|
-
declare function resolveWorldPath(explicit?: string, cwd?: string): string | undefined;
|
|
790
|
-
/**
|
|
791
|
-
* Describe how the current world was resolved (for "Using world:" messages).
|
|
792
|
-
* Returns { name, source } or undefined if no world is active.
|
|
793
|
-
*/
|
|
794
|
-
declare function describeActiveWorld(explicit?: string, cwd?: string): {
|
|
795
|
-
name: string;
|
|
796
|
-
source: string;
|
|
797
|
-
} | undefined;
|
|
798
|
-
|
|
799
|
-
/**
|
|
800
|
-
* Condition Engine — Structured operator evaluation
|
|
801
|
-
*
|
|
802
|
-
* Ported from the OpenClaw governance plugin. Provides 12 operators
|
|
803
|
-
* for evaluating conditions against guard events:
|
|
804
|
-
*
|
|
805
|
-
* ==, !=, >, <, >=, <=, in,
|
|
806
|
-
* contains, contains_any, matches_pattern, starts_with, ends_with
|
|
807
|
-
*
|
|
808
|
-
* Supports dot-notation field resolution (e.g. "args.command", "args.file_path")
|
|
809
|
-
* for inspecting tool arguments.
|
|
810
|
-
*
|
|
811
|
-
* Deterministic. No AI. No network. Sub-millisecond per evaluation.
|
|
812
|
-
*/
|
|
813
|
-
|
|
814
|
-
type ConditionOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | 'in' | 'contains' | 'contains_any' | 'matches_pattern' | 'starts_with' | 'ends_with';
|
|
815
|
-
interface Condition {
|
|
816
|
-
field: string;
|
|
817
|
-
operator: ConditionOperator;
|
|
818
|
-
value: string | string[] | number | boolean;
|
|
819
|
-
}
|
|
820
|
-
interface ConditionResult {
|
|
821
|
-
matched: boolean;
|
|
822
|
-
evidence: string | null;
|
|
823
|
-
}
|
|
824
|
-
/**
|
|
825
|
-
* Evaluate a single condition against a guard event.
|
|
826
|
-
* Returns whether it matched and what evidence was found.
|
|
827
|
-
*/
|
|
828
|
-
declare function evaluateCondition(condition: Condition, event: GuardEvent): ConditionResult;
|
|
829
|
-
|
|
830
|
-
/**
|
|
831
|
-
* Validate Contract — CLI World File Static Analysis Types
|
|
832
|
-
*
|
|
833
|
-
* Defines the input/output contract for `neuroverse validate`.
|
|
834
|
-
*
|
|
835
|
-
* WorldDefinition comes in (loaded from .nv-world.zip or directory).
|
|
836
|
-
* ValidateReport goes out (stdout JSON).
|
|
837
|
-
* Exit code encodes health: 0=PASS, 1=FAIL, 2=WARN.
|
|
838
|
-
*
|
|
839
|
-
* The validate engine performs static analysis on world files:
|
|
840
|
-
* - Completeness: Are all required blocks present and non-empty?
|
|
841
|
-
* - Referential integrity: Do rules reference declared state variables?
|
|
842
|
-
* - Guard coverage: Do invariants have backing structural guards?
|
|
843
|
-
* - Contradiction detection: Do rules conflict with each other?
|
|
844
|
-
* - Orphan detection: Are there unreachable rules or unused variables?
|
|
845
|
-
*
|
|
846
|
-
* INVARIANTS:
|
|
847
|
-
* - Deterministic: same world → same report.
|
|
848
|
-
* - Zero network calls.
|
|
849
|
-
* - Every finding includes the source block and a human-readable message.
|
|
850
|
-
*/
|
|
851
|
-
/**
|
|
852
|
-
* Controls the strictness of governance validation.
|
|
853
|
-
*
|
|
854
|
-
* - `dev`: Lenient — governance findings are downgraded to info. Build always succeeds.
|
|
855
|
-
* - `standard`: Recommended default — governance findings are warnings. Build always succeeds.
|
|
856
|
-
* - `strict`: Compliance — governance findings stay as warnings but are flagged for attention.
|
|
857
|
-
* Build still succeeds (worlds always work) but the report highlights all gaps.
|
|
858
|
-
*
|
|
859
|
-
* Structural issues (missing blocks, broken references, schema violations) are
|
|
860
|
-
* always reported at their natural severity regardless of mode.
|
|
861
|
-
*/
|
|
862
|
-
type ValidationMode = 'dev' | 'standard' | 'strict';
|
|
863
|
-
type FindingSeverity = 'error' | 'warning' | 'info';
|
|
864
|
-
type FindingCategory = 'completeness' | 'referential-integrity' | 'guard-coverage' | 'contradiction' | 'orphan' | 'schema-violation' | 'semantic-tension';
|
|
865
|
-
/**
|
|
866
|
-
* A single finding from static analysis.
|
|
867
|
-
*/
|
|
868
|
-
interface ValidateFinding {
|
|
869
|
-
/** Unique ID for this finding type (e.g., "missing-thesis", "orphan-rule-003") */
|
|
870
|
-
id: string;
|
|
871
|
-
/** Human-readable message */
|
|
872
|
-
message: string;
|
|
873
|
-
/** Error, warning, or informational */
|
|
874
|
-
severity: FindingSeverity;
|
|
875
|
-
/** What category of issue this is */
|
|
876
|
-
category: FindingCategory;
|
|
877
|
-
/** Which world file block(s) are affected */
|
|
878
|
-
affectedBlocks: string[];
|
|
879
|
-
/** Specific field or rule ID that triggered this finding */
|
|
880
|
-
source?: string;
|
|
881
|
-
/** Suggested fix (when deterministically derivable) */
|
|
882
|
-
suggestion?: string;
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Summary of world health by category.
|
|
886
|
-
*/
|
|
887
|
-
interface ValidateSummary {
|
|
888
|
-
/** Total findings by severity */
|
|
889
|
-
errors: number;
|
|
890
|
-
warnings: number;
|
|
891
|
-
info: number;
|
|
892
|
-
/** Block completeness score (0-100) */
|
|
893
|
-
completenessScore: number;
|
|
894
|
-
/** Invariant coverage percentage (invariants with backing guards) */
|
|
895
|
-
invariantCoverage: number;
|
|
896
|
-
/** Whether the world is valid enough to run */
|
|
897
|
-
canRun: boolean;
|
|
898
|
-
/** Whether the world passes full validation (no errors) */
|
|
899
|
-
isHealthy: boolean;
|
|
900
|
-
/** Governance health — actionable summary of coverage gaps */
|
|
901
|
-
governanceHealth?: GovernanceHealth;
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Actionable governance health summary.
|
|
905
|
-
* Provides at-a-glance understanding of how well-governed a world is.
|
|
906
|
-
*/
|
|
907
|
-
interface GovernanceHealth {
|
|
908
|
-
/** How many declared action surfaces are governed vs total */
|
|
909
|
-
surfacesCovered: number;
|
|
910
|
-
surfacesTotal: number;
|
|
911
|
-
/** Individual surface governance status */
|
|
912
|
-
surfaces: Array<{
|
|
913
|
-
name: string;
|
|
914
|
-
governed: boolean;
|
|
915
|
-
}>;
|
|
916
|
-
/** How many structural invariants are enforced vs total */
|
|
917
|
-
invariantsEnforced: number;
|
|
918
|
-
invariantsTotal: number;
|
|
919
|
-
/** Number of shadowed guards detected */
|
|
920
|
-
shadowedGuards: number;
|
|
921
|
-
/** Number of unenforced invariants */
|
|
922
|
-
unenforcedInvariants: number;
|
|
923
|
-
/** Number of unreachable rules/gates (dead policy logic) */
|
|
924
|
-
unreachableRules: number;
|
|
925
|
-
/** Number of enum variables with incomplete state coverage */
|
|
926
|
-
incompleteStateCoverage: number;
|
|
927
|
-
/** Overall risk level */
|
|
928
|
-
riskLevel: 'low' | 'moderate' | 'high';
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* The validate report — what goes to stdout.
|
|
932
|
-
*
|
|
933
|
-
* Exit codes:
|
|
934
|
-
* 0 = PASS (no errors, world is healthy)
|
|
935
|
-
* 1 = FAIL (errors found, world cannot run safely)
|
|
936
|
-
* 2 = WARN (warnings found but world can run)
|
|
937
|
-
* 3 = ERROR (invalid input, could not parse world)
|
|
938
|
-
*/
|
|
939
|
-
interface ValidateReport {
|
|
940
|
-
/** World identity */
|
|
941
|
-
worldId: string;
|
|
942
|
-
worldName: string;
|
|
943
|
-
worldVersion: string;
|
|
944
|
-
/** When the validation ran */
|
|
945
|
-
validatedAt: number;
|
|
946
|
-
/** Duration of validation */
|
|
947
|
-
durationMs: number;
|
|
948
|
-
/** High-level summary */
|
|
949
|
-
summary: ValidateSummary;
|
|
950
|
-
/** Validation mode used */
|
|
951
|
-
validationMode: ValidationMode;
|
|
952
|
-
/** All findings, ordered by severity (errors first) */
|
|
953
|
-
findings: ValidateFinding[];
|
|
954
|
-
}
|
|
955
|
-
declare const VALIDATE_EXIT_CODES: {
|
|
956
|
-
readonly PASS: 0;
|
|
957
|
-
readonly FAIL: 1;
|
|
958
|
-
readonly WARN: 2;
|
|
959
|
-
readonly ERROR: 3;
|
|
960
|
-
};
|
|
961
|
-
type ValidateExitCode = (typeof VALIDATE_EXIT_CODES)[keyof typeof VALIDATE_EXIT_CODES];
|
|
962
|
-
|
|
963
|
-
/**
|
|
964
|
-
* Validate Engine — World File Static Analysis
|
|
965
|
-
*
|
|
966
|
-
* Pure function: (world) → report
|
|
967
|
-
*
|
|
968
|
-
* Performs comprehensive static analysis on a WorldDefinition:
|
|
969
|
-
* 1. Completeness — are required blocks present and non-empty?
|
|
970
|
-
* 2. Referential integrity — do rules reference declared variables?
|
|
971
|
-
* 3. Guard coverage — do invariants have backing structural guards?
|
|
972
|
-
* 3b. Semantic coverage — can any guard actually intercept the invariant's action class?
|
|
973
|
-
* 4. Contradiction detection — do rules conflict?
|
|
974
|
-
* 5. Guard shadow detection — do guards shadow or conflict with each other?
|
|
975
|
-
* 5b. Fail-closed surface detection — are action surfaces ungoverned?
|
|
976
|
-
* 6. Reachability analysis — are there rules/guards that can never trigger?
|
|
977
|
-
* 7. State space coverage — do guard conditions cover all enumerated states?
|
|
978
|
-
* 8. Orphan detection — unused variables, unreachable rules
|
|
979
|
-
* 9. Schema validation — values within declared ranges
|
|
980
|
-
*
|
|
981
|
-
* INVARIANTS:
|
|
982
|
-
* - Deterministic: same world → same report, always.
|
|
983
|
-
* - Zero network calls. Zero LLM calls. Zero async.
|
|
984
|
-
* - Every finding is traceable to specific world file blocks.
|
|
985
|
-
*/
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* Validate a world definition and produce a report.
|
|
989
|
-
*
|
|
990
|
-
* This is the entire validate engine. One function. Deterministic.
|
|
991
|
-
*/
|
|
992
|
-
declare function validateWorld(world: WorldDefinition, mode?: ValidationMode): ValidateReport;
|
|
993
|
-
|
|
994
|
-
/**
|
|
995
|
-
* Bootstrap Contract — Markdown → WorldDefinition Compilation Types
|
|
996
|
-
*
|
|
997
|
-
* Defines the input/output contract for `neuroverse bootstrap`.
|
|
998
|
-
*
|
|
999
|
-
* Input: .nv-world.md file (structured markdown)
|
|
1000
|
-
* Output: WorldDefinition (passed to validate, guard, or compileWorldToZip)
|
|
1001
|
-
*
|
|
1002
|
-
* The markdown format is:
|
|
1003
|
-
* - YAML frontmatter for world identity and metadata
|
|
1004
|
-
* - H1 sections for each block (Thesis, Invariants, State, etc.)
|
|
1005
|
-
* - Structured sub-sections within each block
|
|
1006
|
-
* - Deterministically parseable — no LLM, no heuristics
|
|
1007
|
-
*
|
|
1008
|
-
* Exit codes:
|
|
1009
|
-
* 0 = SUCCESS (compiled cleanly)
|
|
1010
|
-
* 1 = FAIL (parse errors, missing required sections)
|
|
1011
|
-
* 3 = ERROR (file not found, invalid input)
|
|
1012
|
-
*/
|
|
1013
|
-
type ParseSeverity = 'error' | 'warning' | 'info';
|
|
1014
|
-
/**
|
|
1015
|
-
* A single parse issue found during markdown compilation.
|
|
1016
|
-
*/
|
|
1017
|
-
interface ParseIssue {
|
|
1018
|
-
/** Line number in the source markdown (1-based) */
|
|
1019
|
-
line: number;
|
|
1020
|
-
/** Which section the issue was found in */
|
|
1021
|
-
section: string;
|
|
1022
|
-
/** Human-readable message */
|
|
1023
|
-
message: string;
|
|
1024
|
-
/** Severity */
|
|
1025
|
-
severity: ParseSeverity;
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* The result of parsing a .nv-world.md file.
|
|
1029
|
-
*/
|
|
1030
|
-
interface BootstrapResult {
|
|
1031
|
-
/** Whether compilation succeeded (no errors) */
|
|
1032
|
-
success: boolean;
|
|
1033
|
-
/** Source file path */
|
|
1034
|
-
sourcePath: string;
|
|
1035
|
-
/** All parse issues */
|
|
1036
|
-
issues: ParseIssue[];
|
|
1037
|
-
/** Parsed sections (for debugging) */
|
|
1038
|
-
parsedSections: string[];
|
|
1039
|
-
/** Duration */
|
|
1040
|
-
durationMs: number;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* YAML frontmatter parsed from the markdown header.
|
|
1044
|
-
*/
|
|
1045
|
-
interface ParsedFrontmatter {
|
|
1046
|
-
world_id: string;
|
|
1047
|
-
name: string;
|
|
1048
|
-
version?: string;
|
|
1049
|
-
runtime_mode?: string;
|
|
1050
|
-
default_profile?: string;
|
|
1051
|
-
alternative_profile?: string;
|
|
1052
|
-
}
|
|
1053
|
-
/**
|
|
1054
|
-
* A parsed invariant from the Invariants section.
|
|
1055
|
-
*/
|
|
1056
|
-
interface ParsedInvariant {
|
|
1057
|
-
id: string;
|
|
1058
|
-
label: string;
|
|
1059
|
-
enforcement: string;
|
|
1060
|
-
mutable: boolean;
|
|
1061
|
-
line: number;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* A parsed state variable from the State section.
|
|
1065
|
-
*/
|
|
1066
|
-
interface ParsedStateVariable {
|
|
1067
|
-
id: string;
|
|
1068
|
-
type: 'number' | 'enum' | 'boolean';
|
|
1069
|
-
default: string | number | boolean;
|
|
1070
|
-
label: string;
|
|
1071
|
-
description: string;
|
|
1072
|
-
min?: number;
|
|
1073
|
-
max?: number;
|
|
1074
|
-
step?: number;
|
|
1075
|
-
options?: string[];
|
|
1076
|
-
line: number;
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* A parsed assumption profile from the Assumptions section.
|
|
1080
|
-
*/
|
|
1081
|
-
interface ParsedAssumptionProfile {
|
|
1082
|
-
id: string;
|
|
1083
|
-
name: string;
|
|
1084
|
-
description: string;
|
|
1085
|
-
parameters: Record<string, string | number | boolean>;
|
|
1086
|
-
line: number;
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* A parsed trigger from a rule.
|
|
1090
|
-
*/
|
|
1091
|
-
interface ParsedTrigger {
|
|
1092
|
-
field: string;
|
|
1093
|
-
operator: string;
|
|
1094
|
-
value: string | number | boolean;
|
|
1095
|
-
source: 'state' | 'assumption';
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* A parsed effect from a rule.
|
|
1099
|
-
*/
|
|
1100
|
-
interface ParsedEffect {
|
|
1101
|
-
target: string;
|
|
1102
|
-
operation: string;
|
|
1103
|
-
value: number | boolean | string;
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* A parsed rule from the Rules section.
|
|
1107
|
-
*/
|
|
1108
|
-
interface ParsedRule {
|
|
1109
|
-
id: string;
|
|
1110
|
-
label: string;
|
|
1111
|
-
severity: string;
|
|
1112
|
-
description?: string;
|
|
1113
|
-
order: number;
|
|
1114
|
-
triggers: ParsedTrigger[];
|
|
1115
|
-
effects: ParsedEffect[];
|
|
1116
|
-
collapse_check?: {
|
|
1117
|
-
field: string;
|
|
1118
|
-
operator: string;
|
|
1119
|
-
value: number;
|
|
1120
|
-
};
|
|
1121
|
-
causal_translation?: {
|
|
1122
|
-
trigger_text: string;
|
|
1123
|
-
rule_text: string;
|
|
1124
|
-
shift_text: string;
|
|
1125
|
-
effect_text: string;
|
|
1126
|
-
};
|
|
1127
|
-
line: number;
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* A parsed gate from the Gates section.
|
|
1131
|
-
*/
|
|
1132
|
-
interface ParsedGate {
|
|
1133
|
-
status: string;
|
|
1134
|
-
field: string;
|
|
1135
|
-
operator: string;
|
|
1136
|
-
value: number;
|
|
1137
|
-
line: number;
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* A parsed outcome from the Outcomes section.
|
|
1141
|
-
*/
|
|
1142
|
-
interface ParsedOutcome {
|
|
1143
|
-
id: string;
|
|
1144
|
-
type: string;
|
|
1145
|
-
range?: [number, number];
|
|
1146
|
-
display?: string;
|
|
1147
|
-
label: string;
|
|
1148
|
-
primary?: boolean;
|
|
1149
|
-
assignment?: string;
|
|
1150
|
-
line: number;
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* The full parsed intermediate representation.
|
|
1154
|
-
*/
|
|
1155
|
-
interface ParsedWorld {
|
|
1156
|
-
frontmatter: ParsedFrontmatter;
|
|
1157
|
-
thesis: string;
|
|
1158
|
-
invariants: ParsedInvariant[];
|
|
1159
|
-
stateVariables: ParsedStateVariable[];
|
|
1160
|
-
assumptions: ParsedAssumptionProfile[];
|
|
1161
|
-
rules: ParsedRule[];
|
|
1162
|
-
gates: ParsedGate[];
|
|
1163
|
-
outcomes: ParsedOutcome[];
|
|
1164
|
-
}
|
|
1165
|
-
declare const BOOTSTRAP_EXIT_CODES: {
|
|
1166
|
-
readonly SUCCESS: 0;
|
|
1167
|
-
readonly FAIL: 1;
|
|
1168
|
-
readonly ERROR: 3;
|
|
1169
|
-
};
|
|
1170
|
-
type BootstrapExitCode = (typeof BOOTSTRAP_EXIT_CODES)[keyof typeof BOOTSTRAP_EXIT_CODES];
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* Bootstrap Parser — .nv-world.md → ParsedWorld
|
|
1174
|
-
*
|
|
1175
|
-
* Deterministic markdown parser for the NeuroVerse world authoring format.
|
|
1176
|
-
* No LLM calls. No heuristics. Pattern matching on structured markdown.
|
|
1177
|
-
*
|
|
1178
|
-
* ## Markdown Format (.nv-world.md)
|
|
1179
|
-
*
|
|
1180
|
-
* ```markdown
|
|
1181
|
-
* ---
|
|
1182
|
-
* world_id: my-world
|
|
1183
|
-
* name: My World
|
|
1184
|
-
* version: 1.0.0
|
|
1185
|
-
* default_profile: baseline
|
|
1186
|
-
* alternative_profile: alternative
|
|
1187
|
-
* ---
|
|
1188
|
-
*
|
|
1189
|
-
* # Thesis
|
|
1190
|
-
* The structural claim this world tests...
|
|
1191
|
-
*
|
|
1192
|
-
* # Invariants
|
|
1193
|
-
* - `invariant_id` — Label text (structural, immutable)
|
|
1194
|
-
* - `another_id` — Another label (structural, immutable)
|
|
1195
|
-
*
|
|
1196
|
-
* # State
|
|
1197
|
-
* ## variable_name
|
|
1198
|
-
* - type: number
|
|
1199
|
-
* - min: 0
|
|
1200
|
-
* - max: 100
|
|
1201
|
-
* - step: 5
|
|
1202
|
-
* - default: 50
|
|
1203
|
-
* - label: Human Label
|
|
1204
|
-
* - description: What this variable represents
|
|
1205
|
-
*
|
|
1206
|
-
* ## another_variable
|
|
1207
|
-
* - type: enum
|
|
1208
|
-
* - options: option_a, option_b, option_c
|
|
1209
|
-
* - default: option_a
|
|
1210
|
-
* - label: Another Variable
|
|
1211
|
-
* - description: Description here
|
|
1212
|
-
*
|
|
1213
|
-
* # Assumptions
|
|
1214
|
-
* ## baseline
|
|
1215
|
-
* - name: Baseline Scenario
|
|
1216
|
-
* - description: The default conditions
|
|
1217
|
-
* - param_key: param_value
|
|
1218
|
-
*
|
|
1219
|
-
* ## alternative
|
|
1220
|
-
* - name: Alternative Scenario
|
|
1221
|
-
* - description: What changes
|
|
1222
|
-
* - param_key: different_value
|
|
1223
|
-
*
|
|
1224
|
-
* # Rules
|
|
1225
|
-
* ## rule-001: Rule Label (structural)
|
|
1226
|
-
* Description of what this rule does.
|
|
1227
|
-
*
|
|
1228
|
-
* When field == "value" [state] AND other_field > 50 [assumption]
|
|
1229
|
-
* Then target *= 0.30, other_target = false
|
|
1230
|
-
* Collapse: field < 0.03
|
|
1231
|
-
*
|
|
1232
|
-
* > trigger: Trigger text here
|
|
1233
|
-
* > rule: Rule text here
|
|
1234
|
-
* > shift: Shift text here
|
|
1235
|
-
* > effect: Effect text here
|
|
1236
|
-
*
|
|
1237
|
-
* # Gates
|
|
1238
|
-
* - THRIVING: effective_margin >= 40
|
|
1239
|
-
* - STABLE: effective_margin >= 20
|
|
1240
|
-
* - COMPRESSED: effective_margin >= 10
|
|
1241
|
-
* - CRITICAL: effective_margin > 3
|
|
1242
|
-
* - MODEL_COLLAPSES: effective_margin <= 3
|
|
1243
|
-
*
|
|
1244
|
-
* # Outcomes
|
|
1245
|
-
* ## outcome_id
|
|
1246
|
-
* - type: number
|
|
1247
|
-
* - range: 0-100
|
|
1248
|
-
* - display: percentage
|
|
1249
|
-
* - label: Outcome Label
|
|
1250
|
-
* - primary: true
|
|
1251
|
-
* ```
|
|
1252
|
-
*/
|
|
1253
|
-
|
|
1254
|
-
/**
|
|
1255
|
-
* Parse a .nv-world.md string into a ParsedWorld.
|
|
1256
|
-
*
|
|
1257
|
-
* Returns the parsed world and a list of issues.
|
|
1258
|
-
* Callers should check issues for severity === 'error' before proceeding.
|
|
1259
|
-
*/
|
|
1260
|
-
declare function parseWorldMarkdown(markdown: string): {
|
|
1261
|
-
world: ParsedWorld | null;
|
|
1262
|
-
issues: ParseIssue[];
|
|
1263
|
-
};
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Bootstrap Emitter — ParsedWorld → WorldDefinition
|
|
1267
|
-
*
|
|
1268
|
-
* Converts the intermediate representation from the parser
|
|
1269
|
-
* into a proper WorldDefinition that the guard engine, validate engine,
|
|
1270
|
-
* and compileWorldToZip() all consume.
|
|
1271
|
-
*
|
|
1272
|
-
* Fills in sensible defaults for optional fields.
|
|
1273
|
-
* Reports issues when the parsed data can't cleanly map to the target type.
|
|
1274
|
-
*
|
|
1275
|
-
* Deterministic. Same parsed input → same WorldDefinition output.
|
|
1276
|
-
*/
|
|
1277
|
-
|
|
1278
|
-
/**
|
|
1279
|
-
* Convert a ParsedWorld into a WorldDefinition.
|
|
1280
|
-
*
|
|
1281
|
-
* Returns the world definition and any issues encountered during emission.
|
|
1282
|
-
*/
|
|
1283
|
-
declare function emitWorldDefinition(parsed: ParsedWorld): {
|
|
1284
|
-
world: WorldDefinition;
|
|
1285
|
-
issues: ParseIssue[];
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
/**
|
|
1289
|
-
* Derive Contract — AI-Assisted World Synthesis Types
|
|
1290
|
-
*
|
|
1291
|
-
* Defines the input/output contract for `neuroverse derive`.
|
|
1292
|
-
*
|
|
1293
|
-
* Input: Arbitrary markdown files/directories
|
|
1294
|
-
* Output: .nv-world.md file constrained by DerivationWorld
|
|
1295
|
-
*
|
|
1296
|
-
* Exit codes:
|
|
1297
|
-
* 0 = SUCCESS (valid file written)
|
|
1298
|
-
* 1 = VALIDATION_FAIL (output failed parseWorldMarkdown)
|
|
1299
|
-
* 2 = INPUT_ERROR (missing input, empty dir, unreadable)
|
|
1300
|
-
* 3 = PROVIDER_ERROR (no config, API failure, timeout)
|
|
1301
|
-
*/
|
|
1302
|
-
declare const DERIVE_EXIT_CODES: {
|
|
1303
|
-
readonly SUCCESS: 0;
|
|
1304
|
-
readonly VALIDATION_FAIL: 1;
|
|
1305
|
-
readonly INPUT_ERROR: 2;
|
|
1306
|
-
readonly PROVIDER_ERROR: 3;
|
|
1307
|
-
};
|
|
1308
|
-
type DeriveExitCode = (typeof DERIVE_EXIT_CODES)[keyof typeof DERIVE_EXIT_CODES];
|
|
1309
|
-
declare const CONFIGURE_AI_EXIT_CODES: {
|
|
1310
|
-
readonly SUCCESS: 0;
|
|
1311
|
-
readonly VALIDATION_FAIL: 1;
|
|
1312
|
-
readonly ERROR: 3;
|
|
1313
|
-
};
|
|
1314
|
-
interface DeriveResult {
|
|
1315
|
-
success: boolean;
|
|
1316
|
-
outputPath: string;
|
|
1317
|
-
sectionsDetected: string[];
|
|
1318
|
-
validationErrors: number;
|
|
1319
|
-
validationWarnings: number;
|
|
1320
|
-
findings: DeriveFinding[];
|
|
1321
|
-
gate?: string;
|
|
1322
|
-
normalization?: NormalizationSummary;
|
|
1323
|
-
durationMs: number;
|
|
1324
|
-
}
|
|
1325
|
-
interface NormalizationSummary {
|
|
1326
|
-
fixCount: number;
|
|
1327
|
-
invariantIds: number;
|
|
1328
|
-
gateThresholds: number;
|
|
1329
|
-
triggerTags: number;
|
|
1330
|
-
}
|
|
1331
|
-
interface DeriveFinding {
|
|
1332
|
-
severity: 'error' | 'warning';
|
|
1333
|
-
section: string;
|
|
1334
|
-
message: string;
|
|
1335
|
-
line?: number;
|
|
1336
|
-
}
|
|
1337
|
-
interface CollectedSource {
|
|
1338
|
-
filename: string;
|
|
1339
|
-
content: string;
|
|
1340
|
-
}
|
|
1341
|
-
interface AIProviderConfig {
|
|
1342
|
-
provider: string;
|
|
1343
|
-
model: string;
|
|
1344
|
-
apiKey: string;
|
|
1345
|
-
endpoint: string | null;
|
|
1346
|
-
}
|
|
1347
|
-
interface AIProvider {
|
|
1348
|
-
complete(systemPrompt: string, userPrompt: string): Promise<string>;
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
/**
|
|
1352
|
-
* Derive Engine — AI-Assisted World Synthesis Pipeline
|
|
1353
|
-
*
|
|
1354
|
-
* Pipeline:
|
|
1355
|
-
* collect → prompt → AI → extract → parseWorldMarkdown → write → JSON
|
|
1356
|
-
*
|
|
1357
|
-
* DerivationWorld is advisory only:
|
|
1358
|
-
* - Gate status is reported but never blocks file writing
|
|
1359
|
-
* - parseWorldMarkdown errors ARE blocking (invalid .nv-world.md)
|
|
1360
|
-
* - Governance engine does NOT run during derive
|
|
1361
|
-
*/
|
|
1362
|
-
|
|
1363
|
-
/**
|
|
1364
|
-
* Extract .nv-world.md content from LLM response.
|
|
1365
|
-
*
|
|
1366
|
-
* Handles:
|
|
1367
|
-
* - Triple backtick fences (```markdown ... ``` or ``` ... ```)
|
|
1368
|
-
* - Sentinel markers (BEGIN NV WORLD / END NV WORLD)
|
|
1369
|
-
* - Raw content starting with ---
|
|
1370
|
-
*
|
|
1371
|
-
* Pre-parse safety: output must contain `world_id:` in frontmatter.
|
|
1372
|
-
*/
|
|
1373
|
-
declare function extractWorldMarkdown(raw: string): string | null;
|
|
1374
|
-
interface DeriveOptions {
|
|
1375
|
-
inputPath: string;
|
|
1376
|
-
outputPath: string;
|
|
1377
|
-
validate: boolean;
|
|
1378
|
-
dryRun: boolean;
|
|
1379
|
-
providerOverride?: Partial<AIProviderConfig>;
|
|
1380
|
-
}
|
|
1381
|
-
declare function deriveWorld(options: DeriveOptions): Promise<{
|
|
1382
|
-
result: DeriveResult;
|
|
1383
|
-
exitCode: number;
|
|
1384
|
-
dryRunOutput?: {
|
|
1385
|
-
systemPrompt: string;
|
|
1386
|
-
userPrompt: string;
|
|
1387
|
-
};
|
|
1388
|
-
}>;
|
|
1389
|
-
|
|
1390
|
-
/**
|
|
1391
|
-
* Derive Normalizer — Post-processing pass for AI output drift
|
|
1392
|
-
*
|
|
1393
|
-
* Runs AFTER AI generation but BEFORE parsing. Normalizes common
|
|
1394
|
-
* deviations from the strict .nv-world.md grammar so the parser
|
|
1395
|
-
* can accept the output.
|
|
1396
|
-
*
|
|
1397
|
-
* Transformations:
|
|
1398
|
-
* 1. Invariant lines: adds backtick-wrapped IDs when missing
|
|
1399
|
-
* 2. Gate lines: converts symbolic values to numeric thresholds
|
|
1400
|
-
* 3. Trigger lines: ensures [state] / [assumption] source tags
|
|
1401
|
-
*
|
|
1402
|
-
* INVARIANTS:
|
|
1403
|
-
* - Deterministic: same input → same output, always.
|
|
1404
|
-
* - Zero network calls. Zero LLM calls.
|
|
1405
|
-
* - Never removes content — only reformats.
|
|
1406
|
-
* - Operates on raw markdown string, not parsed structures.
|
|
1407
|
-
*/
|
|
1408
|
-
interface NormalizerReport {
|
|
1409
|
-
/** Total number of lines fixed */
|
|
1410
|
-
fixCount: number;
|
|
1411
|
-
/** Number of invariant IDs wrapped in backticks */
|
|
1412
|
-
invariantIds: number;
|
|
1413
|
-
/** Number of symbolic gate thresholds converted to numeric */
|
|
1414
|
-
gateThresholds: number;
|
|
1415
|
-
/** Number of triggers tagged with [state] */
|
|
1416
|
-
triggerTags: number;
|
|
1417
|
-
}
|
|
1418
|
-
/**
|
|
1419
|
-
* Normalize AI-generated .nv-world.md content to fix common drift patterns.
|
|
1420
|
-
*
|
|
1421
|
-
* Returns the normalized markdown string and a detailed fix report.
|
|
1422
|
-
*/
|
|
1423
|
-
declare function normalizeWorldMarkdown(markdown: string): {
|
|
1424
|
-
normalized: string;
|
|
1425
|
-
fixCount: number;
|
|
1426
|
-
report: NormalizerReport;
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
/**
|
|
1430
|
-
* Explain Engine — Generates human-readable narrative summaries from compiled worlds.
|
|
1431
|
-
*
|
|
1432
|
-
* No AI calls. Pure template-based rendering from WorldDefinition data.
|
|
1433
|
-
*
|
|
1434
|
-
* Sections:
|
|
1435
|
-
* 1. Core thesis and identity
|
|
1436
|
-
* 2. Key dynamics (rules with causal_translation)
|
|
1437
|
-
* 3. State variables (what can change)
|
|
1438
|
-
* 4. Invariants (what cannot change)
|
|
1439
|
-
* 5. Viability gates (health thresholds)
|
|
1440
|
-
* 6. Dramatic tensions (opposing rule effects)
|
|
1441
|
-
* 7. Outcomes (what gets measured)
|
|
1442
|
-
*/
|
|
1443
|
-
|
|
1444
|
-
interface ExplainOutput {
|
|
1445
|
-
worldName: string;
|
|
1446
|
-
worldId: string;
|
|
1447
|
-
thesis: string;
|
|
1448
|
-
dynamics: DynamicSummary[];
|
|
1449
|
-
stateVariables: VariableSummary[];
|
|
1450
|
-
invariants: InvariantSummary[];
|
|
1451
|
-
gates: GateSummary[];
|
|
1452
|
-
tensions: TensionSummary[];
|
|
1453
|
-
outcomes: OutcomeSummary[];
|
|
1454
|
-
stats: WorldStats;
|
|
1455
|
-
}
|
|
1456
|
-
interface DynamicSummary {
|
|
1457
|
-
ruleId: string;
|
|
1458
|
-
label: string;
|
|
1459
|
-
severity: string;
|
|
1460
|
-
triggerDescription: string;
|
|
1461
|
-
effectDescription: string;
|
|
1462
|
-
targets: string[];
|
|
1463
|
-
}
|
|
1464
|
-
interface VariableSummary {
|
|
1465
|
-
name: string;
|
|
1466
|
-
label: string;
|
|
1467
|
-
type: string;
|
|
1468
|
-
defaultValue: string | number | boolean;
|
|
1469
|
-
range?: string;
|
|
1470
|
-
}
|
|
1471
|
-
interface InvariantSummary {
|
|
1472
|
-
id: string;
|
|
1473
|
-
label: string;
|
|
1474
|
-
enforcement: string;
|
|
1475
|
-
}
|
|
1476
|
-
interface GateSummary {
|
|
1477
|
-
status: string;
|
|
1478
|
-
field: string;
|
|
1479
|
-
threshold: string;
|
|
1480
|
-
}
|
|
1481
|
-
interface TensionSummary {
|
|
1482
|
-
variable: string;
|
|
1483
|
-
increasedBy: string[];
|
|
1484
|
-
decreasedBy: string[];
|
|
1485
|
-
}
|
|
1486
|
-
interface OutcomeSummary {
|
|
1487
|
-
id: string;
|
|
1488
|
-
label: string;
|
|
1489
|
-
type: string;
|
|
1490
|
-
primary: boolean;
|
|
1491
|
-
}
|
|
1492
|
-
interface WorldStats {
|
|
1493
|
-
invariants: number;
|
|
1494
|
-
stateVariables: number;
|
|
1495
|
-
rules: number;
|
|
1496
|
-
gates: number;
|
|
1497
|
-
outcomes: number;
|
|
1498
|
-
assumptions: number;
|
|
1499
|
-
}
|
|
1500
|
-
declare function explainWorld(world: WorldDefinition): ExplainOutput;
|
|
1501
|
-
declare function renderExplainText(output: ExplainOutput): string;
|
|
1502
|
-
|
|
1503
|
-
/**
|
|
1504
|
-
* Simulate Engine — Deterministic State Evolution
|
|
1505
|
-
*
|
|
1506
|
-
* Pure function: (world, options) → SimulationResult
|
|
1507
|
-
*
|
|
1508
|
-
* Evaluates all rules against the current state, applies effects,
|
|
1509
|
-
* classifies viability via gates, and produces a step-by-step trace.
|
|
1510
|
-
*
|
|
1511
|
-
* Supports:
|
|
1512
|
-
* - Single-step evaluation (default)
|
|
1513
|
-
* - Multi-step iteration (--steps N)
|
|
1514
|
-
* - State overrides (start from non-default values)
|
|
1515
|
-
* - Assumption profile selection
|
|
1516
|
-
* - Collapse detection (early termination)
|
|
1517
|
-
*
|
|
1518
|
-
* INVARIANTS:
|
|
1519
|
-
* - Deterministic: same world + same options → same result.
|
|
1520
|
-
* - Zero network calls. Zero LLM calls. Zero async.
|
|
1521
|
-
* - Every rule evaluation is recorded in the trace.
|
|
1522
|
-
*/
|
|
1523
|
-
|
|
1524
|
-
interface SimulateOptions {
|
|
1525
|
-
/** Number of simulation steps (default: 1) */
|
|
1526
|
-
steps?: number;
|
|
1527
|
-
/** State variable overrides (start values) */
|
|
1528
|
-
stateOverrides?: Record<string, string | number | boolean>;
|
|
1529
|
-
/** Assumption profile to use (default: world default) */
|
|
1530
|
-
profile?: string;
|
|
1531
|
-
}
|
|
1532
|
-
interface SimulationResult {
|
|
1533
|
-
worldId: string;
|
|
1534
|
-
worldName: string;
|
|
1535
|
-
profile: string;
|
|
1536
|
-
initialState: Record<string, string | number | boolean>;
|
|
1537
|
-
steps: SimulationStep[];
|
|
1538
|
-
finalState: Record<string, string | number | boolean>;
|
|
1539
|
-
finalViability: ViabilityStatus;
|
|
1540
|
-
collapsed: boolean;
|
|
1541
|
-
collapseStep?: number;
|
|
1542
|
-
collapseRule?: string;
|
|
1543
|
-
}
|
|
1544
|
-
interface SimulationStep {
|
|
1545
|
-
step: number;
|
|
1546
|
-
rulesEvaluated: RuleEvaluation[];
|
|
1547
|
-
rulesFired: number;
|
|
1548
|
-
stateAfter: Record<string, string | number | boolean>;
|
|
1549
|
-
viability: ViabilityStatus;
|
|
1550
|
-
collapsed: boolean;
|
|
1551
|
-
}
|
|
1552
|
-
interface RuleEvaluation {
|
|
1553
|
-
ruleId: string;
|
|
1554
|
-
label: string;
|
|
1555
|
-
triggered: boolean;
|
|
1556
|
-
excluded: boolean;
|
|
1557
|
-
effects: AppliedEffect[];
|
|
1558
|
-
collapsed: boolean;
|
|
1559
|
-
collapseField?: string;
|
|
1560
|
-
}
|
|
1561
|
-
interface AppliedEffect {
|
|
1562
|
-
target: string;
|
|
1563
|
-
operation: string;
|
|
1564
|
-
value: number | boolean | string;
|
|
1565
|
-
before: string | number | boolean;
|
|
1566
|
-
after: string | number | boolean;
|
|
1567
|
-
}
|
|
1568
|
-
declare function simulateWorld(world: WorldDefinition, options?: SimulateOptions): SimulationResult;
|
|
1569
|
-
declare function renderSimulateText(result: SimulationResult): string;
|
|
1570
|
-
|
|
1571
|
-
/**
|
|
1572
|
-
* Improve Engine — Actionable Suggestions from World Analysis
|
|
1573
|
-
*
|
|
1574
|
-
* Pure function: (world) → ImprovementReport
|
|
1575
|
-
*
|
|
1576
|
-
* Runs validation, simulation, and structural analysis to produce
|
|
1577
|
-
* prioritized, actionable suggestions for improving a world.
|
|
1578
|
-
*
|
|
1579
|
-
* Categories:
|
|
1580
|
-
* 1. Critical fixes — errors that prevent the world from running
|
|
1581
|
-
* 2. Structural gaps — missing guards, orphan variables, etc.
|
|
1582
|
-
* 3. Balance suggestions — detected from simulation dynamics
|
|
1583
|
-
* 4. Completeness — optional blocks that would strengthen the world
|
|
1584
|
-
*
|
|
1585
|
-
* INVARIANTS:
|
|
1586
|
-
* - Deterministic: same world → same report.
|
|
1587
|
-
* - Zero network calls. Zero LLM calls. Zero async.
|
|
1588
|
-
*/
|
|
1589
|
-
|
|
1590
|
-
type SuggestionPriority = 'critical' | 'high' | 'medium' | 'low';
|
|
1591
|
-
type SuggestionCategory = 'fix' | 'structure' | 'balance' | 'completeness' | 'coverage';
|
|
1592
|
-
interface Suggestion {
|
|
1593
|
-
id: string;
|
|
1594
|
-
priority: SuggestionPriority;
|
|
1595
|
-
category: SuggestionCategory;
|
|
1596
|
-
title: string;
|
|
1597
|
-
description: string;
|
|
1598
|
-
action: string;
|
|
1599
|
-
affectedFiles: string[];
|
|
1600
|
-
}
|
|
1601
|
-
interface ImprovementReport {
|
|
1602
|
-
worldId: string;
|
|
1603
|
-
worldName: string;
|
|
1604
|
-
score: number;
|
|
1605
|
-
suggestions: Suggestion[];
|
|
1606
|
-
stats: {
|
|
1607
|
-
critical: number;
|
|
1608
|
-
high: number;
|
|
1609
|
-
medium: number;
|
|
1610
|
-
low: number;
|
|
1611
|
-
};
|
|
1612
|
-
}
|
|
1613
|
-
declare function improveWorld(world: WorldDefinition): ImprovementReport;
|
|
1614
|
-
declare function renderImproveText(report: ImprovementReport): string;
|
|
1615
|
-
|
|
1616
|
-
export { type AIProvider, type AIProviderConfig, AdvanceResult, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, ConsoleAuditLogger, DERIVE_EXIT_CODES, type DeriveExitCode, type DeriveFinding, type DeriveResult, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FormatVerdictOptions, type GovernanceEngineOptions, type GovernanceHealth, GuardEngineOptions, GuardEvent, GuardVerdict, type ImpactReport, type ImprovementReport, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NormalizationSummary, 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, type RuleEvaluation, 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, advancePlan, buildPlanCheck, createGovernanceEngine, deriveWorld, describeActiveWorld, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluatePlan, eventToAllowlistKey, explainWorld, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, validateWorld, verdictToAuditEvent };
|