hanzo-mcp 0.6.13__py3-none-any.whl → 0.7.1__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.
Potentially problematic release.
This version of hanzo-mcp might be problematic. Click here for more details.
- hanzo_mcp/analytics/__init__.py +5 -0
- hanzo_mcp/analytics/posthog_analytics.py +364 -0
- hanzo_mcp/cli.py +3 -3
- hanzo_mcp/cli_enhanced.py +3 -3
- hanzo_mcp/config/settings.py +1 -1
- hanzo_mcp/config/tool_config.py +18 -4
- hanzo_mcp/server.py +34 -1
- hanzo_mcp/tools/__init__.py +65 -2
- hanzo_mcp/tools/agent/__init__.py +84 -3
- hanzo_mcp/tools/agent/agent_tool.py +102 -4
- hanzo_mcp/tools/agent/agent_tool_v2.py +492 -0
- hanzo_mcp/tools/agent/clarification_protocol.py +220 -0
- hanzo_mcp/tools/agent/clarification_tool.py +68 -0
- hanzo_mcp/tools/agent/claude_cli_tool.py +125 -0
- hanzo_mcp/tools/agent/claude_desktop_auth.py +508 -0
- hanzo_mcp/tools/agent/cli_agent_base.py +191 -0
- hanzo_mcp/tools/agent/code_auth.py +436 -0
- hanzo_mcp/tools/agent/code_auth_tool.py +194 -0
- hanzo_mcp/tools/agent/codex_cli_tool.py +123 -0
- hanzo_mcp/tools/agent/critic_tool.py +376 -0
- hanzo_mcp/tools/agent/gemini_cli_tool.py +128 -0
- hanzo_mcp/tools/agent/grok_cli_tool.py +128 -0
- hanzo_mcp/tools/agent/iching_tool.py +380 -0
- hanzo_mcp/tools/agent/network_tool.py +273 -0
- hanzo_mcp/tools/agent/prompt.py +62 -20
- hanzo_mcp/tools/agent/review_tool.py +433 -0
- hanzo_mcp/tools/agent/swarm_tool.py +535 -0
- hanzo_mcp/tools/agent/swarm_tool_v2.py +654 -0
- hanzo_mcp/tools/common/base.py +1 -0
- hanzo_mcp/tools/common/batch_tool.py +102 -10
- hanzo_mcp/tools/common/fastmcp_pagination.py +369 -0
- hanzo_mcp/tools/common/forgiving_edit.py +243 -0
- hanzo_mcp/tools/common/paginated_base.py +230 -0
- hanzo_mcp/tools/common/paginated_response.py +307 -0
- hanzo_mcp/tools/common/pagination.py +226 -0
- hanzo_mcp/tools/common/tool_list.py +3 -0
- hanzo_mcp/tools/common/truncate.py +101 -0
- hanzo_mcp/tools/filesystem/__init__.py +29 -0
- hanzo_mcp/tools/filesystem/ast_multi_edit.py +562 -0
- hanzo_mcp/tools/filesystem/directory_tree_paginated.py +338 -0
- hanzo_mcp/tools/lsp/__init__.py +5 -0
- hanzo_mcp/tools/lsp/lsp_tool.py +512 -0
- hanzo_mcp/tools/memory/__init__.py +76 -0
- hanzo_mcp/tools/memory/knowledge_tools.py +518 -0
- hanzo_mcp/tools/memory/memory_tools.py +456 -0
- hanzo_mcp/tools/search/__init__.py +6 -0
- hanzo_mcp/tools/search/find_tool.py +581 -0
- hanzo_mcp/tools/search/unified_search.py +953 -0
- hanzo_mcp/tools/shell/__init__.py +5 -0
- hanzo_mcp/tools/shell/auto_background.py +203 -0
- hanzo_mcp/tools/shell/base_process.py +53 -27
- hanzo_mcp/tools/shell/bash_tool.py +17 -33
- hanzo_mcp/tools/shell/npx_tool.py +15 -32
- hanzo_mcp/tools/shell/streaming_command.py +594 -0
- hanzo_mcp/tools/shell/uvx_tool.py +15 -32
- hanzo_mcp/types.py +23 -0
- {hanzo_mcp-0.6.13.dist-info → hanzo_mcp-0.7.1.dist-info}/METADATA +229 -71
- {hanzo_mcp-0.6.13.dist-info → hanzo_mcp-0.7.1.dist-info}/RECORD +61 -24
- hanzo_mcp-0.6.13.dist-info/licenses/LICENSE +0 -21
- {hanzo_mcp-0.6.13.dist-info → hanzo_mcp-0.7.1.dist-info}/WHEEL +0 -0
- {hanzo_mcp-0.6.13.dist-info → hanzo_mcp-0.7.1.dist-info}/entry_points.txt +0 -0
- {hanzo_mcp-0.6.13.dist-info → hanzo_mcp-0.7.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Grok CLI agent tool.
|
|
2
|
+
|
|
3
|
+
This tool provides integration with xAI's Grok CLI,
|
|
4
|
+
allowing programmatic execution of Grok models for code tasks.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Optional, override, final
|
|
8
|
+
from mcp.server import FastMCP
|
|
9
|
+
from mcp.server.fastmcp import Context as MCPContext
|
|
10
|
+
|
|
11
|
+
from hanzo_mcp.tools.agent.cli_agent_base import CLIAgentBase
|
|
12
|
+
from hanzo_mcp.tools.common.permissions import PermissionManager
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@final
|
|
16
|
+
class GrokCLITool(CLIAgentBase):
|
|
17
|
+
"""Tool for executing Grok CLI."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
permission_manager: PermissionManager,
|
|
22
|
+
model: Optional[str] = None,
|
|
23
|
+
**kwargs
|
|
24
|
+
):
|
|
25
|
+
"""Initialize Grok CLI tool.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
permission_manager: Permission manager for access control
|
|
29
|
+
model: Optional model override (defaults to grok-2)
|
|
30
|
+
**kwargs: Additional arguments
|
|
31
|
+
"""
|
|
32
|
+
super().__init__(
|
|
33
|
+
permission_manager=permission_manager,
|
|
34
|
+
command_name="grok",
|
|
35
|
+
provider_name="xAI Grok",
|
|
36
|
+
default_model=model or "grok-2",
|
|
37
|
+
env_vars=["XAI_API_KEY", "GROK_API_KEY"],
|
|
38
|
+
**kwargs
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
@override
|
|
43
|
+
def name(self) -> str:
|
|
44
|
+
"""Get the tool name."""
|
|
45
|
+
return "grok_cli"
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
@override
|
|
49
|
+
def description(self) -> str:
|
|
50
|
+
"""Get the tool description."""
|
|
51
|
+
return """Execute xAI Grok CLI for code tasks.
|
|
52
|
+
|
|
53
|
+
This tool runs the Grok CLI for code generation, analysis,
|
|
54
|
+
and reasoning tasks. It uses Grok-2 by default.
|
|
55
|
+
|
|
56
|
+
Features:
|
|
57
|
+
- Grok-2 with advanced reasoning capabilities
|
|
58
|
+
- Real-time information access
|
|
59
|
+
- Code generation and analysis
|
|
60
|
+
- Humor and personality in responses
|
|
61
|
+
|
|
62
|
+
Usage:
|
|
63
|
+
grok_cli(prompts="Write a Python web scraper with async support")
|
|
64
|
+
grok_cli(prompts="Explain quantum computing like I'm a programmer", model="grok-1")
|
|
65
|
+
|
|
66
|
+
Requirements:
|
|
67
|
+
- Grok CLI must be installed
|
|
68
|
+
- XAI_API_KEY or GROK_API_KEY environment variable
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@override
|
|
72
|
+
def get_cli_args(self, prompt: str, **kwargs) -> List[str]:
|
|
73
|
+
"""Get CLI arguments for Grok.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
prompt: The prompt to send
|
|
77
|
+
**kwargs: Additional arguments (model, temperature, etc.)
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
List of command arguments
|
|
81
|
+
"""
|
|
82
|
+
args = ["chat"]
|
|
83
|
+
|
|
84
|
+
# Add model
|
|
85
|
+
model = kwargs.get("model", self.default_model)
|
|
86
|
+
args.extend(["--model", model])
|
|
87
|
+
|
|
88
|
+
# Add temperature if specified
|
|
89
|
+
if "temperature" in kwargs:
|
|
90
|
+
args.extend(["--temperature", str(kwargs["temperature"])])
|
|
91
|
+
|
|
92
|
+
# Add max tokens if specified
|
|
93
|
+
if "max_tokens" in kwargs:
|
|
94
|
+
args.extend(["--max-tokens", str(kwargs["max_tokens"])])
|
|
95
|
+
|
|
96
|
+
# Add system prompt if specified
|
|
97
|
+
if "system_prompt" in kwargs:
|
|
98
|
+
args.extend(["--system", kwargs["system_prompt"]])
|
|
99
|
+
|
|
100
|
+
# Add the prompt
|
|
101
|
+
args.append(prompt)
|
|
102
|
+
|
|
103
|
+
return args
|
|
104
|
+
|
|
105
|
+
@override
|
|
106
|
+
def register(self, mcp_server: FastMCP) -> None:
|
|
107
|
+
"""Register this tool with the MCP server."""
|
|
108
|
+
tool_self = self
|
|
109
|
+
|
|
110
|
+
@mcp_server.tool(name=self.name, description=self.description)
|
|
111
|
+
async def grok_cli(
|
|
112
|
+
ctx: MCPContext,
|
|
113
|
+
prompts: str,
|
|
114
|
+
model: Optional[str] = None,
|
|
115
|
+
temperature: Optional[float] = None,
|
|
116
|
+
max_tokens: Optional[int] = None,
|
|
117
|
+
working_dir: Optional[str] = None,
|
|
118
|
+
system_prompt: Optional[str] = None,
|
|
119
|
+
) -> str:
|
|
120
|
+
return await tool_self.call(
|
|
121
|
+
ctx,
|
|
122
|
+
prompts=prompts,
|
|
123
|
+
model=model,
|
|
124
|
+
temperature=temperature,
|
|
125
|
+
max_tokens=max_tokens,
|
|
126
|
+
working_dir=working_dir,
|
|
127
|
+
system_prompt=system_prompt,
|
|
128
|
+
)
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"""I Ching tool for creative problem solving using Hanzo principles."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
from typing import Any, Dict, List, Optional, override
|
|
5
|
+
from enum import Enum
|
|
6
|
+
|
|
7
|
+
from hanzo_mcp.tools.common.base import BaseTool
|
|
8
|
+
from mcp.server.fastmcp import Context as MCPContext
|
|
9
|
+
from mcp.server import FastMCP
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HanzoPrinciple(Enum):
|
|
13
|
+
"""Hanzo principles organized by category."""
|
|
14
|
+
# Empathy
|
|
15
|
+
AUTONOMY = ("Autonomy", "Trust fully; freedom fuels genius", "🦅")
|
|
16
|
+
BALANCE = ("Balance", "Steady wins; burnout loses every time", "⚖️")
|
|
17
|
+
CUSTOMER_OBSESSION = ("Customer Obsession", "Coach relentlessly; their victories yours", "🎓")
|
|
18
|
+
HUMILITY = ("Humility", "Quiet confidence; greatness emerges naturally", "🧘")
|
|
19
|
+
INTEGRITY = ("Integrity", "Principles never break; reputation never fades", "🛡️")
|
|
20
|
+
SELFLESSNESS = ("Selflessness", "Elevate others; personal success follows", "🤝")
|
|
21
|
+
|
|
22
|
+
# Science
|
|
23
|
+
CURIOSITY = ("Curiosity", "Question always; truth never ends", "🌱")
|
|
24
|
+
EMPIRICISM = ("Empiricism", "Hypothesize, measure; reality defines truth", "🔬")
|
|
25
|
+
PRECISION = ("Precision", "Discipline in data; eliminate guesswork completely", "🎯")
|
|
26
|
+
VALIDATION = ("Validation", "Test assumptions hard; illusions crumble fast", "✅")
|
|
27
|
+
OBJECTIVITY = ("Objectivity", "Ego out; results speak plainly", "🧊")
|
|
28
|
+
REPEATABILITY = ("Repeatability", "Do it again; success repeats systematically", "🔄")
|
|
29
|
+
|
|
30
|
+
# Design
|
|
31
|
+
ACCESSIBILITY = ("Accessibility", "Open doors wide; adoption thrives naturally", "🌐")
|
|
32
|
+
BEAUTY = ("Beauty", "Form speaks louder; aesthetics lift utility", "🎨")
|
|
33
|
+
CLARITY = ("Clarity", "Obvious is perfect; complexity hidden cleanly", "🔍")
|
|
34
|
+
CONSISTENCY = ("Consistency", "Uniform patterns; predictable results always", "🎯")
|
|
35
|
+
SIMPLICITY = ("Simplicity", "Cut ruthlessly; essential alone remains", "🪶")
|
|
36
|
+
FLOW = ("Flow", "Remove friction; natural motion prevails", "🌊")
|
|
37
|
+
|
|
38
|
+
# Engineering
|
|
39
|
+
BATTERIES_INCLUDED = ("Batteries Included", "Ready instantly; everything you need to start", "🔋")
|
|
40
|
+
CONCURRENCY = ("Concurrency", "Parallel flows; frictionless scale", "⚡")
|
|
41
|
+
COMPOSABLE = ("Composable", "Modular magic; pieces multiply power", "🧩")
|
|
42
|
+
INTEROPERABLE = ("Interoperable", "Integrate effortlessly; value compounds infinitely", "🔗")
|
|
43
|
+
ORTHOGONAL = ("Orthogonal", "Each tool exact; no overlap, no waste", "⚙️")
|
|
44
|
+
SCALABLE = ("Scalable", "Growth limitless; obstacles removed at inception", "📈")
|
|
45
|
+
|
|
46
|
+
# Scale
|
|
47
|
+
DISRUPTION = ("Disruption", "Reinvent boldly; transcend competition entirely", "💥")
|
|
48
|
+
EXPERIMENTATION = ("Experimentation", "Test quickly; iterate endlessly", "🧪")
|
|
49
|
+
EXPONENTIALITY = ("Exponentiality", "Compound constantly; incremental fades", "📈")
|
|
50
|
+
VELOCITY = ("Velocity", "Ship fast; refine faster", "🚀")
|
|
51
|
+
URGENCY = ("Urgency", "Act now; delays destroy opportunity", "⏱️")
|
|
52
|
+
|
|
53
|
+
# Wisdom
|
|
54
|
+
ADAPTABILITY = ("Adaptability", "Pivot sharply; fluid response accelerates evolution", "🌊")
|
|
55
|
+
DECENTRALIZATION = ("Decentralization", "Distribute power; resilience born from autonomy", "🕸️")
|
|
56
|
+
FREEDOM = ("Freedom", "Democratize creativity; tools liberated, gatekeepers removed", "🗽")
|
|
57
|
+
LONGEVITY = ("Longevity", "Build timelessly; greatness endures beyond lifetimes", "⏳")
|
|
58
|
+
SECURITY = ("Security", "Encryption first; privacy non-negotiable", "🔐")
|
|
59
|
+
ZEN = ("Zen", "Calm mastery; effortless excellence every moment", "☯️")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Hexagram:
|
|
63
|
+
"""I Ching hexagram with interpretation."""
|
|
64
|
+
|
|
65
|
+
HEXAGRAMS = {
|
|
66
|
+
"111111": ("乾 (Qián)", "Creative", "Initiating force, pure yang energy. Time for bold action."),
|
|
67
|
+
"000000": ("坤 (Kūn)", "Receptive", "Pure receptivity, yielding. Time to listen and adapt."),
|
|
68
|
+
"100010": ("屯 (Zhūn)", "Initial Difficulty", "Growing pains. Persevere through early challenges."),
|
|
69
|
+
"010001": ("蒙 (Méng)", "Youthful Folly", "Beginner's mind. Learn humbly, question assumptions."),
|
|
70
|
+
"111010": ("需 (Xū)", "Waiting", "Strategic patience. Prepare while waiting for the right moment."),
|
|
71
|
+
"010111": ("訟 (Sòng)", "Conflict", "Address conflicts directly but seek resolution, not victory."),
|
|
72
|
+
"010000": ("師 (Shī)", "Army", "Organize resources, build strong teams, lead by example."),
|
|
73
|
+
"000010": ("比 (Bǐ)", "Holding Together", "Unity and collaboration. Strengthen bonds."),
|
|
74
|
+
"111011": ("小畜 (Xiǎo Chù)", "Small Accumulation", "Small consistent improvements compound over time."),
|
|
75
|
+
"110111": ("履 (Lǚ)", "Treading", "Careful progress. Mind the details while moving forward."),
|
|
76
|
+
"111000": ("泰 (Tài)", "Peace", "Harmony achieved. Maintain balance while building."),
|
|
77
|
+
"000111": ("否 (Pǐ)", "Standstill", "Blockage present. Pause, reassess, find new paths."),
|
|
78
|
+
"101111": ("同人 (Tóng Rén)", "Fellowship", "Community strength. Build alliances and share knowledge."),
|
|
79
|
+
"111101": ("大有 (Dà Yǒu)", "Great Possession", "Abundance available. Share generously to multiply value."),
|
|
80
|
+
"001000": ("謙 (Qiān)", "Modesty", "Humble confidence. Let work speak for itself."),
|
|
81
|
+
"000100": ("豫 (Yù)", "Enthusiasm", "Infectious energy. Channel excitement into action."),
|
|
82
|
+
"100110": ("隨 (Suí)", "Following", "Adaptive leadership. Know when to lead and when to follow."),
|
|
83
|
+
"011001": ("蠱 (Gǔ)", "Work on Decay", "Fix technical debt. Address root causes."),
|
|
84
|
+
"110000": ("臨 (Lín)", "Approach", "Opportunity approaching. Prepare to receive it."),
|
|
85
|
+
"000011": ("觀 (Guān)", "Contemplation", "Step back for perspective. See the whole system."),
|
|
86
|
+
"100101": ("噬嗑 (Shì Kè)", "Biting Through", "Remove obstacles decisively. Clear blockages."),
|
|
87
|
+
"101001": ("賁 (Bì)", "Grace", "Polish and refine. Beauty enhances function."),
|
|
88
|
+
"000001": ("剝 (Bō)", "Splitting Apart", "Decay phase. Let go of what's not working."),
|
|
89
|
+
"100000": ("復 (Fù)", "Return", "New cycle begins. Start fresh with lessons learned."),
|
|
90
|
+
"100111": ("無妄 (Wú Wàng)", "Innocence", "Act with pure intention. Avoid overthinking."),
|
|
91
|
+
"111001": ("大畜 (Dà Chù)", "Great Accumulation", "Build reserves. Invest in infrastructure."),
|
|
92
|
+
"100001": ("頤 (Yí)", "Nourishment", "Feed growth. Provide resources teams need."),
|
|
93
|
+
"011110": ("大過 (Dà Guò)", "Great Excess", "Extraordinary measures needed. Bold action required."),
|
|
94
|
+
"010010": ("坎 (Kǎn)", "Abysmal", "Navigate danger carefully. Trust your training."),
|
|
95
|
+
"101101": ("離 (Lí)", "Clinging Fire", "Clarity and vision. Illuminate the path forward."),
|
|
96
|
+
"001110": ("咸 (Xián)", "Influence", "Mutual attraction. Build on natural affinities."),
|
|
97
|
+
"011100": ("恆 (Héng)", "Duration", "Persistence pays. Maintain steady effort."),
|
|
98
|
+
"001111": ("遯 (Dùn)", "Retreat", "Strategic withdrawal. Regroup and refocus."),
|
|
99
|
+
"111100": ("大壯 (Dà Zhuàng)", "Great Power", "Strength available. Use power responsibly."),
|
|
100
|
+
"000101": ("晉 (Jìn)", "Progress", "Advance steadily. Each step builds momentum."),
|
|
101
|
+
"101000": ("明夷 (Míng Yí)", "Darkening Light", "Work quietly. Keep brilliance hidden for now."),
|
|
102
|
+
"101011": ("家人 (Jiā Rén)", "Family", "Team harmony. Strengthen internal culture."),
|
|
103
|
+
"110101": ("睽 (Kuí)", "Opposition", "Creative tension. Find synthesis in differences."),
|
|
104
|
+
"001010": ("蹇 (Jiǎn)", "Obstruction", "Difficulty ahead. Find alternative routes."),
|
|
105
|
+
"010100": ("解 (Xiè)", "Deliverance", "Breakthrough achieved. Consolidate gains."),
|
|
106
|
+
"110001": ("損 (Sǔn)", "Decrease", "Simplify ruthlessly. Less is more."),
|
|
107
|
+
"100011": ("益 (Yì)", "Increase", "Multiply value. Invest in growth."),
|
|
108
|
+
"111110": ("夬 (Guài)", "Breakthrough", "Decisive moment. Act with conviction."),
|
|
109
|
+
"011111": ("姤 (Gòu)", "Coming to Meet", "Unexpected encounter. Stay alert to opportunity."),
|
|
110
|
+
"000110": ("萃 (Cuì)", "Gathering", "Convergence point. Bring elements together."),
|
|
111
|
+
"011000": ("升 (Shēng)", "Pushing Upward", "Gradual ascent. Build systematically."),
|
|
112
|
+
"010110": ("困 (Kùn)", "Exhaustion", "Resources depleted. Rest and recharge."),
|
|
113
|
+
"011010": ("井 (Jǐng)", "The Well", "Deep resources. Draw from fundamentals."),
|
|
114
|
+
"101110": ("革 (Gé)", "Revolution", "Transform completely. Embrace radical change."),
|
|
115
|
+
"011101": ("鼎 (Dǐng)", "The Cauldron", "Transformation vessel. Cook new solutions."),
|
|
116
|
+
"100100": ("震 (Zhèn)", "Thunder", "Shocking awakening. Respond to wake-up calls."),
|
|
117
|
+
"001001": ("艮 (Gèn)", "Mountain", "Stillness and stability. Find solid ground."),
|
|
118
|
+
"001011": ("漸 (Jiàn)", "Gradual Progress", "Step by step. Patient development."),
|
|
119
|
+
"110100": ("歸妹 (Guī Mèi)", "Marrying Maiden", "New partnerships. Align expectations."),
|
|
120
|
+
"101100": ("豐 (Fēng)", "Abundance", "Peak achievement. Prepare for cycles."),
|
|
121
|
+
"001101": ("旅 (Lǚ)", "The Wanderer", "Explorer mindset. Learn from journey."),
|
|
122
|
+
"011011": ("巽 (Xùn)", "Gentle Wind", "Subtle influence. Persistent gentle pressure."),
|
|
123
|
+
"110110": ("兌 (Duì)", "Joy", "Infectious happiness. Celebrate progress."),
|
|
124
|
+
"010011": ("渙 (Huàn)", "Dispersion", "Break up rigidity. Dissolve barriers."),
|
|
125
|
+
"110010": ("節 (Jié)", "Limitation", "Healthy constraints. Focus through limits."),
|
|
126
|
+
"110011": ("中孚 (Zhōng Fú)", "Inner Truth", "Authentic core. Build from truth."),
|
|
127
|
+
"001100": ("小過 (Xiǎo Guò)", "Small Excess", "Minor adjustments. Fine-tune carefully."),
|
|
128
|
+
"101010": ("既濟 (Jì Jì)", "After Completion", "Success achieved. Maintain vigilance."),
|
|
129
|
+
"010101": ("未濟 (Wèi Jì)", "Before Completion", "Almost there. Final push needed."),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
def __init__(self, lines: str):
|
|
133
|
+
self.lines = lines
|
|
134
|
+
self.name, self.title, self.meaning = self.HEXAGRAMS.get(
|
|
135
|
+
lines,
|
|
136
|
+
("Unknown", "Mystery", "The pattern is unclear. Trust your intuition.")
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def get_changing_lines(self) -> List[int]:
|
|
140
|
+
"""Identify which lines are changing (would be 6 or 9 in traditional I Ching)."""
|
|
141
|
+
# For simplicity, randomly select 0-2 changing lines
|
|
142
|
+
num_changes = random.choice([0, 1, 1, 2])
|
|
143
|
+
if num_changes == 0:
|
|
144
|
+
return []
|
|
145
|
+
positions = list(range(6))
|
|
146
|
+
return sorted(random.sample(positions, num_changes))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class IChing:
|
|
150
|
+
"""I Ching oracle for engineering guidance."""
|
|
151
|
+
|
|
152
|
+
def __init__(self):
|
|
153
|
+
self.principles = list(HanzoPrinciple)
|
|
154
|
+
|
|
155
|
+
def cast_hexagram(self) -> Hexagram:
|
|
156
|
+
"""Cast a hexagram using virtual coins."""
|
|
157
|
+
lines = ""
|
|
158
|
+
for _ in range(6):
|
|
159
|
+
# Three coin tosses: heads=3, tails=2
|
|
160
|
+
coins = sum(random.choice([2, 3]) for _ in range(3))
|
|
161
|
+
# 6=old yin(changing 0), 7=young yang(1), 8=young yin(0), 9=old yang(changing 1)
|
|
162
|
+
if coins in [6, 8]:
|
|
163
|
+
lines += "0"
|
|
164
|
+
else:
|
|
165
|
+
lines += "1"
|
|
166
|
+
return Hexagram(lines)
|
|
167
|
+
|
|
168
|
+
def select_principles(self, hexagram: Hexagram, challenge: str) -> List[HanzoPrinciple]:
|
|
169
|
+
"""Select relevant Hanzo principles based on hexagram and challenge."""
|
|
170
|
+
# Use hexagram pattern to deterministically but creatively select principles
|
|
171
|
+
selected = []
|
|
172
|
+
|
|
173
|
+
# Primary principle based on hexagram pattern
|
|
174
|
+
primary_index = sum(int(bit) * (2**i) for i, bit in enumerate(hexagram.lines)) % len(self.principles)
|
|
175
|
+
selected.append(self.principles[primary_index])
|
|
176
|
+
|
|
177
|
+
# Supporting principles based on challenge keywords
|
|
178
|
+
keywords = challenge.lower().split()
|
|
179
|
+
keyword_matches = {
|
|
180
|
+
"scale": [HanzoPrinciple.SCALABLE, HanzoPrinciple.EXPONENTIALITY],
|
|
181
|
+
"speed": [HanzoPrinciple.VELOCITY, HanzoPrinciple.URGENCY],
|
|
182
|
+
"quality": [HanzoPrinciple.PRECISION, HanzoPrinciple.VALIDATION],
|
|
183
|
+
"team": [HanzoPrinciple.AUTONOMY, HanzoPrinciple.BALANCE],
|
|
184
|
+
"design": [HanzoPrinciple.SIMPLICITY, HanzoPrinciple.BEAUTY],
|
|
185
|
+
"bug": [HanzoPrinciple.EMPIRICISM, HanzoPrinciple.OBJECTIVITY],
|
|
186
|
+
"refactor": [HanzoPrinciple.CLARITY, HanzoPrinciple.COMPOSABLE],
|
|
187
|
+
"security": [HanzoPrinciple.SECURITY, HanzoPrinciple.INTEGRITY],
|
|
188
|
+
"performance": [HanzoPrinciple.CONCURRENCY, HanzoPrinciple.ORTHOGONAL],
|
|
189
|
+
"user": [HanzoPrinciple.CUSTOMER_OBSESSION, HanzoPrinciple.ACCESSIBILITY],
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
for keyword, principles in keyword_matches.items():
|
|
193
|
+
if keyword in keywords:
|
|
194
|
+
selected.extend(principles)
|
|
195
|
+
|
|
196
|
+
# Add complementary principle based on changing lines
|
|
197
|
+
changing_lines = hexagram.get_changing_lines()
|
|
198
|
+
if changing_lines:
|
|
199
|
+
complement_index = (primary_index + sum(changing_lines)) % len(self.principles)
|
|
200
|
+
selected.append(self.principles[complement_index])
|
|
201
|
+
|
|
202
|
+
# Ensure uniqueness and limit to 3-5 principles
|
|
203
|
+
seen = set()
|
|
204
|
+
unique_selected = []
|
|
205
|
+
for principle in selected:
|
|
206
|
+
if principle not in seen:
|
|
207
|
+
seen.add(principle)
|
|
208
|
+
unique_selected.append(principle)
|
|
209
|
+
|
|
210
|
+
return unique_selected[:5]
|
|
211
|
+
|
|
212
|
+
def generate_guidance(
|
|
213
|
+
self,
|
|
214
|
+
hexagram: Hexagram,
|
|
215
|
+
principles: List[HanzoPrinciple],
|
|
216
|
+
challenge: str
|
|
217
|
+
) -> str:
|
|
218
|
+
"""Generate creative guidance combining I Ching wisdom and Hanzo principles."""
|
|
219
|
+
guidance = f"☯️ I CHING GUIDANCE FOR ENGINEERING CHALLENGE ☯️\n\n"
|
|
220
|
+
guidance += f"**Your Challenge:** {challenge}\n\n"
|
|
221
|
+
|
|
222
|
+
guidance += f"**Hexagram Cast:** {hexagram.name} - {hexagram.title}\n"
|
|
223
|
+
guidance += f"**Pattern:** {''.join('━━━' if l == '1' else '━ ━' for l in hexagram.lines[::-1])}\n"
|
|
224
|
+
guidance += f"**Ancient Wisdom:** {hexagram.meaning}\n\n"
|
|
225
|
+
|
|
226
|
+
guidance += "**Hanzo Principles to Apply:**\n\n"
|
|
227
|
+
|
|
228
|
+
for principle in principles:
|
|
229
|
+
name, wisdom, emoji = principle.value
|
|
230
|
+
guidance += f"{emoji} **{name}**\n"
|
|
231
|
+
guidance += f" *{wisdom}*\n\n"
|
|
232
|
+
|
|
233
|
+
# Generate specific actionable advice
|
|
234
|
+
guidance += "**Synthesized Approach:**\n\n"
|
|
235
|
+
|
|
236
|
+
# Hexagram-specific guidance
|
|
237
|
+
if "Creative" in hexagram.title:
|
|
238
|
+
guidance += "• This is a time for bold innovation. Don't hold back on ambitious ideas.\n"
|
|
239
|
+
elif "Receptive" in hexagram.title:
|
|
240
|
+
guidance += "• Listen deeply to user needs and system constraints before acting.\n"
|
|
241
|
+
elif "Difficulty" in hexagram.title:
|
|
242
|
+
guidance += "• Challenges are teachers. Each obstacle reveals the path forward.\n"
|
|
243
|
+
elif "Waiting" in hexagram.title:
|
|
244
|
+
guidance += "• Strategic patience required. Prepare thoroughly before implementation.\n"
|
|
245
|
+
elif "Conflict" in hexagram.title:
|
|
246
|
+
guidance += "• Technical disagreements? Seek data-driven resolution.\n"
|
|
247
|
+
elif "Peace" in hexagram.title:
|
|
248
|
+
guidance += "• Harmony achieved. Now build sustainably on this foundation.\n"
|
|
249
|
+
|
|
250
|
+
# Principle-specific actionable advice
|
|
251
|
+
principle_actions = {
|
|
252
|
+
HanzoPrinciple.SCALABLE: "• Design for 10x growth from day one. Remove scaling bottlenecks now.",
|
|
253
|
+
HanzoPrinciple.VELOCITY: "• Ship an MVP today. Perfect is the enemy of shipped.",
|
|
254
|
+
HanzoPrinciple.SIMPLICITY: "• Delete half your code. The best code is no code.",
|
|
255
|
+
HanzoPrinciple.EMPIRICISM: "• Measure everything. Let data guide your decisions.",
|
|
256
|
+
HanzoPrinciple.CUSTOMER_OBSESSION: "• Talk to users now. Their pain is your roadmap.",
|
|
257
|
+
HanzoPrinciple.CONCURRENCY: "• Parallelize everything possible. Sequential is slow.",
|
|
258
|
+
HanzoPrinciple.SECURITY: "• Security is not optional. Encrypt by default.",
|
|
259
|
+
HanzoPrinciple.ZEN: "• Find calm in the chaos. Clear mind writes better code.",
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
for principle in principles:
|
|
263
|
+
if principle in principle_actions:
|
|
264
|
+
guidance += principle_actions[principle] + "\n"
|
|
265
|
+
|
|
266
|
+
# Changing lines wisdom
|
|
267
|
+
changing_lines = hexagram.get_changing_lines()
|
|
268
|
+
if changing_lines:
|
|
269
|
+
guidance += f"\n**Lines in Transition:** {', '.join(str(i+1) for i in changing_lines)}\n"
|
|
270
|
+
guidance += "• Change is imminent in these areas. Prepare for transformation.\n"
|
|
271
|
+
|
|
272
|
+
# Final synthesis
|
|
273
|
+
guidance += "\n**The Way Forward:**\n"
|
|
274
|
+
guidance += self._synthesize_action_plan(hexagram, principles, challenge)
|
|
275
|
+
|
|
276
|
+
guidance += "\n\n*Remember: The I Ching reveals patterns, not prescriptions. "
|
|
277
|
+
guidance += "Let this wisdom guide your intuition as you craft your solution.*"
|
|
278
|
+
|
|
279
|
+
return guidance
|
|
280
|
+
|
|
281
|
+
def _synthesize_action_plan(
|
|
282
|
+
self,
|
|
283
|
+
hexagram: Hexagram,
|
|
284
|
+
principles: List[HanzoPrinciple],
|
|
285
|
+
challenge: str
|
|
286
|
+
) -> str:
|
|
287
|
+
"""Create a specific action plan based on the reading."""
|
|
288
|
+
plan = ""
|
|
289
|
+
|
|
290
|
+
# Determine the nature of the challenge
|
|
291
|
+
if any(word in challenge.lower() for word in ["bug", "error", "fix", "broken"]):
|
|
292
|
+
plan += "1. **Diagnose systematically** - Use empirical debugging, not guesswork\n"
|
|
293
|
+
plan += "2. **Fix root cause** - Address the source, not just symptoms\n"
|
|
294
|
+
plan += "3. **Prevent recurrence** - Add tests and monitoring\n"
|
|
295
|
+
elif any(word in challenge.lower() for word in ["scale", "performance", "slow"]):
|
|
296
|
+
plan += "1. **Measure first** - Profile to find actual bottlenecks\n"
|
|
297
|
+
plan += "2. **Parallelize** - Use concurrency where possible\n"
|
|
298
|
+
plan += "3. **Simplify** - Remove complexity before optimizing\n"
|
|
299
|
+
elif any(word in challenge.lower() for word in ["design", "architect", "structure"]):
|
|
300
|
+
plan += "1. **Start simple** - MVP first, elaborate later\n"
|
|
301
|
+
plan += "2. **Stay flexible** - Design for change\n"
|
|
302
|
+
plan += "3. **Think holistically** - Consider entire system\n"
|
|
303
|
+
elif any(word in challenge.lower() for word in ["team", "collaborate", "people"]):
|
|
304
|
+
plan += "1. **Enable autonomy** - Trust your team\n"
|
|
305
|
+
plan += "2. **Maintain balance** - Sustainable pace wins\n"
|
|
306
|
+
plan += "3. **Share knowledge** - Elevate everyone\n"
|
|
307
|
+
else:
|
|
308
|
+
plan += "1. **Clarify intent** - What problem are you really solving?\n"
|
|
309
|
+
plan += "2. **Start small** - Build incrementally\n"
|
|
310
|
+
plan += "3. **Iterate rapidly** - Fast feedback loops\n"
|
|
311
|
+
|
|
312
|
+
return plan
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class IChingTool(BaseTool):
|
|
316
|
+
"""Tool for applying I Ching wisdom to engineering challenges."""
|
|
317
|
+
|
|
318
|
+
name = "iching"
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
@override
|
|
322
|
+
def description(self) -> str:
|
|
323
|
+
"""Get the tool description."""
|
|
324
|
+
return """Apply I Ching wisdom and Hanzo principles to engineering challenges.
|
|
325
|
+
|
|
326
|
+
This tool casts an I Ching hexagram and selects relevant Hanzo principles
|
|
327
|
+
to provide creative guidance for your engineering challenge.
|
|
328
|
+
|
|
329
|
+
Parameters:
|
|
330
|
+
- challenge: Description of the engineering challenge or question
|
|
331
|
+
|
|
332
|
+
The oracle will:
|
|
333
|
+
1. Cast a hexagram representing the current situation
|
|
334
|
+
2. Select relevant Hanzo principles
|
|
335
|
+
3. Synthesize actionable guidance
|
|
336
|
+
4. Provide specific recommendations
|
|
337
|
+
|
|
338
|
+
Example:
|
|
339
|
+
iching(
|
|
340
|
+
challenge="How should I approach refactoring this legacy codebase?"
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
Use this when you need:
|
|
344
|
+
- Fresh perspective on a problem
|
|
345
|
+
- Creative approach to challenges
|
|
346
|
+
- Wisdom for difficult decisions
|
|
347
|
+
- Alignment with Hanzo principles"""
|
|
348
|
+
|
|
349
|
+
def __init__(self):
|
|
350
|
+
"""Initialize the I Ching tool."""
|
|
351
|
+
super().__init__()
|
|
352
|
+
self.oracle = IChing()
|
|
353
|
+
|
|
354
|
+
async def call(
|
|
355
|
+
self,
|
|
356
|
+
ctx: MCPContext,
|
|
357
|
+
challenge: str
|
|
358
|
+
) -> str:
|
|
359
|
+
"""Cast I Ching and provide guidance."""
|
|
360
|
+
# Cast hexagram
|
|
361
|
+
hexagram = self.oracle.cast_hexagram()
|
|
362
|
+
|
|
363
|
+
# Select relevant principles
|
|
364
|
+
principles = self.oracle.select_principles(hexagram, challenge)
|
|
365
|
+
|
|
366
|
+
# Generate guidance
|
|
367
|
+
guidance = self.oracle.generate_guidance(hexagram, principles, challenge)
|
|
368
|
+
|
|
369
|
+
return guidance
|
|
370
|
+
|
|
371
|
+
def register(self, server: FastMCP) -> None:
|
|
372
|
+
"""Register the tool with the MCP server."""
|
|
373
|
+
tool_self = self
|
|
374
|
+
|
|
375
|
+
@server.tool(name=self.name, description=self.description)
|
|
376
|
+
async def iching(
|
|
377
|
+
ctx: MCPContext,
|
|
378
|
+
challenge: str
|
|
379
|
+
) -> str:
|
|
380
|
+
return await tool_self.call(ctx, challenge)
|