crystalplane 0.1.0__tar.gz

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.
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: crystalplane
3
+ Version: 0.1.0
4
+ Summary: Hermetic, zero-dependency slim runtime client for Crystalplane / Crystalspace knowledge and skill crystals across non-Vanguard agent systems.
5
+ Author-email: Enterprise Picard Engineering <engineering@picard.enterprise>
6
+ License: Apache-2.0
7
+ Keywords: crystalplane,crystalspace,agents,langchain,mcp,skills,knowledge,rag
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ Provides-Extra: langchain
21
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
22
+ Provides-Extra: crewai
23
+ Requires-Dist: crewai>=0.1.0; extra == "crewai"
24
+ Provides-Extra: all
25
+ Requires-Dist: langchain-core>=0.1.0; extra == "all"
26
+ Requires-Dist: crewai>=0.1.0; extra == "all"
27
+
28
+ # Crystalplane Python Slim Runtime Client (`crystalplane`)
29
+
30
+ A hermetic, zero-dependency Python client for connecting any AI agent system (LangChain, LlamaIndex, CrewAI, AutoGen, OpenAI, Claude/MCP) to **Crystalplane** knowledge and skill crystals.
31
+
32
+ ## Features
33
+ - **Zero External Dependencies**: Pure Python standard library (`urllib.request`, `hashlib`, `json`).
34
+ - **Prompt Hydration**: Automatically resolves `~~shardID~~` markers in system prompts into verified authoritative skills.
35
+ - **Dynamic Skill Assembly**: Call `/api/assemble` to compile composite skills within a specified token budget.
36
+ - **Memory & Crystal Ingestion**: Ingest agent traces and learned workflows into durable SHA-256 microchain shards.
37
+ - **Dual-Layer Caching**: In-memory LRU + optional persistent disk cache with SHA-256 node integrity verification.
38
+ - **Universal MCP Bridge**: Run `python -m crystalplane.mcp_bridge` to expose Crystalplane tools to Claude Desktop, Cursor, or Zed.
39
+
40
+ ## Quickstart
41
+
42
+ ```python
43
+ from crystalplane import CrystalClient
44
+
45
+ # Automatically reads CRYSTAL_SERVER_URL and CRYSTAL_API_KEY from environment
46
+ client = CrystalClient()
47
+
48
+ # 1. Hydrate a prompt template with authoritative skill shards
49
+ prompt = client.hydrate("""
50
+ You are Picard's Chief Architect. Adhere to our platform invariants:
51
+ ~~sh_core_directive_mathematical_fidelity~~
52
+
53
+ Task: {task}
54
+ """, task="Verify the Reed-Solomon polynomial codec.")
55
+
56
+ # 2. Search knowledge crystals
57
+ results = client.search(query="distributed database locking", limit=5)
58
+
59
+ # 3. Dynamic context assembly within token budget
60
+ assembled = client.assemble(query="motor safety", max_tokens=2048)
61
+ print(assembled.prompt_injection)
62
+ ```
@@ -0,0 +1,35 @@
1
+ # Crystalplane Python Slim Runtime Client (`crystalplane`)
2
+
3
+ A hermetic, zero-dependency Python client for connecting any AI agent system (LangChain, LlamaIndex, CrewAI, AutoGen, OpenAI, Claude/MCP) to **Crystalplane** knowledge and skill crystals.
4
+
5
+ ## Features
6
+ - **Zero External Dependencies**: Pure Python standard library (`urllib.request`, `hashlib`, `json`).
7
+ - **Prompt Hydration**: Automatically resolves `~~shardID~~` markers in system prompts into verified authoritative skills.
8
+ - **Dynamic Skill Assembly**: Call `/api/assemble` to compile composite skills within a specified token budget.
9
+ - **Memory & Crystal Ingestion**: Ingest agent traces and learned workflows into durable SHA-256 microchain shards.
10
+ - **Dual-Layer Caching**: In-memory LRU + optional persistent disk cache with SHA-256 node integrity verification.
11
+ - **Universal MCP Bridge**: Run `python -m crystalplane.mcp_bridge` to expose Crystalplane tools to Claude Desktop, Cursor, or Zed.
12
+
13
+ ## Quickstart
14
+
15
+ ```python
16
+ from crystalplane import CrystalClient
17
+
18
+ # Automatically reads CRYSTAL_SERVER_URL and CRYSTAL_API_KEY from environment
19
+ client = CrystalClient()
20
+
21
+ # 1. Hydrate a prompt template with authoritative skill shards
22
+ prompt = client.hydrate("""
23
+ You are Picard's Chief Architect. Adhere to our platform invariants:
24
+ ~~sh_core_directive_mathematical_fidelity~~
25
+
26
+ Task: {task}
27
+ """, task="Verify the Reed-Solomon polynomial codec.")
28
+
29
+ # 2. Search knowledge crystals
30
+ results = client.search(query="distributed database locking", limit=5)
31
+
32
+ # 3. Dynamic context assembly within token budget
33
+ assembled = client.assemble(query="motor safety", max_tokens=2048)
34
+ print(assembled.prompt_injection)
35
+ ```
@@ -0,0 +1,32 @@
1
+ """
2
+ Crystalplane — Hermetic Slim Runtime Client for AI Agent Systems
3
+ """
4
+
5
+ from crystalplane.client import (
6
+ AssembledCrystal,
7
+ CrystalClient,
8
+ CrystalClientError,
9
+ RegistrationResult,
10
+ Shard,
11
+ )
12
+ from crystalplane.cache import ShardCache
13
+ from crystalplane.rate_limiter import RateLimiter
14
+ from crystalplane.crawler import SkillCrawler
15
+ from crystalplane.archive_crawler import ArchiveBookCrawler
16
+ from crystalplane.research_lattice import ResearchLatticeEngine
17
+
18
+ __version__ = "0.1.0"
19
+ __all__ = [
20
+ "CrystalClient",
21
+ "CrystalClientError",
22
+ "Shard",
23
+ "AssembledCrystal",
24
+ "RegistrationResult",
25
+ "ShardCache",
26
+ "RateLimiter",
27
+ "SkillCrawler",
28
+ "ArchiveBookCrawler",
29
+ "ResearchLatticeEngine",
30
+ "__version__",
31
+ ]
32
+
@@ -0,0 +1,4 @@
1
+ from crystalplane.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,3 @@
1
+ """
2
+ Crystalplane Adapters for Non-Vanguard Agent Frameworks
3
+ """
@@ -0,0 +1,40 @@
1
+ """
2
+ Crystalplane — CrewAI Tool Adapter
3
+ Provides native CrewAI BaseTool implementations.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any, List, Optional
9
+
10
+ from crystalplane.client import CrystalClient
11
+
12
+
13
+ def get_crewai_tools(client: CrystalClient) -> List[Any]:
14
+ """Returns CrewAI compatible BaseTool instances."""
15
+ try:
16
+ from crewai.tools import tool
17
+ except ImportError:
18
+ raise ImportError(
19
+ "CrewAI is not installed. Run `pip install crewai` or `pip install 'crystalplane[crewai]'`."
20
+ )
21
+
22
+ @tool("Search Crystalplane Knowledge")
23
+ def search_shards(query: str, domain: Optional[str] = None) -> str:
24
+ """Search Crystalplane for authoritative skills, directives, or knowledge shards by keyword."""
25
+ from crystalplane.adapters.openai import execute_tool_call
26
+ return execute_tool_call(client, "crystal_search", {"query": query, "domain": domain})
27
+
28
+ @tool("Get Shard by ID")
29
+ def get_shard(shard_id: str) -> str:
30
+ """Retrieve full authoritative markdown text of a specific Shard by its ID."""
31
+ from crystalplane.adapters.openai import execute_tool_call
32
+ return execute_tool_call(client, "crystal_get_shard", {"shard_id": shard_id})
33
+
34
+ @tool("Assemble Context Crystal")
35
+ def assemble_crystal(query: str, max_tokens: int = 2048) -> str:
36
+ """Dynamically assemble composite prompt injection context across shards within a token budget."""
37
+ from crystalplane.adapters.openai import execute_tool_call
38
+ return execute_tool_call(client, "crystal_assemble", {"query": query, "max_tokens": max_tokens})
39
+
40
+ return [search_shards, get_shard, assemble_crystal]
@@ -0,0 +1,51 @@
1
+ """
2
+ Crystalplane — LangChain & LangGraph Adapter
3
+ Provides native LangChain BaseTool and Retriever components.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any, List, Optional
9
+
10
+ from crystalplane.client import CrystalClient
11
+
12
+
13
+ def get_crystal_tools(client: CrystalClient) -> List[Any]:
14
+ """Returns a list of LangChain BaseTool instances bound to the given CrystalClient."""
15
+ try:
16
+ from langchain_core.tools import tool
17
+ except ImportError:
18
+ raise ImportError(
19
+ "LangChain is not installed. Run `pip install langchain-core` or `pip install 'crystalplane[langchain]'`."
20
+ )
21
+
22
+ @tool
23
+ def crystal_search(query: str, domain: Optional[str] = None, limit: int = 5) -> str:
24
+ """Search Crystalplane for authoritative skill and knowledge shards by keywords."""
25
+ from crystalplane.adapters.openai import execute_tool_call
26
+ return execute_tool_call(client, "crystal_search", {"query": query, "domain": domain, "limit": limit})
27
+
28
+ @tool
29
+ def crystal_get_shard(shard_id: str) -> str:
30
+ """Retrieve the complete authoritative markdown content and metadata for a specific Shard by ID."""
31
+ from crystalplane.adapters.openai import execute_tool_call
32
+ return execute_tool_call(client, "crystal_get_shard", {"shard_id": shard_id})
33
+
34
+ @tool
35
+ def crystal_assemble(query: str, max_tokens: int = 2048) -> str:
36
+ """Assemble a Composite Skill Crystal within a token budget and return the compiled prompt injection."""
37
+ from crystalplane.adapters.openai import execute_tool_call
38
+ return execute_tool_call(client, "crystal_assemble", {"query": query, "max_tokens": max_tokens})
39
+
40
+ @tool
41
+ def crystal_crystallize(title: str, domain: str, raw_text: str, author_id: str = "agent:langchain") -> str:
42
+ """Persist a new skill, trace, or memory into a durable SHA-256 microchain Shard."""
43
+ from crystalplane.adapters.openai import execute_tool_call
44
+ return execute_tool_call(client, "crystal_crystallize", {
45
+ "title": title,
46
+ "domain": domain,
47
+ "raw_text": raw_text,
48
+ "author_id": author_id
49
+ })
50
+
51
+ return [crystal_search, crystal_get_shard, crystal_assemble, crystal_crystallize]
@@ -0,0 +1,162 @@
1
+ """
2
+ Crystalplane — OpenAI Function Calling & Swarm Adapter
3
+ Provides standard OpenAI JSON tool schemas and automatic tool call execution.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ from typing import Any, Dict, List
10
+
11
+ from crystalplane.client import CrystalClient
12
+
13
+
14
+ def get_openai_tools() -> List[Dict[str, Any]]:
15
+ """Returns tool schemas compatible with `client.chat.completions.create(tools=...)`."""
16
+ return [
17
+ {
18
+ "type": "function",
19
+ "function": {
20
+ "name": "crystal_search",
21
+ "description": "Search the Crystalplane repository for authoritative skill and knowledge shards.",
22
+ "parameters": {
23
+ "type": "object",
24
+ "properties": {
25
+ "query": {
26
+ "type": "string",
27
+ "description": "Keywords or semantic terms to search for (e.g. 'GAAP revenue recognition' or 'dead-time insertion')"
28
+ },
29
+ "domain": {
30
+ "type": "string",
31
+ "description": "Optional lab domain filter (e.g. 'software', 'research', 'hardware', 'accounting')"
32
+ },
33
+ "limit": {
34
+ "type": "integer",
35
+ "description": "Maximum number of shards to return (default: 5)"
36
+ }
37
+ },
38
+ "required": ["query"]
39
+ }
40
+ }
41
+ },
42
+ {
43
+ "type": "function",
44
+ "function": {
45
+ "name": "crystal_get_shard",
46
+ "description": "Retrieve the complete authoritative markdown content and metadata for a specific Shard by ID.",
47
+ "parameters": {
48
+ "type": "object",
49
+ "properties": {
50
+ "shard_id": {
51
+ "type": "string",
52
+ "description": "The canonical ID of the shard (e.g. 'sh_core_directive_mathematical_fidelity')"
53
+ }
54
+ },
55
+ "required": ["shard_id"]
56
+ }
57
+ }
58
+ },
59
+ {
60
+ "type": "function",
61
+ "function": {
62
+ "name": "crystal_assemble",
63
+ "description": "Assemble a Composite Skill Crystal within a strict token budget and retrieve the compiled prompt injection.",
64
+ "parameters": {
65
+ "type": "object",
66
+ "properties": {
67
+ "query": {
68
+ "type": "string",
69
+ "description": "Search query describing the domain skills needed"
70
+ },
71
+ "max_tokens": {
72
+ "type": "integer",
73
+ "description": "Maximum token budget (e.g. 2048)"
74
+ }
75
+ },
76
+ "required": ["query"]
77
+ }
78
+ }
79
+ },
80
+ {
81
+ "type": "function",
82
+ "function": {
83
+ "name": "crystal_crystallize",
84
+ "description": "Persist a newly discovered skill, execution trace, or episodic memory into a durable SHA-256 microchain Shard.",
85
+ "parameters": {
86
+ "type": "object",
87
+ "properties": {
88
+ "title": { "type": "string", "description": "Title of the knowledge or skill shard" },
89
+ "domain": { "type": "string", "description": "Domain (e.g. 'software', 'research')" },
90
+ "raw_text": { "type": "string", "description": "Markdown specification or documentation" },
91
+ "author_id": { "type": "string", "description": "Agent handle or identifier" },
92
+ "tags": { "type": "array", "items": { "type": "string" }, "description": "Optional search tags" }
93
+ },
94
+ "required": ["title", "domain", "raw_text", "author_id"]
95
+ }
96
+ }
97
+ }
98
+ ]
99
+
100
+
101
+ def execute_tool_call(client: CrystalClient, tool_name: str, arguments: str | Dict[str, Any]) -> str:
102
+ """Dispatches an OpenAI tool call and returns stringified JSON result."""
103
+ if isinstance(arguments, str):
104
+ try:
105
+ args = json.loads(arguments)
106
+ except Exception:
107
+ args = {}
108
+ else:
109
+ args = arguments
110
+
111
+ if tool_name == "crystal_search":
112
+ shards = client.search(
113
+ query=args.get("query", ""),
114
+ domain=args.get("domain"),
115
+ limit=args.get("limit", 5)
116
+ )
117
+ return json.dumps([
118
+ {
119
+ "id": s.id,
120
+ "title": s.title,
121
+ "domain": s.domain,
122
+ "tokens": s.token_count,
123
+ "preview": s.plaintext[:300] + ("..." if len(s.plaintext) > 300 else "")
124
+ }
125
+ for s in shards
126
+ ])
127
+
128
+ elif tool_name == "crystal_get_shard":
129
+ shard = client.get_shard(shard_id=args.get("shard_id", ""))
130
+ if not shard:
131
+ return json.dumps({"error": f"Shard '{args.get('shard_id')}' not found."})
132
+ return json.dumps(shard.to_dict())
133
+
134
+ elif tool_name == "crystal_assemble":
135
+ assembled = client.assemble(
136
+ query=args.get("query"),
137
+ max_tokens=args.get("max_tokens", 2048)
138
+ )
139
+ return json.dumps({
140
+ "title": assembled.title,
141
+ "crystalId": assembled.crystal_id,
142
+ "totalTokens": assembled.total_tokens,
143
+ "shardsCount": assembled.shards_count,
144
+ "promptInjection": assembled.prompt_injection
145
+ })
146
+
147
+ elif tool_name == "crystal_crystallize":
148
+ shard = client.crystallize(
149
+ title=args.get("title", "Untitled Shard"),
150
+ domain=args.get("domain", "software"),
151
+ raw_text=args.get("raw_text", ""),
152
+ author_id=args.get("author_id", "agent:openai"),
153
+ tags=args.get("tags")
154
+ )
155
+ return json.dumps({
156
+ "message": "Shard successfully crystallized and committed to blockchain.",
157
+ "shardId": shard.id,
158
+ "title": shard.title,
159
+ "tokens": shard.token_count
160
+ })
161
+
162
+ return json.dumps({"error": f"Unknown tool: {tool_name}"})