sycommon-python-lib 0.2.7a29__py3-none-any.whl → 0.2.7a30__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.
@@ -35,6 +35,7 @@
35
35
  """
36
36
 
37
37
  import asyncio
38
+ import hashlib
38
39
  import json
39
40
  import os
40
41
  import re
@@ -1366,6 +1367,79 @@ def _parse_skill_version(content: str) -> str:
1366
1367
  return ""
1367
1368
 
1368
1369
 
1370
+ def _decode_remote_skillmd(content: str) -> str:
1371
+ """把沙箱 /read 返回的 SKILL.md 内容统一解成明文。
1372
+
1373
+ 沙箱 /read 对大文件(如 skill-creator 的 34KB SKILL.md)返回 base64,
1374
+ 且 encoding 标志位可能漏标/误标。判断策略(不依赖 encoding 字段):
1375
+ - 明文 SKILL.md 一定含 frontmatter 标志 `---`;含则当明文直接返回。
1376
+ - 不含 `---` 则当作 base64,解码后返回;解码失败或解码后仍无 `---` 返回原值。
1377
+ """
1378
+ if not content:
1379
+ return content
1380
+ if "---" in content:
1381
+ return content # 明文
1382
+ try:
1383
+ import base64 as _b64
1384
+ decoded = _b64.b64decode(content).decode("utf-8", errors="replace")
1385
+ return decoded
1386
+ except Exception:
1387
+ return content
1388
+
1389
+
1390
+ def _skill_signature(content: str) -> str:
1391
+ """计算 SKILL.md 正文内容的指纹,用于检测「版本号一致但正文未同步」的脏数据。
1392
+
1393
+ 取正文(去掉 frontmatter)的前 N 行规范化后的拼接 + md5,作为轻量指纹。
1394
+ 版本号相同时若指纹不同,说明沙箱里的正文是旧的,需强制重传。
1395
+ frontmatter 跳过逻辑与 _parse_skill_version 一致(逐行数 ---)。
1396
+ """
1397
+ lines = content.split("\n")
1398
+ in_frontmatter = False
1399
+ body_start = 0
1400
+ for i, line in enumerate(lines):
1401
+ if line.strip() == "---":
1402
+ if not in_frontmatter:
1403
+ in_frontmatter = True # 进入 frontmatter
1404
+ else:
1405
+ body_start = i + 1 # 离开 frontmatter,正文从这里开始
1406
+ break
1407
+ body = "\n".join(lines[body_start:])
1408
+ # 规范化:去掉空白行和首尾空格,只取前 40 行做指纹(足够区分新旧大改)
1409
+ norm_lines = [l.rstrip() for l in body.split("\n") if l.strip()]
1410
+ head = "\n".join(norm_lines[:40])
1411
+ return f"{len(norm_lines)}:{hashlib.md5(head.encode('utf-8')).hexdigest()[:12]}"
1412
+
1413
+
1414
+ async def _verify_skill_content_fresh(
1415
+ backend, sandbox_dest: str, skill_name: str, local_src: str
1416
+ ) -> bool:
1417
+ """版本一致时,再校验沙箱 SKILL.md 正文指纹是否与本地一致。
1418
+ 一致返回 True(可跳过同步);不一致返回 False(需强制重传)。
1419
+ 任何读取异常返回 False(保守起见触发重传,宁可多传不可漏传)。"""
1420
+ local_md = os.path.join(local_src, "SKILL.md")
1421
+ if not os.path.isfile(local_md):
1422
+ return True # 本地没 SKILL.md,无法校验,交给版本逻辑
1423
+ try:
1424
+ with open(local_md, "r", encoding="utf-8") as f:
1425
+ local_sig = _skill_signature(f.read())
1426
+ except Exception:
1427
+ return True
1428
+
1429
+ try:
1430
+ remote = await backend.aread(
1431
+ f"{sandbox_dest}/{skill_name}/SKILL.md", _skip_lazy_sync=True)
1432
+ if not remote or not remote.file_data:
1433
+ return False # 读不到 → 当作不一致,触发重传
1434
+ raw = remote.file_data.get("content", "") or ""
1435
+ # 统一用 _decode_remote_skillmd 处理明文/base64 两种返回
1436
+ content = _decode_remote_skillmd(raw)
1437
+ remote_sig = _skill_signature(content)
1438
+ return bool(remote_sig) and local_sig == remote_sig
1439
+ except Exception:
1440
+ return False
1441
+
1442
+
1369
1443
  async def _sync_skills_to_sandbox(
1370
1444
  skills_dir: str,
1371
1445
  backend: HTTPSandboxBackend,
@@ -1424,21 +1498,11 @@ async def _sync_skills_to_sandbox(
1424
1498
  if remote_content and remote_content.file_data:
1425
1499
  # FileData 是 TypedDict(dict), 用键访问而非属性
1426
1500
  content = remote_content.file_data.get("content", "") or ""
1427
- # 优先直接解 version(明文小文件最快);
1428
- # 解不出再兜底解码 base64——沙箱 /read 对大文件(如 skill-creator 的
1429
- # 34KB SKILL.md)返回 base64, encoding 标志位可能漏标/误标,
1430
- # 若依赖该标志位,漏标时会因找不到 "version:" 行误判为"无版本"
1431
- # → 每次新建 Agent 都全量重传。改为「先解 → 解不出再 b64 兜底」,
1432
- # 不依赖 encoding 字段, 对明文/base64 两种返回都正确。
1433
- version = _parse_skill_version(content)
1434
- if version:
1435
- return version
1436
- try:
1437
- import base64 as _b64
1438
- decoded = _b64.b64decode(content).decode("utf-8", errors="replace")
1439
- return _parse_skill_version(decoded)
1440
- except Exception:
1441
- return ""
1501
+ # 沙箱 /read 对大文件(如 skill-creator 的 34KB SKILL.md)返回 base64,
1502
+ # encoding 标志位可能漏标/误标。统一用 _decode_remote_skillmd
1503
+ # 处理明文/base64 两种返回(不依赖 encoding 字段),再解 version。
1504
+ plain = _decode_remote_skillmd(content)
1505
+ return _parse_skill_version(plain)
1442
1506
  except Exception:
1443
1507
  pass
1444
1508
  return ""
@@ -1456,25 +1520,45 @@ async def _sync_skills_to_sandbox(
1456
1520
  remote_version = remote_version_map.get(skill_name, "")
1457
1521
 
1458
1522
  if remote_version and remote_version == local_version:
1459
- SYLogger.debug(
1460
- f"[DeepAgent] 技能版本一致,跳过: {skill_name} v{local_version}")
1461
- backend._synced_skills.add(skill_name)
1462
- skip_count += 1
1463
- continue
1523
+ # 版本一致仍校验正文关键内容,防止"version 字段已更新但正文未同步"
1524
+ # (历史上出现过沙箱 SKILL.md 版本号新、正文旧的脏数据,导致 agent
1525
+ # 永远读不到新版指令)。校验失败则强制走删除+重传。
1526
+ if not await _verify_skill_content_fresh(
1527
+ backend, sandbox_dest, skill_name, src
1528
+ ):
1529
+ SYLogger.warning(
1530
+ f"[DeepAgent] 技能版本一致但正文不一致,强制重传: {skill_name} "
1531
+ f"v{local_version}")
1532
+ # 落到下方的删除+重传分支
1533
+ else:
1534
+ SYLogger.debug(
1535
+ f"[DeepAgent] 技能版本一致,跳过: {skill_name} v{local_version}")
1536
+ backend._synced_skills.add(skill_name)
1537
+ skip_count += 1
1538
+ continue
1464
1539
 
1465
- # 版本不一致或无版本,删除旧目录(走 /delete,跳过懒同步,毫秒级)
1540
+ # 版本不一致或无版本(或正文校验失败),删除旧目录(走 /delete,跳过懒同步,毫秒级)
1466
1541
  if skill_name in existing_dirs:
1467
- try:
1468
- await backend.adelete(
1469
- f"{sandbox_dest}/{skill_name}",
1470
- recursive=True,
1471
- _skip_lazy_sync=True)
1542
+ deleted_ok = False
1543
+ for _attempt in range(2): # 最多重试一次,确保旧内容真删掉
1544
+ try:
1545
+ await backend.adelete(
1546
+ f"{sandbox_dest}/{skill_name}",
1547
+ recursive=True,
1548
+ _skip_lazy_sync=True)
1549
+ deleted_ok = True
1550
+ break
1551
+ except Exception as e:
1552
+ SYLogger.warning(
1553
+ f"[DeepAgent] 删除旧版技能失败(尝试{_attempt+1}): "
1554
+ f"{skill_name}, {e}")
1555
+ if deleted_ok:
1472
1556
  SYLogger.info(
1473
- f"[DeepAgent] 技能版本不一致,覆盖: {skill_name} "
1557
+ f"[DeepAgent] 技能版本不一致,已删除旧目录: {skill_name} "
1474
1558
  f"({remote_version or '无版本'} → {local_version})")
1475
- except Exception as e:
1476
- SYLogger.warning(
1477
- f"[DeepAgent] 删除旧版技能失败: {skill_name}, {e}")
1559
+ else:
1560
+ SYLogger.error(
1561
+ f"[DeepAgent] 删除旧版技能彻底失败,本次跳过: {skill_name}")
1478
1562
 
1479
1563
  # 全量上传整个技能目录到沙箱(batch_upload 服务端无条件覆盖)
1480
1564
  await backend.async_sync_dirs([(src, f"{sandbox_dest}/{skill_name}")])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sycommon-python-lib
3
- Version: 0.2.7a29
3
+ Version: 0.2.7a30
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -136,7 +136,7 @@ sycommon/services.py,sha256=iC73h5d5bpNqW2qjRUGODZFhUhcwvKVnKUFLKJlBSq0,25322
136
136
  sycommon/agent/__init__.py,sha256=mxceAeUifQ-DKvWp7ZEJIFlmOCb5wpYHPGQw3rwEN8I,4378
137
137
  sycommon/agent/agent_manager.py,sha256=UhhaekEumT7g4v_Z1UB4jTp13X0n8M8erYaQdkGGWkA,13620
138
138
  sycommon/agent/chat_events.py,sha256=t7qWa6OrIWLfqtd1AnqaVP67QWkn1JxpCBTZYQpoLuM,14226
139
- sycommon/agent/deep_agent.py,sha256=XdKpBC5ik-GHU2PyZ4KOeSF3EB2-A-r0SmAV3XJN7lI,74799
139
+ sycommon/agent/deep_agent.py,sha256=uLqhiBLcNQlmaYcg0L6dreJGKHDJ4XFU7GWjuVioIkY,78708
140
140
  sycommon/agent/multi_agent_team.py,sha256=RFXHB9q5j1_2B-MDZVRTcbXHdEpRIXpAhrm1yroUDYI,30460
141
141
  sycommon/agent/summarization_utils.py,sha256=bqZRFqSekNGlv2mYQPaT_s2QNA5VDTKddi2Va_SkHWc,18376
142
142
  sycommon/agent/acp/__init__.py,sha256=vQGMQYAA5-ZaejYmDZ4r4Fklqs17qH3cDXQ5pZlwj-0,1844
@@ -308,8 +308,8 @@ sycommon/tools/syemail.py,sha256=BDFhgf7WDOQeTcjxJEQdu0dQhnHFPO_p3eI0-Ni3LhQ,561
308
308
  sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
309
309
  sycommon/xxljob/__init__.py,sha256=7eoBlQxv-B39IfRSCY2bkqdGYs1QRe1umAWd88VMEEM,86
310
310
  sycommon/xxljob/xxljob_service.py,sha256=1yifwIBNGsCIxLnQjHKiBlbsigc_zvPH-dMTZcNxe-Q,7649
311
- sycommon_python_lib-0.2.7a29.dist-info/METADATA,sha256=gq42NKV6-MSlGgQftI3YmU0DiUDErLKMZZOEbMtrOGQ,7962
312
- sycommon_python_lib-0.2.7a29.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
313
- sycommon_python_lib-0.2.7a29.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
314
- sycommon_python_lib-0.2.7a29.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
315
- sycommon_python_lib-0.2.7a29.dist-info/RECORD,,
311
+ sycommon_python_lib-0.2.7a30.dist-info/METADATA,sha256=A_VXT1ygWDo4Hkvwonq65az8FeY0k_8ik6hkReVPKWY,7962
312
+ sycommon_python_lib-0.2.7a30.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
313
+ sycommon_python_lib-0.2.7a30.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
314
+ sycommon_python_lib-0.2.7a30.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
315
+ sycommon_python_lib-0.2.7a30.dist-info/RECORD,,