@neuroverseos/governance 0.1.5 → 0.2.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.
Files changed (82) hide show
  1. package/README.md +279 -423
  2. package/dist/adapters/express.cjs +242 -2
  3. package/dist/adapters/express.d.cts +1 -1
  4. package/dist/adapters/express.d.ts +1 -1
  5. package/dist/adapters/express.js +5 -3
  6. package/dist/adapters/index.cjs +301 -5
  7. package/dist/adapters/index.d.cts +1 -1
  8. package/dist/adapters/index.d.ts +1 -1
  9. package/dist/adapters/index.js +8 -6
  10. package/dist/adapters/langchain.cjs +267 -3
  11. package/dist/adapters/langchain.d.cts +8 -1
  12. package/dist/adapters/langchain.d.ts +8 -1
  13. package/dist/adapters/langchain.js +5 -3
  14. package/dist/adapters/openai.cjs +267 -3
  15. package/dist/adapters/openai.d.cts +8 -1
  16. package/dist/adapters/openai.d.ts +8 -1
  17. package/dist/adapters/openai.js +5 -3
  18. package/dist/adapters/openclaw.cjs +267 -3
  19. package/dist/adapters/openclaw.d.cts +8 -1
  20. package/dist/adapters/openclaw.d.ts +8 -1
  21. package/dist/adapters/openclaw.js +5 -3
  22. package/dist/{bootstrap-H4HHKQ5G.js → bootstrap-GXVDZNF7.js} +2 -1
  23. package/dist/{build-73KAVHEY.js → build-P42YFKQV.js} +34 -3
  24. package/dist/{chunk-FYPYZFV5.js → chunk-2JQJ5U5X.js} +1 -1
  25. package/dist/chunk-37JG24WH.js +161 -0
  26. package/dist/chunk-5EDDNJU6.js +321 -0
  27. package/dist/{chunk-O5OMJMIE.js → chunk-7P3S7MAY.js} +502 -2
  28. package/dist/chunk-A5W4GNQO.js +130 -0
  29. package/dist/{chunk-ITJ3LCPG.js → chunk-ADV7Q2LJ.js} +1 -1
  30. package/dist/chunk-AKW5YVCE.js +96 -0
  31. package/dist/{chunk-EIUHJXBB.js → chunk-GR6DGCZ2.js} +1 -1
  32. package/dist/{chunk-EQXFOKH2.js → chunk-IVPKFJX3.js} +24 -3
  33. package/dist/{chunk-D7BGWV2J.js → chunk-NF5POFCI.js} +5 -3
  34. package/dist/chunk-OT6PXH54.js +61 -0
  35. package/dist/chunk-P74Y66ZV.js +205 -0
  36. package/dist/chunk-PAX2P6ZP.js +601 -0
  37. package/dist/{chunk-B4NF3OLW.js → chunk-PQBJBVSW.js} +56 -2
  38. package/dist/{chunk-T4X42QXC.js → chunk-Q6O7ZLO2.js} +0 -59
  39. package/dist/{chunk-FZQCRGUU.js → chunk-TINSRYXQ.js} +24 -3
  40. package/dist/{chunk-CROPZ75A.js → chunk-UPJNTSVM.js} +24 -3
  41. package/dist/chunk-YZFATT7X.js +9 -0
  42. package/dist/{chunk-Z2S2HIV5.js → chunk-ZL4AHY4X.js} +2 -2
  43. package/dist/cli/neuroverse.cjs +5287 -740
  44. package/dist/cli/neuroverse.js +69 -13
  45. package/dist/cli/plan.cjs +1554 -0
  46. package/dist/cli/plan.d.cts +20 -0
  47. package/dist/cli/plan.d.ts +20 -0
  48. package/dist/cli/plan.js +346 -0
  49. package/dist/cli/run.cjs +1716 -0
  50. package/dist/cli/run.d.cts +20 -0
  51. package/dist/cli/run.d.ts +20 -0
  52. package/dist/cli/run.js +143 -0
  53. package/dist/{configure-ai-46JVG56I.js → configure-ai-TK67ZWZL.js} +5 -2
  54. package/dist/{derive-6NAEWLM5.js → derive-TLIV4OOU.js} +6 -4
  55. package/dist/doctor-V72UM2TC.js +170 -0
  56. package/dist/{explain-3B3VB6TL.js → explain-IDCRWMPX.js} +2 -1
  57. package/dist/{guard-67Y66P3I.js → guard-WA3FCCIO.js} +20 -6
  58. package/dist/{guard-contract-D_RQz9kt.d.ts → guard-contract-D-2LQInm.d.cts} +144 -2
  59. package/dist/{guard-contract-D_RQz9kt.d.cts → guard-contract-D-2LQInm.d.ts} +144 -2
  60. package/dist/guard-engine-D7X4CVAE.js +10 -0
  61. package/dist/{impact-CHERK3O6.js → impact-BWULZ5RP.js} +5 -3
  62. package/dist/{improve-YG6I6ERG.js → improve-GPUBKTEA.js} +4 -3
  63. package/dist/index.cjs +2095 -89
  64. package/dist/index.d.cts +466 -12
  65. package/dist/index.d.ts +466 -12
  66. package/dist/index.js +70 -20
  67. package/dist/{init-Z66T6TDI.js → init-PKPIYHYE.js} +2 -0
  68. package/dist/mcp-server-YUOQP4M5.js +13 -0
  69. package/dist/model-adapter-BB7G4MFI.js +11 -0
  70. package/dist/playground-CBXMAW2B.js +550 -0
  71. package/dist/redteam-SSNABQ7W.js +357 -0
  72. package/dist/session-MWRBTCYX.js +14 -0
  73. package/dist/{simulate-ETHHINZ4.js → simulate-VDOYQFRO.js} +2 -1
  74. package/dist/test-3GZSG5FR.js +217 -0
  75. package/dist/{trace-3YODSSIP.js → trace-TM4Z7G73.js} +4 -2
  76. package/dist/{validate-UVE6GKQU.js → validate-LLBWVPGV.js} +15 -6
  77. package/dist/validate-engine-UIABSIHD.js +7 -0
  78. package/dist/{world-WLNHL5XC.js → world-LAXO6DOX.js} +87 -7
  79. package/dist/world-loader-HMPTOEA2.js +9 -0
  80. package/package.json +19 -5
  81. package/dist/validate-engine-657D75OG.js +0 -6
  82. /package/dist/{chunk-M3TZFGHO.js → chunk-JZPQGIKR.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, G as GuardVerdict, V as ViabilityStatus } from './guard-contract-D_RQz9kt.js';
