framework-py 0.1.0.dev18__py3-none-any.whl → 0.1.0.dev20__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 +3 -3
- framework/connections.py +5 -0
- framework/data_registry.py +181 -116
- framework/skill_pull.py +45 -23
- framework/skill_sync.py +36 -18
- framework/sync_all.py +870 -0
- {framework_py-0.1.0.dev18.dist-info → framework_py-0.1.0.dev20.dist-info}/METADATA +16 -1
- {framework_py-0.1.0.dev18.dist-info → framework_py-0.1.0.dev20.dist-info}/RECORD +10 -10
- framework/setup_sync.py +0 -534
- {framework_py-0.1.0.dev18.dist-info → framework_py-0.1.0.dev20.dist-info}/WHEEL +0 -0
- {framework_py-0.1.0.dev18.dist-info → framework_py-0.1.0.dev20.dist-info}/licenses/LICENSE +0 -0
framework/__init__.py
CHANGED
|
@@ -129,7 +129,6 @@ from framework.scaffold import project_info, scaffold, status
|
|
|
129
129
|
from framework.scratch import scratch_capture, scratch_clean
|
|
130
130
|
from framework.security import AuditResult, git_security_audit
|
|
131
131
|
from framework.settings import settings, settings_read, settings_write
|
|
132
|
-
from framework.setup_sync import pull_setup, push_setup
|
|
133
132
|
from framework.skill_pull import pull_skills, push_skills
|
|
134
133
|
from framework.skill_sync import skills_sync
|
|
135
134
|
from framework.spec.check import spec_check
|
|
@@ -143,6 +142,7 @@ from framework.storage import (
|
|
|
143
142
|
publish_notebook,
|
|
144
143
|
storage_test,
|
|
145
144
|
)
|
|
145
|
+
from framework.sync_all import pull_all, push_all
|
|
146
146
|
from framework.upgrade import UpgradeResult, upgrade
|
|
147
147
|
|
|
148
148
|
try:
|
|
@@ -250,11 +250,11 @@ __all__ = [
|
|
|
250
250
|
"publish_dir",
|
|
251
251
|
"publish_list",
|
|
252
252
|
"publish_notebook",
|
|
253
|
+
"pull_all",
|
|
253
254
|
"pull_data_registry",
|
|
254
|
-
"pull_setup",
|
|
255
255
|
"pull_skills",
|
|
256
|
+
"push_all",
|
|
256
257
|
"push_data_registry",
|
|
257
|
-
"push_setup",
|
|
258
258
|
"push_skills",
|
|
259
259
|
"quarto_generate_all",
|
|
260
260
|
"quarto_regenerate",
|
framework/connections.py
CHANGED
|
@@ -639,6 +639,11 @@ def db_execute_file(
|
|
|
639
639
|
cursor = opened.cursor()
|
|
640
640
|
try:
|
|
641
641
|
cursor.execute(statement.sql)
|
|
642
|
+
if opened.driver == "sqlserver":
|
|
643
|
+
# A batch returns one result per statement, and pyodbc raises a
|
|
644
|
+
# later statement's error only when its result is read.
|
|
645
|
+
while cursor.nextset():
|
|
646
|
+
pass
|
|
642
647
|
except Exception as error:
|
|
643
648
|
raise FrameworkError(
|
|
644
649
|
f"Statement {number} of {len(statements)} in {source.name} (line "
|
framework/data_registry.py
CHANGED
|
@@ -280,11 +280,168 @@ def _call(
|
|
|
280
280
|
|
|
281
281
|
|
|
282
282
|
def _project_name(root: Path) -> str:
|
|
283
|
-
from framework.
|
|
283
|
+
from framework.sync_all import _project_name as name
|
|
284
284
|
|
|
285
285
|
return name(root)
|
|
286
286
|
|
|
287
287
|
|
|
288
|
+
# Plans, shared with pull_all() and push_all() ------------------------------------------
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _pull_plan(
|
|
292
|
+
root: Path, server: str, token: str, overwrite: bool, fn: str = "pull_data_registry()"
|
|
293
|
+
) -> dict[str, Any]:
|
|
294
|
+
"""What pulling the registry would change. ``fn`` is the call the overwrite advice names."""
|
|
295
|
+
registry = _call(token, server)
|
|
296
|
+
revision = str(registry.get("revision") or "")
|
|
297
|
+
local = _local(root)
|
|
298
|
+
cloud = {
|
|
299
|
+
str(r["name"]): r
|
|
300
|
+
for r in registry.get("entries") or []
|
|
301
|
+
if isinstance(r, dict) and r.get("name")
|
|
302
|
+
}
|
|
303
|
+
added = [cloud[n] for n in cloud if n not in local]
|
|
304
|
+
differ = [n for n in cloud if n in local and not _same(local[n], cloud[n])]
|
|
305
|
+
kept_local = [n for n in local if n not in cloud]
|
|
306
|
+
|
|
307
|
+
lines: list[str] = []
|
|
308
|
+
if added:
|
|
309
|
+
lines.append(f" Entries to add: {_names(added)}")
|
|
310
|
+
if differ:
|
|
311
|
+
details = "; ".join(f"{n} ({_diff(local[n], cloud[n])})" for n in differ)
|
|
312
|
+
advice = fn.replace("()", "(overwrite=True)")
|
|
313
|
+
tail = "Cloud's will be used" if overwrite else f"kept; {advice} uses Cloud's"
|
|
314
|
+
lines.append(f" Entries that differ (local -> Cloud): {details} — {tail}")
|
|
315
|
+
if kept_local:
|
|
316
|
+
lines.append(f" Only in this project (kept): {', '.join(kept_local)}")
|
|
317
|
+
rows = added + ([cloud[n] for n in differ] if overwrite else [])
|
|
318
|
+
return {
|
|
319
|
+
"revision": revision,
|
|
320
|
+
"lines": lines,
|
|
321
|
+
"quiet": not lines,
|
|
322
|
+
"pending": bool(rows),
|
|
323
|
+
"rows": rows,
|
|
324
|
+
"entries": {
|
|
325
|
+
"added": [str(r["name"]) for r in added],
|
|
326
|
+
"changed": differ if overwrite else [],
|
|
327
|
+
"differ_kept": [] if overwrite else differ,
|
|
328
|
+
"kept_local": kept_local,
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def _pull_apply(root: Path, plan: dict[str, Any], server: str) -> None:
|
|
334
|
+
"""Write a pull plan's entries and record the revision pulled."""
|
|
335
|
+
from framework._log import inform
|
|
336
|
+
|
|
337
|
+
rows = plan["rows"]
|
|
338
|
+
if rows:
|
|
339
|
+
_write(root, rows)
|
|
340
|
+
_lock_write(root, plan["revision"], server)
|
|
341
|
+
if rows:
|
|
342
|
+
inform(
|
|
343
|
+
f"✓ Data registry: {len(rows)} {'entry' if len(rows) == 1 else 'entries'} "
|
|
344
|
+
"added or updated"
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _push_plan(
|
|
349
|
+
root: Path,
|
|
350
|
+
server: str,
|
|
351
|
+
token: str,
|
|
352
|
+
remove: bool,
|
|
353
|
+
force: bool,
|
|
354
|
+
pull_fn: str = "pull_data_registry()",
|
|
355
|
+
push_fn: str = "push_data_registry(force=True)",
|
|
356
|
+
) -> dict[str, Any]:
|
|
357
|
+
"""What pushing the registry would change, from Cloud's dry run. A registry that changed
|
|
358
|
+
on Cloud since the last pull raises "Pull first", naming ``pull_fn`` and ``push_fn``."""
|
|
359
|
+
from framework.cloud import CloudConflictError, CloudError
|
|
360
|
+
|
|
361
|
+
local = _local(root)
|
|
362
|
+
# The base revision for a project that never pulled its registry
|
|
363
|
+
base = _lock_read(root).get("revision")
|
|
364
|
+
if base is None:
|
|
365
|
+
base = _call(token, server).get("revision")
|
|
366
|
+
|
|
367
|
+
def send(dry: bool) -> dict[str, Any]:
|
|
368
|
+
body = {
|
|
369
|
+
"base_revision": base,
|
|
370
|
+
"entries": list(local.values()),
|
|
371
|
+
"remove": remove,
|
|
372
|
+
"force": force,
|
|
373
|
+
"dry_run": dry,
|
|
374
|
+
}
|
|
375
|
+
try:
|
|
376
|
+
return _call(token, server, "POST", body)
|
|
377
|
+
except CloudConflictError as error:
|
|
378
|
+
latest = error.body.get("revision") or "unknown"
|
|
379
|
+
raise CloudError(
|
|
380
|
+
"Framework Cloud's data registry changed since this project last pulled it "
|
|
381
|
+
f"(revision {latest}). Pull first: {pull_fn}. "
|
|
382
|
+
f"{push_fn} replaces Cloud's changes."
|
|
383
|
+
) from error
|
|
384
|
+
|
|
385
|
+
preview = send(True)
|
|
386
|
+
changes = preview.get("changes") or {}
|
|
387
|
+
added = changes.get("added") or []
|
|
388
|
+
changed = changes.get("changed") or []
|
|
389
|
+
removed = changes.get("removed") or []
|
|
390
|
+
kept = changes.get("kept") or []
|
|
391
|
+
|
|
392
|
+
lines: list[str] = []
|
|
393
|
+
if added:
|
|
394
|
+
lines.append(f" Entries to add: {_names(added)}")
|
|
395
|
+
if changed:
|
|
396
|
+
details = "; ".join(f"{c['name']} ({_diff(c['from'], c['to'])})" for c in changed)
|
|
397
|
+
lines.append(f" Entries to change: {details}")
|
|
398
|
+
if removed:
|
|
399
|
+
lines.append(f" Entries to remove: {_names(removed)}")
|
|
400
|
+
if kept:
|
|
401
|
+
lines.append(f" On Cloud only (kept): {_names(kept)}")
|
|
402
|
+
pending = bool(added or changed or removed)
|
|
403
|
+
warnings: list[str] = []
|
|
404
|
+
if pending:
|
|
405
|
+
warnings.append(
|
|
406
|
+
f"This changes {_project_name(root)}'s data registry on Framework Cloud. "
|
|
407
|
+
"New copies of the project, zips, and Update on GitHub will use it. "
|
|
408
|
+
"Only definitions are sent: no data files and no hashes."
|
|
409
|
+
)
|
|
410
|
+
if force and preview.get("revision") is not None and base != preview.get("revision"):
|
|
411
|
+
warnings.append(
|
|
412
|
+
"Cloud's newer data registry changes will be replaced by this project's entries."
|
|
413
|
+
)
|
|
414
|
+
return {
|
|
415
|
+
"revision": preview.get("revision"),
|
|
416
|
+
"lines": lines,
|
|
417
|
+
"warnings": warnings,
|
|
418
|
+
"quiet": not pending,
|
|
419
|
+
"pending": pending,
|
|
420
|
+
"send": send,
|
|
421
|
+
"changes": {"added": added, "changed": changed, "removed": removed, "kept": kept},
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def _push_apply(root: Path, plan: dict[str, Any], server: str) -> dict[str, Any]:
|
|
426
|
+
"""Push a plan's entries and record the new revision."""
|
|
427
|
+
from framework._log import inform
|
|
428
|
+
|
|
429
|
+
reply = plan["send"](False)
|
|
430
|
+
revision = str(reply.get("revision") or "")
|
|
431
|
+
_lock_write(root, revision, server)
|
|
432
|
+
done = reply.get("changes") or plan["changes"]
|
|
433
|
+
if reply.get("applied"):
|
|
434
|
+
parts = [
|
|
435
|
+
f"{len(done.get(key) or [])} {key}"
|
|
436
|
+
for key in ("added", "changed", "removed")
|
|
437
|
+
if done.get(key)
|
|
438
|
+
]
|
|
439
|
+
inform(f"✓ Data registry pushed: revision {revision} ({', '.join(parts)})")
|
|
440
|
+
else:
|
|
441
|
+
inform("Already up to date.")
|
|
442
|
+
return {"applied": bool(reply.get("applied")), "revision": revision}
|
|
443
|
+
|
|
444
|
+
|
|
288
445
|
# Pull and push -----------------------------------------------------------------------------
|
|
289
446
|
|
|
290
447
|
|
|
@@ -306,6 +463,7 @@ def pull_data_registry(
|
|
|
306
463
|
Local entries are never removed, and an entry whose local definition differs keeps it
|
|
307
464
|
unless ``overwrite=True``. Fields Framework Cloud doesn't keep stay as they are. The
|
|
308
465
|
revision pulled is kept in ``.framework/data.lock.json`` for ``push_data_registry()``.
|
|
466
|
+
``pull_all()`` pulls it with the packages and skills.
|
|
309
467
|
|
|
310
468
|
Args:
|
|
311
469
|
project_path: The project's root directory. Default: the current directory.
|
|
@@ -323,71 +481,40 @@ def pull_data_registry(
|
|
|
323
481
|
FrameworkError: Without a console and without ``confirm=True`` or ``dry_run=True``.
|
|
324
482
|
"""
|
|
325
483
|
from framework._log import inform, show_messages
|
|
326
|
-
from framework.setup_sync import _ask
|
|
327
484
|
from framework.skill_pull import _root
|
|
485
|
+
from framework.sync_all import _ask
|
|
328
486
|
|
|
329
487
|
show_messages()
|
|
330
488
|
root = _root(project_path)
|
|
331
489
|
server, token = _connection(root)
|
|
332
|
-
|
|
333
|
-
revision =
|
|
334
|
-
|
|
335
|
-
local = _local(root)
|
|
336
|
-
cloud = {
|
|
337
|
-
str(r["name"]): r
|
|
338
|
-
for r in registry.get("entries") or []
|
|
339
|
-
if isinstance(r, dict) and r.get("name")
|
|
340
|
-
}
|
|
341
|
-
added = [cloud[n] for n in cloud if n not in local]
|
|
342
|
-
differ = [n for n in cloud if n in local and not _same(local[n], cloud[n])]
|
|
343
|
-
kept_local = [n for n in local if n not in cloud]
|
|
344
|
-
|
|
345
|
-
lines = [f"Data registry changes from Framework Cloud (revision {revision}):"]
|
|
346
|
-
if added:
|
|
347
|
-
lines.append(f" Entries to add: {_names(added)}")
|
|
348
|
-
if differ:
|
|
349
|
-
details = "; ".join(f"{n} ({_diff(local[n], cloud[n])})" for n in differ)
|
|
350
|
-
tail = (
|
|
351
|
-
"Cloud's will be used"
|
|
352
|
-
if overwrite
|
|
353
|
-
else "kept; pull_data_registry(overwrite=True) uses Cloud's"
|
|
354
|
-
)
|
|
355
|
-
lines.append(f" Entries that differ (local -> Cloud): {details} — {tail}")
|
|
356
|
-
if kept_local:
|
|
357
|
-
lines.append(f" Only in this project (kept): {', '.join(kept_local)}")
|
|
358
|
-
changes = bool(added or (differ and overwrite))
|
|
359
|
-
if not added and not differ and not kept_local:
|
|
490
|
+
plan = _pull_plan(root, server, token, overwrite)
|
|
491
|
+
revision = plan["revision"]
|
|
492
|
+
if plan["quiet"]:
|
|
360
493
|
lines = [f"Data registry is up to date with Framework Cloud (revision {revision})."]
|
|
494
|
+
else:
|
|
495
|
+
lines = [
|
|
496
|
+
f"Data registry changes from Framework Cloud (revision {revision}):",
|
|
497
|
+
*plan["lines"],
|
|
498
|
+
]
|
|
361
499
|
for line in lines:
|
|
362
500
|
inform(line)
|
|
363
501
|
|
|
364
502
|
result: dict[str, Any] = {
|
|
365
503
|
"revision": revision,
|
|
366
|
-
"entries":
|
|
367
|
-
"added": [str(r["name"]) for r in added],
|
|
368
|
-
"changed": differ if overwrite else [],
|
|
369
|
-
"differ_kept": [] if overwrite else differ,
|
|
370
|
-
"kept_local": kept_local,
|
|
371
|
-
},
|
|
504
|
+
"entries": plan["entries"],
|
|
372
505
|
"applied": False,
|
|
373
506
|
"dry_run": dry_run,
|
|
374
507
|
"message": "\n".join(lines),
|
|
375
508
|
}
|
|
376
509
|
if dry_run:
|
|
377
510
|
return result
|
|
378
|
-
if not
|
|
511
|
+
if not plan["pending"]:
|
|
379
512
|
_lock_write(root, revision, server)
|
|
380
513
|
return result
|
|
381
514
|
if not _ask("Apply these changes?", confirm, "pull_data_registry"):
|
|
382
515
|
inform("Nothing changed.")
|
|
383
516
|
return result
|
|
384
|
-
|
|
385
|
-
rows = added + ([cloud[n] for n in differ] if overwrite else [])
|
|
386
|
-
_write(root, rows)
|
|
387
|
-
_lock_write(root, revision, server)
|
|
388
|
-
inform(
|
|
389
|
-
f"✓ Data registry: {len(rows)} {'entry' if len(rows) == 1 else 'entries'} added or updated"
|
|
390
|
-
)
|
|
517
|
+
_pull_apply(root, plan, server)
|
|
391
518
|
result["applied"] = True
|
|
392
519
|
return result
|
|
393
520
|
|
|
@@ -432,94 +559,32 @@ def push_data_registry(
|
|
|
432
559
|
FrameworkError: Without a console and without ``confirm=True`` or ``dry_run=True``.
|
|
433
560
|
"""
|
|
434
561
|
from framework._log import inform, show_messages
|
|
435
|
-
from framework.cloud import CloudConflictError, CloudError
|
|
436
|
-
from framework.setup_sync import _ask
|
|
437
562
|
from framework.skill_pull import _root
|
|
563
|
+
from framework.sync_all import _ask
|
|
438
564
|
|
|
439
565
|
show_messages()
|
|
440
566
|
root = _root(project_path)
|
|
441
567
|
server, token = _connection(root)
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if base is None:
|
|
446
|
-
base = _call(token, server).get("revision")
|
|
447
|
-
|
|
448
|
-
def send(dry: bool) -> dict[str, Any]:
|
|
449
|
-
body = {
|
|
450
|
-
"base_revision": base,
|
|
451
|
-
"entries": list(local.values()),
|
|
452
|
-
"remove": remove,
|
|
453
|
-
"force": force,
|
|
454
|
-
"dry_run": dry,
|
|
455
|
-
}
|
|
456
|
-
try:
|
|
457
|
-
return _call(token, server, "POST", body)
|
|
458
|
-
except CloudConflictError as error:
|
|
459
|
-
latest = error.body.get("revision") or "unknown"
|
|
460
|
-
raise CloudError(
|
|
461
|
-
"Framework Cloud's data registry changed since this project last pulled it "
|
|
462
|
-
f"(revision {latest}). Pull first: pull_data_registry(). "
|
|
463
|
-
"push_data_registry(force=True) replaces Cloud's changes."
|
|
464
|
-
) from error
|
|
465
|
-
|
|
466
|
-
preview = send(True)
|
|
467
|
-
changes = preview.get("changes") or {}
|
|
468
|
-
added = changes.get("added") or []
|
|
469
|
-
changed = changes.get("changed") or []
|
|
470
|
-
removed = changes.get("removed") or []
|
|
471
|
-
kept = changes.get("kept") or []
|
|
472
|
-
|
|
473
|
-
lines = ["Data registry changes for Framework Cloud:"]
|
|
474
|
-
if added:
|
|
475
|
-
lines.append(f" Entries to add: {_names(added)}")
|
|
476
|
-
if changed:
|
|
477
|
-
details = "; ".join(f"{c['name']} ({_diff(c['from'], c['to'])})" for c in changed)
|
|
478
|
-
lines.append(f" Entries to change: {details}")
|
|
479
|
-
if removed:
|
|
480
|
-
lines.append(f" Entries to remove: {_names(removed)}")
|
|
481
|
-
if kept:
|
|
482
|
-
lines.append(f" On Cloud only (kept): {_names(kept)}")
|
|
483
|
-
pending = bool(added or changed or removed)
|
|
484
|
-
if not pending:
|
|
485
|
-
lines[0] = "Data registry on Framework Cloud already matches this project."
|
|
568
|
+
plan = _push_plan(root, server, token, remove, force)
|
|
569
|
+
if plan["pending"]:
|
|
570
|
+
lines = ["Data registry changes for Framework Cloud:", *plan["lines"], *plan["warnings"]]
|
|
486
571
|
else:
|
|
487
|
-
lines.
|
|
488
|
-
f"This changes {_project_name(root)}'s data registry on Framework Cloud. "
|
|
489
|
-
"New copies of the project, zips, and Update on GitHub will use it. "
|
|
490
|
-
"Only definitions are sent: no data files and no hashes."
|
|
491
|
-
)
|
|
492
|
-
if force and preview.get("revision") is not None and base != preview.get("revision"):
|
|
493
|
-
lines.append(
|
|
494
|
-
"Cloud's newer data registry changes will be replaced by this project's entries."
|
|
495
|
-
)
|
|
572
|
+
lines = ["Data registry on Framework Cloud already matches this project.", *plan["lines"]]
|
|
496
573
|
for line in lines:
|
|
497
574
|
inform(line)
|
|
498
575
|
result: dict[str, Any] = {
|
|
499
|
-
"revision":
|
|
500
|
-
"changes":
|
|
576
|
+
"revision": plan["revision"],
|
|
577
|
+
"changes": plan["changes"],
|
|
501
578
|
"applied": False,
|
|
502
579
|
"dry_run": dry_run,
|
|
503
580
|
"message": "\n".join(lines),
|
|
504
581
|
}
|
|
505
|
-
if not pending or dry_run:
|
|
582
|
+
if not plan["pending"] or dry_run:
|
|
506
583
|
return result
|
|
507
584
|
|
|
508
585
|
if not _ask("Push these changes?", confirm, "push_data_registry"):
|
|
509
586
|
inform("Data registry not pushed.")
|
|
510
587
|
return result
|
|
511
|
-
reply =
|
|
512
|
-
|
|
513
|
-
result.update(applied=bool(reply.get("applied")), revision=revision)
|
|
514
|
-
_lock_write(root, revision, server)
|
|
515
|
-
done = reply.get("changes") or changes
|
|
516
|
-
if reply.get("applied"):
|
|
517
|
-
parts = [
|
|
518
|
-
f"{len(done.get(key) or [])} {key}"
|
|
519
|
-
for key in ("added", "changed", "removed")
|
|
520
|
-
if done.get(key)
|
|
521
|
-
]
|
|
522
|
-
inform(f"Data registry pushed: revision {revision} ({', '.join(parts)})")
|
|
523
|
-
else:
|
|
524
|
-
inform("Already up to date.")
|
|
588
|
+
reply = _push_apply(root, plan, server)
|
|
589
|
+
result.update(applied=reply["applied"], revision=reply["revision"])
|
|
525
590
|
return result
|
framework/skill_pull.py
CHANGED
|
@@ -343,21 +343,58 @@ def pull_skills(
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
def _push_edited(root: Path) -> list[tuple[dict[str, Any], list[str]]]:
|
|
347
|
+
"""Tracked skills whose files changed since the last pull, with their present paths.
|
|
348
|
+
|
|
349
|
+
Reads only the project; checking them against Cloud needs your login.
|
|
350
|
+
"""
|
|
351
|
+
from framework.skill_sync import _load, _path, bundle_hash, scan
|
|
352
|
+
|
|
353
|
+
edited = []
|
|
354
|
+
for entry in _load(root)["skills"].values():
|
|
355
|
+
paths = [p for p in entry["paths"] if _path(root, p).exists()]
|
|
356
|
+
if not paths:
|
|
357
|
+
continue
|
|
358
|
+
if all(bundle_hash(scan(_path(root, p))) == entry.get("hash") for p in paths):
|
|
359
|
+
continue
|
|
360
|
+
edited.append((entry, paths))
|
|
361
|
+
return edited
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _push_apply(root: Path, plans: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
365
|
+
"""Push each planned skill; its status becomes pushed, refused, or failed."""
|
|
366
|
+
from framework.skill_sync import skills_sync
|
|
367
|
+
|
|
368
|
+
for plan in plans:
|
|
369
|
+
if plan["status"] != "push":
|
|
370
|
+
continue
|
|
371
|
+
try:
|
|
372
|
+
result = skills_sync(
|
|
373
|
+
plan["path"],
|
|
374
|
+
root,
|
|
375
|
+
direction="push",
|
|
376
|
+
resolve="local" if plan["forced"] else None,
|
|
377
|
+
)
|
|
378
|
+
except Exception as error:
|
|
379
|
+
plan.update(status="failed", reason=str(error))
|
|
380
|
+
continue
|
|
381
|
+
if result["action"] == "push":
|
|
382
|
+
plan.update(status="pushed", version=result.get("version"))
|
|
383
|
+
else:
|
|
384
|
+
plan["status"] = "refused"
|
|
385
|
+
return plans
|
|
386
|
+
|
|
387
|
+
|
|
346
388
|
def _push_plan(root: Path, force: bool) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
347
389
|
"""Locally edited tracked skills and what pushing each would do, and untracked folders."""
|
|
348
390
|
from framework.ai import _installed_spec
|
|
349
|
-
from framework.skill_sync import _load,
|
|
391
|
+
from framework.skill_sync import _load, skills_sync
|
|
350
392
|
|
|
351
393
|
state = _load(root)
|
|
352
394
|
tracked = {p for e in state["skills"].values() for p in e["paths"]}
|
|
353
395
|
plans: list[dict[str, Any]] = []
|
|
354
|
-
for entry in
|
|
355
|
-
paths = [p for p in entry["paths"] if _path(root, p).exists()]
|
|
356
|
-
if not paths:
|
|
357
|
-
continue
|
|
396
|
+
for entry, paths in _push_edited(root):
|
|
358
397
|
name = Path(paths[0]).name
|
|
359
|
-
if all(bundle_hash(scan(_path(root, p))) == entry.get("hash") for p in paths):
|
|
360
|
-
continue
|
|
361
398
|
builtin = not entry.get("skill_id") or str(entry["skill_id"]).startswith("framework:")
|
|
362
399
|
try:
|
|
363
400
|
action = skills_sync(paths[0], root, direction="status")["action"]
|
|
@@ -431,7 +468,6 @@ def push_skills(
|
|
|
431
468
|
"""
|
|
432
469
|
from framework._log import inform, show_messages
|
|
433
470
|
from framework.cloud import _require_token, cloud_server
|
|
434
|
-
from framework.skill_sync import skills_sync
|
|
435
471
|
|
|
436
472
|
show_messages()
|
|
437
473
|
root = _root(project_path).resolve()
|
|
@@ -452,21 +488,7 @@ def push_skills(
|
|
|
452
488
|
for plan in pushes:
|
|
453
489
|
plan["status"] = "cancelled"
|
|
454
490
|
else:
|
|
455
|
-
|
|
456
|
-
try:
|
|
457
|
-
result = skills_sync(
|
|
458
|
-
plan["path"],
|
|
459
|
-
root,
|
|
460
|
-
direction="push",
|
|
461
|
-
resolve="local" if plan["forced"] else None,
|
|
462
|
-
)
|
|
463
|
-
except Exception as error:
|
|
464
|
-
plan.update(status="failed", reason=str(error))
|
|
465
|
-
continue
|
|
466
|
-
if result["action"] == "push":
|
|
467
|
-
plan.update(status="pushed", version=result.get("version"))
|
|
468
|
-
else:
|
|
469
|
-
plan["status"] = "refused"
|
|
491
|
+
_push_apply(root, plans)
|
|
470
492
|
elif pushes:
|
|
471
493
|
for plan in pushes:
|
|
472
494
|
inform(_warning(plan))
|
framework/skill_sync.py
CHANGED
|
@@ -76,10 +76,17 @@ def validate(files: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
|
76
76
|
return sorted(result, key=lambda f: f["path"])
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
def hash_bytes(raw: bytes) -> bytes:
|
|
80
|
+
"""Text files hash with LF line endings, so a CRLF checkout (git's
|
|
81
|
+
core.autocrlf on Windows) matches its LF twin. A file with a NUL byte is
|
|
82
|
+
binary and hashes raw. R, Go, and Cloud normalize the same way."""
|
|
83
|
+
return raw if b"\0" in raw else raw.replace(b"\r\n", b"\n")
|
|
84
|
+
|
|
85
|
+
|
|
79
86
|
def bundle_hash(files: list[dict[str, Any]]) -> str:
|
|
80
87
|
manifest = "framework-skill-bundle-v1\n"
|
|
81
88
|
for file in validate(files):
|
|
82
|
-
raw = base64.b64decode(file["content"])
|
|
89
|
+
raw = hash_bytes(base64.b64decode(file["content"]))
|
|
83
90
|
manifest += (
|
|
84
91
|
f"{file['path']}\t{hashlib.sha256(raw).hexdigest()}\t"
|
|
85
92
|
f"{755 if file['executable'] else 644}\t{len(raw)}\n"
|
|
@@ -240,6 +247,22 @@ def _install(
|
|
|
240
247
|
# Backups retain the replaced bytes for recovery and explicit conflict resolution.
|
|
241
248
|
|
|
242
249
|
|
|
250
|
+
def _project_token(root: Path, server: str) -> str | None:
|
|
251
|
+
"""The project's token when the project is on this server, else None.
|
|
252
|
+
|
|
253
|
+
A push that names the project lets Cloud list a pushed copy of a built-in
|
|
254
|
+
skill in the project's setup, so the next pull keeps it.
|
|
255
|
+
"""
|
|
256
|
+
from framework.cloud import cloud_server, project_token
|
|
257
|
+
|
|
258
|
+
token = project_token(root)
|
|
259
|
+
if not token:
|
|
260
|
+
return None
|
|
261
|
+
if cloud_server(scope="project", project_dir=root).url.rstrip("/") != server:
|
|
262
|
+
return None
|
|
263
|
+
return token
|
|
264
|
+
|
|
265
|
+
|
|
243
266
|
def skills_sync(
|
|
244
267
|
path: str,
|
|
245
268
|
project_path: str | Path = ".",
|
|
@@ -376,20 +399,17 @@ def skills_sync(
|
|
|
376
399
|
entry["pending"] = pending
|
|
377
400
|
state["skills"][key] = entry
|
|
378
401
|
_save(root, state) # Retry identity survives a lost HTTP response.
|
|
379
|
-
|
|
380
|
-
"
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
"client": {"app": "framework-py"},
|
|
391
|
-
},
|
|
392
|
-
)
|
|
402
|
+
body = {
|
|
403
|
+
"request_id": pending["request_id"],
|
|
404
|
+
"skill_id": remote["skill_id"] if remote else None,
|
|
405
|
+
"expected_version": expected,
|
|
406
|
+
"variant": variant,
|
|
407
|
+
"bundle": files,
|
|
408
|
+
"client": {"app": "framework-py"},
|
|
409
|
+
}
|
|
410
|
+
if named := _project_token(root, server):
|
|
411
|
+
body["project_token"] = named
|
|
412
|
+
remote = api("/api/v1/skills/sync", token, server, method="POST", body=body)
|
|
393
413
|
if remote:
|
|
394
414
|
if bundle_hash(remote["bundle"]) != remote["hash"]:
|
|
395
415
|
raise ValueError("Cloud skill verification failed")
|
|
@@ -450,9 +470,7 @@ def shipped_release(target: Path, name: str) -> bool:
|
|
|
450
470
|
return False
|
|
451
471
|
raw = base64.b64decode(files[0]["content"])
|
|
452
472
|
known = set(_shipped_history().get(name) or [])
|
|
453
|
-
return any(
|
|
454
|
-
hashlib.sha256(data).hexdigest() in known for data in (raw, raw.replace(b"\r\n", b"\n"))
|
|
455
|
-
)
|
|
473
|
+
return any(hashlib.sha256(data).hexdigest() in known for data in (raw, hash_bytes(raw)))
|
|
456
474
|
|
|
457
475
|
|
|
458
476
|
def package_status(source: Traversable, root: Path, relative: str, name: str) -> str:
|