framework-py 0.1.0.dev15__py3-none-any.whl → 0.1.0.dev17__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 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 _skills(skills: list[str], skills_dir: str) -> str:
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}` | {SKILL_DESCRIPTIONS.get(skill, '')} | `{skills_dir}/{skill}/SKILL.md` |"
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/_pages.py CHANGED
@@ -36,7 +36,11 @@ class _Remote:
36
36
 
37
37
  def _git(top: Path, *args: str) -> subprocess.CompletedProcess[str]:
38
38
  return subprocess.run(
39
- ["git", "-C", str(top), *args], capture_output=True, text=True, check=False
39
+ ["git", "-C", str(top), *args],
40
+ capture_output=True,
41
+ encoding="utf-8",
42
+ errors="replace",
43
+ check=False,
40
44
  )
41
45
 
42
46
 
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 = ".") -> list[str]:
214
- """Refresh clean Framework skills. Preserve local edits and account forks.
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
- Only skills that ship with Framework are updated. Skills from a blueprint
217
- or facet, and skills you wrote, are left alone. A skill installed before
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
- The skill folders whose files changed. Skills that were already current are left
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._log import inform, show_messages
228
+ from framework.skill_pull import pull_skills
235
229
 
236
- show_messages()
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))
framework/create.py CHANGED
@@ -403,7 +403,11 @@ def _git_init(root: Path) -> None:
403
403
 
404
404
  def git(*args: str) -> subprocess.CompletedProcess[str]:
405
405
  return subprocess.run(
406
- ["git", "-C", str(root), *args], capture_output=True, text=True, check=False
406
+ ["git", "-C", str(root), *args],
407
+ capture_output=True,
408
+ encoding="utf-8",
409
+ errors="replace",
410
+ check=False,
407
411
  )
408
412
 
409
413
  from framework.hooks import git_hooks_install, outer_repository
framework/hooks.py CHANGED
@@ -132,8 +132,13 @@ def _hook_name(name: str) -> str:
132
132
 
133
133
 
134
134
  def _git(root: Path, *args: str) -> subprocess.CompletedProcess[str]:
135
+ # git writes paths as UTF-8, whatever the locale (cp1252 on Windows)
135
136
  return subprocess.run(
136
- ["git", "-C", str(root), *args], capture_output=True, text=True, check=False
137
+ ["git", "-C", str(root), *args],
138
+ capture_output=True,
139
+ encoding="utf-8",
140
+ errors="replace",
141
+ check=False,
137
142
  )
138
143
 
139
144
 
framework/scaffold.py CHANGED
@@ -268,7 +268,9 @@ def _create_private_folders(root: Path, config: dict[str, Any]) -> list[str]:
268
268
  def _git(*args: str) -> str | None:
269
269
  if shutil.which("git") is None:
270
270
  return None
271
- result = subprocess.run(["git", *args], capture_output=True, text=True, check=False)
271
+ result = subprocess.run(
272
+ ["git", *args], capture_output=True, encoding="utf-8", errors="replace", check=False
273
+ )
272
274
  return result.stdout.strip() if result.returncode == 0 else None
273
275
 
274
276