cadskill 0.1.0__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.
- cadskill-0.1.0.dist-info/METADATA +48 -0
- cadskill-0.1.0.dist-info/RECORD +13 -0
- cadskill-0.1.0.dist-info/WHEEL +4 -0
- cadskill-0.1.0.dist-info/entry_points.txt +3 -0
- cadskill_mcp/__init__.py +0 -0
- cadskill_mcp/cli.py +474 -0
- cadskill_mcp/daemon.py +131 -0
- cadskill_mcp/runner.py +149 -0
- cadskill_mcp/server.py +485 -0
- cadskill_mcp/skill/SKILL.md +168 -0
- cadskill_mcp/static/viewer.html +4506 -0
- cadskill_mcp/store.py +101 -0
- cadskill_mcp/worker.py +643 -0
cadskill_mcp/store.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Models on disk. One folder per model:
|
|
2
|
+
|
|
3
|
+
<root>/<model>/current.py the script the model is built from
|
|
4
|
+
<root>/<model>/versions/0001.py every script that ran successfully, in order
|
|
5
|
+
<root>/<model>/versions.json one line of metadata per version
|
|
6
|
+
<root>/<model>/assets/ files imported for the script to load
|
|
7
|
+
<root>/<model>/exports/ files written by the export tool
|
|
8
|
+
|
|
9
|
+
The folder is plain files on purpose: a person can read, copy or version it.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import shutil
|
|
17
|
+
import time
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
DEFAULT_ROOT = Path.home() / "Documents" / "CadSkill"
|
|
21
|
+
LEGACY_ROOT = Path.home() / "Documents" / "CadDraft" # the folder's name before the project was CadSkill
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def root() -> Path:
|
|
25
|
+
if os.environ.get("CADSKILL_HOME"):
|
|
26
|
+
return Path(os.environ["CADSKILL_HOME"]).expanduser()
|
|
27
|
+
if not DEFAULT_ROOT.exists() and LEGACY_ROOT.is_dir():
|
|
28
|
+
try:
|
|
29
|
+
LEGACY_ROOT.rename(DEFAULT_ROOT) # carry models made under the old name over, once
|
|
30
|
+
except OSError:
|
|
31
|
+
return LEGACY_ROOT
|
|
32
|
+
return DEFAULT_ROOT
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def clean(model: str | None) -> str:
|
|
36
|
+
name = re.sub(r"[^a-z0-9_-]+", "-", (model or "default").strip().lower()).strip("-")
|
|
37
|
+
return name or "default"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Store:
|
|
41
|
+
def __init__(self, base: Path | None = None) -> None:
|
|
42
|
+
self.base = Path(base) if base else root()
|
|
43
|
+
|
|
44
|
+
def dir(self, model: str) -> Path:
|
|
45
|
+
return self.base / clean(model)
|
|
46
|
+
|
|
47
|
+
def models(self) -> list[dict]:
|
|
48
|
+
if not self.base.exists():
|
|
49
|
+
return []
|
|
50
|
+
out = []
|
|
51
|
+
for d in sorted(self.base.iterdir()):
|
|
52
|
+
if (d / "current.py").exists():
|
|
53
|
+
versions = self.versions(d.name)
|
|
54
|
+
out.append({"model": d.name, "versions": len(versions), "last": versions[-1] if versions else None})
|
|
55
|
+
return out
|
|
56
|
+
|
|
57
|
+
def current(self, model: str) -> str | None:
|
|
58
|
+
path = self.dir(model) / "current.py"
|
|
59
|
+
return path.read_text() if path.exists() else None
|
|
60
|
+
|
|
61
|
+
def versions(self, model: str) -> list[dict]:
|
|
62
|
+
path = self.dir(model) / "versions.json"
|
|
63
|
+
return json.loads(path.read_text()) if path.exists() else []
|
|
64
|
+
|
|
65
|
+
def version(self, model: str) -> int:
|
|
66
|
+
"""Number of the version current.py corresponds to (0 when there is none)."""
|
|
67
|
+
versions = self.versions(model)
|
|
68
|
+
return versions[-1]["version"] if versions else 0
|
|
69
|
+
|
|
70
|
+
def code(self, model: str, n: int) -> str:
|
|
71
|
+
path = self.dir(model) / "versions" / f"{n:04d}.py"
|
|
72
|
+
if not path.exists():
|
|
73
|
+
raise KeyError(n)
|
|
74
|
+
return path.read_text()
|
|
75
|
+
|
|
76
|
+
def save(self, model: str, code: str, summary: str, note: str | None = None) -> int:
|
|
77
|
+
"""Record a script that ran successfully as the next version and make it current."""
|
|
78
|
+
d = self.dir(model)
|
|
79
|
+
(d / "versions").mkdir(parents=True, exist_ok=True)
|
|
80
|
+
versions = self.versions(model)
|
|
81
|
+
n = (versions[-1]["version"] + 1) if versions else 1
|
|
82
|
+
(d / "versions" / f"{n:04d}.py").write_text(code)
|
|
83
|
+
(d / "current.py").write_text(code)
|
|
84
|
+
entry = {"version": n, "time": time.strftime("%Y-%m-%d %H:%M:%S"), "summary": summary}
|
|
85
|
+
if note:
|
|
86
|
+
entry["note"] = note
|
|
87
|
+
versions.append(entry)
|
|
88
|
+
(d / "versions.json").write_text(json.dumps(versions, indent=1))
|
|
89
|
+
return n
|
|
90
|
+
|
|
91
|
+
def add_asset(self, model: str, source: str) -> str:
|
|
92
|
+
src = Path(source).expanduser()
|
|
93
|
+
if not src.is_file():
|
|
94
|
+
raise FileNotFoundError(source)
|
|
95
|
+
dest = self.dir(model) / "assets"
|
|
96
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
97
|
+
shutil.copy2(src, dest / src.name)
|
|
98
|
+
return src.name
|
|
99
|
+
|
|
100
|
+
def export_path(self, model: str, filename: str) -> str:
|
|
101
|
+
return str(self.dir(model) / "exports" / filename)
|