@neuroverseos/governance 0.1.0 → 0.1.2
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/LICENSE.md +190 -0
- package/README.md +472 -115
- package/dist/adapters/express.cjs +874 -0
- package/dist/adapters/express.d.cts +66 -0
- package/dist/adapters/express.d.ts +66 -0
- package/dist/adapters/express.js +10 -0
- package/dist/adapters/index.cjs +1166 -0
- package/dist/adapters/index.d.cts +5 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +40 -0
- package/dist/adapters/langchain.cjs +861 -0
- package/dist/adapters/langchain.d.cts +82 -0
- package/dist/adapters/langchain.d.ts +82 -0
- package/dist/adapters/langchain.js +14 -0
- package/dist/adapters/openai.cjs +891 -0
- package/dist/adapters/openai.d.cts +92 -0
- package/dist/adapters/openai.d.ts +92 -0
- package/dist/adapters/openai.js +14 -0
- package/dist/adapters/openclaw.cjs +883 -0
- package/dist/adapters/openclaw.d.cts +92 -0
- package/dist/adapters/openclaw.d.ts +92 -0
- package/dist/adapters/openclaw.js +14 -0
- package/dist/bootstrap-H4HHKQ5G.js +113 -0
- package/dist/build-73KAVHEY.js +308 -0
- package/dist/chunk-4NGDRRQH.js +10 -0
- package/dist/chunk-B4NF3OLW.js +673 -0
- package/dist/chunk-BUWWN2NX.js +192 -0
- package/dist/chunk-CROPZ75A.js +107 -0
- package/dist/chunk-D7BGWV2J.js +620 -0
- package/dist/chunk-EIUHJXBB.js +340 -0
- package/dist/chunk-EQXFOKH2.js +85 -0
- package/dist/chunk-FYPYZFV5.js +187 -0
- package/dist/chunk-FYS2CBUW.js +304 -0
- package/dist/chunk-FZQCRGUU.js +115 -0
- package/dist/chunk-I3RRAYK2.js +11 -0
- package/dist/chunk-ITJ3LCPG.js +225 -0
- package/dist/chunk-M3TZFGHO.js +79 -0
- package/dist/chunk-MWDQ4MJB.js +11 -0
- package/dist/chunk-O5OMJMIE.js +590 -0
- package/dist/chunk-T4X42QXC.js +121 -0
- package/dist/chunk-XPDMYECO.js +642 -0
- package/dist/chunk-Z2S2HIV5.js +100 -0
- package/dist/cli/neuroverse.cjs +5864 -0
- package/dist/cli/neuroverse.d.cts +1 -0
- package/dist/cli/neuroverse.d.ts +1 -0
- package/dist/cli/neuroverse.js +128 -0
- package/dist/configure-ai-46JVG56I.js +129 -0
- package/dist/derive-6NAEWLM5.js +150 -0
- package/dist/explain-3B3VB6TL.js +69 -0
- package/dist/guard-67Y66P3I.js +82 -0
- package/dist/guard-contract-D_RQz9kt.d.cts +529 -0
- package/dist/guard-contract-D_RQz9kt.d.ts +529 -0
- package/dist/impact-CHERK3O6.js +57 -0
- package/dist/improve-YG6I6ERG.js +84 -0
- package/dist/index.cjs +4227 -0
- package/dist/index.d.cts +1147 -0
- package/dist/index.d.ts +1139 -25
- package/dist/index.js +318 -1159
- package/dist/init-Z66T6TDI.js +142 -0
- package/dist/simulate-ETHHINZ4.js +107 -0
- package/dist/trace-3YODSSIP.js +164 -0
- package/dist/validate-UVE6GKQU.js +72 -0
- package/dist/validate-engine-657D75OG.js +6 -0
- package/dist/world-WLNHL5XC.js +298 -0
- package/dist/worlds/derivation-world.nv-world.md +278 -0
- package/package.json +74 -26
- package/LICENSE +0 -21
- package/dist/audit-logger.d.ts +0 -38
- package/dist/audit-logger.d.ts.map +0 -1
- package/dist/audit-logger.js +0 -100
- package/dist/audit-logger.js.map +0 -1
- package/dist/condition-engine.d.ts +0 -16
- package/dist/condition-engine.d.ts.map +0 -1
- package/dist/condition-engine.js +0 -186
- package/dist/condition-engine.js.map +0 -1
- package/dist/drift-monitor.d.ts +0 -81
- package/dist/drift-monitor.d.ts.map +0 -1
- package/dist/drift-monitor.js +0 -228
- package/dist/drift-monitor.js.map +0 -1
- package/dist/governance-engine.d.ts +0 -131
- package/dist/governance-engine.d.ts.map +0 -1
- package/dist/governance-engine.js +0 -660
- package/dist/governance-engine.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -196
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -9
- package/dist/types.js.map +0 -1
- package/dist/world-bootstrap.d.ts +0 -31
- package/dist/world-bootstrap.d.ts.map +0 -1
- package/dist/world-bootstrap.js +0 -415
- package/dist/world-bootstrap.js.map +0 -1
- package/openclaw.plugin.json +0 -59
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* World Engine Types — Subset for Governance Engine
|
|
3
|
+
*
|
|
4
|
+
* These types map to the .nv-world.zip file format.
|
|
5
|
+
* This file contains only the types referenced by the governance
|
|
6
|
+
* engine (guard, validate, bootstrap). The full type system lives
|
|
7
|
+
* in the main NeuroVerse OS repo.
|
|
8
|
+
*/
|
|
9
|
+
interface ModelIdentity {
|
|
10
|
+
modelName: string;
|
|
11
|
+
acronymExpansion?: string;
|
|
12
|
+
nameType: 'acronym' | 'metaphor';
|
|
13
|
+
purpose: string;
|
|
14
|
+
domain?: string;
|
|
15
|
+
}
|
|
16
|
+
interface WorldIdentity {
|
|
17
|
+
world_id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
thesis: string;
|
|
20
|
+
version: string;
|
|
21
|
+
runtime_mode: 'SIMULATION' | 'NARRATIVE' | 'COMPLIANCE' | 'CUSTOM';
|
|
22
|
+
default_assumption_profile: string;
|
|
23
|
+
default_alternative_profile: string;
|
|
24
|
+
modules: string[];
|
|
25
|
+
players: {
|
|
26
|
+
thinking_space: boolean;
|
|
27
|
+
experience_space: boolean;
|
|
28
|
+
action_space: boolean;
|
|
29
|
+
};
|
|
30
|
+
modelIdentity?: ModelIdentity;
|
|
31
|
+
}
|
|
32
|
+
interface Invariant {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
enforcement: 'structural' | 'prompt';
|
|
36
|
+
mutable: false;
|
|
37
|
+
}
|
|
38
|
+
interface AssumptionProfile {
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
is_default_baseline?: boolean;
|
|
42
|
+
is_default_alternative?: boolean;
|
|
43
|
+
parameters: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
interface ParameterDefinition {
|
|
46
|
+
type: 'enum' | 'number' | 'boolean';
|
|
47
|
+
options?: string[];
|
|
48
|
+
min?: number;
|
|
49
|
+
max?: number;
|
|
50
|
+
label: string;
|
|
51
|
+
description: string;
|
|
52
|
+
}
|
|
53
|
+
interface AssumptionConfig {
|
|
54
|
+
profiles: Record<string, AssumptionProfile>;
|
|
55
|
+
parameter_definitions: Record<string, ParameterDefinition>;
|
|
56
|
+
}
|
|
57
|
+
interface StateVariable {
|
|
58
|
+
type: 'enum' | 'number' | 'boolean';
|
|
59
|
+
options?: string[];
|
|
60
|
+
min?: number;
|
|
61
|
+
max?: number;
|
|
62
|
+
step?: number;
|
|
63
|
+
default: string | number | boolean;
|
|
64
|
+
mutable: boolean;
|
|
65
|
+
label: string;
|
|
66
|
+
description: string;
|
|
67
|
+
display_as?: 'percentage' | 'integer' | 'decimal';
|
|
68
|
+
}
|
|
69
|
+
interface StatePreset {
|
|
70
|
+
description: string;
|
|
71
|
+
values: Record<string, string | number | boolean>;
|
|
72
|
+
}
|
|
73
|
+
interface StateSchema {
|
|
74
|
+
variables: Record<string, StateVariable>;
|
|
75
|
+
presets: Record<string, StatePreset>;
|
|
76
|
+
}
|
|
77
|
+
type TriggerOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | 'in';
|
|
78
|
+
type EffectOperation = 'multiply' | 'add' | 'subtract' | 'set' | 'set_boolean' | 'multiply_dynamic' | 'add_dynamic' | 'subtract_dynamic' | 'set_dynamic';
|
|
79
|
+
type RuleSeverity = 'structural' | 'degradation' | 'advantage';
|
|
80
|
+
interface Trigger {
|
|
81
|
+
field: string;
|
|
82
|
+
operator: TriggerOperator;
|
|
83
|
+
value: string | number | boolean | string[];
|
|
84
|
+
source: 'state' | 'assumption';
|
|
85
|
+
}
|
|
86
|
+
interface Effect {
|
|
87
|
+
target: string;
|
|
88
|
+
operation: EffectOperation;
|
|
89
|
+
value: number | boolean | string;
|
|
90
|
+
value_formula?: string;
|
|
91
|
+
}
|
|
92
|
+
interface CollapseCheck {
|
|
93
|
+
field: string;
|
|
94
|
+
operator: TriggerOperator;
|
|
95
|
+
value: number;
|
|
96
|
+
result: 'MODEL_COLLAPSES';
|
|
97
|
+
}
|
|
98
|
+
interface ConditionalEffect {
|
|
99
|
+
condition: Trigger;
|
|
100
|
+
and?: Trigger;
|
|
101
|
+
or?: Trigger;
|
|
102
|
+
condition_any?: Trigger[];
|
|
103
|
+
effects: Effect[];
|
|
104
|
+
}
|
|
105
|
+
interface CausalTranslation {
|
|
106
|
+
trigger_text: string;
|
|
107
|
+
rule_text: string;
|
|
108
|
+
shift_text: string;
|
|
109
|
+
effect_text: string;
|
|
110
|
+
}
|
|
111
|
+
interface RuleRedirect {
|
|
112
|
+
suggested_action: string;
|
|
113
|
+
reason: string;
|
|
114
|
+
fallback_state_changes?: Record<string, string | number | boolean>;
|
|
115
|
+
}
|
|
116
|
+
interface Rule {
|
|
117
|
+
id: string;
|
|
118
|
+
severity: RuleSeverity;
|
|
119
|
+
label: string;
|
|
120
|
+
description: string;
|
|
121
|
+
order: number;
|
|
122
|
+
triggers: Trigger[];
|
|
123
|
+
effects?: Effect[];
|
|
124
|
+
effects_conditional?: ConditionalEffect[];
|
|
125
|
+
collapse_check?: CollapseCheck;
|
|
126
|
+
secondary_check?: CollapseCheck;
|
|
127
|
+
exclusive_with?: string;
|
|
128
|
+
causal_translation: CausalTranslation;
|
|
129
|
+
redirect?: RuleRedirect;
|
|
130
|
+
}
|
|
131
|
+
type ViabilityStatus = 'THRIVING' | 'STABLE' | 'COMPRESSED' | 'CRITICAL' | 'MODEL_COLLAPSES';
|
|
132
|
+
interface ViabilityGate {
|
|
133
|
+
status: ViabilityStatus;
|
|
134
|
+
field: string;
|
|
135
|
+
operator: TriggerOperator;
|
|
136
|
+
value: number;
|
|
137
|
+
color: string;
|
|
138
|
+
icon: string;
|
|
139
|
+
}
|
|
140
|
+
interface CollapseVisual {
|
|
141
|
+
background: string;
|
|
142
|
+
text: string;
|
|
143
|
+
border: string;
|
|
144
|
+
label: string;
|
|
145
|
+
}
|
|
146
|
+
interface GatesConfig {
|
|
147
|
+
viability_classification: ViabilityGate[];
|
|
148
|
+
structural_override: {
|
|
149
|
+
description: string;
|
|
150
|
+
enforcement: 'mandatory';
|
|
151
|
+
};
|
|
152
|
+
sustainability_threshold: number;
|
|
153
|
+
collapse_visual: CollapseVisual;
|
|
154
|
+
}
|
|
155
|
+
interface ComputedOutcome {
|
|
156
|
+
id: string;
|
|
157
|
+
type: 'number' | 'boolean' | 'enum';
|
|
158
|
+
range?: [number, number];
|
|
159
|
+
options?: string[];
|
|
160
|
+
default?: number | boolean | string;
|
|
161
|
+
display_as?: 'percentage' | 'integer' | 'decimal';
|
|
162
|
+
label: string;
|
|
163
|
+
primary?: boolean;
|
|
164
|
+
initial_value?: string;
|
|
165
|
+
derived_from?: string;
|
|
166
|
+
assignment?: 'rule' | 'external';
|
|
167
|
+
show_in_comparison: boolean;
|
|
168
|
+
structural_indicator?: boolean;
|
|
169
|
+
}
|
|
170
|
+
interface ComparisonLayout {
|
|
171
|
+
primary_card: string;
|
|
172
|
+
status_badge: string;
|
|
173
|
+
structural_indicators: string[];
|
|
174
|
+
}
|
|
175
|
+
interface OutcomesConfig {
|
|
176
|
+
computed_outcomes: ComputedOutcome[];
|
|
177
|
+
comparison_layout: ComparisonLayout;
|
|
178
|
+
}
|
|
179
|
+
interface WorldMetadata {
|
|
180
|
+
format_version: string;
|
|
181
|
+
created_at: string;
|
|
182
|
+
last_modified: string;
|
|
183
|
+
authoring_method: 'manual-authoring' | 'configurator-ai' | 'migration';
|
|
184
|
+
integrity_hash?: string;
|
|
185
|
+
}
|
|
186
|
+
interface KernelConfig {
|
|
187
|
+
artifact_type: string;
|
|
188
|
+
kernel_id: string;
|
|
189
|
+
version: string;
|
|
190
|
+
domain: string;
|
|
191
|
+
enforcement_level: 'standard' | 'strict' | 'permissive';
|
|
192
|
+
input_boundaries: {
|
|
193
|
+
forbidden_patterns: Array<{
|
|
194
|
+
id: string;
|
|
195
|
+
pattern: string;
|
|
196
|
+
reason: string;
|
|
197
|
+
action: 'BLOCK' | 'WARN';
|
|
198
|
+
}>;
|
|
199
|
+
};
|
|
200
|
+
output_boundaries: {
|
|
201
|
+
forbidden_patterns: Array<{
|
|
202
|
+
id: string;
|
|
203
|
+
pattern: string;
|
|
204
|
+
reason: string;
|
|
205
|
+
action: 'BLOCK' | 'WARN';
|
|
206
|
+
}>;
|
|
207
|
+
};
|
|
208
|
+
response_vocabulary: Record<string, string>;
|
|
209
|
+
metadata: {
|
|
210
|
+
compiled_by: string;
|
|
211
|
+
compiled_at: string;
|
|
212
|
+
source_hash: string;
|
|
213
|
+
compiler_version: string;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
type RoleArchetype = 'observer' | 'operator' | 'strategist' | 'guardian' | 'steward' | 'executor';
|
|
217
|
+
type RoleAuthority = 'none' | 'execute_within_limits' | 'reprioritize_within_bounds' | 'block_violations' | 'escalate_audit_freeze' | 'execute_declared_actions';
|
|
218
|
+
type RolePosture = 'analyze' | 'task_oriented' | 'long_term_coherence' | 'constraint_aware' | 'system_integrity' | 'efficient';
|
|
219
|
+
interface WorldRoleDefinition {
|
|
220
|
+
id: string;
|
|
221
|
+
archetype: RoleArchetype;
|
|
222
|
+
authority: RoleAuthority;
|
|
223
|
+
posture: RolePosture;
|
|
224
|
+
name: string;
|
|
225
|
+
description: string;
|
|
226
|
+
icon?: string;
|
|
227
|
+
roleMandate: string;
|
|
228
|
+
voiceStyle?: string;
|
|
229
|
+
canDo: string[];
|
|
230
|
+
cannotDo: string[];
|
|
231
|
+
requiresApproval?: boolean;
|
|
232
|
+
trackedOutcomes?: string[];
|
|
233
|
+
ownedRules?: string[];
|
|
234
|
+
}
|
|
235
|
+
type RoleAssignment = 'dynamic' | 'per_session' | 'permanent';
|
|
236
|
+
interface RoleTransition {
|
|
237
|
+
from: string;
|
|
238
|
+
to: string;
|
|
239
|
+
initiator: 'self' | 'steward' | 'any';
|
|
240
|
+
condition?: string;
|
|
241
|
+
}
|
|
242
|
+
interface RolesConfig {
|
|
243
|
+
assignment: RoleAssignment;
|
|
244
|
+
roles: WorldRoleDefinition[];
|
|
245
|
+
transitions?: RoleTransition[];
|
|
246
|
+
}
|
|
247
|
+
interface Guard {
|
|
248
|
+
id: string;
|
|
249
|
+
label: string;
|
|
250
|
+
description: string;
|
|
251
|
+
category: 'structural' | 'operational' | 'advisory';
|
|
252
|
+
enforcement: 'block' | 'pause' | 'warn';
|
|
253
|
+
immutable: boolean;
|
|
254
|
+
invariant_ref?: string;
|
|
255
|
+
intent_patterns: string[];
|
|
256
|
+
required_roles?: string[];
|
|
257
|
+
redirect?: string;
|
|
258
|
+
default_enabled?: boolean;
|
|
259
|
+
/** Tool names this guard applies to (case-insensitive). Empty/absent = all tools. */
|
|
260
|
+
appliesTo?: string[];
|
|
261
|
+
player_modes?: {
|
|
262
|
+
thinking?: 'annotate' | 'block' | 'ignore';
|
|
263
|
+
experience?: 'simulate' | 'score' | 'ignore';
|
|
264
|
+
action?: 'block' | 'pause' | 'warn';
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
interface IntentPattern {
|
|
268
|
+
label: string;
|
|
269
|
+
pattern: string;
|
|
270
|
+
}
|
|
271
|
+
interface GuardsConfig {
|
|
272
|
+
guards: Guard[];
|
|
273
|
+
intent_vocabulary: Record<string, IntentPattern>;
|
|
274
|
+
}
|
|
275
|
+
interface WorldDefinition {
|
|
276
|
+
world: WorldIdentity;
|
|
277
|
+
invariants: Invariant[];
|
|
278
|
+
assumptions: AssumptionConfig;
|
|
279
|
+
stateSchema: StateSchema;
|
|
280
|
+
rules: Rule[];
|
|
281
|
+
gates: GatesConfig;
|
|
282
|
+
outcomes: OutcomesConfig;
|
|
283
|
+
guards?: GuardsConfig;
|
|
284
|
+
roles?: RolesConfig;
|
|
285
|
+
kernel?: KernelConfig;
|
|
286
|
+
enforcement?: string;
|
|
287
|
+
metadata: WorldMetadata;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Guard Contract — CLI Governance Evaluation Types
|
|
292
|
+
*
|
|
293
|
+
* Defines the input/output contract for `neuroverse guard`.
|
|
294
|
+
*
|
|
295
|
+
* GuardEvent comes in (stdin JSON).
|
|
296
|
+
* GuardVerdict goes out (stdout JSON).
|
|
297
|
+
* Exit code encodes status: 0=ALLOW, 1=BLOCK, 2=PAUSE.
|
|
298
|
+
*
|
|
299
|
+
* The EvaluationTrace is the internal debugging structure that records
|
|
300
|
+
* every check performed, whether it matched, and how precedence resolved.
|
|
301
|
+
* Included in the verdict when trace mode is enabled. Powers:
|
|
302
|
+
* - OS debugging UI
|
|
303
|
+
* - Explainability features
|
|
304
|
+
* - Evidence generation for enterprise compliance
|
|
305
|
+
* - CI/CD audit trails
|
|
306
|
+
*
|
|
307
|
+
* INVARIANTS:
|
|
308
|
+
* - Deterministic: same event + same world → same verdict, always.
|
|
309
|
+
* - Zero network calls. All evaluation is local pattern matching.
|
|
310
|
+
* - Single event in, single verdict out.
|
|
311
|
+
* - Trace records every check, not just the deciding one.
|
|
312
|
+
*/
|
|
313
|
+
/**
|
|
314
|
+
* A governance event to evaluate.
|
|
315
|
+
* This is the CLI-facing contract — simpler than ExecutionEvent,
|
|
316
|
+
* focused on what the guard engine actually needs.
|
|
317
|
+
*/
|
|
318
|
+
interface GuardEvent {
|
|
319
|
+
/** Human-readable intent description. REQUIRED. */
|
|
320
|
+
intent: string;
|
|
321
|
+
/** Tool being invoked (e.g., "shell", "browser", "fs", "http") */
|
|
322
|
+
tool?: string;
|
|
323
|
+
/** Scope of the action (file path, domain, resource identifier) */
|
|
324
|
+
scope?: string;
|
|
325
|
+
/** Role ID of the actor (for multi-agent worlds) */
|
|
326
|
+
roleId?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Direction of the event.
|
|
329
|
+
* - 'input': user/agent → system (pre-check)
|
|
330
|
+
* - 'output': system → user/agent (post-check)
|
|
331
|
+
*
|
|
332
|
+
* When set, enables direction-specific safety checks:
|
|
333
|
+
* - direction='input': execution intent detection
|
|
334
|
+
* - direction='output': execution claim detection
|
|
335
|
+
*
|
|
336
|
+
* When absent, direction-specific checks are skipped.
|
|
337
|
+
*/
|
|
338
|
+
direction?: 'input' | 'output';
|
|
339
|
+
/** Action category for quick classification */
|
|
340
|
+
actionCategory?: 'read' | 'write' | 'delete' | 'network' | 'shell' | 'browser' | 'other';
|
|
341
|
+
/** Risk level hint from the caller */
|
|
342
|
+
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
343
|
+
/** Whether the action is irreversible (advisory hint) */
|
|
344
|
+
irreversible?: boolean;
|
|
345
|
+
/** Raw payload data (used for injection detection) */
|
|
346
|
+
payload?: unknown;
|
|
347
|
+
/** Tool arguments — supports dot-notation field resolution (e.g. args.file_path) */
|
|
348
|
+
args?: Record<string, unknown>;
|
|
349
|
+
/** Environment context (e.g. "development", "production") */
|
|
350
|
+
environment?: string;
|
|
351
|
+
}
|
|
352
|
+
type GuardStatus = 'ALLOW' | 'BLOCK' | 'PAUSE';
|
|
353
|
+
/**
|
|
354
|
+
* Evidence attached to every verdict for audit purposes.
|
|
355
|
+
* Always present, regardless of trace mode.
|
|
356
|
+
*/
|
|
357
|
+
interface VerdictEvidence {
|
|
358
|
+
/** World identity */
|
|
359
|
+
worldId: string;
|
|
360
|
+
worldName: string;
|
|
361
|
+
worldVersion: string;
|
|
362
|
+
/** Evaluation timestamp */
|
|
363
|
+
evaluatedAt: number;
|
|
364
|
+
/** Invariant coverage summary */
|
|
365
|
+
invariantsSatisfied: number;
|
|
366
|
+
invariantsTotal: number;
|
|
367
|
+
/** IDs of guards that matched the event */
|
|
368
|
+
guardsMatched: string[];
|
|
369
|
+
/** IDs of kernel rules that matched the event */
|
|
370
|
+
rulesMatched: string[];
|
|
371
|
+
/** Enforcement level used for evaluation */
|
|
372
|
+
enforcementLevel: string;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The verdict — what goes to stdout.
|
|
376
|
+
*
|
|
377
|
+
* Exit codes:
|
|
378
|
+
* 0 = ALLOW (proceed)
|
|
379
|
+
* 1 = BLOCK (denied, do not proceed)
|
|
380
|
+
* 2 = PAUSE (needs human decision)
|
|
381
|
+
* 3 = ERROR (invalid input, missing world, etc.)
|
|
382
|
+
*/
|
|
383
|
+
interface GuardVerdict {
|
|
384
|
+
/** The governance decision */
|
|
385
|
+
status: GuardStatus;
|
|
386
|
+
/** Human-readable reason (for BLOCK/PAUSE) */
|
|
387
|
+
reason?: string;
|
|
388
|
+
/** ID of the rule/guard that produced this verdict */
|
|
389
|
+
ruleId?: string;
|
|
390
|
+
/** Advisory warning (for ALLOW with warn-mode guards) */
|
|
391
|
+
warning?: string;
|
|
392
|
+
/** Audit evidence — always present */
|
|
393
|
+
evidence: VerdictEvidence;
|
|
394
|
+
/** Evaluation trace — present when trace mode is enabled */
|
|
395
|
+
trace?: EvaluationTrace;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The evaluation trace records every check the engine performed.
|
|
399
|
+
* Not just the deciding check — ALL of them. This is what powers
|
|
400
|
+
* the debugging UI, explainability, and enterprise audit.
|
|
401
|
+
*
|
|
402
|
+
* Internal by default. Exposed via --trace flag or programmatic option.
|
|
403
|
+
*/
|
|
404
|
+
interface EvaluationTrace {
|
|
405
|
+
/** Every invariant coverage check */
|
|
406
|
+
invariantChecks: InvariantCheck[];
|
|
407
|
+
/** Safety checks (injection, scope escape) */
|
|
408
|
+
safetyChecks: SafetyCheck[];
|
|
409
|
+
/** Every role rule checked */
|
|
410
|
+
roleChecks: RoleCheck[];
|
|
411
|
+
/** Every declarative guard checked */
|
|
412
|
+
guardChecks: GuardCheck[];
|
|
413
|
+
/** Every kernel rule checked */
|
|
414
|
+
kernelRuleChecks: KernelRuleCheck[];
|
|
415
|
+
/** Level constraint checks */
|
|
416
|
+
levelChecks: LevelCheck[];
|
|
417
|
+
/** How the final verdict was determined */
|
|
418
|
+
precedenceResolution: PrecedenceResolution;
|
|
419
|
+
/** Wall-clock duration */
|
|
420
|
+
durationMs: number;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Invariant coverage check.
|
|
424
|
+
* Verifies that the world's invariants are properly backed by guards.
|
|
425
|
+
*/
|
|
426
|
+
interface InvariantCheck {
|
|
427
|
+
invariantId: string;
|
|
428
|
+
label: string;
|
|
429
|
+
/** Whether a structural guard references this invariant */
|
|
430
|
+
hasGuardCoverage: boolean;
|
|
431
|
+
/** ID of the guard that covers this invariant (if any) */
|
|
432
|
+
coveringGuardId?: string;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Safety check result (injection detection, scope escape).
|
|
436
|
+
*/
|
|
437
|
+
interface SafetyCheck {
|
|
438
|
+
checkType: 'prompt-injection' | 'scope-escape' | 'execution-claim' | 'execution-intent';
|
|
439
|
+
triggered: boolean;
|
|
440
|
+
/** Which pattern matched (if triggered) */
|
|
441
|
+
matchedPattern?: string;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Role rule evaluation result.
|
|
445
|
+
*/
|
|
446
|
+
interface RoleCheck {
|
|
447
|
+
roleId: string;
|
|
448
|
+
roleName: string;
|
|
449
|
+
rule: string;
|
|
450
|
+
ruleType: 'canDo' | 'cannotDo' | 'requiresApproval';
|
|
451
|
+
matched: boolean;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Declarative guard evaluation result.
|
|
455
|
+
*/
|
|
456
|
+
interface GuardCheck {
|
|
457
|
+
guardId: string;
|
|
458
|
+
label: string;
|
|
459
|
+
category: 'structural' | 'operational' | 'advisory';
|
|
460
|
+
enabled: boolean;
|
|
461
|
+
matched: boolean;
|
|
462
|
+
enforcement: 'block' | 'pause' | 'warn';
|
|
463
|
+
/** Which intent patterns matched (if any) */
|
|
464
|
+
matchedPatterns: string[];
|
|
465
|
+
/** Whether the guard was skipped due to role gating */
|
|
466
|
+
roleGated: boolean;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Kernel rule evaluation result.
|
|
470
|
+
*/
|
|
471
|
+
interface KernelRuleCheck {
|
|
472
|
+
ruleId: string;
|
|
473
|
+
text: string;
|
|
474
|
+
category: 'allowed' | 'forbidden';
|
|
475
|
+
matched: boolean;
|
|
476
|
+
/** How the match was performed */
|
|
477
|
+
matchMethod: 'pattern' | 'keyword' | 'none';
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Level constraint check result.
|
|
481
|
+
*/
|
|
482
|
+
interface LevelCheck {
|
|
483
|
+
checkType: 'delete' | 'write-external' | 'network-mutate' | 'credential-access' | 'irreversible';
|
|
484
|
+
level: string;
|
|
485
|
+
triggered: boolean;
|
|
486
|
+
reason?: string;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* How the engine resolved precedence to produce the final verdict.
|
|
490
|
+
*/
|
|
491
|
+
interface PrecedenceResolution {
|
|
492
|
+
/** Which check category produced the final verdict */
|
|
493
|
+
decidingLayer: 'session-allowlist' | 'safety' | 'role' | 'guard' | 'kernel-rule' | 'level-constraint' | 'default-allow';
|
|
494
|
+
/** Specific ID of the deciding check (guard ID, rule ID, etc.) */
|
|
495
|
+
decidingId?: string;
|
|
496
|
+
/** Resolution strategy used */
|
|
497
|
+
strategy: 'first-match-wins';
|
|
498
|
+
/** The full evaluation chain in order */
|
|
499
|
+
chainOrder: string[];
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Options for the guard engine evaluation.
|
|
503
|
+
*/
|
|
504
|
+
interface GuardEngineOptions {
|
|
505
|
+
/** Include full evaluation trace in verdict. Default: false. */
|
|
506
|
+
trace?: boolean;
|
|
507
|
+
/** Enforcement level override. If not set, uses world default or 'standard'. */
|
|
508
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
509
|
+
/**
|
|
510
|
+
* Session allowlist — set of pre-approved event keys.
|
|
511
|
+
* Use `eventToAllowlistKey(event)` to build keys.
|
|
512
|
+
*
|
|
513
|
+
* If the event's key is in this set, the engine returns ALLOW
|
|
514
|
+
* immediately (before safety checks).
|
|
515
|
+
*
|
|
516
|
+
* The engine reads but never mutates this set.
|
|
517
|
+
* The caller owns persistence (allow-once, allow-always, etc.).
|
|
518
|
+
*/
|
|
519
|
+
sessionAllowlist?: Set<string>;
|
|
520
|
+
}
|
|
521
|
+
declare const GUARD_EXIT_CODES: {
|
|
522
|
+
readonly ALLOW: 0;
|
|
523
|
+
readonly BLOCK: 1;
|
|
524
|
+
readonly PAUSE: 2;
|
|
525
|
+
readonly ERROR: 3;
|
|
526
|
+
};
|
|
527
|
+
type GuardExitCode = (typeof GUARD_EXIT_CODES)[keyof typeof GUARD_EXIT_CODES];
|
|
528
|
+
|
|
529
|
+
export { type EvaluationTrace as E, type GuardVerdict as G, type InvariantCheck as I, type KernelRuleCheck as K, type LevelCheck as L, type PrecedenceResolution as P, type RoleCheck as R, type SafetyCheck as S, type ViabilityStatus as V, type WorldDefinition as W, type GuardEvent as a, type GuardEngineOptions as b, GUARD_EXIT_CODES as c, type GuardCheck as d, type GuardExitCode as e, type GuardStatus as f, type VerdictEvidence as g };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateImpactReport,
|
|
3
|
+
renderImpactReport
|
|
4
|
+
} from "./chunk-ITJ3LCPG.js";
|
|
5
|
+
import {
|
|
6
|
+
readAuditLog
|
|
7
|
+
} from "./chunk-FYPYZFV5.js";
|
|
8
|
+
import "./chunk-B4NF3OLW.js";
|
|
9
|
+
|
|
10
|
+
// src/cli/impact.ts
|
|
11
|
+
var USAGE = `
|
|
12
|
+
neuroverse impact \u2014 Counterfactual governance impact report
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
neuroverse impact [options]
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--log <path> Path to audit log (default: .neuroverse/audit.ndjson)
|
|
19
|
+
--json Raw JSON output
|
|
20
|
+
|
|
21
|
+
Shows what governance prevented: blocked actions, risk categories,
|
|
22
|
+
repeat violations, and actor behavior patterns.
|
|
23
|
+
`.trim();
|
|
24
|
+
function parseArgs(argv) {
|
|
25
|
+
const args = {};
|
|
26
|
+
for (let i = 0; i < argv.length; i++) {
|
|
27
|
+
const arg = argv[i];
|
|
28
|
+
if (arg === "--json") args.json = true;
|
|
29
|
+
else if (arg === "--help" || arg === "-h") args.help = true;
|
|
30
|
+
else if (arg === "--log" && argv[i + 1]) args.log = argv[++i];
|
|
31
|
+
}
|
|
32
|
+
return args;
|
|
33
|
+
}
|
|
34
|
+
async function main(argv = process.argv.slice(2)) {
|
|
35
|
+
const args = parseArgs(argv);
|
|
36
|
+
if (args.help) {
|
|
37
|
+
process.stdout.write(USAGE + "\n");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
const logPath = args.log ?? ".neuroverse/audit.ndjson";
|
|
41
|
+
const events = await readAuditLog(logPath);
|
|
42
|
+
if (events.length === 0) {
|
|
43
|
+
process.stderr.write(`No audit events found in ${logPath}
|
|
44
|
+
`);
|
|
45
|
+
process.stderr.write("Run governance evaluations with audit logging enabled to generate events.\n");
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
const report = generateImpactReport(events);
|
|
49
|
+
if (args.json) {
|
|
50
|
+
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
51
|
+
} else {
|
|
52
|
+
process.stdout.write(renderImpactReport(report) + "\n");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
main
|
|
57
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
improveWorld,
|
|
3
|
+
renderImproveText
|
|
4
|
+
} from "./chunk-EIUHJXBB.js";
|
|
5
|
+
import "./chunk-FYS2CBUW.js";
|
|
6
|
+
import {
|
|
7
|
+
loadWorld
|
|
8
|
+
} from "./chunk-M3TZFGHO.js";
|
|
9
|
+
import "./chunk-O5OMJMIE.js";
|
|
10
|
+
|
|
11
|
+
// src/cli/improve.ts
|
|
12
|
+
function parseArgs(argv) {
|
|
13
|
+
let worldPath = "";
|
|
14
|
+
let json = false;
|
|
15
|
+
for (let i = 0; i < argv.length; i++) {
|
|
16
|
+
const arg = argv[i];
|
|
17
|
+
if (arg === "--json") {
|
|
18
|
+
json = true;
|
|
19
|
+
} else if (!arg.startsWith("--") && !worldPath) {
|
|
20
|
+
worldPath = arg;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!worldPath) {
|
|
24
|
+
throw new Error("Usage: neuroverse improve <world-path-or-id>");
|
|
25
|
+
}
|
|
26
|
+
return { worldPath, json };
|
|
27
|
+
}
|
|
28
|
+
async function resolveWorldPath(input) {
|
|
29
|
+
const { stat } = await import("fs/promises");
|
|
30
|
+
try {
|
|
31
|
+
const info = await stat(input);
|
|
32
|
+
if (info.isDirectory()) return input;
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
const neuroversePath = `.neuroverse/worlds/${input}`;
|
|
36
|
+
try {
|
|
37
|
+
const info = await stat(neuroversePath);
|
|
38
|
+
if (info.isDirectory()) return neuroversePath;
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
throw new Error(
|
|
42
|
+
`World not found: "${input}"
|
|
43
|
+
Tried:
|
|
44
|
+
${input}
|
|
45
|
+
${neuroversePath}
|
|
46
|
+
|
|
47
|
+
Build a world first: neuroverse build <input.md>`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
async function main(argv = process.argv.slice(2)) {
|
|
51
|
+
try {
|
|
52
|
+
const args = parseArgs(argv);
|
|
53
|
+
const resolvedPath = await resolveWorldPath(args.worldPath);
|
|
54
|
+
const world = await loadWorld(resolvedPath);
|
|
55
|
+
const report = improveWorld(world);
|
|
56
|
+
if (args.json) {
|
|
57
|
+
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
58
|
+
} else {
|
|
59
|
+
process.stderr.write("\n");
|
|
60
|
+
process.stderr.write(renderImproveText(report) + "\n");
|
|
61
|
+
}
|
|
62
|
+
if (!args.json) {
|
|
63
|
+
process.stderr.write("\nNext steps:\n");
|
|
64
|
+
if (report.stats.critical > 0) {
|
|
65
|
+
process.stderr.write(` Fix critical issues, then re-run: neuroverse improve ${args.worldPath}
|
|
66
|
+
`);
|
|
67
|
+
} else {
|
|
68
|
+
process.stderr.write(` Simulate neuroverse simulate ${args.worldPath}
|
|
69
|
+
`);
|
|
70
|
+
process.stderr.write(` Explain neuroverse explain ${args.worldPath}
|
|
71
|
+
`);
|
|
72
|
+
}
|
|
73
|
+
process.stderr.write("\n");
|
|
74
|
+
}
|
|
75
|
+
process.exit(report.stats.critical > 0 ? 2 : 0);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
process.stderr.write(`${e instanceof Error ? e.message : String(e)}
|
|
78
|
+
`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
main
|
|
84
|
+
};
|