@ltm-blueverse/alpha-semantic-hub 0.7.0

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 (146) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1674 -0
  3. package/explorer/README.md +282 -0
  4. package/explorer/src/App.css +0 -0
  5. package/explorer/src/App.tsx +2035 -0
  6. package/explorer/src/ErrorBoundary.tsx +112 -0
  7. package/explorer/src/ExploreWorkspaceTabs.tsx +29 -0
  8. package/explorer/src/assets/hero.png +0 -0
  9. package/explorer/src/assets/react.svg +1 -0
  10. package/explorer/src/assets/vite.svg +1 -0
  11. package/explorer/src/explorerCapabilities.ts +24 -0
  12. package/explorer/src/index.css +71 -0
  13. package/explorer/src/main.tsx +7 -0
  14. package/explorer/src/store/edgePairKeys.d.ts +2 -0
  15. package/explorer/src/store/edgePairKeys.js +7 -0
  16. package/explorer/src/store/graphStore.ts +183 -0
  17. package/explorer/src/store/registryStore.ts +78 -0
  18. package/explorer/src/types.d.ts +16 -0
  19. package/explorer/src/ui/primitives.css +414 -0
  20. package/explorer/src/ui/primitives.tsx +170 -0
  21. package/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx +279 -0
  22. package/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx +121 -0
  23. package/explorer/src/workspaces/EnrichWorkspace/EntityResolutionTab.tsx +454 -0
  24. package/explorer/src/workspaces/EnrichWorkspace/RegistryTab.tsx +285 -0
  25. package/explorer/src/workspaces/GraphWorkspace/GraphCanvas.tsx +2673 -0
  26. package/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx +771 -0
  27. package/explorer/src/workspaces/GraphWorkspace/GraphLoadingOverlay.tsx +410 -0
  28. package/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx +3584 -0
  29. package/explorer/src/workspaces/GraphWorkspace/MarkdownContentViewer.tsx +705 -0
  30. package/explorer/src/workspaces/GraphWorkspace/SigmaSceneAdapter.tsx +55 -0
  31. package/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsx +193 -0
  32. package/explorer/src/workspaces/GraphWorkspace/behaviors/clickSelectionBehavior.ts +29 -0
  33. package/explorer/src/workspaces/GraphWorkspace/behaviors/fitViewBehavior.ts +15 -0
  34. package/explorer/src/workspaces/GraphWorkspace/behaviors/focusCameraBehavior.ts +25 -0
  35. package/explorer/src/workspaces/GraphWorkspace/behaviors/hoverActivationBehavior.ts +15 -0
  36. package/explorer/src/workspaces/GraphWorkspace/behaviors/pathHighlightBehavior.ts +52 -0
  37. package/explorer/src/workspaces/GraphWorkspace/behaviors/searchFocusBehavior.ts +36 -0
  38. package/explorer/src/workspaces/GraphWorkspace/behaviors/types.ts +41 -0
  39. package/explorer/src/workspaces/GraphWorkspace/behaviors/viewModeSwitchBehavior.ts +29 -0
  40. package/explorer/src/workspaces/GraphWorkspace/graphAnalytics.ts +779 -0
  41. package/explorer/src/workspaces/GraphWorkspace/graphColorLegend.ts +36 -0
  42. package/explorer/src/workspaces/GraphWorkspace/graphConfig.ts +102 -0
  43. package/explorer/src/workspaces/GraphWorkspace/graphEntityShape.ts +34 -0
  44. package/explorer/src/workspaces/GraphWorkspace/graphLoading.ts +84 -0
  45. package/explorer/src/workspaces/GraphWorkspace/graphSceneLayers.ts +775 -0
  46. package/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts +2753 -0
  47. package/explorer/src/workspaces/GraphWorkspace/graphStructureLayer.ts +335 -0
  48. package/explorer/src/workspaces/GraphWorkspace/graphTheme.ts +1078 -0
  49. package/explorer/src/workspaces/GraphWorkspace/graphViewCopy.ts +41 -0
  50. package/explorer/src/workspaces/GraphWorkspace/localGraphTransition.ts +9 -0
  51. package/explorer/src/workspaces/GraphWorkspace/markdownEditorState.ts +114 -0
  52. package/explorer/src/workspaces/GraphWorkspace/markdownResourceClient.ts +103 -0
  53. package/explorer/src/workspaces/GraphWorkspace/markdownUrlSafety.ts +29 -0
  54. package/explorer/src/workspaces/GraphWorkspace/nodeMarkdownSync.ts +81 -0
  55. package/explorer/src/workspaces/GraphWorkspace/pluginRegistryPredicates.ts +24 -0
  56. package/explorer/src/workspaces/GraphWorkspace/plugins/explorationEffectsPlugin.tsx +353 -0
  57. package/explorer/src/workspaces/GraphWorkspace/plugins/explorationEffectsPluginPhaseC.tsx +522 -0
  58. package/explorer/src/workspaces/GraphWorkspace/plugins/index.ts +16 -0
  59. package/explorer/src/workspaces/GraphWorkspace/plugins/legendPlugin.tsx +120 -0
  60. package/explorer/src/workspaces/GraphWorkspace/plugins/neighborhoodPanelPlugin.tsx +231 -0
  61. package/explorer/src/workspaces/GraphWorkspace/plugins/temporalOverlayPlugin.tsx +142 -0
  62. package/explorer/src/workspaces/GraphWorkspace/plugins/types.ts +106 -0
  63. package/explorer/src/workspaces/GraphWorkspace/realtimeGraphAttributes.ts +50 -0
  64. package/explorer/src/workspaces/GraphWorkspace/scene.ts +79 -0
  65. package/explorer/src/workspaces/GraphWorkspace/sigmaNativeRendering.ts +421 -0
  66. package/explorer/src/workspaces/GraphWorkspace/smallGraphLayout.ts +135 -0
  67. package/explorer/src/workspaces/GraphWorkspace/temporalLifecyclePredicates.ts +31 -0
  68. package/explorer/src/workspaces/GraphWorkspace/temporalScrubberBounds.ts +46 -0
  69. package/explorer/src/workspaces/GraphWorkspace/temporalSnapshotGuards.ts +113 -0
  70. package/explorer/src/workspaces/GraphWorkspace/types.ts +395 -0
  71. package/explorer/src/workspaces/GraphWorkspace/useLoadGraph.ts +746 -0
  72. package/explorer/src/workspaces/GraphWorkspace/useMarkdownEditor.ts +177 -0
  73. package/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx +196 -0
  74. package/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx +177 -0
  75. package/explorer/src/workspaces/ManageWorkspace/KGOverviewTab.tsx +291 -0
  76. package/explorer/src/workspaces/ManageWorkspace/OntologySummaryTab.tsx +346 -0
  77. package/explorer/src/workspaces/MemoryWorkspace.tsx +464 -0
  78. package/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx +437 -0
  79. package/explorer/src/workspaces/OntologyWorkspace/HealthTab.tsx +214 -0
  80. package/explorer/src/workspaces/OntologyWorkspace/OntologyEditor.tsx +770 -0
  81. package/explorer/src/workspaces/OntologyWorkspace/OntologyLoader.tsx +913 -0
  82. package/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx +930 -0
  83. package/explorer/src/workspaces/OntologyWorkspace/OntologySearch.tsx +590 -0
  84. package/explorer/src/workspaces/OntologyWorkspace/ProposalReview.tsx +429 -0
  85. package/explorer/src/workspaces/OntologyWorkspace/SKOSVocabularyManager.tsx +696 -0
  86. package/explorer/src/workspaces/OntologyWorkspace/ShaclStudio.tsx +363 -0
  87. package/explorer/src/workspaces/OntologyWorkspace/VersionsTab.tsx +546 -0
  88. package/explorer/src/workspaces/OntologyWorkspace/api.ts +164 -0
  89. package/explorer/src/workspaces/OntologyWorkspace/index.tsx +101 -0
  90. package/explorer/src/workspaces/OntologyWorkspace/ontologyEditorModel.ts +87 -0
  91. package/explorer/src/workspaces/OntologyWorkspace/ontologyUrlState.ts +94 -0
  92. package/explorer/src/workspaces/OntologyWorkspace/types.ts +119 -0
  93. package/explorer/src/workspaces/ReasoningWorkspace.tsx +243 -0
  94. package/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx +271 -0
  95. package/explorer/src/workspaces/VocabularyWorkspace/ConceptTree.tsx +97 -0
  96. package/explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx +95 -0
  97. package/explorer/src/workspaces/VocabularyWorkspace/PropertyPanel.tsx +116 -0
  98. package/explorer/src/workspaces/VocabularyWorkspace/Sidebar.tsx +112 -0
  99. package/explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx +70 -0
  100. package/explorer/src/workspaces/VocabularyWorkspace/queries.ts +52 -0
  101. package/explorer/src/workspaces/VocabularyWorkspace/types.ts +24 -0
  102. package/package.json +31 -0
  103. package/plugins/.claude-plugin/README.md +262 -0
  104. package/plugins/.claude-plugin/marketplace.json +20 -0
  105. package/plugins/.claude-plugin/plugin.json +33 -0
  106. package/plugins/.cline-plugin/README.md +32 -0
  107. package/plugins/.cline-plugin/marketplace.json +17 -0
  108. package/plugins/.cline-plugin/plugin.json +35 -0
  109. package/plugins/.codex-plugin/marketplace.json +21 -0
  110. package/plugins/.codex-plugin/plugin.json +35 -0
  111. package/plugins/.continue-plugin/README.md +34 -0
  112. package/plugins/.continue-plugin/marketplace.json +17 -0
  113. package/plugins/.continue-plugin/plugin.json +33 -0
  114. package/plugins/.cursor-plugin/marketplace.json +18 -0
  115. package/plugins/.cursor-plugin/plugin.json +32 -0
  116. package/plugins/.openclaw-plugin/README.md +62 -0
  117. package/plugins/.openclaw-plugin/marketplace.json +18 -0
  118. package/plugins/.openclaw-plugin/plugin.json +46 -0
  119. package/plugins/.pi-plugin/README.md +35 -0
  120. package/plugins/.vscode-plugin/README.md +48 -0
  121. package/plugins/.vscode-plugin/marketplace.json +17 -0
  122. package/plugins/.vscode-plugin/plugin.json +35 -0
  123. package/plugins/.windsurf-plugin/README.md +39 -0
  124. package/plugins/.windsurf-plugin/marketplace.json +17 -0
  125. package/plugins/.windsurf-plugin/plugin.json +35 -0
  126. package/plugins/agents/decision-advisor.md +126 -0
  127. package/plugins/agents/explainability.md +129 -0
  128. package/plugins/agents/kg-assistant.md +73 -0
  129. package/plugins/hooks/hooks.json +12 -0
  130. package/plugins/skills/causal/SKILL.md +74 -0
  131. package/plugins/skills/change/SKILL.md +80 -0
  132. package/plugins/skills/decision/SKILL.md +197 -0
  133. package/plugins/skills/deduplicate/SKILL.md +41 -0
  134. package/plugins/skills/embed/SKILL.md +230 -0
  135. package/plugins/skills/explain/SKILL.md +44 -0
  136. package/plugins/skills/export/SKILL.md +67 -0
  137. package/plugins/skills/extract/SKILL.md +93 -0
  138. package/plugins/skills/ingest/SKILL.md +38 -0
  139. package/plugins/skills/ontology/SKILL.md +89 -0
  140. package/plugins/skills/policy/SKILL.md +66 -0
  141. package/plugins/skills/provenance/SKILL.md +70 -0
  142. package/plugins/skills/query/SKILL.md +84 -0
  143. package/plugins/skills/reason/SKILL.md +201 -0
  144. package/plugins/skills/temporal/SKILL.md +164 -0
  145. package/plugins/skills/validate/SKILL.md +228 -0
  146. package/plugins/skills/visualize/SKILL.md +249 -0
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: export
3
+ description: Export Alpha Semantic Hub graphs, results, and provenance to JSON, RDF, Parquet, CSV, GraphML, and other formats.
4
+ ---
5
+
6
+ # /alphasemantichub:export
7
+
8
+ Export knowledge graph data. Usage: `/alphasemantichub:export <format> [args]`
9
+
10
+ `$ARGUMENTS` = format + optional target or destination.
11
+
12
+ ---
13
+
14
+ ## `json [--output <path>] [--filter <query>]`
15
+
16
+ Export graph data as JSON.
17
+
18
+ ```python
19
+ from alphasemantichub.export.methods import export_json
20
+
21
+ export_json(data=graph_data, file_path=output, format='json')
22
+ ```
23
+
24
+ Output: JSON file or inline JSON payload.
25
+
26
+ ---
27
+
28
+ ## `rdf [--format turtle|rdfxml|jsonld|ntriples|n3] [--output <path>]`
29
+
30
+ Export the graph in RDF serialization.
31
+
32
+ ```python
33
+ from alphasemantichub.export.methods import export_rdf
34
+
35
+ export_rdf(data=graph_data, file_path=output, format='turtle')
36
+ ```
37
+
38
+ Return: RDF text or file path.
39
+
40
+ ---
41
+
42
+ ## `parquet [--output <path>]`
43
+
44
+ Export nodes and edges to Parquet for analytics.
45
+
46
+ ```python
47
+ from alphasemantichub.export.methods import export_parquet
48
+
49
+ export_parquet(data=graph_data, file_path=output, compression='snappy')
50
+ ```
51
+
52
+ Output: Parquet dataset ready for downstream processing.
53
+
54
+ ---
55
+
56
+ ## `graphml|gexf|dot [--output <path>]`
57
+
58
+ Export the graph to a supported graph format.
59
+
60
+ ```python
61
+ from alphasemantichub.export import GraphExporter
62
+
63
+ exporter = GraphExporter(format='graphml', include_attributes=True)
64
+ exporter.export(graph_data, output)
65
+ ```
66
+
67
+ Output: Graph format file suitable for visualization tools.
@@ -0,0 +1,93 @@
1
+ ---
2
+ name: extract
3
+ description: Run the full Alpha Semantic Hub semantic extraction pipeline on a file or selected text — NER, relations, events, coreference resolution, triplets, and validation. Clears result cache before each run. Returns Markdown tables with entity/relation/event/triplet results and inline validator warnings.
4
+ ---
5
+
6
+ # /alphasemantichub:extract
7
+
8
+ Run the full extraction pipeline. Usage: `/alphasemantichub:extract [file_path | "inline text"]`
9
+
10
+ `$ARGUMENTS` = file path, inline text in quotes, or blank (uses active editor file).
11
+
12
+ ---
13
+
14
+ ## Steps
15
+
16
+ **1. Resolve the source.**
17
+ - If `$ARGUMENTS` is a readable file path → `text = open(path).read()`
18
+ - If it's quoted inline text → use directly
19
+ - If blank → use the active editor file
20
+
21
+ **2. Clear the result cache** to prevent cross-invocation pollution:
22
+
23
+ ```python
24
+ from alphasemantichub.semantic_extract.cache import extraction_cache
25
+ extraction_cache.clear()
26
+ ```
27
+
28
+ **3. Run the full pipeline:**
29
+
30
+ ```python
31
+ from alphasemantichub.semantic_extract import (
32
+ NamedEntityRecognizer,
33
+ RelationExtractor,
34
+ EventDetector,
35
+ CoreferenceResolver,
36
+ TripletExtractor,
37
+ ExtractionValidator,
38
+ )
39
+
40
+ # Named Entity Recognition
41
+ ner = NamedEntityRecognizer()
42
+ entities = ner.extract(text)
43
+
44
+ # Relation Extraction
45
+ rel = RelationExtractor()
46
+ relations = rel.extract(text)
47
+
48
+ # Event Detection
49
+ evt = EventDetector()
50
+ events = evt.extract(text)
51
+
52
+ # Coreference Resolution — resolve pronouns/aliases before extraction
53
+ coref = CoreferenceResolver()
54
+ resolved_text = coref.resolve(text)
55
+
56
+ # Triplet Extraction (subject–predicate–object)
57
+ triplet = TripletExtractor()
58
+ triplets = triplet.extract(resolved_text)
59
+
60
+ # Validate quality
61
+ validator = ExtractionValidator()
62
+ issues = validator.validate(entities, relations)
63
+ ```
64
+
65
+ **4. Report validator warnings** above results:
66
+ ```
67
+ ⚠ ExtractionValidator: <warning message>
68
+ ```
69
+
70
+ **5. Return results as Markdown tables:**
71
+
72
+ **Entities** (N total)
73
+ | Label | Type | Confidence | Span |
74
+ |-------|------|------------|------|
75
+
76
+ **Relations** (M total)
77
+ | Source | Relation Type | Target | Confidence |
78
+ |--------|---------------|--------|------------|
79
+
80
+ **Events** (K total)
81
+ | Label | Type | Participants | Confidence |
82
+ |-------|------|--------------|------------|
83
+
84
+ **Triplets** (J total)
85
+ | Subject | Predicate | Object | Confidence |
86
+ |---------|-----------|--------|------------|
87
+
88
+ **6. Summary line:**
89
+ ```
90
+ Extracted: N entities, M relations, K events, J triplets — from <source>
91
+ ```
92
+
93
+ For large files (>50KB), process in chunks and show a progress indicator. Highlight any entities appearing in the context graph already (`ContextGraph.has_node(label)`) with `[in graph]` tag.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: ingest
3
+ description: Ingest data from files, databases, APIs, or streams into Alpha Semantic Hub knowledge graphs with schema mapping and entity linking.
4
+ ---
5
+
6
+ # /alphasemantichub:ingest
7
+
8
+ Ingest new data into the knowledge graph. Usage: `/alphasemantichub:ingest <source> [args]`
9
+
10
+ `$ARGUMENTS` = source type + optional file path, connection string, or dataset identifier.
11
+
12
+ ---
13
+
14
+ ## `file <path> [--format json|csv|yaml|xml]`
15
+
16
+ Ingest structured data from a local file.
17
+
18
+ ```python
19
+ from alphasemantichub.ingest import ingest_file
20
+
21
+ data = ingest_file(file_path=path, method='file', file_format=file_format)
22
+ ```
23
+
24
+ Output: imported node/edge count and ingestion summary.
25
+
26
+ ---
27
+
28
+ ## `db <connection> [--query <sql>]`
29
+
30
+ Ingest data from a database source.
31
+
32
+ ```python
33
+ from alphasemantichub.ingest import ingest_database
34
+
35
+ result = ingest_database(connection_string=conn, query=query)
36
+ ```
37
+
38
+ Return: rows ingested, mapped entities, and warnings.
@@ -0,0 +1,89 @@
1
+ ---
2
+ name: ontology
3
+ description: Manage ontology schemas, concepts, alignments, and SHACL/OWL validation for Alpha Semantic Hub knowledge graphs. Uses OntologyEngine and OntologyValidator.
4
+ ---
5
+
6
+ # /alphasemantichub:ontology
7
+
8
+ Manage ontology definitions and validation. Usage: `/alphasemantichub:ontology <task> [args]`
9
+
10
+ > Entry points: `OntologyEngine` (authoring, export, alignments) and
11
+ > `OntologyValidator` (consistency checking).
12
+
13
+ ---
14
+
15
+ ## `concepts <scheme_uri>`
16
+
17
+ List SKOS concepts in a vocabulary scheme.
18
+
19
+ ```python
20
+ from alphasemantichub.ontology import OntologyEngine
21
+ from alphasemantichub.triplet_store import TripletStore
22
+
23
+ store = TripletStore(backend="oxigraph") # needs alphasemantichub[tripletstore-oxigraph]
24
+ engine = OntologyEngine(store=store) # list_concepts/list_vocabularies need a
25
+ # configured store — raises ProcessingError without one
26
+ concepts = engine.list_concepts(scheme_uri)
27
+ vocabs = engine.list_vocabularies()
28
+ ```
29
+
30
+ ---
31
+
32
+ ## `validate <ontology>`
33
+
34
+ Check an ontology for consistency and satisfiability.
35
+
36
+ ```python
37
+ from alphasemantichub.ontology import OntologyValidator
38
+
39
+ validator = OntologyValidator(check_consistency=True, check_satisfiability=True)
40
+ result = validator.validate(ontology) # dict or path to an ontology file
41
+ # result.valid, result.errors, result.warnings
42
+ ```
43
+
44
+ For SHACL shape validation of instance data use `SHACLGenerator` / `SHACLValidationReport`:
45
+
46
+ ```python
47
+ from alphasemantichub.ontology import SHACLGenerator
48
+ ```
49
+
50
+ ---
51
+
52
+ ## `build <text|data>`
53
+
54
+ Generate an ontology from unstructured text or structured records.
55
+
56
+ ```python
57
+ engine = OntologyEngine()
58
+ onto = engine.from_text(text) # LLM-assisted (needs an llm-* extra + API key)
59
+ onto = engine.from_data(records) # deterministic, from structured data
60
+ ```
61
+
62
+ ---
63
+
64
+ ## `export <ontology> <path> [--format turtle]`
65
+
66
+ ```python
67
+ engine.export_owl(onto, path, format="turtle")
68
+ engine.export_shacl(onto, path, format="turtle")
69
+ ```
70
+
71
+ ---
72
+
73
+ ## `align <source_uri> <target_uri> <predicate>`
74
+
75
+ ```python
76
+ engine.create_alignment(source_uri, target_uri, predicate)
77
+ engine.get_alignments(entity_uri)
78
+ engine.list_alignments()
79
+ ```
80
+
81
+ ---
82
+
83
+ ## `evaluate <ontology>`
84
+
85
+ Quality-gate an ontology (`OntologyEvaluator` / `OntologyQualityReport` under the hood).
86
+
87
+ ```python
88
+ report = engine.evaluate(onto)
89
+ ```
@@ -0,0 +1,66 @@
1
+ ---
2
+ name: policy
3
+ description: Define and enforce decision policies, compliance rules, and exceptions over Alpha Semantic Hub graphs. Uses ContextGraph.check_decision_rules/enforce_decision_policy and context.PolicyEngine.
4
+ ---
5
+
6
+ # /alphasemantichub:policy
7
+
8
+ Policy governance over recorded decisions. Usage: `/alphasemantichub:policy <task> [args]`
9
+
10
+ > `PolicyEngine` lives in `alphasemantichub.context`. For most cases the two policy
11
+ > methods on `ContextGraph` itself are enough.
12
+
13
+ ---
14
+
15
+ ## `check <decision>` — the simple path
16
+
17
+ No policy store needed; rules default to a built-in policy set.
18
+
19
+ ```python
20
+ from alphasemantichub.context import ContextGraph
21
+
22
+ graph = ContextGraph()
23
+ result = graph.check_decision_rules({
24
+ "category": "vendor_selection",
25
+ "outcome": "approved",
26
+ "confidence": 0.93,
27
+ "decision_maker": "gyro",
28
+ })
29
+ # {'compliant': bool, 'violations': [...], 'warnings': [...], 'policy_rules': {...}}
30
+ ```
31
+
32
+ Default rules: `min_confidence=0.7`, `required_outcomes=['approved','rejected','flagged']`,
33
+ `required_metadata=['decision_maker']`, `max_reasoning_length=1000`. Override by
34
+ passing your own `rules=` dict.
35
+
36
+ ## `enforce <decision> [--rules <dict>]`
37
+
38
+ ```python
39
+ verdict = graph.enforce_decision_policy(decision_data, policy_rules=None)
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Managed policies — the full path
45
+
46
+ `PolicyEngine` requires a graph store and versioned `Policy` objects.
47
+
48
+ ```python
49
+ from alphasemantichub.context import PolicyEngine
50
+ from alphasemantichub.context.decision_models import Policy
51
+
52
+ engine = PolicyEngine(graph_store)
53
+
54
+ policy_id = engine.add_policy(Policy(...))
55
+ policies = engine.get_applicable_policies(category="vendor_selection", entities=[...])
56
+ ok = engine.check_compliance(decision, policy_id)
57
+ history = engine.get_policy_history(policy_id)
58
+
59
+ engine.update_policy(policy_id, rules={...}, change_reason="tightened threshold")
60
+ engine.record_exception(decision_id, policy_id, reason="...", approver="...")
61
+ impact = engine.analyze_policy_impact(policy_id, proposed_rules={...})
62
+ affected = engine.get_affected_decisions(policy_id, from_version, to_version)
63
+ ```
64
+
65
+ Note `check_compliance` takes a `Decision` object, not a dict — fetch it from the
66
+ graph rather than constructing one by hand.
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: provenance
3
+ description: Trace data lineage, source attribution, audit trails, and W3C PROV-O export in Alpha Semantic Hub graphs. Uses ProvenanceManager.
4
+ ---
5
+
6
+ # /alphasemantichub:provenance
7
+
8
+ Lineage and audit trails. Usage: `/alphasemantichub:provenance <task> [args]`
9
+
10
+ ---
11
+
12
+ ## `lineage <entity_id> [--depth N]`
13
+
14
+ ```python
15
+ import os
16
+ from alphasemantichub.provenance import ProvenanceManager
17
+
18
+ db_path = os.path.expanduser("~/.alphasemantichub/prov.db") # storage_path is passed to
19
+ os.makedirs(os.path.dirname(db_path), exist_ok=True) # sqlite3.connect() unexpanded
20
+ pm = ProvenanceManager(storage_path=db_path) # SQLite, or omit for in-memory
21
+ chain = pm.lineage(entity_id, depth=3)
22
+ full = pm.get_lineage(entity_id) # complete ancestry
23
+ down = pm.get_descendants(entity_id) # what this entity influenced
24
+ ```
25
+
26
+ ---
27
+
28
+ ## `sources <entity_id>`
29
+
30
+ ```python
31
+ srcs = pm.get_all_sources(entity_id) # every source that contributed
32
+ prov = pm.get_provenance(entity_id) # the raw PROV entry
33
+ hist = pm.revision_history(entity_id)
34
+ ```
35
+
36
+ ---
37
+
38
+ ## `audit [--since <iso-date>] [--format table|json]`
39
+
40
+ ```python
41
+ log = pm.audit_log(since="2026-01-01", format="table")
42
+ between = pm.query_recorded_between(start, end)
43
+ stats = pm.get_statistics()
44
+ ```
45
+
46
+ ---
47
+
48
+ ## `export [--format turtle|json-ld|xml]`
49
+
50
+ W3C PROV-O export — this is the regulator-facing artifact.
51
+
52
+ ```python
53
+ rdf = pm.export_prov(format="turtle", base_uri="https://example.org/prov/")
54
+ ```
55
+
56
+ ---
57
+
58
+ ## `invalidate <entity_id> <agent_id> [--reason ...]`
59
+
60
+ Mark an entity superseded without deleting history.
61
+
62
+ ```python
63
+ pm.invalidate(entity_id, agent_id, reason="source retracted")
64
+ ```
65
+
66
+ ## `check [--strict]`
67
+
68
+ ```python
69
+ report = pm.check(strict=False) # integrity check over the provenance store
70
+ ```
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: query
3
+ description: Query Alpha Semantic Hub knowledge graphs — in-memory ContextGraph search, SPARQL over RDF triple stores, and Cypher over LPG backends.
4
+ ---
5
+
6
+ # /alphasemantichub:query
7
+
8
+ Query the graph. Usage: `/alphasemantichub:query <task> [args]`
9
+
10
+ > Which API you want depends on where the graph lives.
11
+
12
+ ---
13
+
14
+ ## `search "<keywords>"` — the in-memory ContextGraph
15
+
16
+ This is the one that works with no external server.
17
+
18
+ ```python
19
+ import os
20
+ from alphasemantichub.context import ContextGraph
21
+
22
+ graph = ContextGraph()
23
+ graph.load_from_file(os.path.expanduser("~/.alphasemantichub/kg.json")) # load_from_file does not expand ~
24
+
25
+ results = graph.query("vendor selection", skip=0, limit=20)
26
+ ```
27
+
28
+ Related lookups on the same object:
29
+
30
+ ```python
31
+ graph.find_nodes(...) graph.find_node(...)
32
+ graph.find_related_nodes(...) graph.get_neighbors(node_id)
33
+ graph.find_similar_nodes(...) graph.get_nodes_by_label(label)
34
+ ```
35
+
36
+ Decision-specific queries belong to `/alphasemantichub:decision`.
37
+
38
+ ---
39
+
40
+ ## `sparql "<query>"` — RDF triple stores
41
+
42
+ ```python
43
+ from alphasemantichub.triplet_store import TripletStore
44
+
45
+ store = TripletStore(backend="oxigraph") # embedded; needs alphasemantichub[tripletstore-oxigraph]
46
+ # or backend="blazegraph" | "jena" | "rdf4j" with endpoint="http://..."
47
+ result = store.execute_query(sparql)
48
+ ```
49
+
50
+ For query planning, optimisation, and caching over a backend:
51
+
52
+ ```python
53
+ from alphasemantichub.triplet_store import QueryEngine, OxigraphStore
54
+
55
+ # QueryEngine needs an object exposing execute_sparql() — the raw backend,
56
+ # not the TripletStore wrapper above (which only exposes execute_query()).
57
+ backend = OxigraphStore()
58
+
59
+ qe = QueryEngine()
60
+ plan = qe.plan_query(sparql)
61
+ tuned = qe.optimize_query(sparql)
62
+ result = qe.execute_query(sparql, store_backend=backend)
63
+ stats = qe.get_query_statistics()
64
+ ```
65
+
66
+ Blazegraph / Jena / RDF4J need **no** extra — `alphasemantichub.triplet_store` speaks
67
+ SPARQL over HTTP using the core `requests` dependency.
68
+
69
+ ---
70
+
71
+ ## `cypher "<query>"` — labeled property graphs
72
+
73
+ ```python
74
+ from alphasemantichub.graph_store import Neo4jStore # needs alphasemantichub[graph-neo4j]
75
+
76
+ store = Neo4jStore(uri=..., user=..., password=...)
77
+ result = store.execute_query(query, parameters={...})
78
+ ```
79
+
80
+ Also available: `FalkorDBStore`, `ApacheAgeStore`, `AmazonNeptuneStore`,
81
+ and `GraphManager` / `GraphStore` for backend-agnostic access.
82
+
83
+ **Not installed in this environment** — add the backend extra first, e.g.
84
+ `pip install "alphasemantichub[graph-neo4j]"`.
@@ -0,0 +1,201 @@
1
+ ---
2
+ name: reason
3
+ description: Run reasoning over the Alpha Semantic Hub knowledge graph — deductive logic, abductive hypothesis generation, Datalog programs, SPARQL queries, Rete network evaluation. Uses DeductiveReasoner, AbductiveReasoner, DatalogReasoner, SPARQLReasoner, ReteEngine. Sub-commands: deductive, abductive, datalog, sparql, rete, prove, hypotheses.
4
+ ---
5
+
6
+ # /alphasemantichub:reason
7
+
8
+ Apply reasoning over the knowledge graph. Usage: `/alphasemantichub:reason <mode> [args]`
9
+
10
+ `$ARGUMENTS` = reasoning mode + rules/observations/query.
11
+
12
+ ---
13
+
14
+ ## `deductive [--facts '<json-list>'] [--rules '<rule1>|<rule2>']`
15
+
16
+ Apply deductive rules to known facts to derive new conclusions.
17
+
18
+ ```python
19
+ from alphasemantichub.reasoning.deductive_reasoner import DeductiveReasoner, Premise
20
+
21
+ reasoner = DeductiveReasoner()
22
+
23
+ # Add base facts to working memory
24
+ # Facts can be strings like "Person(John)" or structured dicts
25
+ import json
26
+ facts = json.loads(facts_json) if facts_json else []
27
+ reasoner.add_facts(facts)
28
+
29
+ # Apply logic with explicit premises
30
+ # Premise objects have: statement, confidence, source
31
+ premises = [
32
+ Premise(statement=fact, confidence=1.0)
33
+ for fact in facts
34
+ ]
35
+
36
+ conclusions = reasoner.apply_logic(premises=premises)
37
+ ```
38
+
39
+ Return: `| Conclusion | Triggering Premises | Confidence | Rule Applied |`
40
+
41
+ If zero rules given, run `reasoner.prove_theorem()` on any provided theorem:
42
+ ```python
43
+ proof = reasoner.prove_theorem(theorem=theorem_text)
44
+ ```
45
+
46
+ Output: `Proof: <proof.steps> | Valid: YES / NO`
47
+
48
+ ---
49
+
50
+ ## `prove <theorem> [--facts '<json-list>']`
51
+
52
+ Prove or disprove a theorem against known facts.
53
+
54
+ ```python
55
+ from alphasemantichub.reasoning.deductive_reasoner import DeductiveReasoner
56
+
57
+ reasoner = DeductiveReasoner()
58
+ import json
59
+ reasoner.add_facts(json.loads(facts_json) if facts_json else [])
60
+
61
+ proof = reasoner.prove_theorem(theorem=theorem)
62
+ ```
63
+
64
+ Output:
65
+ ```
66
+ Theorem: "<theorem>"
67
+ Result: PROVED ✓ | DISPROVED ✗ | UNDECIDABLE ⚠
68
+
69
+ Proof steps:
70
+ 1. <premise> — <justification>
71
+ 2. ...
72
+ → QED: <theorem>
73
+
74
+ Confidence: <proof.confidence>
75
+ ```
76
+
77
+ ---
78
+
79
+ ## `abductive <observation> [--knowledge '<json-list>'] [--top N]`
80
+
81
+ Generate and rank hypotheses that explain an observation.
82
+
83
+ ```python
84
+ from alphasemantichub.reasoning.abductive_reasoner import (
85
+ AbductiveReasoner, Observation
86
+ )
87
+
88
+ reasoner = AbductiveReasoner()
89
+
90
+ import json
91
+ if knowledge_json:
92
+ reasoner.add_knowledge(json.loads(knowledge_json))
93
+
94
+ obs = Observation(description=observation)
95
+
96
+ # Generate all hypotheses then rank them
97
+ hypotheses = reasoner.generate_hypotheses(observations=[obs])
98
+ ranked = reasoner.rank_hypotheses(hypotheses)
99
+ best = reasoner.get_best_explanation(obs)
100
+
101
+ # Also get full explanations with evidence
102
+ explanations = reasoner.find_explanations(observations=[obs])
103
+ ```
104
+
105
+ Output:
106
+ ```
107
+ Abductive Reasoning for: "<observation>"
108
+
109
+ Best explanation:
110
+ <best.description> (confidence: 0.87)
111
+
112
+ All hypotheses (ranked):
113
+ | Rank | Hypothesis | Confidence | Supporting Evidence |
114
+ | 1 | <hyp> | 0.87 | <evidence> |
115
+ | 2 | ...
116
+
117
+ Full explanations:
118
+ Explanation 1: <explanation.summary>
119
+ Evidence: <evidence items>
120
+ ```
121
+
122
+ ---
123
+
124
+ ## `datalog <program>`
125
+
126
+ Evaluate a Datalog program over graph facts.
127
+
128
+ ```python
129
+ from alphasemantichub.reasoning.datalog_reasoner import DatalogReasoner
130
+ from alphasemantichub.context import ContextGraph
131
+
132
+ graph = ContextGraph()
133
+ reasoner = DatalogReasoner()
134
+
135
+ # program is a string of Datalog rules and queries
136
+ results = reasoner.evaluate(program=program, graph=graph)
137
+ ```
138
+
139
+ Return derived tuples as a relation table. Show rule derivation counts.
140
+
141
+ ---
142
+
143
+ ## `sparql <query>`
144
+
145
+ Run a SPARQL query over the knowledge graph and return results.
146
+
147
+ ```python
148
+ from alphasemantichub.reasoning.sparql_reasoner import SPARQLReasoner
149
+ from alphasemantichub.context import ContextGraph
150
+
151
+ graph = ContextGraph()
152
+ reasoner = SPARQLReasoner()
153
+
154
+ results = reasoner.query(sparql_query=query, graph=graph)
155
+ ```
156
+
157
+ Return as a Markdown table with bound variable columns matching the SELECT clause.
158
+
159
+ ---
160
+
161
+ ## `rete [--rules '<rule1>|<rule2>'] [--facts '<json-list>']`
162
+
163
+ Incremental rule evaluation using the Rete network with working memory.
164
+
165
+ ```python
166
+ from alphasemantichub.reasoning.rete_engine import ReteEngine
167
+ import json
168
+
169
+ engine = ReteEngine()
170
+
171
+ rules = rules_str.split("|") if rules_str else []
172
+ facts = json.loads(facts_json) if facts_json else []
173
+
174
+ engine.load_rules(rules)
175
+ engine.process_facts(facts)
176
+ activations = engine.get_activations()
177
+ ```
178
+
179
+ Return: `| Rule Fired | Variable Bindings | Working Memory Delta | Activation Order |`
180
+
181
+ ---
182
+
183
+ ## `hypotheses "<scenario>" [--knowledge '<json-list>'] [--top N]`
184
+
185
+ Generate the top-N most probable explanations for a complex scenario.
186
+
187
+ ```python
188
+ from alphasemantichub.reasoning.abductive_reasoner import AbductiveReasoner, Observation
189
+ import json
190
+
191
+ reasoner = AbductiveReasoner()
192
+ if knowledge_json:
193
+ reasoner.add_knowledge(json.loads(knowledge_json))
194
+
195
+ obs = Observation(description=scenario)
196
+ hypotheses = reasoner.generate_hypotheses(observations=[obs])
197
+ ranked = reasoner.rank_hypotheses(hypotheses)
198
+ top_n = ranked[:int(n) if n else 5]
199
+ ```
200
+
201
+ For each hypothesis also show: what evidence supports it, what would falsify it, and which is the most parsimonious (fewest assumptions).