2
- export { E as EvaluationTrace, c as GUARD_EXIT_CODES, d as GuardCheck, e as GuardExitCode, f as GuardStatus, I as InvariantCheck, K as KernelRuleCheck, L as LevelCheck, P as PrecedenceResolution, R as RoleCheck, S as SafetyCheck, g as VerdictEvidence } from './guard-contract-D_RQz9kt.js';
1
+ import { a as GuardEvent, W as WorldDefinition, c as GuardEngineOptions, G as GuardVerdict, P as PlanDefinition, d as PlanVerdict, e as PlanCheck, b as PlanProgress, V as ViabilityStatus } from './guard-contract-D-2LQInm.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 PlanConstraint, l as PlanExitCode, m as PlanStatus, n as PlanStep, o as PrecedenceResolution, R as RoleCheck, S as SafetyCheck, p as VerdictEvidence } from './guard-contract-D-2LQInm.js';
3
3
 
4
4
  /**
5
5
  * Guard Engine — Deterministic Governance Evaluator
@@ -10,12 +10,13 @@ export { E as EvaluationTrace, c as GUARD_EXIT_CODES, d as GuardCheck, e as Guar
10
10
  * a GuardVerdict with evidence and optional evaluation trace.
11
11
  *
12
12
  * Evaluation chain (first-match-wins on BLOCK/PAUSE):
13
- * 1. Safety checks (prompt injection, scope escape) → PAUSE
14
- * 2. Role-specific rules (cannotDo, requiresApproval) → BLOCK/PAUSE
15
- * 3. Declarative guards (guards.json) → BLOCK/PAUSE/WARN
16
- * 4. Kernel rules (kernel.json forbidden patterns) → BLOCK
17
- * 5. Level constraints (basic/standard/strict) PAUSE
18
- * 6. Default ALLOW
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
19
20
  *
20
21
  * Invariant checks run unconditionally and are recorded in evidence
21
22
  * but do not produce verdicts — they measure world health.
@@ -49,6 +50,363 @@ declare function evaluateGuard(event: GuardEvent, world: WorldDefinition, option
49
50
  */
