@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.
- package/LICENSE +21 -0
- package/README.md +1674 -0
- package/explorer/README.md +282 -0
- package/explorer/src/App.css +0 -0
- package/explorer/src/App.tsx +2035 -0
- package/explorer/src/ErrorBoundary.tsx +112 -0
- package/explorer/src/ExploreWorkspaceTabs.tsx +29 -0
- package/explorer/src/assets/hero.png +0 -0
- package/explorer/src/assets/react.svg +1 -0
- package/explorer/src/assets/vite.svg +1 -0
- package/explorer/src/explorerCapabilities.ts +24 -0
- package/explorer/src/index.css +71 -0
- package/explorer/src/main.tsx +7 -0
- package/explorer/src/store/edgePairKeys.d.ts +2 -0
- package/explorer/src/store/edgePairKeys.js +7 -0
- package/explorer/src/store/graphStore.ts +183 -0
- package/explorer/src/store/registryStore.ts +78 -0
- package/explorer/src/types.d.ts +16 -0
- package/explorer/src/ui/primitives.css +414 -0
- package/explorer/src/ui/primitives.tsx +170 -0
- package/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx +279 -0
- package/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx +121 -0
- package/explorer/src/workspaces/EnrichWorkspace/EntityResolutionTab.tsx +454 -0
- package/explorer/src/workspaces/EnrichWorkspace/RegistryTab.tsx +285 -0
- package/explorer/src/workspaces/GraphWorkspace/GraphCanvas.tsx +2673 -0
- package/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx +771 -0
- package/explorer/src/workspaces/GraphWorkspace/GraphLoadingOverlay.tsx +410 -0
- package/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx +3584 -0
- package/explorer/src/workspaces/GraphWorkspace/MarkdownContentViewer.tsx +705 -0
- package/explorer/src/workspaces/GraphWorkspace/SigmaSceneAdapter.tsx +55 -0
- package/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsx +193 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/clickSelectionBehavior.ts +29 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/fitViewBehavior.ts +15 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/focusCameraBehavior.ts +25 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/hoverActivationBehavior.ts +15 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/pathHighlightBehavior.ts +52 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/searchFocusBehavior.ts +36 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/types.ts +41 -0
- package/explorer/src/workspaces/GraphWorkspace/behaviors/viewModeSwitchBehavior.ts +29 -0
- package/explorer/src/workspaces/GraphWorkspace/graphAnalytics.ts +779 -0
- package/explorer/src/workspaces/GraphWorkspace/graphColorLegend.ts +36 -0
- package/explorer/src/workspaces/GraphWorkspace/graphConfig.ts +102 -0
- package/explorer/src/workspaces/GraphWorkspace/graphEntityShape.ts +34 -0
- package/explorer/src/workspaces/GraphWorkspace/graphLoading.ts +84 -0
- package/explorer/src/workspaces/GraphWorkspace/graphSceneLayers.ts +775 -0
- package/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts +2753 -0
- package/explorer/src/workspaces/GraphWorkspace/graphStructureLayer.ts +335 -0
- package/explorer/src/workspaces/GraphWorkspace/graphTheme.ts +1078 -0
- package/explorer/src/workspaces/GraphWorkspace/graphViewCopy.ts +41 -0
- package/explorer/src/workspaces/GraphWorkspace/localGraphTransition.ts +9 -0
- package/explorer/src/workspaces/GraphWorkspace/markdownEditorState.ts +114 -0
- package/explorer/src/workspaces/GraphWorkspace/markdownResourceClient.ts +103 -0
- package/explorer/src/workspaces/GraphWorkspace/markdownUrlSafety.ts +29 -0
- package/explorer/src/workspaces/GraphWorkspace/nodeMarkdownSync.ts +81 -0
- package/explorer/src/workspaces/GraphWorkspace/pluginRegistryPredicates.ts +24 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/explorationEffectsPlugin.tsx +353 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/explorationEffectsPluginPhaseC.tsx +522 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/index.ts +16 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/legendPlugin.tsx +120 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/neighborhoodPanelPlugin.tsx +231 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/temporalOverlayPlugin.tsx +142 -0
- package/explorer/src/workspaces/GraphWorkspace/plugins/types.ts +106 -0
- package/explorer/src/workspaces/GraphWorkspace/realtimeGraphAttributes.ts +50 -0
- package/explorer/src/workspaces/GraphWorkspace/scene.ts +79 -0
- package/explorer/src/workspaces/GraphWorkspace/sigmaNativeRendering.ts +421 -0
- package/explorer/src/workspaces/GraphWorkspace/smallGraphLayout.ts +135 -0
- package/explorer/src/workspaces/GraphWorkspace/temporalLifecyclePredicates.ts +31 -0
- package/explorer/src/workspaces/GraphWorkspace/temporalScrubberBounds.ts +46 -0
- package/explorer/src/workspaces/GraphWorkspace/temporalSnapshotGuards.ts +113 -0
- package/explorer/src/workspaces/GraphWorkspace/types.ts +395 -0
- package/explorer/src/workspaces/GraphWorkspace/useLoadGraph.ts +746 -0
- package/explorer/src/workspaces/GraphWorkspace/useMarkdownEditor.ts +177 -0
- package/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx +196 -0
- package/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx +177 -0
- package/explorer/src/workspaces/ManageWorkspace/KGOverviewTab.tsx +291 -0
- package/explorer/src/workspaces/ManageWorkspace/OntologySummaryTab.tsx +346 -0
- package/explorer/src/workspaces/MemoryWorkspace.tsx +464 -0
- package/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx +437 -0
- package/explorer/src/workspaces/OntologyWorkspace/HealthTab.tsx +214 -0
- package/explorer/src/workspaces/OntologyWorkspace/OntologyEditor.tsx +770 -0
- package/explorer/src/workspaces/OntologyWorkspace/OntologyLoader.tsx +913 -0
- package/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx +930 -0
- package/explorer/src/workspaces/OntologyWorkspace/OntologySearch.tsx +590 -0
- package/explorer/src/workspaces/OntologyWorkspace/ProposalReview.tsx +429 -0
- package/explorer/src/workspaces/OntologyWorkspace/SKOSVocabularyManager.tsx +696 -0
- package/explorer/src/workspaces/OntologyWorkspace/ShaclStudio.tsx +363 -0
- package/explorer/src/workspaces/OntologyWorkspace/VersionsTab.tsx +546 -0
- package/explorer/src/workspaces/OntologyWorkspace/api.ts +164 -0
- package/explorer/src/workspaces/OntologyWorkspace/index.tsx +101 -0
- package/explorer/src/workspaces/OntologyWorkspace/ontologyEditorModel.ts +87 -0
- package/explorer/src/workspaces/OntologyWorkspace/ontologyUrlState.ts +94 -0
- package/explorer/src/workspaces/OntologyWorkspace/types.ts +119 -0
- package/explorer/src/workspaces/ReasoningWorkspace.tsx +243 -0
- package/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx +271 -0
- package/explorer/src/workspaces/VocabularyWorkspace/ConceptTree.tsx +97 -0
- package/explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx +95 -0
- package/explorer/src/workspaces/VocabularyWorkspace/PropertyPanel.tsx +116 -0
- package/explorer/src/workspaces/VocabularyWorkspace/Sidebar.tsx +112 -0
- package/explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx +70 -0
- package/explorer/src/workspaces/VocabularyWorkspace/queries.ts +52 -0
- package/explorer/src/workspaces/VocabularyWorkspace/types.ts +24 -0
- package/package.json +31 -0
- package/plugins/.claude-plugin/README.md +262 -0
- package/plugins/.claude-plugin/marketplace.json +20 -0
- package/plugins/.claude-plugin/plugin.json +33 -0
- package/plugins/.cline-plugin/README.md +32 -0
- package/plugins/.cline-plugin/marketplace.json +17 -0
- package/plugins/.cline-plugin/plugin.json +35 -0
- package/plugins/.codex-plugin/marketplace.json +21 -0
- package/plugins/.codex-plugin/plugin.json +35 -0
- package/plugins/.continue-plugin/README.md +34 -0
- package/plugins/.continue-plugin/marketplace.json +17 -0
- package/plugins/.continue-plugin/plugin.json +33 -0
- package/plugins/.cursor-plugin/marketplace.json +18 -0
- package/plugins/.cursor-plugin/plugin.json +32 -0
- package/plugins/.openclaw-plugin/README.md +62 -0
- package/plugins/.openclaw-plugin/marketplace.json +18 -0
- package/plugins/.openclaw-plugin/plugin.json +46 -0
- package/plugins/.pi-plugin/README.md +35 -0
- package/plugins/.vscode-plugin/README.md +48 -0
- package/plugins/.vscode-plugin/marketplace.json +17 -0
- package/plugins/.vscode-plugin/plugin.json +35 -0
- package/plugins/.windsurf-plugin/README.md +39 -0
- package/plugins/.windsurf-plugin/marketplace.json +17 -0
- package/plugins/.windsurf-plugin/plugin.json +35 -0
- package/plugins/agents/decision-advisor.md +126 -0
- package/plugins/agents/explainability.md +129 -0
- package/plugins/agents/kg-assistant.md +73 -0
- package/plugins/hooks/hooks.json +12 -0
- package/plugins/skills/causal/SKILL.md +74 -0
- package/plugins/skills/change/SKILL.md +80 -0
- package/plugins/skills/decision/SKILL.md +197 -0
- package/plugins/skills/deduplicate/SKILL.md +41 -0
- package/plugins/skills/embed/SKILL.md +230 -0
- package/plugins/skills/explain/SKILL.md +44 -0
- package/plugins/skills/export/SKILL.md +67 -0
- package/plugins/skills/extract/SKILL.md +93 -0
- package/plugins/skills/ingest/SKILL.md +38 -0
- package/plugins/skills/ontology/SKILL.md +89 -0
- package/plugins/skills/policy/SKILL.md +66 -0
- package/plugins/skills/provenance/SKILL.md +70 -0
- package/plugins/skills/query/SKILL.md +84 -0
- package/plugins/skills/reason/SKILL.md +201 -0
- package/plugins/skills/temporal/SKILL.md +164 -0
- package/plugins/skills/validate/SKILL.md +228 -0
- package/plugins/skills/visualize/SKILL.md +249 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: causal
|
|
3
|
+
description: Analyze cause-and-effect relationships in the Alpha Semantic Hub knowledge graph — causal chains, interventions, counterfactuals, and causal influence scores.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:causal
|
|
7
|
+
|
|
8
|
+
Analyze causal relationships and infer impacts. Usage: `/alphasemantichub:causal <task> [args]`
|
|
9
|
+
|
|
10
|
+
`$ARGUMENTS` = task + optional target entity, filter, or intervention.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `chain [--subject <node>] [--depth N]`
|
|
15
|
+
|
|
16
|
+
Build and inspect causal chains for a subject or category.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from alphasemantichub.context.causal_analyzer import CausalChainAnalyzer
|
|
20
|
+
from alphasemantichub.context import AgentContext
|
|
21
|
+
|
|
22
|
+
# Option 1: Use an existing AgentContext decision backend
|
|
23
|
+
chain = ctx.get_causal_chain(
|
|
24
|
+
decision_id=decision_id,
|
|
25
|
+
direction="upstream",
|
|
26
|
+
max_depth=depth,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Option 2: Use CausalChainAnalyzer directly
|
|
30
|
+
analyzer = CausalChainAnalyzer(graph_store=ctx.knowledge_graph)
|
|
31
|
+
downstream = analyzer.get_causal_chain(
|
|
32
|
+
decision_id=decision_id,
|
|
33
|
+
direction="downstream",
|
|
34
|
+
max_depth=depth,
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Output: chain steps, cause strength, effect reach, and summary graph.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## `intervene <node> <action> [--scenario <json>]`
|
|
43
|
+
|
|
44
|
+
Analyze decision impact and influenced decisions (current causal API).
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
analyzer = CausalChainAnalyzer(graph_store=ctx.knowledge_graph)
|
|
48
|
+
impact_score = analyzer.get_causal_impact_score(decision_id=decision_id)
|
|
49
|
+
influenced = analyzer.get_influenced_decisions(
|
|
50
|
+
decision_id=decision_id,
|
|
51
|
+
max_depth=depth,
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Return: impact score, influenced decisions, and downstream scope.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## `counterfactual <fact> [--weight N]`
|
|
60
|
+
|
|
61
|
+
Trace root causes and temporal causal paths.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
analyzer = CausalChainAnalyzer(graph_store=ctx.knowledge_graph)
|
|
65
|
+
roots = analyzer.find_root_causes(decision_id=decision_id, max_depth=depth)
|
|
66
|
+
historical_chain = analyzer.trace_at_time(
|
|
67
|
+
event_id=decision_id,
|
|
68
|
+
at_time="2026-01-01T00:00:00Z",
|
|
69
|
+
direction="upstream",
|
|
70
|
+
max_depth=depth,
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Output: root decision lineage and time-bounded causal context.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: change
|
|
3
|
+
description: Inspect graph changes over time and ontology version diffs in Alpha Semantic Hub. Uses ContextGraph.state_at for point-in-time graph state and change_management.VersionManager for ontology versioning.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:change
|
|
7
|
+
|
|
8
|
+
Track what changed. Usage: `/alphasemantichub:change <task> [args]`
|
|
9
|
+
|
|
10
|
+
> Two distinct mechanisms cover this, and they are **not** interchangeable:
|
|
11
|
+
>
|
|
12
|
+
> | Question | Tool |
|
|
13
|
+
> | --- | --- |
|
|
14
|
+
> | "What did the *graph* look like on date X?" | `ContextGraph.state_at()` |
|
|
15
|
+
> | "What changed between *ontology* versions?" | `change_management.VersionManager` |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## `graph-at <timestamp>` — point-in-time graph state
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import os
|
|
23
|
+
from alphasemantichub.context import ContextGraph
|
|
24
|
+
|
|
25
|
+
graph = ContextGraph()
|
|
26
|
+
graph.load_from_file(os.path.expanduser("~/.alphasemantichub/kg.json")) # load_from_file does not expand ~
|
|
27
|
+
|
|
28
|
+
snapshot = graph.state_at("2026-06-01") # str | int | float | datetime
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Diff two moments by comparing node IDs — `state_at()["nodes"]` is a list of
|
|
32
|
+
dicts (unhashable), so compare the `id` fields, not the dicts themselves:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
before = graph.state_at("2026-06-01")
|
|
36
|
+
after = graph.state_at("2026-09-01")
|
|
37
|
+
before_ids = {n["id"] for n in before["nodes"]}
|
|
38
|
+
after_ids = {n["id"] for n in after["nodes"]}
|
|
39
|
+
added = after_ids - before_ids
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For richer temporal work (scrubbing, evolution, temporal patterns) use
|
|
43
|
+
`/alphasemantichub:temporal`, which wraps the same layer.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## `node-history <node_id>` — who touched this node
|
|
48
|
+
|
|
49
|
+
Node-level history is provenance, not change management:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import os
|
|
53
|
+
from alphasemantichub.provenance import ProvenanceManager
|
|
54
|
+
|
|
55
|
+
db_path = os.path.expanduser("~/.alphasemantichub/prov.db") # storage_path is passed to
|
|
56
|
+
os.makedirs(os.path.dirname(db_path), exist_ok=True) # sqlite3.connect() unexpanded
|
|
57
|
+
pm = ProvenanceManager(storage_path=db_path)
|
|
58
|
+
history = pm.revision_history(node_id)
|
|
59
|
+
log = pm.audit_log(since="2026-01-01")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## `versions` / `diff <v1> <v2>` — ontology versioning
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from alphasemantichub.change_management import VersionManager
|
|
68
|
+
|
|
69
|
+
vm = VersionManager()
|
|
70
|
+
vm.create_version("1.1.0", ontology)
|
|
71
|
+
vm.list_versions()
|
|
72
|
+
vm.get_latest_version()
|
|
73
|
+
|
|
74
|
+
delta = vm.compare_versions("1.0.0", "1.1.0")
|
|
75
|
+
delta = vm.diff_ontologies(base_ontology, target_ontology)
|
|
76
|
+
migrated = vm.migrate_ontology("1.0.0", "1.1.0", ontology)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`TemporalVersionManager` and `OntologyVersionManager` are also exported for
|
|
80
|
+
time-scoped and ontology-specific variants.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: decision
|
|
3
|
+
description: Full decision lifecycle in Alpha Semantic Hub — record, query, find precedents (hybrid/advanced), analyze influence, explain, insights dashboard, list, and record exceptions. Uses AgentContext, ContextGraph, DecisionQuery, CausalChainAnalyzer, DecisionRecorder.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:decision
|
|
7
|
+
|
|
8
|
+
Full decision lifecycle management. Usage: `/alphasemantichub:decision <sub-command> [args]`
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## `record <category> "<scenario>" "<reasoning>" <outcome> <confidence>`
|
|
13
|
+
|
|
14
|
+
Record a decision with full context.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from alphasemantichub.context import AgentContext
|
|
18
|
+
|
|
19
|
+
ctx = AgentContext(decision_tracking=True)
|
|
20
|
+
decision_id = ctx.record_decision(
|
|
21
|
+
category=category, # "loan_approval", "deployment", "hiring"
|
|
22
|
+
scenario=scenario, # natural-language situation description
|
|
23
|
+
reasoning=reasoning, # why this decision was made
|
|
24
|
+
outcome=outcome, # "approved", "rejected", "deferred"
|
|
25
|
+
confidence=float(confidence),
|
|
26
|
+
entities=entities or [],
|
|
27
|
+
decision_maker="ai_agent",
|
|
28
|
+
valid_from=valid_from, # optional ISO date string
|
|
29
|
+
valid_until=valid_until,
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Output: `Decision <decision_id> recorded | <category> | <outcome> (conf: 0.95)`
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## `query "<question>" [--hops N] [--hybrid]`
|
|
38
|
+
|
|
39
|
+
Query decisions using natural language with multi-hop graph traversal.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from alphasemantichub.context import AgentContext
|
|
43
|
+
|
|
44
|
+
ctx = AgentContext(decision_tracking=True, advanced_analytics=True)
|
|
45
|
+
results = ctx.query_decisions(
|
|
46
|
+
query=question,
|
|
47
|
+
max_hops=int(hops) if hops else 3,
|
|
48
|
+
include_context=True,
|
|
49
|
+
use_hybrid_search="--hybrid" in args,
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For structured lookups use `DecisionQuery`:
|
|
54
|
+
```python
|
|
55
|
+
from alphasemantichub.context.decision_query import DecisionQuery
|
|
56
|
+
dq = DecisionQuery(graph_store=ctx.graph_store)
|
|
57
|
+
# dq.find_by_category(category, limit=100)
|
|
58
|
+
# dq.find_by_entity(entity_id, limit=100)
|
|
59
|
+
# dq.find_by_time_range(start, end, limit=100)
|
|
60
|
+
# dq.multi_hop_reasoning(start_entity, query_context, max_hops=3)
|
|
61
|
+
# dq.trace_decision_path(decision_id, relationship_types)
|
|
62
|
+
# dq.analyze_decision_influence(decision_id, max_depth=3)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Return: `| ID | Category | Scenario | Outcome | Confidence | Timestamp |`
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## `precedents "<scenario>" [--category <cat>] [--advanced] [--hops N] [--as-of <date>]`
|
|
70
|
+
|
|
71
|
+
Find similar past decisions using hybrid semantic + structural + vector search.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from alphasemantichub.context import AgentContext
|
|
75
|
+
|
|
76
|
+
ctx = AgentContext(decision_tracking=True, kg_algorithms=True, vector_store_features=True)
|
|
77
|
+
|
|
78
|
+
if "--advanced" in args:
|
|
79
|
+
precedents = ctx.find_precedents_advanced(
|
|
80
|
+
scenario=scenario, category=category, limit=10,
|
|
81
|
+
use_kg_features=True,
|
|
82
|
+
similarity_weights={"semantic": 0.5, "structural": 0.3, "vector": 0.2},
|
|
83
|
+
)
|
|
84
|
+
else:
|
|
85
|
+
precedents = ctx.find_precedents(
|
|
86
|
+
scenario=scenario, category=category, limit=10,
|
|
87
|
+
use_hybrid_search=True,
|
|
88
|
+
max_hops=int(hops) if hops else 3,
|
|
89
|
+
include_context=True,
|
|
90
|
+
include_superseded=False,
|
|
91
|
+
as_of=as_of_date or None, # temporal filter: only precedents that existed as_of this date
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Return ranked: `| Rank | ID | Scenario | Outcome | Confidence | Similarity | Date |`
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## `influence <decision_id> [--depth N]`
|
|
100
|
+
|
|
101
|
+
Analyze how a decision influences others across the graph.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from alphasemantichub.context import AgentContext
|
|
105
|
+
|
|
106
|
+
ctx = AgentContext(decision_tracking=True, advanced_analytics=True, kg_algorithms=True)
|
|
107
|
+
influence = ctx.analyze_decision_influence(decision_id, max_depth=int(depth) if depth else 3)
|
|
108
|
+
predictions = ctx.predict_decision_relationships(decision_id, top_k=5)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Output: Influence score + influenced decisions table + predicted new relationships.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## `explain <decision_id>`
|
|
116
|
+
|
|
117
|
+
Full explainability trace — reasoning steps, causal antecedents, policy compliance.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from alphasemantichub.context import AgentContext, ContextGraph
|
|
121
|
+
|
|
122
|
+
ctx = AgentContext(decision_tracking=True)
|
|
123
|
+
explainability = ctx.trace_decision_explainability(decision_id)
|
|
124
|
+
|
|
125
|
+
graph = ContextGraph(advanced_analytics=True)
|
|
126
|
+
chain = graph.trace_decision_chain(decision_id, max_steps=5)
|
|
127
|
+
causality = graph.trace_decision_causality(decision_id, max_depth=5)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Output: Reasoning steps, causal antecedents, evidence items, policy compliance status.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## `insights`
|
|
135
|
+
|
|
136
|
+
Comprehensive analytics across all tracked decisions.
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from alphasemantichub.context import ContextGraph, AgentContext
|
|
140
|
+
|
|
141
|
+
ctx = AgentContext(decision_tracking=True, advanced_analytics=True)
|
|
142
|
+
graph = ContextGraph(advanced_analytics=True)
|
|
143
|
+
|
|
144
|
+
insights = graph.get_decision_insights()
|
|
145
|
+
summary = graph.get_decision_summary()
|
|
146
|
+
context_insights = ctx.get_context_insights()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Output: Total count, category breakdown, outcome distribution, avg confidence, top influential.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## `list [--category <cat>] [--entity <id>] [--from <date>] [--to <date>]`
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from alphasemantichub.context.decision_query import DecisionQuery
|
|
157
|
+
from alphasemantichub.context import AgentContext
|
|
158
|
+
from datetime import datetime
|
|
159
|
+
|
|
160
|
+
ctx = AgentContext(decision_tracking=True)
|
|
161
|
+
dq = DecisionQuery(graph_store=ctx.graph_store)
|
|
162
|
+
|
|
163
|
+
if category: decisions = dq.find_by_category(category, limit=100)
|
|
164
|
+
elif entity: decisions = dq.find_by_entity(entity, limit=100)
|
|
165
|
+
elif from_date: decisions = dq.find_by_time_range(
|
|
166
|
+
start=datetime.fromisoformat(from_date),
|
|
167
|
+
end=datetime.fromisoformat(to_date or "2099-12-31"),
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Return: `| ID | Category | Scenario | Outcome | Confidence | Maker | Timestamp |`
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## `exception <decision_id> <policy_id> "<reason>" --approver <name>`
|
|
176
|
+
|
|
177
|
+
Record a formal policy exception.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from alphasemantichub.context.decision_recorder import DecisionRecorder
|
|
181
|
+
from alphasemantichub.context import AgentContext
|
|
182
|
+
|
|
183
|
+
ctx = AgentContext(decision_tracking=True)
|
|
184
|
+
recorder = DecisionRecorder(graph_store=ctx.graph_store)
|
|
185
|
+
|
|
186
|
+
exception_id = recorder.record_exception(
|
|
187
|
+
decision_id=decision_id, policy_id=policy_id,
|
|
188
|
+
reason=reason, approver=approver,
|
|
189
|
+
approval_method="manual_override", justification=reason,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
from alphasemantichub.context.decision_query import DecisionQuery
|
|
193
|
+
dq = DecisionQuery(graph_store=ctx.graph_store)
|
|
194
|
+
similar = dq.find_similar_exceptions(exception_reason=reason, limit=5)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Output: `Exception recorded: <exception_id>` + similar past exceptions for audit context.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deduplicate
|
|
3
|
+
description: Detect duplicate entities, duplicate groups, and relationship duplicates in Alpha Semantic Hub using fuzzy matching, schema heuristics, and graph similarity.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:deduplicate
|
|
7
|
+
|
|
8
|
+
Remove duplicates from the knowledge graph. Usage: `/alphasemantichub:deduplicate <strategy> [args]`
|
|
9
|
+
|
|
10
|
+
`$ARGUMENTS` = deduplication strategy + optional entity or threshold.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `entities [--threshold <score>] [--field <name>]`
|
|
15
|
+
|
|
16
|
+
Detect duplicate entities and group them by similarity.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from alphasemantichub.deduplication import DuplicateDetector
|
|
20
|
+
|
|
21
|
+
finder = DuplicateDetector()
|
|
22
|
+
candidates = finder.detect_duplicates(entities, threshold=threshold)
|
|
23
|
+
groups = finder.detect_duplicate_groups(entities, threshold=threshold)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Output: duplicate candidate list, duplicate groups, and representative merge recommendations.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## `relations [--similarity <score>]`
|
|
31
|
+
|
|
32
|
+
Detect duplicate relationships and normalize edge representations.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from alphasemantichub.deduplication import DuplicateDetector
|
|
36
|
+
|
|
37
|
+
finder = DuplicateDetector()
|
|
38
|
+
relations = finder.detect_duplicates(relation_list, threshold=similarity)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Result: duplicate relation candidates, normalized relationship groups, and cleanup summary.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: embed
|
|
3
|
+
description: Generate, inspect, and use node/text embeddings in Alpha Semantic Hub — compute Node2Vec embeddings, find similar nodes, score link predictions, batch similarity, and pairwise similarity. Uses NodeEmbedder, SimilarityCalculator, LinkPredictor, and AgentContext. Sub-commands: compute, similar, similarity, predict-link, top-links, batch, pairwise.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:embed
|
|
7
|
+
|
|
8
|
+
Generate and inspect graph embeddings. Usage: `/alphasemantichub:embed <sub-command> [args]`
|
|
9
|
+
|
|
10
|
+
`$ARGUMENTS` = sub-command + arguments.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `compute [--labels <t1,t2>] [--rels <r1,r2>] [--dim N] [--walks N]`
|
|
15
|
+
|
|
16
|
+
Generate Node2Vec embeddings for graph nodes.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from alphasemantichub.kg.node_embeddings import NodeEmbedder
|
|
20
|
+
from alphasemantichub.context import ContextGraph
|
|
21
|
+
|
|
22
|
+
graph = ContextGraph()
|
|
23
|
+
embedder = NodeEmbedder()
|
|
24
|
+
|
|
25
|
+
node_labels = labels_arg.split(",") if labels_arg else graph.get_all_node_types()
|
|
26
|
+
rel_types = rels_arg.split(",") if rels_arg else []
|
|
27
|
+
|
|
28
|
+
# All positional args required: graph_store, node_labels, relationship_types
|
|
29
|
+
embeddings = embedder.compute_embeddings(
|
|
30
|
+
graph_store=graph,
|
|
31
|
+
node_labels=node_labels,
|
|
32
|
+
relationship_types=rel_types,
|
|
33
|
+
embedding_dimension=int(dim_arg) if dim_arg else None,
|
|
34
|
+
num_walks=int(walks_arg) if walks_arg else None,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Store embeddings back on nodes
|
|
38
|
+
embedder.store_embeddings(
|
|
39
|
+
graph_store=graph,
|
|
40
|
+
embeddings=embeddings,
|
|
41
|
+
property_name="node2vec_embedding",
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Output:
|
|
46
|
+
```
|
|
47
|
+
Embeddings computed and stored.
|
|
48
|
+
Nodes embedded: N
|
|
49
|
+
Embedding dim: 128
|
|
50
|
+
Node types covered: [type1, type2, ...]
|
|
51
|
+
|
|
52
|
+
Sample (first 5 nodes):
|
|
53
|
+
| Node | Type | Embedding dim | Stored |
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## `similar <node_id> [--top N]`
|
|
59
|
+
|
|
60
|
+
Find the most similar nodes to a given node in embedding space.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from alphasemantichub.kg.node_embeddings import NodeEmbedder
|
|
64
|
+
from alphasemantichub.context import ContextGraph, AgentContext
|
|
65
|
+
|
|
66
|
+
graph = ContextGraph()
|
|
67
|
+
embedder = NodeEmbedder()
|
|
68
|
+
|
|
69
|
+
# NodeEmbedder.find_similar_nodes uses the stored node2vec_embedding property
|
|
70
|
+
neighbors = embedder.find_similar_nodes(
|
|
71
|
+
graph_store=graph,
|
|
72
|
+
node_id=node_id,
|
|
73
|
+
top_k=int(top_n) if top_n else 10,
|
|
74
|
+
embedding_property="node2vec_embedding",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Also use AgentContext for richer similarity with metadata
|
|
78
|
+
ctx = AgentContext(kg_algorithms=True)
|
|
79
|
+
entity_similar = ctx.find_similar_entities(
|
|
80
|
+
entity_id=node_id,
|
|
81
|
+
similarity_type="content", # or "structural", "hybrid"
|
|
82
|
+
top_k=int(top_n) if top_n else 10,
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Return: `| Rank | Node ID | Type | Cosine Similarity | Shared Properties |`
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## `similarity <n1> <n2> [--method cosine|euclidean|manhattan|correlation]`
|
|
91
|
+
|
|
92
|
+
Compute pairwise similarity between two nodes.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from alphasemantichub.kg.similarity_calculator import SimilarityCalculator
|
|
96
|
+
from alphasemantichub.kg.node_embeddings import NodeEmbedder
|
|
97
|
+
from alphasemantichub.context import ContextGraph
|
|
98
|
+
|
|
99
|
+
graph = ContextGraph()
|
|
100
|
+
embedder = NodeEmbedder()
|
|
101
|
+
calc = SimilarityCalculator()
|
|
102
|
+
|
|
103
|
+
# Get embeddings for both nodes
|
|
104
|
+
v1 = embedder.find_similar_nodes(graph, n1, top_k=1) # placeholder — use stored embedding
|
|
105
|
+
v2 = embedder.find_similar_nodes(graph, n2, top_k=1)
|
|
106
|
+
|
|
107
|
+
method = method_arg or "cosine"
|
|
108
|
+
if method == "cosine":
|
|
109
|
+
score = calc.cosine_similarity(vector1=v1, vector2=v2)
|
|
110
|
+
elif method == "euclidean":
|
|
111
|
+
score = calc.euclidean_distance(v1, v2)
|
|
112
|
+
elif method == "manhattan":
|
|
113
|
+
score = calc.manhattan_distance(v1, v2)
|
|
114
|
+
elif method == "correlation":
|
|
115
|
+
score = calc.correlation_similarity(v1, v2)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Output:
|
|
119
|
+
```
|
|
120
|
+
Similarity: "<n1>" ↔ "<n2>"
|
|
121
|
+
Method: cosine
|
|
122
|
+
Score: 0.847
|
|
123
|
+
|
|
124
|
+
Interpretation: HIGH similarity (>0.8)
|
|
125
|
+
Shared neighbors: K
|
|
126
|
+
Common node types: [types]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## `predict-link <n1> <n2> [--method cosine|jaccard|adamic-adar|common-neighbors]`
|
|
132
|
+
|
|
133
|
+
Score the likelihood of a relationship between two nodes.
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from alphasemantichub.kg.link_predictor import LinkPredictor
|
|
137
|
+
from alphasemantichub.context import ContextGraph
|
|
138
|
+
|
|
139
|
+
graph = ContextGraph()
|
|
140
|
+
predictor = LinkPredictor()
|
|
141
|
+
|
|
142
|
+
# score_link(graph_store, node_id1, node_id2, method=)
|
|
143
|
+
score = predictor.score_link(
|
|
144
|
+
graph_store=graph,
|
|
145
|
+
node_id1=n1,
|
|
146
|
+
node_id2=n2,
|
|
147
|
+
method=method_arg or None,
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Output:
|
|
152
|
+
```
|
|
153
|
+
Link Prediction: "<n1>" → "<n2>"
|
|
154
|
+
Method: cosine
|
|
155
|
+
Score: 0.723 (threshold: 0.5 → LIKELY)
|
|
156
|
+
|
|
157
|
+
Recommendation: This link is LIKELY to be meaningful.
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## `top-links <node_id> [--top N] [--method <method>]`
|
|
163
|
+
|
|
164
|
+
Find the top-N most likely new connections for a node.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from alphasemantichub.kg.link_predictor import LinkPredictor
|
|
168
|
+
from alphasemantichub.context import ContextGraph
|
|
169
|
+
|
|
170
|
+
graph = ContextGraph()
|
|
171
|
+
predictor = LinkPredictor()
|
|
172
|
+
|
|
173
|
+
top = predictor.predict_top_links(
|
|
174
|
+
graph_store=graph,
|
|
175
|
+
node_id=node_id,
|
|
176
|
+
top_k=int(top_n) if top_n else 10,
|
|
177
|
+
method=method_arg or None,
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Return: `| Rank | Target Node | Type | Score | Existing Link? |`
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## `batch <query_node> [--against <n1,n2,...>] [--top N]`
|
|
186
|
+
|
|
187
|
+
Score similarity between a query node and a set of target nodes (or all nodes).
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from alphasemantichub.kg.similarity_calculator import SimilarityCalculator
|
|
191
|
+
from alphasemantichub.kg.node_embeddings import NodeEmbedder
|
|
192
|
+
from alphasemantichub.context import ContextGraph
|
|
193
|
+
|
|
194
|
+
graph = ContextGraph()
|
|
195
|
+
embedder = NodeEmbedder()
|
|
196
|
+
calc = SimilarityCalculator()
|
|
197
|
+
|
|
198
|
+
# Get query embedding and all target embeddings
|
|
199
|
+
query_vec = ... # from stored node2vec_embedding
|
|
200
|
+
target_embeddings = {n: embedder.get_embedding(n) for n in targets}
|
|
201
|
+
|
|
202
|
+
scores = calc.batch_similarity(
|
|
203
|
+
embeddings=target_embeddings,
|
|
204
|
+
query_embedding=query_vec,
|
|
205
|
+
top_k=int(top_n) if top_n else 20,
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Return: `| Node | Type | Score |` sorted descending.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## `pairwise [--labels <t1,t2>] [--method cosine|euclidean]`
|
|
214
|
+
|
|
215
|
+
Compute all pairwise similarities among a set of nodes.
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from alphasemantichub.kg.similarity_calculator import SimilarityCalculator
|
|
219
|
+
|
|
220
|
+
calc = SimilarityCalculator()
|
|
221
|
+
|
|
222
|
+
pairwise = calc.pairwise_similarity(
|
|
223
|
+
embeddings=embeddings_dict,
|
|
224
|
+
method=method_arg or None,
|
|
225
|
+
)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Show as a heatmap summary — top-5 most similar pairs and bottom-5 most dissimilar pairs. Full matrix on request.
|
|
229
|
+
|
|
230
|
+
Also use `AgentContext.predict_decision_relationships(decision_id, top_k)` when working within decision graphs for relationship prediction enriched with KG algorithms.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explain
|
|
3
|
+
description: Explain Alpha Semantic Hub reasoning, decision logic, and graph results with traceability, causal context, and human-readable rationale.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /alphasemantichub:explain
|
|
7
|
+
|
|
8
|
+
Produce explanations for decisions, rules, and graph analytics. Usage: `/alphasemantichub:explain <target> [args]`
|
|
9
|
+
|
|
10
|
+
`$ARGUMENTS` = explanation target + optional detail level.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `decision <decision_id> [--detail <level>]`
|
|
15
|
+
|
|
16
|
+
Explain why a decision was reached.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from alphasemantichub.reasoning.explanation_generator import ExplanationGenerator
|
|
20
|
+
|
|
21
|
+
# For decision explainability in Alpha Semantic Hub contexts:
|
|
22
|
+
decision_trace = ctx.trace_decision_explainability(decision_id=decision_id)
|
|
23
|
+
|
|
24
|
+
# For reasoning/proof explanations:
|
|
25
|
+
generator = ExplanationGenerator(detail_level=detail)
|
|
26
|
+
explanation = generator.generate_explanation(reasoning_result)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Output: decision factors, rule traces, confidence, and suggested next steps.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## `graph <node_id> [--path N]`
|
|
34
|
+
|
|
35
|
+
Explain graph relationships and why a node is connected.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
# Use AgentContext explainability + causal tracing for graph-connected decisions
|
|
39
|
+
graph_explanation = ctx.trace_decision_explainability(decision_id=node_id)
|
|
40
|
+
upstream = ctx.get_causal_chain(decision_id=node_id, direction="upstream", max_depth=depth)
|
|
41
|
+
downstream = ctx.get_causal_chain(decision_id=node_id, direction="downstream", max_depth=depth)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Return: cause/effect chains, supporting evidence, and relevant metadata.
|