import os base = r'c:\Users\Mohd Kaif\semantica\plugins\skills' SKILLS = {} SKILLS['causal'] = """--- name: causal description: Causal chain analysis on Semantica decision graphs — upstream traces, downstream impact, root causes, impact scoring, network analysis, loop detection, precedent chains, and temporal causal queries. Uses CausalChainAnalyzer, ContextGraph, and AgentContext. --- # /semantica:causal Causal chain analysis. Usage: `/semantica:causal [options]` --- ## `trace [--direction upstream|downstream] [--depth N]` Walk the causal chain upstream (what caused this?) or downstream (what did this cause?). ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) chain = analyzer.get_causal_chain( decision_id=decision_id, direction=direction or "upstream", max_depth=int(depth) if depth else 10, ) ``` Output as Mermaid `graph TD` + table: `| Step | ID | Category | Outcome | Confidence | Depth |` --- ## `impact [--depth N] [--indirect]` Full downstream impact — direct and indirect influenced decisions. ```python from semantica.context import ContextGraph from semantica.context.causal_analyzer import CausalChainAnalyzer graph = ContextGraph(advanced_analytics=True) analyzer = CausalChainAnalyzer(graph_store=graph) impact = graph.analyze_decision_impact(decision_id, include_indirect="--indirect" in args) influence = graph.analyze_decision_influence(decision_id, max_depth=int(depth) if depth else 3, include_indirect=True) influenced = analyzer.get_influenced_decisions(decision_id, max_depth=int(depth) if depth else 10) score = analyzer.get_causal_impact_score(decision_id) ``` Output: Impact score (0-1) + direct/indirect counts + Mermaid downstream tree. --- ## `roots [--depth N]` Find root cause decisions at the origin of a causal chain. ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) roots = analyzer.find_root_causes(decision_id, max_depth=int(depth) if depth else 10) ``` Output: Root list + Mermaid path from root to target. --- ## `score ` Causal impact score + centrality breakdown. ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import ContextGraph, AgentContext ctx = AgentContext(decision_tracking=True, kg_algorithms=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) graph = ContextGraph() score = analyzer.get_causal_impact_score(decision_id) centrality = graph.get_node_centrality(decision_id) importance = graph.get_node_importance(decision_id) ``` Output: Score (0=isolated, 1=max) + degree/betweenness/closeness/eigenvector + interpretation. --- ## `network [ ...]` Analyze the full causal network structure. ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True, advanced_analytics=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) network = analyzer.analyze_causal_network(decision_ids=decision_ids or None) ``` Output: Network stats (edges, density, longest chain) + Mermaid of top-15 by impact. --- ## `loops [--depth N]` Detect circular causal dependencies. ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) loops = analyzer.find_causal_loops(max_depth=int(depth) if depth else 10) ``` Output: Each loop as `A -> B -> C -> A` chain + risk warning. --- ## `precedent-chain [--depth N]` Walk the full precedent chain (what decisions was this derived from?). ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) chain = analyzer.get_precedent_chain(decision_id, max_depth=int(depth) if depth else 10) ``` Return: `| Step | ID | Scenario | Outcome | Confidence | Date |` --- ## `at-time [--direction upstream|downstream]` Trace causal chain as it existed at a specific point in time. ```python from semantica.context.causal_analyzer import CausalChainAnalyzer from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) analyzer = CausalChainAnalyzer(graph_store=ctx.graph_store) historical = analyzer.trace_at_time( event_id=decision_id, at_time=at_time, direction=direction or "upstream", max_depth=10, ) ``` Output: Historical chain at `` + diff vs. current (added/removed decisions since then). """ SKILLS['policy'] = """--- name: policy description: Decision policy governance in Semantica — check compliance, find applicable policies, add/update/version policies, enforce rules against decision data, analyze change impact, track affected decisions, and record exceptions. Uses PolicyEngine, ContextGraph, and DecisionQuery. --- # /semantica:policy Policy governance. Usage: `/semantica:policy [args]` --- ## `check ` Check whether a decision complies with a policy. ```python from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) engine = ctx.get_policy_engine() decision = ctx.query_decisions(query=decision_id, max_hops=1)[0] compliant = engine.check_compliance(decision=decision, policy_id=policy_id) ``` Output: `COMPLIANT ✓ | NON-COMPLIANT ✗` + violated rules with details. --- ## `applicable [--entities ]` Find all policies applicable to a decision category and entity set. ```python engine = ctx.get_policy_engine() policies = engine.get_applicable_policies( category=category, entities=entities.split(",") if entities else None, ) ``` Return: `| Policy ID | Name | Version | Rules Count | Active Since |` --- ## `add "" --rules ''` Register a new policy. ```python from semantica.context.decision_models import Policy import json engine = ctx.get_policy_engine() policy = Policy(policy_id=policy_id, name=name, rules=json.loads(rules_json)) registered_id = engine.add_policy(policy) ``` --- ## `update --rules '' --reason "" [--version ]` Update policy rules with versioning and audit trail. ```python new_version = engine.update_policy( policy_id=policy_id, rules=json.loads(rules_json), change_reason=reason, new_version=version or None, ) ``` --- ## `enforce [--rules '']` Apply policy enforcement against decision data and report violations. ```python from semantica.context import ContextGraph import json graph = ContextGraph(advanced_analytics=True) result = graph.enforce_decision_policy( decision_data=json.loads(decision_data_json), policy_rules=json.loads(rules_json) if rules_json else None, ) rule_check = graph.check_decision_rules( decision_data=json.loads(decision_data_json), rules=json.loads(rules_json) if rules_json else None, ) ``` Output: Actions applied, violations list, ENFORCED/BLOCKED status. --- ## `history ` Show version history of a policy. ```python history = engine.get_policy_history(policy_id) ``` Return: `| Version | Changed At | Reason | Rules Delta |` --- ## `impact --rules ''` Analyze the effect of proposed policy changes on existing decisions. ```python import json impact = engine.analyze_policy_impact( policy_id=policy_id, proposed_rules=json.loads(proposed_rules_json), ) ``` Output: Count compliant -> non-compliant (risk) and non-compliant -> compliant (gain). --- ## `affected ` List all decisions affected by a policy version change. ```python affected = engine.get_affected_decisions(policy_id, from_version, to_version) ``` Return: `| Decision ID | Category | Was Compliant | Now Compliant |` --- ## `exception "" --approver ` Record a formal policy exception. ```python exception_id = engine.record_exception( decision_id=decision_id, policy_id=policy_id, reason=reason, approver=approver, justification=reason, ) from semantica.context.decision_query import DecisionQuery dq = DecisionQuery(graph_store=ctx.graph_store) similar = dq.find_similar_exceptions(exception_reason=reason, limit=5) ``` Output: `Exception recorded` + similar past exceptions for audit. """ SKILLS['query'] = """--- name: query description: Query the Semantica ContextGraph and AgentContext using natural language, multi-hop traversal, LLM reasoning, and direct graph queries. Sub-commands: retrieve, decisions, multi-hop, expand, reasoning, similar, graph. --- # /semantica:query Query the context graph. Usage: `/semantica:query "" [options]` --- ## `retrieve "" [--max N] [--graph] [--entities] [--expand]` Hybrid vector + graph retrieval. ```python from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True, graph_expansion=True, advanced_analytics=True) results = ctx.retrieve( query=question, max_results=int(max_n) if max_n else 5, use_graph="--graph" in args, include_entities="--entities" in args, include_relationships=True, expand_graph="--expand" in args, deduplicate=True, ) ``` Return: `| Rank | Content | Type | Score | Source | Timestamp |` --- ## `decisions "" [--hops N] [--hybrid]` Query decisions with multi-hop graph reasoning. ```python ctx = AgentContext(decision_tracking=True, advanced_analytics=True) decisions = ctx.query_decisions( query=question, max_hops=int(hops) if hops else 3, include_context=True, use_hybrid_search="--hybrid" in args, ) ``` Return: `| ID | Category | Scenario | Outcome | Confidence | Hops | Timestamp |` --- ## `multi-hop "" [--hops N]` Multi-hop graph traversal from a known entity. ```python ctx = AgentContext(decision_tracking=True, graph_expansion=True, advanced_analytics=True) result = ctx.multi_hop_context_query( start_entity=start_entity, query=question, max_hops=int(hops) if hops else 3, ) ``` Output: Traversal path + ranked results + Mermaid hop graph. --- ## `expand "" [--hops N]` Expand a query through the graph to find adjacent context. ```python ctx = AgentContext(graph_expansion=True) expanded = ctx.expand_query(query=question, max_hops=int(hops) if hops else 2) ``` Shows which expansion hops added what context. --- ## `reasoning "" [--max N] [--hops N]` LLM-powered reasoning over retrieved graph context. ```python ctx = AgentContext(decision_tracking=True, graph_expansion=True, advanced_analytics=True) result = ctx.query_with_reasoning( query=question, llm_provider=None, max_results=int(max_n) if max_n else 10, max_hops=int(hops) if hops else 2, ) ``` Output: LLM-synthesized answer + supporting evidence nodes + reasoning chain. --- ## `similar "" [--max N]` Find memories and nodes semantically similar to content. ```python ctx = AgentContext() results = ctx.find_similar(content=content, limit=int(max_n) if max_n else 5) ``` --- ## `graph "" [--skip N] [--limit N]` Direct query via ContextGraph.query(). ```python from semantica.context import ContextGraph graph = ContextGraph() results = graph.query( query=query_str, skip=int(skip) if skip else 0, limit=int(limit) if limit else 50, ) ``` Return: `| Node ID | Type | Properties | Neighbors |` + Mermaid pie of type distribution. """ SKILLS['explain'] = """--- name: explain description: Generate natural-language explanations for decisions, reasoning paths, inferences, node paths, and policy compliance. Uses ExplanationGenerator.generate_explanation, show_reasoning_path, justify_conclusion, AgentContext.trace_decision_explainability, and ContextGraph.trace_decision_chain. --- # /semantica:explain Generate explanations. Usage: `/semantica:explain ` --- ## `decision ` Full explainability trace for a decision. ```python from semantica.context import AgentContext, ContextGraph ctx = AgentContext(decision_tracking=True, advanced_analytics=True) explainability = ctx.trace_decision_explainability(decision_id) graph = ContextGraph(advanced_analytics=True) chain = graph.trace_decision_chain(decision_id, max_steps=5) causality = graph.trace_decision_causality(decision_id, max_depth=5) influence = ctx.analyze_decision_influence(decision_id, max_depth=3) ``` Output: Reasoning steps, causal antecedents, evidence items, policy compliance per policy. --- ## `reasoning ` Explain any reasoning object — generates natural-language summary and step trace. ```python from semantica.reasoning.explanation_generator import ExplanationGenerator gen = ExplanationGenerator() explanation = gen.generate_explanation(reasoning=reasoning_input) # explanation.summary, .confidence, .evidence path = gen.show_reasoning_path(reasoning=reasoning_input) # path.steps: [Step(type, description, confidence)] # path.conclusion ``` Output: Summary + step-by-step path + confidence score. --- ## `inference ""` Justify a conclusion against its reasoning context. ```python from semantica.reasoning.explanation_generator import ExplanationGenerator gen = ExplanationGenerator() path = gen.show_reasoning_path(reasoning=reasoning_context) justification = gen.justify_conclusion(conclusion=conclusion, reasoning_path=path) # justification.is_justified, .confidence, .supporting_steps, .opposing_factors ``` Output: `JUSTIFIED ✓ | NOT JUSTIFIED ✗ | PARTIAL ⚠` + supporting steps + opposing factors. --- ## `path ` Explain the semantic relationship between two nodes. ```python from semantica.kg.path_finder import PathFinder from semantica.context import ContextGraph from semantica.reasoning.explanation_generator import ExplanationGenerator graph = ContextGraph(advanced_analytics=True) finder = PathFinder() paths = finder.find_k_shortest_paths(graph, source=n1, target=n2, k=3) lengths = [finder.path_length(graph, p) for p in paths] gen = ExplanationGenerator() explanation = gen.generate_explanation(reasoning={"paths": paths, "source": n1, "target": n2}) ``` Output: Top-3 paths + prose summary + Mermaid sequenceDiagram. --- ## `compliance ` Explain policy compliance status of a decision. ```python from semantica.context import AgentContext ctx = AgentContext(decision_tracking=True) engine = ctx.get_policy_engine() decision = ctx.query_decisions(query=decision_id, max_hops=1)[0] applicable = engine.get_applicable_policies( category=decision.category, entities=decision.metadata.get("entities", []), ) results = [ {"policy": p, "compliant": engine.check_compliance(decision, p.policy_id)} for p in applicable ] ``` Output: Per-policy COMPLIANT/NON-COMPLIANT + violated rules + remediation suggestions. """ SKILLS['change'] = """--- name: change description: Track, review, and version Semantica knowledge graph changes. Sub-commands: log, diff, rollback, tag. Uses ChangeLog and OntologyVersionManager. --- # /semantica:change Track graph versions and changes. Usage: `/semantica:change [args]` --- ## `log [n]` Show last N change log entries (default: 20). ```python from semantica.change_management import ChangeLog log = ChangeLog() entries = log.get_recent(n=int(args) if args else 20) ``` Return: `| # | Timestamp | Operation | Target | Actor | Version |` --- ## `diff ` Structural diff between two versions. ```python from semantica.change_management import OntologyVersionManager manager = OntologyVersionManager() diff = manager.diff(v1, v2) ``` Output: Added/removed/modified classes, properties, and nodes. --- ## `rollback ` > **CONFIRMATION REQUIRED** before proceeding. Revert graph to a prior version snapshot. ```python manager.rollback(version) ``` --- ## `tag