50
51
  declare function eventToAllowlistKey(event: GuardEvent): string;
51
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, 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
+ declare function advancePlan(plan: PlanDefinition, stepId: string): PlanDefinition;
125
+ /**
126
+ * Evaluate an event against a plan.
127
+ *
128
+ * Returns a PlanVerdict indicating whether the action is on-plan,
129
+ * off-plan, violates constraints, or the plan is complete.
130
+ */
131
+ declare function evaluatePlan(event: GuardEvent, plan: PlanDefinition): PlanVerdict;
132
+ /**
133
+ * Build a PlanCheck for inclusion in the guard engine's EvaluationTrace.
134
+ */
135
+ declare function buildPlanCheck(event: GuardEvent, plan: PlanDefinition, verdict: PlanVerdict): PlanCheck;
136
+
137
+ /**
138
+ * Model Adapter — Minimal LLM Connection Layer
139
+ *
140
+ * Connects to any OpenAI-compatible API (OpenAI, Anthropic, Ollama, etc.)
141
+ * using Node's built-in fetch. Zero dependencies.
142
+ *
143
+ * The adapter does exactly two things:
144
+ * 1. Send messages to the model
145
+ * 2. Receive responses (text + tool calls)
146
+ *
147
+ * No orchestration, no memory management, no retries.
148
+ * The session manager handles all of that.
149
+ */
150
+ interface ModelConfig {
151
+ /** API base URL (e.g., "https://api.openai.com/v1") */
152
+ baseUrl: string;
153
+ /** API key for authentication */
154
+ apiKey: string;
155
+ /** Model identifier (e.g., "gpt-4o", "claude-sonnet-4-20250514") */
156
+ model: string;
157
+ /** System prompt prepended to all conversations */
158
+ systemPrompt?: string;
159
+ /** Max tokens for response. Default: 4096. */
160
+ maxTokens?: number;
161
+ }
162
+ interface ToolDefinition {
163
+ type: 'function';
164
+ function: {
165
+ name: string;
166
+ description: string;
167
+ parameters: Record<string, unknown>;
168
+ };
169
+ }
170
+ interface ChatMessage {
171
+ role: 'system' | 'user' | 'assistant' | 'tool';
172
+ content: string | null;
173
+ tool_calls?: ToolCall[];
174
+ tool_call_id?: string;
175
+ }
176
+ interface ToolCall {
177
+ id: string;
178
+ type: 'function';
179
+ function: {
180
+ name: string;
181
+ arguments: string;
182
+ };
183
+ }
184
+ interface ModelResponse {
185
+ content: string | null;
186
+ toolCalls: ToolCall[];
187
+ finishReason: string;
188
+ }
189
+ declare class ModelAdapter {
190
+ private config;
191
+ private messages;
192
+ private tools;
193
+ constructor(config: ModelConfig, tools?: ToolDefinition[]);
194
+ /**
195
+ * Send a user message and get the model's response.
196
+ */
197
+ chat(userMessage: string): Promise<ModelResponse>;
198
+ /**
199
+ * Send a tool result back to the model and get the next response.
200
+ */
201
+ sendToolResult(toolCallId: string, result: string): Promise<ModelResponse>;
202
+ /**
203
+ * Send a governance block message as a tool result.
204
+ */
205
+ sendBlockedResult(toolCallId: string, reason: string): Promise<ModelResponse>;
206
+ /**
207
+ * Call the model API and parse the response.
208
+ */
209
+ private complete;
210
+ /** Get current message count (for context tracking). */
211
+ get messageCount(): number;
212
+ }
213
+ interface ProviderPreset {
214
+ baseUrl: string;
215
+ defaultModel: string;
216
+ envVar: string;
217
+ }
218
+ declare const PROVIDERS: Record<string, ProviderPreset>;
219
+ /**
220
+ * Resolve a provider name to a ModelConfig.
221
+ * Reads API key from environment variable.
222
+ */
223
+ declare function resolveProvider(provider: string, overrides?: Partial<ModelConfig>): ModelConfig;
224
+
225
+ /**
226
+ * Session Manager — Governed Runtime Session
227
+ *
228
+ * Orchestrates a governed AI session:
229
+ * 1. Load world + plan
230
+ * 2. Connect to model
231
+ * 3. Intercept tool calls
232
+ * 4. Evaluate with guard engine
233
+ * 5. Execute or block
234
+ * 6. Track plan progress
235
+ *
236
+ * The session manager is thin orchestration, not a framework.
237
+ * All intelligence lives in the guard engine and plan engine.
238
+ */
239
+
240
+ interface SessionConfig {
241
+ /** Path to world directory. */
242
+ worldPath?: string;
243
+ /** Pre-loaded world definition (alternative to worldPath). */
244
+ world?: WorldDefinition;
245
+ /** Plan definition (pre-loaded). */
246
+ plan?: PlanDefinition;
247
+ /** Enforcement level override. */
248
+ level?: 'basic' | 'standard' | 'strict';
249
+ /** Include trace in verdicts. */
250
+ trace?: boolean;
251
+ /** Called when a verdict is produced. */
252
+ onVerdict?: (verdict: GuardVerdict, event: GuardEvent) => void;
253
+ /** Called when plan progress changes. */
254
+ onPlanProgress?: (progress: PlanProgress) => void;
255
+ /** Called when the plan is complete. */
256
+ onPlanComplete?: () => void;
257
+ /** Called when a tool is executed successfully. */
258
+ onToolResult?: (toolName: string, result: string) => void;
259
+ /** Tool executor — runs the actual tool. */
260
+ toolExecutor?: (name: string, args: Record<string, unknown>) => Promise<string>;
261
+ }
262
+ interface SessionState {
263
+ /** Whether the session is active. */
264
+ active: boolean;
265
+ /** Loaded world. */
266
+ world: WorldDefinition;
267
+ /** Active plan (mutable as steps complete). */
268
+ plan?: PlanDefinition;
269
+ /** Current plan progress. */
270
+ progress?: PlanProgress;
271
+ /** Total actions evaluated. */
272
+ actionsEvaluated: number;
273
+ /** Total actions allowed. */
274
+ actionsAllowed: number;
275
+ /** Total actions blocked. */
276
+ actionsBlocked: number;
277
+ /** Total actions paused. */
278
+ actionsPaused: number;
279
+ }
280
+ declare class SessionManager {
281
+ private config;
282
+ private state;
283
+ private engineOptions;
284
+ private executor;
285
+ constructor(config: SessionConfig);
286
+ /**
287
+ * Initialize the session — load world from disk if needed.
288
+ */
289
+ start(): Promise<SessionState>;
290
+ /**
291
+ * Evaluate a single event against governance.
292
+ * Returns the verdict without executing anything.
293
+ */
294
+ evaluate(event: GuardEvent): GuardVerdict;
295
+ /**
296
+ * Evaluate and execute a tool call.
297
+ * Returns the execution result or block reason.
298
+ */
299
+ executeToolCall(toolCall: ToolCall): Promise<{
300
+ allowed: boolean;
301
+ verdict: GuardVerdict;
302
+ result?: string;
303
+ }>;
304
+ /**
305
+ * Process a model response — evaluate and execute all tool calls.
306
+ * Returns results for each tool call.
307
+ */
308
+ processModelResponse(response: ModelResponse, model: ModelAdapter): Promise<ModelResponse>;
309
+ /** Get current session state. */
310
+ getState(): SessionState;
311
+ /** Stop the session. */
312
+ stop(): SessionState;
313
+ }
314
+ /**
315
+ * Run in pipe mode — read JSON lines from stdin, evaluate each,
316
+ * write verdicts to stdout. Works with any language or framework.
317
+ *
318
+ * Usage:
319
+ * my_agent | neuroverse run --pipe --world ./world/ --plan plan.json
320
+ *
321
+ * Each line of stdin should be a GuardEvent JSON.
322
+ * Each line of stdout will be a GuardVerdict JSON.
323
+ */
324
+ declare function runPipeMode(config: SessionConfig): Promise<void>;
325
+ /**
326
+ * Run an interactive governed chat session.
327
+ *
328
+ * Usage:
329
+ * neuroverse run --world ./world/ --plan plan.json --provider openai
330
+ */
331
+ declare function runInteractiveMode(config: SessionConfig, model: ModelAdapter): Promise<void>;
332
+
333
+ /**
334
+ * NeuroVerse MCP Server — Governance as an MCP Tool Provider
335
+ *
336
+ * Implements the Model Context Protocol (MCP) over stdio.
337
+ * Any MCP-compatible client (Claude Desktop, Cursor, etc.) can
338
+ * connect to this server and get governed tool access.
339
+ *
340
+ * Architecture:
341
+ * MCP Client (Claude, Cursor, etc.)
342
+ * ↓ stdio (JSON-RPC)
343
+ * NeuroVerse MCP Server
344
+ * ↓ evaluateGuard()
345
+ * Tool Execution (shell, http, file, etc.)
346
+ *
347
+ * The server exposes governance-wrapped tools. Every tool call
348
+ * passes through the guard engine before execution. Blocked
349
+ * actions return the governance reason to the model.
350
+ *
351
+ * MCP Protocol: JSON-RPC 2.0 over stdio
352
+ * - initialize → capabilities
353
+ * - tools/list → available tools
354
+ * - tools/call → evaluate + execute
355
+ */
356
+
357
+ interface McpServerConfig {
358
+ /** Path to world directory. */
359
+ worldPath?: string;
360
+ /** Pre-loaded world. */
361
+ world?: WorldDefinition;
362
+ /** Active plan. */
363
+ plan?: PlanDefinition;
364
+ /** Path to plan.json (loaded on start). */
365
+ planPath?: string;
366
+ /** Enforcement level. */
367
+ level?: 'basic' | 'standard' | 'strict';
368
+ /** Include trace in verdicts. */
369
+ trace?: boolean;
370
+ /** Enable shell tool. Default: true. */
371
+ enableShell?: boolean;
372
+ /** Enable file tools. Default: true. */
373
+ enableFiles?: boolean;
374
+ /** Enable HTTP tool. Default: true. */
375
+ enableHttp?: boolean;
376
+ /** Working directory for file/shell operations. */
377
+ workingDir?: string;
378
+ }
379
+ declare class McpGovernanceServer {
380
+ private world;
381
+ private plan?;
382
+ private config;
383
+ private engineOptions;
384
+ private initialized;
385
+ private actionsEvaluated;
386
+ private actionsAllowed;
387
+ private actionsBlocked;
388
+ constructor(config: McpServerConfig);
389
+ /**
390
+ * Start the MCP server — reads JSON-RPC from stdin, writes to stdout.
391
+ */
392
+ start(): Promise<void>;
393
+ private handleRawLine;
394
+ private send;
395
+ private sendResult;
396
+ private sendError;
397
+ private handleRequest;
398
+ private handleNotification;
399
+ private handleInitialize;
400
+ private handleToolsList;
401
+ private handleToolsCall;
402
+ private executeTool;
403
+ private buildEvent;
404
+ private executeActualTool;
405
+ private toolGovernanceCheck;
406
+ private toolPlanStatus;
407
+ private toolPlanAdvance;
408
+ }
409
+
52
410
  /**
53
411
  * Audit Logger — Runtime Governance Telemetry
54
412
  *
@@ -375,6 +733,54 @@ declare function loadWorldFromDirectory(dirPath: string): Promise<WorldDefinitio
375
733
  */
