worldview 0.1.0__py3-none-any.whl

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.
worldview/__init__.py ADDED
@@ -0,0 +1,40 @@
1
+ """worldview — Philosophical-ethical worldview layer with normative metrics.
2
+
3
+ This package provides the WorldviewEngine for assessing philosophical coherence,
4
+ ethical implications, and common-good alignment of world-models in the GenesisAeon
5
+ ecosystem.
6
+
7
+ References
8
+ ----------
9
+ - CREP: Critical Reflexive Evaluation Protocol
10
+ - Sigillin: Symbolic integration layer for GenesisAeon
11
+ - GenesisAeon Normative Framework v0.2
12
+ """
13
+
14
+ from worldview.core.critique import CriticalityChecker, CritiqueReport
15
+ from worldview.core.worldview import (
16
+ NormativeMetrics,
17
+ WorldviewAssessment,
18
+ WorldviewEngine,
19
+ )
20
+ from worldview.governance.alignment import (
21
+ AlignmentFramework,
22
+ CommonGoodMetric,
23
+ PersonhoodLevel,
24
+ )
25
+
26
+ __version__ = "0.1.0"
27
+ __author__ = "GenesisAeon"
28
+ __license__ = "MIT"
29
+
30
+ __all__ = [
31
+ "WorldviewEngine",
32
+ "WorldviewAssessment",
33
+ "NormativeMetrics",
34
+ "CriticalityChecker",
35
+ "CritiqueReport",
36
+ "AlignmentFramework",
37
+ "CommonGoodMetric",
38
+ "PersonhoodLevel",
39
+ "__version__",
40
+ ]
@@ -0,0 +1 @@
1
+ """Worldview CLI entry point."""
worldview/cli/main.py ADDED
@@ -0,0 +1,377 @@
1
+ """Worldview CLI — normative assessment from the command line.
2
+
3
+ Usage
4
+ -----
5
+ worldview assess --entropy 0.5 --models gpt-4o llama-3 --visualize
6
+ worldview critique --coherence 0.8 --ethical-score 0.9
7
+ worldview align --entity my-agent --scores solidarity=0.8 justice=0.9
8
+ worldview info
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ import sys
15
+ from pathlib import Path
16
+ from typing import Annotated
17
+
18
+ import typer
19
+ from rich import box
20
+ from rich.console import Console
21
+ from rich.panel import Panel
22
+ from rich.table import Table
23
+
24
+ from worldview import __version__
25
+ from worldview.core.critique import CriticalityChecker
26
+ from worldview.core.worldview import NormativeWeights, WorldviewEngine
27
+ from worldview.governance.alignment import AlignmentFramework, PersonhoodLevel
28
+
29
+ app = typer.Typer(
30
+ name="worldview",
31
+ help="Philosophical-ethical worldview assessment CLI (GenesisAeon v0.1.0).",
32
+ add_completion=False,
33
+ rich_markup_mode="rich",
34
+ )
35
+ console = Console()
36
+ err_console = Console(stderr=True)
37
+
38
+
39
+ def _version_callback(value: bool) -> None:
40
+ if value:
41
+ console.print(f"worldview {__version__}")
42
+ raise typer.Exit()
43
+
44
+
45
+ @app.callback()
46
+ def main(
47
+ version: Annotated[
48
+ bool | None,
49
+ typer.Option("--version", "-V", callback=_version_callback, is_eager=True),
50
+ ] = None,
51
+ ) -> None:
52
+ """Worldview — normative metrics for philosophical world-models."""
53
+
54
+
55
+ @app.command()
56
+ def assess(
57
+ worldview_id: Annotated[
58
+ str, typer.Option("--id", help="Worldview identifier.")
59
+ ] = "worldview-1",
60
+ entropy: Annotated[
61
+ float, typer.Option("--entropy", "-e", help="Raw Shannon entropy H(W).", min=0.0)
62
+ ] = 1.0,
63
+ models: Annotated[
64
+ list[str] | None, typer.Option("--models", "-m", help="Model names to evaluate.")
65
+ ] = None,
66
+ kl_divergence: Annotated[
67
+ float, typer.Option("--kl", help="KL divergence from poetic attractor.", min=0.0)
68
+ ] = 0.0,
69
+ coherence_weight: Annotated[
70
+ float, typer.Option("--w-coherence", help="Coherence weight.", min=0.0, max=1.0)
71
+ ] = 0.25,
72
+ resonance_weight: Annotated[
73
+ float, typer.Option("--w-resonance", help="Resonance weight.", min=0.0, max=1.0)
74
+ ] = 0.20,
75
+ emergence_weight: Annotated[
76
+ float, typer.Option("--w-emergence", help="Emergence weight.", min=0.0, max=1.0)
77
+ ] = 0.20,
78
+ poetics_weight: Annotated[
79
+ float, typer.Option("--w-poetics", help="Poetics weight.", min=0.0, max=1.0)
80
+ ] = 0.15,
81
+ criticality_weight: Annotated[
82
+ float, typer.Option("--w-criticality", help="Criticality weight.", min=0.0, max=1.0)
83
+ ] = 0.20,
84
+ visualize: Annotated[
85
+ bool, typer.Option("--visualize", "-v", help="Render metric bars.")
86
+ ] = False,
87
+ export: Annotated[
88
+ Path | None, typer.Option("--export", "-o", help="Export JSON result to file.")
89
+ ] = None,
90
+ ) -> None:
91
+ """[bold]Assess[/bold] a worldview's normative metrics.
92
+
93
+ Computes Coherence, Resonance, Emergence, Poetics, Criticality, and
94
+ Common-Good Alignment scores.
95
+ """
96
+ total_weight = (
97
+ coherence_weight + resonance_weight + emergence_weight + poetics_weight + criticality_weight
98
+ )
99
+ if abs(total_weight - 1.0) > 1e-4:
100
+ err_console.print(
101
+ f"[red]Error:[/red] weights must sum to 1.0, got {total_weight:.4f}. "
102
+ "Adjust --w-* flags."
103
+ )
104
+ raise typer.Exit(code=1)
105
+
106
+ weights = NormativeWeights(
107
+ coherence=coherence_weight,
108
+ resonance=resonance_weight,
109
+ emergence=emergence_weight,
110
+ poetics=poetics_weight,
111
+ criticality=criticality_weight,
112
+ )
113
+ engine = WorldviewEngine(weights=weights)
114
+ assessment = engine.assess(
115
+ worldview_id=worldview_id,
116
+ entropy=entropy,
117
+ model_names=models or [],
118
+ kl_divergence=kl_divergence,
119
+ )
120
+
121
+ console.print(
122
+ Panel(
123
+ f"[bold cyan]Worldview Assessment[/bold cyan] id=[yellow]{worldview_id}[/yellow]",
124
+ subtitle=f"Grade: [bold]{assessment.grade}[/bold]",
125
+ box=box.ROUNDED,
126
+ )
127
+ )
128
+
129
+ table = Table(show_header=True, header_style="bold magenta", box=box.SIMPLE)
130
+ table.add_column("Metric", style="cyan", width=24)
131
+ table.add_column("Score", justify="right", width=8)
132
+ table.add_column("Bar", width=42) if visualize else None
133
+
134
+ m = assessment.metrics
135
+ rows = [
136
+ ("Coherence C(W)", m.coherence),
137
+ ("Resonance R(W)", m.resonance),
138
+ ("Emergence E(W)", m.emergence),
139
+ ("Poetics P(W)", m.poetics),
140
+ ("Criticality K(W)", m.criticality),
141
+ ("Common-Good G(W)", m.common_good),
142
+ ]
143
+
144
+ for name, score in rows:
145
+ color = "green" if score >= 0.7 else "yellow" if score >= 0.4 else "red"
146
+ score_str = f"[{color}]{score:.4f}[/{color}]"
147
+ if visualize:
148
+ bar_filled = int(score * 40)
149
+ bar = f"[{color}]{'█' * bar_filled}{'░' * (40 - bar_filled)}[/{color}]"
150
+ table.add_row(name, score_str, bar)
151
+ else:
152
+ table.add_row(name, score_str)
153
+
154
+ console.print(table)
155
+
156
+ if models:
157
+ console.print(f"[dim]Models evaluated: {', '.join(models)}[/dim]")
158
+
159
+ aligned = "[green]YES[/green]" if assessment.is_aligned else "[red]NO[/red]"
160
+ coherent = "[green]YES[/green]" if assessment.is_coherent else "[red]NO[/red]"
161
+ console.print(f" Aligned: {aligned} Coherent: {coherent}")
162
+
163
+ result = assessment.model_dump()
164
+ if export:
165
+ export.write_text(json.dumps(result, indent=2, default=str))
166
+ console.print(f"\n[green]Result exported to:[/green] {export}")
167
+
168
+ if not assessment.is_aligned:
169
+ raise typer.Exit(code=2)
170
+
171
+
172
+ @app.command()
173
+ def critique(
174
+ worldview_id: Annotated[str, typer.Option("--id")] = "worldview-1",
175
+ coherence: Annotated[float, typer.Option("--coherence", min=0.0, max=1.0)] = 1.0,
176
+ ethical_score: Annotated[float, typer.Option("--ethical-score", min=0.0, max=1.0)] = 1.0,
177
+ contradiction_rate: Annotated[
178
+ float, typer.Option("--contradiction-rate", min=0.0, max=1.0)
179
+ ] = 0.0,
180
+ externality_index: Annotated[
181
+ float, typer.Option("--externality-index", min=0.0, max=1.0)
182
+ ] = 1.0,
183
+ justice_index: Annotated[float, typer.Option("--justice-index", min=0.0, max=1.0)] = 1.0,
184
+ common_good_score: Annotated[float, typer.Option("--common-good", min=0.0, max=1.0)] = 1.0,
185
+ strict: Annotated[bool, typer.Option("--strict/--no-strict")] = False,
186
+ export: Annotated[Path | None, typer.Option("--export", "-o")] = None,
187
+ ) -> None:
188
+ """[bold]Critique[/bold] a worldview using CREP rules.
189
+
190
+ Checks philosophical consistency, ethical implications, and worldview coherence.
191
+ """
192
+ checker = CriticalityChecker(strict_mode=strict)
193
+ report = checker.check(
194
+ worldview_id=worldview_id,
195
+ coherence=coherence,
196
+ ethical_score=ethical_score,
197
+ contradiction_rate=contradiction_rate,
198
+ externality_index=externality_index,
199
+ justice_index=justice_index,
200
+ common_good_score=common_good_score,
201
+ )
202
+
203
+ status = "[green]PASSED[/green]" if report.passed else "[red]FAILED[/red]"
204
+ console.print(
205
+ Panel(
206
+ "[bold cyan]CREP Critique Report[/bold cyan] "
207
+ f"id=[yellow]{worldview_id}[/yellow] {status}",
208
+ subtitle=f"Overall: {report.overall_score:.4f}",
209
+ box=box.ROUNDED,
210
+ )
211
+ )
212
+
213
+ if not report.flags:
214
+ console.print("[green]No flags raised — worldview passes all CREP rules.[/green]")
215
+ else:
216
+ table = Table(show_header=True, header_style="bold magenta", box=box.SIMPLE)
217
+ table.add_column("Ref", width=10)
218
+ table.add_column("Severity", width=10)
219
+ table.add_column("Category", width=26)
220
+ table.add_column("Message")
221
+
222
+ for flag in report.flags:
223
+ sev_color = {
224
+ "critical": "bold red",
225
+ "error": "red",
226
+ "warning": "yellow",
227
+ "info": "blue",
228
+ }.get(flag.severity.value, "white")
229
+ table.add_row(
230
+ flag.crep_ref,
231
+ f"[{sev_color}]{flag.severity.value.upper()}[/{sev_color}]",
232
+ flag.category.value,
233
+ flag.message,
234
+ )
235
+ console.print(table)
236
+
237
+ score_table = Table(show_header=False, box=box.SIMPLE)
238
+ score_table.add_column("Label", style="cyan")
239
+ score_table.add_column("Score", justify="right")
240
+ score_table.add_row(
241
+ "Philosophical Consistency",
242
+ f"{report.philosophical_consistency_score:.4f}",
243
+ )
244
+ score_table.add_row("Ethical Implication", f"{report.ethical_implication_score:.4f}")
245
+ score_table.add_row("Worldview Coherence", f"{report.worldview_coherence_score:.4f}")
246
+ console.print(score_table)
247
+
248
+ if export:
249
+ export.write_text(json.dumps(report.model_dump(), indent=2, default=str))
250
+ console.print(f"\n[green]Report exported to:[/green] {export}")
251
+
252
+ if not report.passed:
253
+ raise typer.Exit(code=2)
254
+
255
+
256
+ @app.command()
257
+ def align(
258
+ entity_id: Annotated[str, typer.Option("--entity", "-e")] = "entity-1",
259
+ scores: Annotated[
260
+ list[str] | None,
261
+ typer.Option(
262
+ "--scores",
263
+ "-s",
264
+ help="Dimension scores as key=value pairs, e.g. solidarity=0.8.",
265
+ ),
266
+ ] = None,
267
+ personhood: Annotated[
268
+ int,
269
+ typer.Option(
270
+ "--personhood",
271
+ "-p",
272
+ help="PersonhoodLevel integer (0-6).",
273
+ min=0,
274
+ max=6,
275
+ ),
276
+ ] = 2,
277
+ export: Annotated[Path | None, typer.Option("--export", "-o")] = None,
278
+ ) -> None:
279
+ """[bold]Align[/bold] an entity against the Common-Good metric.
280
+
281
+ Evaluates solidarity, sustainability, justice, freedom, dignity, participation.
282
+ """
283
+ parsed_scores: dict[str, float] = {}
284
+ if scores:
285
+ for item in scores:
286
+ if "=" not in item:
287
+ err_console.print(
288
+ f"[red]Error:[/red] invalid score format '{item}'. Use key=value."
289
+ )
290
+ raise typer.Exit(code=1)
291
+ key, _, val = item.partition("=")
292
+ try:
293
+ parsed_scores[key.strip()] = float(val.strip())
294
+ except ValueError as exc:
295
+ err_console.print(f"[red]Error:[/red] cannot parse '{val}' as float.")
296
+ raise typer.Exit(code=1) from exc
297
+
298
+ level = PersonhoodLevel(personhood)
299
+ framework = AlignmentFramework()
300
+ metric = framework.evaluate(
301
+ entity_id=entity_id,
302
+ scores=parsed_scores,
303
+ personhood_level=level,
304
+ )
305
+
306
+ grade_color = {"A+": "bright_green", "A": "green", "B": "cyan", "C": "yellow"}.get(
307
+ metric.grade, "red"
308
+ )
309
+ console.print(
310
+ Panel(
311
+ f"[bold cyan]Common-Good Alignment[/bold cyan] entity=[yellow]{entity_id}[/yellow]",
312
+ subtitle=(
313
+ f"Grade: [bold {grade_color}]{metric.grade}[/bold {grade_color}] "
314
+ f"Personhood: [magenta]{level.label}[/magenta]"
315
+ ),
316
+ box=box.ROUNDED,
317
+ )
318
+ )
319
+
320
+ table = Table(show_header=True, header_style="bold magenta", box=box.SIMPLE)
321
+ table.add_column("Dimension", style="cyan", width=20)
322
+ table.add_column("Score", justify="right", width=8)
323
+ table.add_column("Weight", justify="right", width=8)
324
+ table.add_column("Gap", justify="right", width=8)
325
+
326
+ gaps = framework.gap_analysis(metric)
327
+ for dim in metric.dimensions:
328
+ gap = gaps[dim.name]
329
+ gap_color = "green" if gap < 0.2 else "yellow" if gap < 0.5 else "red"
330
+ table.add_row(
331
+ dim.name,
332
+ f"{dim.score:.3f}",
333
+ f"{dim.weight:.1f}",
334
+ f"[{gap_color}]{gap:.3f}[/{gap_color}]",
335
+ )
336
+
337
+ console.print(table)
338
+ console.print(f" Composite: [bold]{metric.composite_score:.4f}[/bold]")
339
+ console.print(
340
+ f" Socially Beneficial: "
341
+ f"{'[green]YES[/green]' if metric.is_socially_beneficial else '[red]NO[/red]'}"
342
+ )
343
+
344
+ entropy = framework.dimension_entropy(metric)
345
+ console.print(f" Dimension Entropy: {entropy:.4f} nats")
346
+
347
+ if export:
348
+ export.write_text(json.dumps(metric.model_dump(), indent=2, default=str))
349
+ console.print(f"\n[green]Result exported to:[/green] {export}")
350
+
351
+
352
+ @app.command()
353
+ def info() -> None:
354
+ """Display package information and GenesisAeon ecosystem links."""
355
+ console.print(
356
+ Panel(
357
+ "[bold cyan]worldview[/bold cyan] — Philosophical-Ethical Worldview Layer",
358
+ subtitle=f"v{__version__} · MIT License · GenesisAeon",
359
+ box=box.DOUBLE_EDGE,
360
+ )
361
+ )
362
+ table = Table(show_header=False, box=box.SIMPLE)
363
+ table.add_column("Key", style="cyan", width=24)
364
+ table.add_column("Value")
365
+ table.add_row("Version", __version__)
366
+ table.add_row("Author", "GenesisAeon")
367
+ table.add_row("Repository", "https://github.com/GenesisAeon/worldview")
368
+ table.add_row("Documentation", "https://genesisaeon.github.io/worldview")
369
+ table.add_row("Zenodo DOI", "https://doi.org/10.5281/zenodo.worldview")
370
+ table.add_row("CREP Reference", "Critical Reflexive Evaluation Protocol v0.3")
371
+ table.add_row("Sigillin Layer", "sigillin >= 0.1.0")
372
+ table.add_row("Python", f"{sys.version_info.major}.{sys.version_info.minor}+")
373
+ console.print(table)
374
+
375
+
376
+ if __name__ == "__main__":
377
+ app()
@@ -0,0 +1 @@
1
+ """Core worldview assessment modules."""