framework-py 0.1.0.dev15__py3-none-any.whl → 0.1.0.dev16__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.
- framework/__init__.py +6 -0
- framework/_agents_md.py +48 -3
- framework/ai.py +7 -45
- framework/cloud.py +13 -0
- framework/setup_sync.py +534 -0
- framework/skill_pull.py +506 -0
- framework/skill_sync.py +38 -14
- {framework_py-0.1.0.dev15.dist-info → framework_py-0.1.0.dev16.dist-info}/METADATA +1 -1
- {framework_py-0.1.0.dev15.dist-info → framework_py-0.1.0.dev16.dist-info}/RECORD +11 -9
- {framework_py-0.1.0.dev15.dist-info → framework_py-0.1.0.dev16.dist-info}/WHEEL +0 -0
- {framework_py-0.1.0.dev15.dist-info → framework_py-0.1.0.dev16.dist-info}/licenses/LICENSE +0 -0
framework/__init__.py
CHANGED
|
@@ -128,6 +128,8 @@ from framework.scaffold import project_info, scaffold, status
|
|
|
128
128
|
from framework.scratch import scratch_capture, scratch_clean
|
|
129
129
|
from framework.security import AuditResult, git_security_audit
|
|
130
130
|
from framework.settings import settings, settings_read, settings_write
|
|
131
|
+
from framework.setup_sync import pull_setup, push_setup
|
|
132
|
+
from framework.skill_pull import pull_skills, push_skills
|
|
131
133
|
from framework.skill_sync import skills_sync
|
|
132
134
|
from framework.spec.check import spec_check
|
|
133
135
|
from framework.spec.merge import SpecError
|
|
@@ -247,6 +249,10 @@ __all__ = [
|
|
|
247
249
|
"publish_dir",
|
|
248
250
|
"publish_list",
|
|
249
251
|
"publish_notebook",
|
|
252
|
+
"pull_setup",
|
|
253
|
+
"pull_skills",
|
|
254
|
+
"push_setup",
|
|
255
|
+
"push_skills",
|
|
250
256
|
"quarto_generate_all",
|
|
251
257
|
"quarto_regenerate",
|
|
252
258
|
"read_framework_template",
|
framework/_agents_md.py
CHANGED
|
@@ -55,10 +55,35 @@ def _header(name: str) -> str:
|
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def
|
|
58
|
+
def skill_description(folder: Path) -> str:
|
|
59
|
+
"""A skill's own description, from its SKILL.md front matter, on one line with pipes
|
|
60
|
+
escaped, for skills Framework has no line for. R: ``.skill_description()``."""
|
|
61
|
+
from framework import _yaml
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
text = (folder / "SKILL.md").read_text(encoding="utf-8")
|
|
65
|
+
except OSError:
|
|
66
|
+
return ""
|
|
67
|
+
found = re.match(r"---\r?\n(.*?)\r?\n---", text, re.DOTALL)
|
|
68
|
+
try:
|
|
69
|
+
meta = _yaml.load(found.group(1)) if found else None
|
|
70
|
+
except Exception:
|
|
71
|
+
meta = None
|
|
72
|
+
value = meta.get("description") if isinstance(meta, dict) else None
|
|
73
|
+
if not isinstance(value, str):
|
|
74
|
+
return ""
|
|
75
|
+
return " ".join(value.split()).replace("|", "\\|")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _skills(skills: list[str], skills_dir: str, root: Path | None = None) -> str:
|
|
79
|
+
def covers(skill: str) -> str:
|
|
80
|
+
known = SKILL_DESCRIPTIONS.get(skill)
|
|
81
|
+
if known is not None or root is None:
|
|
82
|
+
return known or ""
|
|
83
|
+
return skill_description(root / skills_dir / skill)
|
|
84
|
+
|
|
59
85
|
rows = [
|
|
60
|
-
f"| `{skill}` | {
|
|
61
|
-
for skill in skills
|
|
86
|
+
f"| `{skill}` | {covers(skill)} | `{skills_dir}/{skill}/SKILL.md` |" for skill in skills
|
|
62
87
|
]
|
|
63
88
|
return "\n".join(
|
|
64
89
|
[
|
|
@@ -170,6 +195,26 @@ def refresh_packages(root: Path, names: list[str]) -> Path | None:
|
|
|
170
195
|
return path
|
|
171
196
|
|
|
172
197
|
|
|
198
|
+
def refresh_skills(root: Path, skills: list[str], skills_dir: str) -> Path | None:
|
|
199
|
+
"""Rewrite the context file's Skills section to list ``skills`` in ``skills_dir``.
|
|
200
|
+
|
|
201
|
+
Only a file with a ``## Skills`` heading changes; the rest of it is kept. Returns the
|
|
202
|
+
file when it changed.
|
|
203
|
+
"""
|
|
204
|
+
path = context_file(root)
|
|
205
|
+
if path is None:
|
|
206
|
+
return None
|
|
207
|
+
text = path.read_text(encoding="utf-8")
|
|
208
|
+
found = re.search(r"^## Skills[^\n]*\n.*?(?=\n+## |\n*\Z)", text, re.DOTALL | re.MULTILINE)
|
|
209
|
+
if found is None:
|
|
210
|
+
return None
|
|
211
|
+
updated = text[: found.start()] + _skills(skills, skills_dir, root) + text[found.end() :]
|
|
212
|
+
if updated == text:
|
|
213
|
+
return None
|
|
214
|
+
path.write_text(updated, encoding="utf-8")
|
|
215
|
+
return path
|
|
216
|
+
|
|
217
|
+
|
|
173
218
|
def _data(spec: dict[str, Any]) -> str:
|
|
174
219
|
directories = spec.get("directories") or {}
|
|
175
220
|
rows = [
|
framework/ai.py
CHANGED
|
@@ -210,59 +210,21 @@ def _installed_spec(root: Path) -> dict[str, Any]:
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def ai_skills_update(project_path: str | Path = ".") ->
|
|
214
|
-
"""
|
|
213
|
+
def ai_skills_update(project_path: str | Path = ".") -> dict[str, Any]:
|
|
214
|
+
"""Bring the project's skills up to date. The same as ``pull_skills(project_path)``.
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
``.framework/skills.lock.json`` existed counts as clean when it matches a
|
|
219
|
-
SKILL.md framework-py has shipped (``templates/skill-history.json``), and
|
|
220
|
-
is updated, backed up first to ``.framework/skills-backups/``. The skills and assistants
|
|
221
|
-
come from ``.framework/spec.json``, or from the settings for projects
|
|
222
|
-
without one.
|
|
216
|
+
Kept for scripts written before ``pull_skills()``. See ``pull_skills()`` for what is
|
|
217
|
+
added, updated, kept, and listed.
|
|
223
218
|
|
|
224
219
|
Args:
|
|
225
220
|
project_path: The project's root directory. Default: the current directory.
|
|
226
221
|
|
|
227
222
|
Returns:
|
|
228
|
-
|
|
229
|
-
out.
|
|
223
|
+
What ``pull_skills()`` returns.
|
|
230
224
|
|
|
231
225
|
Raises:
|
|
232
226
|
ProjectNotFoundError: When the folder has no ``.framework/spec.json`` or settings file.
|
|
233
227
|
"""
|
|
234
|
-
from framework.
|
|
228
|
+
from framework.skill_pull import pull_skills
|
|
235
229
|
|
|
236
|
-
|
|
237
|
-
root = Path(project_path).expanduser()
|
|
238
|
-
from framework.project import _settings_in
|
|
239
|
-
|
|
240
|
-
if not (root / ".framework/spec.json").is_file() and _settings_in(root) is None:
|
|
241
|
-
from framework.errors import ProjectNotFoundError
|
|
242
|
-
|
|
243
|
-
raise ProjectNotFoundError(
|
|
244
|
-
f"{root} is not a Framework project: it has no .framework/spec.json or settings file."
|
|
245
|
-
)
|
|
246
|
-
spec = _installed_spec(root)
|
|
247
|
-
folders, _ = assistant_targets(spec)
|
|
248
|
-
updated = []
|
|
249
|
-
for name, entry in (spec.get("skills") or {}).items():
|
|
250
|
-
if not (isinstance(entry, dict) and entry.get("package") is True):
|
|
251
|
-
continue
|
|
252
|
-
if not _shipped(name).is_dir():
|
|
253
|
-
continue
|
|
254
|
-
for folder in folders:
|
|
255
|
-
from framework.skill_sync import bundle_hash, install_package, scan
|
|
256
|
-
|
|
257
|
-
target = root / folder / name
|
|
258
|
-
# Only a skill whose files changed counts as updated
|
|
259
|
-
before = bundle_hash(scan(target)) if target.is_dir() else None
|
|
260
|
-
if install_package(_shipped(name), root, f"{folder}/{name}", name) and (
|
|
261
|
-
(bundle_hash(scan(target)) if target.is_dir() else None) != before
|
|
262
|
-
):
|
|
263
|
-
updated.append(f"{folder}/{name}")
|
|
264
|
-
if updated:
|
|
265
|
-
inform(f"✓ Updated {len(updated)} Framework skill(s)")
|
|
266
|
-
else:
|
|
267
|
-
inform("No Framework skills to update")
|
|
268
|
-
return updated
|
|
230
|
+
return pull_skills(project_path)
|
framework/cloud.py
CHANGED
|
@@ -343,6 +343,17 @@ class _MissingEndpointError(CloudError):
|
|
|
343
343
|
"""HTTP 404 or 405: an older server without this endpoint."""
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
class CloudConflictError(CloudError):
|
|
347
|
+
"""HTTP 409: what was sent was based on a version the server has moved past.
|
|
348
|
+
|
|
349
|
+
``body`` is the reply, such as ``{"message": ..., "revision": ...}``.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
def __init__(self, message: str, body: dict[str, Any]) -> None:
|
|
353
|
+
super().__init__(message)
|
|
354
|
+
self.body = body
|
|
355
|
+
|
|
356
|
+
|
|
346
357
|
def _error(response: httpx.Response, what: str) -> CloudError:
|
|
347
358
|
try:
|
|
348
359
|
body = response.json()
|
|
@@ -363,6 +374,8 @@ def _error(response: httpx.Response, what: str) -> CloudError:
|
|
|
363
374
|
message = "\n".join([str(message), *details])
|
|
364
375
|
if response.status_code in (404, 405):
|
|
365
376
|
return _MissingEndpointError(str(message))
|
|
377
|
+
if response.status_code == 409:
|
|
378
|
+
return CloudConflictError(str(message), body)
|
|
366
379
|
if response.status_code >= 500:
|
|
367
380
|
return CloudOfflineError(str(message))
|
|
368
381
|
return CloudError(str(message))
|