376
734
  declare function loadWorld(worldPath: string): Promise<WorldDefinition>;
377
735
 
736
+ /**
737
+ * World Resolver — Resolve world names to paths
738
+ *
739
+ * Resolution order:
740
+ * 1. Explicit path (absolute or relative) → use directly
741
+ * 2. NEUROVERSE_WORLD env var → resolve as name or path
742
+ * 3. .neuroverse/active_world file → read world name
743
+ * 4. Auto-detect if only one world exists in .neuroverse/worlds/
744
+ *
745
+ * World name resolution:
746
+ * "marketing" → .neuroverse/worlds/marketing/
747
+ * "./my-world/" → use as-is
748
+ * "/absolute/path" → use as-is
749
+ */
750
+ interface WorldInfo {
751
+ name: string;
752
+ path: string;
753
+ active: boolean;
754
+ }
755
+ /**
756
+ * List all compiled worlds in .neuroverse/worlds/
757
+ */
758
+ declare function listWorlds(cwd?: string): WorldInfo[];
759
+ /**
760
+ * Get the active world name from .neuroverse/active_world
761
+ */
762
+ declare function getActiveWorldName(cwd?: string): string | undefined;
763
+ /**
764
+ * Set the active world by writing .neuroverse/active_world
765
+ */
766
+ declare function setActiveWorld(name: string, cwd?: string): void;
767
+ /**
768
+ * Resolve a world reference to an absolute path.
769
+ *
770
+ * @param explicit - Value from --world flag (may be undefined)
771
+ * @param cwd - Working directory for relative resolution
772
+ * @returns Resolved absolute path to the world directory
773
+ */
774
+ declare function resolveWorldPath(explicit?: string, cwd?: string): string | undefined;
775
+ /**
776
+ * Describe how the current world was resolved (for "Using world:" messages).
777
+ * Returns { name, source } or undefined if no world is active.
778
+ */
779
+ declare function describeActiveWorld(explicit?: string, cwd?: string): {
780
+ name: string;
781
+ source: string;
782
+ } | undefined;
783
+
378
784
  /**
379
785
  * Condition Engine — Structured operator evaluation
380
786
  *
@@ -427,6 +833,18 @@ declare function evaluateCondition(condition: Condition, event: GuardEvent): Con
427
833
  * - Zero network calls.
428
834
  * - Every finding includes the source block and a human-readable message.
429
835
  */
836
+ /**
837
+ * Controls the strictness of governance validation.
838
+ *
839
+ * - `dev`: Lenient — governance findings are downgraded to info. Build always succeeds.
840
+ * - `standard`: Recommended default — governance findings are warnings. Build always succeeds.
841
+ * - `strict`: Compliance — governance findings stay as warnings but are flagged for attention.
842
+ * Build still succeeds (worlds always work) but the report highlights all gaps.
843
+ *
844
+ * Structural issues (missing blocks, broken references, schema violations) are
845
+ * always reported at their natural severity regardless of mode.
846
+ */
847
+ type ValidationMode = 'dev' | 'standard' | 'strict';
430
848
  type FindingSeverity = 'error' | 'warning' | 'info';
431
849
  type FindingCategory = 'completeness' | 'referential-integrity' | 'guard-coverage' | 'contradiction' | 'orphan' | 'schema-violation' | 'semantic-tension';
432
850
  /**
@@ -464,6 +882,35 @@ interface ValidateSummary {
464
882
  canRun: boolean;
465
883
  /** Whether the world passes full validation (no errors) */
466
884
  isHealthy: boolean;
885
+ /** Governance health — actionable summary of coverage gaps */
886
+ governanceHealth?: GovernanceHealth;
887
+ }
888
+ /**
889
+ * Actionable governance health summary.
890
+ * Provides at-a-glance understanding of how well-governed a world is.
891
+ */
892
+ interface GovernanceHealth {
893
+ /** How many declared action surfaces are governed vs total */
894
+ surfacesCovered: number;
895
+ surfacesTotal: number;
896
+ /** Individual surface governance status */
897
+ surfaces: Array<{
898
+ name: string;
899
+ governed: boolean;
900
+ }>;
901
+ /** How many structural invariants are enforced vs total */
902
+ invariantsEnforced: number;
903
+ invariantsTotal: number;
904
+ /** Number of shadowed guards detected */
905
+ shadowedGuards: number;
906
+ /** Number of unenforced invariants */
907
+ unenforcedInvariants: number;
908
+ /** Number of unreachable rules/gates (dead policy logic) */
909
+ unreachableRules: number;
910
+ /** Number of enum variables with incomplete state coverage */
911
+ incompleteStateCoverage: number;
912
+ /** Overall risk level */
913
+ riskLevel: 'low' | 'moderate' | 'high';
467
914
  }
468
915
  /**
469
916
  * The validate report — what goes to stdout.
@@ -485,6 +932,8 @@ interface ValidateReport {
485
932
  durationMs: number;
486
933
  /** High-level summary */
487
934
  summary: ValidateSummary;
935
+ /** Validation mode used */
936
+ validationMode: ValidationMode;
488
937
  /** All findings, ordered by severity (errors first) */
489
938
  findings: ValidateFinding[];
490
939
  }
@@ -505,9 +954,14 @@ type ValidateExitCode = (typeof VALIDATE_EXIT_CODES)[keyof typeof VALIDATE_EXIT_
505
954
  * 1. Completeness — are required blocks present and non-empty?
506
955
  * 2. Referential integrity — do rules reference declared variables?
507
956
  * 3. Guard coverage — do invariants have backing structural guards?
957
+ * 3b. Semantic coverage — can any guard actually intercept the invariant's action class?
508
958
  * 4. Contradiction detection — do rules conflict?
509
- * 5. Orphan detection — unused variables, unreachable rules
510
- * 6. Schema validationvalues within declared ranges
959
+ * 5. Guard shadow detection — do guards shadow or conflict with each other?
960
+ * 5b. Fail-closed surface detection are action surfaces ungoverned?
961
+ * 6. Reachability analysis — are there rules/guards that can never trigger?
962
+ * 7. State space coverage — do guard conditions cover all enumerated states?
963
+ * 8. Orphan detection — unused variables, unreachable rules
964
+ * 9. Schema validation — values within declared ranges
511
965
  *
512
966
  * INVARIANTS:
513
967
  * - Deterministic: same world → same report, always.
@@ -520,7 +974,7 @@ type ValidateExitCode = (typeof VALIDATE_EXIT_CODES)[keyof typeof VALIDATE_EXIT_
520
974
  *
521
975
  * This is the entire validate engine. One function. Deterministic.
522
976
  */
523
- declare function validateWorld(world: WorldDefinition): ValidateReport;
977
+ declare function validateWorld(world: WorldDefinition, mode?: ValidationMode): ValidateReport;
524
978
 
525
979
  /**
526
980
  * Bootstrap Contract — Markdown → WorldDefinition Compilation Types
@@ -1144,4 +1598,4 @@ interface ImprovementReport {
1144
1598
  declare function improveWorld(world: WorldDefinition): ImprovementReport;
1145
1599
  declare function renderImproveText(report: ImprovementReport): string;
1146
1600
 
1147
- export { type AIProvider, type AIProviderConfig, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, 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, GuardEngineOptions, GuardEvent, GuardVerdict, type ImpactReport, type ImprovementReport, type NormalizationSummary, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, type PreventionCategory, type RuleEvaluation, type SimulateOptions, type SimulationResult, type SimulationStep, type Suggestion, type SuggestionCategory, type SuggestionPriority, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, createGovernanceEngine, deriveWorld, emitWorldDefinition, evaluateCondition, evaluateGuard, eventToAllowlistKey, explainWorld, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateImpactReport, generateImpactReportFromFile, improveWorld, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseWorldMarkdown, readAuditLog, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, simulateWorld, summarizeAuditEvents, validateWorld, verdictToAuditEvent };
1601
+ export { type AIProvider, type AIProviderConfig, 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, 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 };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  generateImpactReport,
3
3
  generateImpactReportFromFile,
4
4
  renderImpactReport
5
- } from "./chunk-ITJ3LCPG.js";
5
+ } from "./chunk-ADV7Q2LJ.js";
6
6
  import {
7
7
  CompositeAuditLogger,
8
8
  ConsoleAuditLogger,
@@ -11,16 +11,7 @@ import {
11
11
  readAuditLog,
12
12
  summarizeAuditEvents,
13
13
  verdictToAuditEvent
14
- } from "./chunk-FYPYZFV5.js";
15
- import {
16
- deriveWorld,
17
- extractWorldMarkdown,
18
- normalizeWorldMarkdown
19
- } from "./chunk-D7BGWV2J.js";
20
- import {
21
- CONFIGURE_AI_EXIT_CODES,
22
- DERIVE_EXIT_CODES
23
- } from "./chunk-T4X42QXC.js";
14
+ } from "./chunk-2JQJ5U5X.js";
24
15
  import {
25
16
  explainWorld,
26
17
  renderExplainText
@@ -28,7 +19,7 @@ import {
28
19
  import {
29
20
  improveWorld,
30
21
  renderImproveText
31
- } from "./chunk-EIUHJXBB.js";
22
+ } from "./chunk-GR6DGCZ2.js";
32
23
  import {
33
24
  renderSimulateText,
34
25
  simulateWorld
@@ -36,27 +27,68 @@ import {
36
27
  import {
37
28
  BOOTSTRAP_EXIT_CODES
38
29
  } from "./chunk-4NGDRRQH.js";
39
- import {
40
- emitWorldDefinition,
41
- parseWorldMarkdown
42
- } from "./chunk-XPDMYECO.js";
43
30
  import {
44
31
  VALIDATE_EXIT_CODES
45
32
  } from "./chunk-I3RRAYK2.js";
46
33
  import {
47
34
  GUARD_EXIT_CODES
48
35
  } from "./chunk-MWDQ4MJB.js";
36
+ import {
37
+ SessionManager,
38
+ runInteractiveMode,
39
+ runPipeMode
40
+ } from "./chunk-5EDDNJU6.js";
41
+ import {
42
+ ModelAdapter,
43
+ PROVIDERS,
44
+ resolveProvider
45
+ } from "./chunk-A5W4GNQO.js";
46
+ import {
47
+ McpGovernanceServer
48
+ } from "./chunk-PAX2P6ZP.js";
49
+ import {
50
+ describeActiveWorld,
51
+ getActiveWorldName,
52
+ listWorlds,
53
+ resolveWorldPath,
54
+ setActiveWorld
55
+ } from "./chunk-AKW5YVCE.js";
56
+ import {
57
+ deriveWorld,
58
+ extractWorldMarkdown,
59
+ normalizeWorldMarkdown
60
+ } from "./chunk-NF5POFCI.js";
61
+ import {
62
+ CONFIGURE_AI_EXIT_CODES,
63
+ DERIVE_EXIT_CODES
64
+ } from "./chunk-Q6O7ZLO2.js";
65
+ import "./chunk-OT6PXH54.js";
66
+ import {
67
+ emitWorldDefinition,
68
+ parseWorldMarkdown
69
+ } from "./chunk-XPDMYECO.js";
70
+ import {
71
+ validateWorld
72
+ } from "./chunk-7P3S7MAY.js";
49
73
  import {
50
74
  evaluateGuard,
51
75
  eventToAllowlistKey
52
- } from "./chunk-B4NF3OLW.js";
76
+ } from "./chunk-PQBJBVSW.js";
53
77
  import {
54
78
  loadWorld,
55
79
  loadWorldFromDirectory
56
- } from "./chunk-M3TZFGHO.js";
80
+ } from "./chunk-JZPQGIKR.js";
57
81
  import {
58
- validateWorld
59
- } from "./chunk-O5OMJMIE.js";
82
+ PLAN_EXIT_CODES,
83
+ parsePlanMarkdown
84
+ } from "./chunk-37JG24WH.js";
85
+ import {
86
+ advancePlan,
87
+ buildPlanCheck,
88
+ evaluatePlan,
89
+ getPlanProgress
90
+ } from "./chunk-P74Y66ZV.js";
91
+ import "./chunk-YZFATT7X.js";
60
92
 
61
93
  // src/engine/verdict-formatter.ts
62
94
  var ANSI = {
@@ -299,12 +331,21 @@ export {
299
331
  DERIVE_EXIT_CODES,
300
332
  FileAuditLogger,
301
333
  GUARD_EXIT_CODES,
334
+ McpGovernanceServer,
335
+ ModelAdapter,
336
+ PLAN_EXIT_CODES,
337
+ PROVIDERS,
338
+ SessionManager,
302
339
  VALIDATE_EXIT_CODES,
340
+ advancePlan,
341
+ buildPlanCheck,
303
342
  createGovernanceEngine,
304
343
  deriveWorld,
344
+ describeActiveWorld,
305
345
  emitWorldDefinition,
306
346
  evaluateCondition,
307
347
  evaluateGuard,
348
+ evaluatePlan,
308
349
  eventToAllowlistKey,
309
350
  explainWorld,
310
351
  extractWorldMarkdown,
@@ -312,16 +353,25 @@ export {
312
353
  formatVerdictOneLine,
313
354
  generateImpactReport,
314
355
  generateImpactReportFromFile,
356
+ getActiveWorldName,
357
+ getPlanProgress,
315
358
  improveWorld,
359
+ listWorlds,
316
360
  loadWorld,
317
361
  loadWorldFromDirectory,
318
362
  normalizeWorldMarkdown,
363
+ parsePlanMarkdown,
319
364
  parseWorldMarkdown,
320
365
  readAuditLog,
321
366
  renderExplainText,
322
367
  renderImpactReport,
323
368
  renderImproveText,
324
369
  renderSimulateText,
370
+ resolveProvider,
371
+ resolveWorldPath,
372
+ runInteractiveMode,
373
+ runPipeMode,
374
+ setActiveWorld,
325
375
  simulateWorld,
326
376
  summarizeAuditEvents,
327
377
  validateWorld,