Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e5a8d5eed | |||
| 6f958ded28 |
@@ -19,3 +19,12 @@ OPENCLAW_ARTIFACTS_ON_FAILURE=1 # 1=失败截图(默认)
|
|||||||
STEP_DELAY_MIN=1.0 # 步骤间随机等待下限(秒)
|
STEP_DELAY_MIN=1.0 # 步骤间随机等待下限(秒)
|
||||||
STEP_DELAY_MAX=5.0 # 步骤间随机等待上限(秒)
|
STEP_DELAY_MAX=5.0 # 步骤间随机等待上限(秒)
|
||||||
HUMAN_WAIT_TIMEOUT=180 # 滑块/验证码/2FA 等人工超时(秒)
|
HUMAN_WAIT_TIMEOUT=180 # 滑块/验证码/2FA 等人工超时(秒)
|
||||||
|
|
||||||
|
# ── 数据目录子路径(见 development/DATA_PATHS.md;留空则用 skill 数据目录下默认子文件夹)──
|
||||||
|
# 相对路径相对于 {JIANGCHANG_DATA_ROOT}/{USER_ID}/{slug}/,不是 workspace / CWD
|
||||||
|
# SKILL_DOWNLOAD_DIR=downloads
|
||||||
|
# SKILL_IMPORT_DIR=imports
|
||||||
|
# SKILL_EXPORT_DIR=exports
|
||||||
|
# SKILL_UPLOAD_DIR=uploads
|
||||||
|
# SKILL_CACHE_DIR=cache
|
||||||
|
# SKILL_TEMP_DIR=temp
|
||||||
|
|||||||
8
SKILL.md
8
SKILL.md
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
name: 技能开发模板(通用业务版)
|
name: 技能开发模板(通用业务版)
|
||||||
description: "OpenClaw 通用业务技能开发模板,供复制后定制新业务 skill。定制步骤见 development/DEVELOPMENT.md。"
|
description: "OpenClaw 通用业务技能开发模板,供复制后定制新业务 skill。定制步骤见 development/DEVELOPMENT.md。"
|
||||||
version: 1.0.32
|
version: 1.0.39
|
||||||
author: 深圳匠厂科技有限公司
|
author: 深圳匠厂科技有限公司
|
||||||
metadata:
|
metadata:
|
||||||
openclaw:
|
openclaw:
|
||||||
slug: your-skill-slug
|
slug: your-skill-slug
|
||||||
platform_kit_min_version: "1.0.17"
|
platform_kit_min_version: "1.2.0"
|
||||||
emoji: "📦"
|
emoji: "📦"
|
||||||
category: "通用"
|
category: "通用"
|
||||||
developer_ids:
|
developer_ids:
|
||||||
@@ -70,10 +70,10 @@ python {baseDir}/scripts/main.py version
|
|||||||
## 运行依赖
|
## 运行依赖
|
||||||
|
|
||||||
- Python 运行环境由匠厂宿主注入**共享 runtime**:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
- Python 运行环境由匠厂宿主注入**共享 runtime**:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
||||||
- 公共能力来自共享 runtime 安装的 `jiangchang-platform-kit>=1.0.17`(`jiangchang_skill_core` 包);**不要 vendor** `scripts/jiangchang_skill_core/`,新技能不得在仓库内保留该目录副本。
|
- 公共能力来自共享 runtime 安装的 `jiangchang-platform-kit>=1.2.0`(`jiangchang_skill_core` 包);**不要 vendor** `scripts/jiangchang_skill_core/`,新技能不得在仓库内保留该目录副本。
|
||||||
- config、logging、runtime_env、rpa、media-assets、video_session、runtime_diagnostics 等均从共享 venv 的 `jiangchang_skill_core` import,而非技能目录副本。
|
- config、logging、runtime_env、rpa、media-assets、video_session、runtime_diagnostics 等均从共享 venv 的 `jiangchang_skill_core` import,而非技能目录副本。
|
||||||
- 根目录 `requirements.txt` **只声明技能特有** Python 三方依赖;`jiangchang-platform-kit`、`playwright` 等公共能力由宿主共享 runtime 提供,**不要**写入技能 requirements。
|
- 根目录 `requirements.txt` **只声明技能特有** Python 三方依赖;`jiangchang-platform-kit`、`playwright` 等公共能力由宿主共享 runtime 提供,**不要**写入技能 requirements。
|
||||||
- `metadata.openclaw.platform_kit_min_version`(当前 `1.0.17`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是**技能 pip 依赖声明。
|
- `metadata.openclaw.platform_kit_min_version`(当前 `1.2.0`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是**技能 pip 依赖声明。
|
||||||
- Skill 代码**不要**自行 `pip install`;系统级依赖(如 VC++ Runtime)仅在 `health` / preflight 中提示用户安装。
|
- Skill 代码**不要**自行 `pip install`;系统级依赖(如 VC++ Runtime)仅在 `health` / preflight 中提示用户安装。
|
||||||
- `health` 使用 `collect_runtime_diagnostics` 输出统一 runtime 诊断(只读,不下载/修复 media-assets)。
|
- `health` 使用 `collect_runtime_diagnostics` 输出统一 runtime 诊断(只读,不下载/修复 media-assets)。
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,15 @@ STEP_DELAY_MAX=5.0
|
|||||||
HUMAN_WAIT_TIMEOUT=180 # 滑块/验证码/2FA 等人工超时(秒)
|
HUMAN_WAIT_TIMEOUT=180 # 滑块/验证码/2FA 等人工超时(秒)
|
||||||
```
|
```
|
||||||
|
|
||||||
**业务专属配置必须带技能前缀**(如 `DEMO_XXX`、`MY_SKILL_XXX`),**不要污染全局命名空间**(禁止 `SCRAPE_1688_*`、`RECEIVE_ORDER_*` 等跨技能前缀写入模板)。
|
**业务专属配置必须带技能前缀**(如 `DEMO_XXX`、`MY_SKILL_XXX`、`SKILL_DOWNLOAD_DIR`),**不要污染全局命名空间**(禁止 `SCRAPE_1688_*`、`RECEIVE_ORDER_*` 等跨技能前缀写入模板)。
|
||||||
|
|
||||||
|
### 数据目录子路径(下载 / 导入 / 导出)
|
||||||
|
|
||||||
|
技能**自己写入**的文件默认在 `{JIANGCHANG_DATA_ROOT}/{USER_ID}/{slug}/` 下标准子目录(`downloads/`、`imports/`、`exports/` 等)。须通过 `util.runtime_paths.resolve_data_path()` 或 `get_*_dir()` 解析,**禁止** `os.path.abspath(config.get(...))` 相对 CWD。
|
||||||
|
|
||||||
|
- 权威说明:[`DATA_PATHS.md`](DATA_PATHS.md)
|
||||||
|
- `.env.example` 中路径类配置**留空即用默认**;若写相对路径,必须相对 **skill 数据目录**,**禁止** `./outputs/...` 这类相对 workspace 的写法
|
||||||
|
- 可选 env:`SKILL_DOWNLOAD_DIR`、`SKILL_IMPORT_DIR`、`SKILL_EXPORT_DIR` 等(见 DATA_PATHS.md)
|
||||||
|
|
||||||
### 录屏开关(`OPENCLAW_RECORD_VIDEO`)
|
### 录屏开关(`OPENCLAW_RECORD_VIDEO`)
|
||||||
|
|
||||||
@@ -91,7 +99,7 @@ config.get_float("STEP_DELAY_MIN", 1.0)
|
|||||||
## health / config-path
|
## health / config-path
|
||||||
|
|
||||||
- **`health`**:输出 `collect_runtime_diagnostics` 字段(`platform_kit_version_ok`、`ffmpeg_path` 等),**不打印敏感值**;补充 `env_path` / `env_exists` / `example_path`。
|
- **`health`**:输出 `collect_runtime_diagnostics` 字段(`platform_kit_version_ok`、`ffmpeg_path` 等),**不打印敏感值**;补充 `env_path` / `env_exists` / `example_path`。
|
||||||
- **`config-path`**:输出 JSON,包含 `skill`、`env_path`(用户数据目录 `.env`)、`example_path`(仓库 `.env.example` 绝对路径),便于排查落盘位置。
|
- **`config-path`**:输出 JSON,包含 `skill`、`env_path`(用户数据目录 `.env`)、`example_path`(仓库 `.env.example` 绝对路径),便于排查落盘位置;业务 skill 建议附加 `list_resolved_data_paths()` 中的子目录路径(见 [`DATA_PATHS.md`](DATA_PATHS.md))。
|
||||||
|
|
||||||
## doctor / setup 命令(可选)
|
## doctor / setup 命令(可选)
|
||||||
|
|
||||||
@@ -104,4 +112,5 @@ config.get_float("STEP_DELAY_MIN", 1.0)
|
|||||||
|
|
||||||
- `RPA.md` — 三端 RPA 标准与各开关含义
|
- `RPA.md` — 三端 RPA 标准与各开关含义
|
||||||
- `ADAPTER.md` — `OPENCLAW_TEST_TARGET` 四档模式
|
- `ADAPTER.md` — `OPENCLAW_TEST_TARGET` 四档模式
|
||||||
- `RUNTIME.md` — `JIANGCHANG_*` 环境变量与数据目录约定
|
- `RUNTIME.md` — `JIANGCHANG_DATA_ROOT` 与数据根约定
|
||||||
|
- `DATA_PATHS.md` — 下载/导入/导出等子目录与 `resolve_data_path` 规范
|
||||||
|
|||||||
160
development/DATA_PATHS.md
Normal file
160
development/DATA_PATHS.md
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
# 用户数据目录与文件路径黄金标准
|
||||||
|
|
||||||
|
> 本文是 skill **读写本地文件** 的权威约定。凡涉及下载、导入、导出、缓存、RPA 存证等路径,复制模板后须遵守本文;Agent 实现业务 skill 时也应先读本文。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 根目录
|
||||||
|
|
||||||
|
所有技能持久化数据(配置、数据库、业务文件)默认落在:
|
||||||
|
|
||||||
|
```text
|
||||||
|
{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{skill_slug}/
|
||||||
|
```
|
||||||
|
|
||||||
|
示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
D:\jiangchang-data\12500\download-video-baidu-haokan\
|
||||||
|
```
|
||||||
|
|
||||||
|
实现:`util.runtime_paths.get_skill_data_dir()`。
|
||||||
|
|
||||||
|
**禁止**把技能自己写入的文件落到:
|
||||||
|
|
||||||
|
- Agent / 宿主 **workspace**(进程 CWD)
|
||||||
|
- 技能安装目录(含 `.openclaw/skills/...`)
|
||||||
|
- 未在本文声明的任意相对 CWD 路径
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 标准子目录树
|
||||||
|
|
||||||
|
| 子目录 | 用途 | 默认 helper |
|
||||||
|
|--------|------|-------------|
|
||||||
|
| `downloads/` | 从外部拉取的原始文件(视频、回单、PDF…) | `get_downloads_dir()` |
|
||||||
|
| `imports/` | 用户/Agent 放入的待处理清单(urls.txt、batch.json、CSV) | `get_imports_dir()` |
|
||||||
|
| `exports/` | 导出给用户的结果(xlsx/csv/json) | `get_exports_dir()` |
|
||||||
|
| `uploads/` | 待发布到外部平台的 staging(可选) | `get_uploads_dir()` |
|
||||||
|
| `cache/` | 可再生缓存(页面快照、解析中间结果) | `get_cache_dir()` |
|
||||||
|
| `temp/` | 单次任务 scratch,任务结束可删 | `get_temp_dir()` |
|
||||||
|
| `rpa-artifacts/` | RPA 失败截图、录屏中间产物 | `get_rpa_artifacts_dir(batch_id)` |
|
||||||
|
| `videos/` | RPA 录屏成片 MP4 | `get_videos_dir()` |
|
||||||
|
| `{skill_slug}.db` | SQLite | `get_db_path()` |
|
||||||
|
| `.env` | 用户配置 | `config.get_env_file_path()` |
|
||||||
|
|
||||||
|
复制后若业务不需要某目录,可不创建;**但一旦写入该类文件,必须走对应 helper**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 两类路径
|
||||||
|
|
||||||
|
### A. 技能拥有(skill-owned)
|
||||||
|
|
||||||
|
技能**创建或更新**的文件:下载结果、导出报表、失败截图、队列 sidecar 等。
|
||||||
|
|
||||||
|
- **默认**必须在 `{skill_data_dir}/<子目录>/` 下。
|
||||||
|
- **必须**通过 `resolve_data_path()` 或 `get_*_dir()` 解析,**禁止** `os.path.abspath(config.get(...))` 相对 CWD。
|
||||||
|
|
||||||
|
### B. 用户显式输入(user-owned)
|
||||||
|
|
||||||
|
用户在 CLI / Agent 对话中给出的**已有文件**绝对路径,例如「发布这个视频 `D:\素材\x.mp4`」。
|
||||||
|
|
||||||
|
- 技能**只读**,路径可以是用户磁盘任意位置。
|
||||||
|
- 使用 `resolve_input_path()`:绝对路径原样;**相对路径**解析为 `{skill_data_dir}/imports/<相对路径>`,**不**相对 workspace/CWD。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 配置项(`.env`)
|
||||||
|
|
||||||
|
可选覆盖项(**留空则用默认子目录**):
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# ── 数据目录子路径(见 development/DATA_PATHS.md)──
|
||||||
|
# 相对路径相对于 {JIANGCHANG_DATA_ROOT}/{USER_ID}/{slug}/,不是 workspace
|
||||||
|
# SKILL_DOWNLOAD_DIR=downloads/videos
|
||||||
|
# SKILL_IMPORT_DIR=imports
|
||||||
|
# SKILL_EXPORT_DIR=exports
|
||||||
|
# SKILL_UPLOAD_DIR=uploads
|
||||||
|
# SKILL_CACHE_DIR=cache
|
||||||
|
# SKILL_TEMP_DIR=temp
|
||||||
|
```
|
||||||
|
|
||||||
|
| 规则 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 未配置 | `{skill_data_dir}/{default_subdir}` |
|
||||||
|
| 相对值 `downloads/videos` | `{skill_data_dir}/downloads/videos` |
|
||||||
|
| 绝对值 `D:\nas\exports` | 高级用户/NAS 挂载,原样使用 |
|
||||||
|
| **禁止** `./outputs/...` | 会随 CWD 漂移,不得作为 `.env.example` 活跃配置行 |
|
||||||
|
|
||||||
|
业务专属路径 env key 须带 **`SKILL_` 前缀**(或技能 slug 前缀),避免污染全局命名空间。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 代码用法
|
||||||
|
|
||||||
|
```python
|
||||||
|
from util.runtime_paths import (
|
||||||
|
get_downloads_dir,
|
||||||
|
get_imports_dir,
|
||||||
|
resolve_data_path,
|
||||||
|
resolve_input_path,
|
||||||
|
list_resolved_data_paths,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 下载保存(A 类)
|
||||||
|
dest = os.path.join(get_downloads_dir(), f"{vid}.mp4")
|
||||||
|
|
||||||
|
# 或带 env 覆盖
|
||||||
|
out_dir = resolve_data_path("SKILL_DOWNLOAD_DIR", "downloads")
|
||||||
|
|
||||||
|
# CLI -i urls.txt(B 类,相对路径 → imports/)
|
||||||
|
manifest = resolve_input_path(args.input_path)
|
||||||
|
|
||||||
|
# health 诊断
|
||||||
|
paths = list_resolved_data_paths()
|
||||||
|
```
|
||||||
|
|
||||||
|
**反模式(禁止):**
|
||||||
|
|
||||||
|
```python
|
||||||
|
# ❌ 相对 CWD,Agent 从 workspace 执行时会写错盘
|
||||||
|
os.path.abspath(config.get("DOWNLOAD_OUTPUT_DIR"))
|
||||||
|
|
||||||
|
# ❌ .env.example 里写 ./outputs/videos
|
||||||
|
DOWNLOAD_OUTPUT_DIR=./outputs/videos
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. health / config-path
|
||||||
|
|
||||||
|
`health` 或 `config-path` 建议输出 `list_resolved_data_paths()` 中的路径,便于排查「文件写到哪里去了」。展示路径须与 `run` 实际使用的一致。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 与 RPA 存证的关系
|
||||||
|
|
||||||
|
- 失败截图、录屏中间文件:`rpa-artifacts/{batch_id}/`(见 [`RPA.md`](RPA.md) §5.1)
|
||||||
|
- 录屏成片:`videos/`(见 [`RPA.md`](RPA.md) §5.3)
|
||||||
|
|
||||||
|
业务 `downloads/` 与 RPA `videos/` **分工不同**:前者是业务产出文件,后者是操作过程录屏。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 测试
|
||||||
|
|
||||||
|
- 单元测试须用 `IsolatedDataRoot`,断言路径落在临时数据根下。
|
||||||
|
- `tests/test_runtime_paths.py` 覆盖 `resolve_data_path` / `resolve_input_path`。
|
||||||
|
- `POLICY-DATA-PATH-001`:禁止 `.env.example` 中 `./` 路径;禁止业务代码 `abspath(config.get(...))`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 相关文档
|
||||||
|
|
||||||
|
| 文档 | 内容 |
|
||||||
|
|------|------|
|
||||||
|
| [`RUNTIME.md`](RUNTIME.md) | 数据根、共享 runtime、编码 |
|
||||||
|
| [`CONFIG.md`](CONFIG.md) | `.env` bootstrap 与三层优先级 |
|
||||||
|
| [`RPA.md`](RPA.md) | rpa-artifacts / videos 存证 |
|
||||||
|
| [`POLICY_MATRIX.md`](POLICY_MATRIX.md) | POLICY-DATA-PATH-001 |
|
||||||
@@ -158,7 +158,7 @@ scripts/
|
|||||||
作用:常量、日志、路径、时间工具、通用帮助函数
|
作用:常量、日志、路径、时间工具、通用帮助函数
|
||||||
`util/logging_config.py` 是 `jiangchang_skill_core.unified_logging` 的**薄封装**,业务代码应通过它获取 logger
|
`util/logging_config.py` 是 `jiangchang_skill_core.unified_logging` 的**薄封装**,业务代码应通过它获取 logger
|
||||||
|
|
||||||
公共能力(config、logging、runtime_env、rpa、media_assets、video_session、runtime_diagnostics)从共享 runtime 的 `jiangchang-platform-kit>=1.0.17` import,**不得**在 `scripts/` 下保留 `jiangchang_skill_core/` 副本。
|
公共能力(config、logging、runtime_env、rpa、media_assets、video_session、runtime_diagnostics、activity/SRCP)从共享 runtime 的 `jiangchang-platform-kit>=1.2.0` import,**不得**在 `scripts/` 下保留 `jiangchang_skill_core/` 副本。
|
||||||
|
|
||||||
## 3.2 开发 RPA 类 skill
|
## 3.2 开发 RPA 类 skill
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ scripts/
|
|||||||
技能根目录的 `requirements.txt` 是**标准文件**,用于声明本技能**特有** Python 三方依赖。
|
技能根目录的 `requirements.txt` 是**标准文件**,用于声明本技能**特有** Python 三方依赖。
|
||||||
|
|
||||||
- **公共依赖**(`jiangchang-platform-kit`、`playwright`、config、runtime diagnostics、RPA 公共能力等)由**宿主共享 runtime** 提供,**不要**写入技能 `requirements.txt`。
|
- **公共依赖**(`jiangchang-platform-kit`、`playwright`、config、runtime diagnostics、RPA 公共能力等)由**宿主共享 runtime** 提供,**不要**写入技能 `requirements.txt`。
|
||||||
- `SKILL.md` 的 `metadata.openclaw.platform_kit_min_version`(当前 `1.0.17`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是** pip 依赖声明。
|
- `SKILL.md` 的 `metadata.openclaw.platform_kit_min_version`(当前 `1.2.0`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是** pip 依赖声明。
|
||||||
- 匠厂宿主安装/更新技能后,会将技能 `requirements.txt` 安装到共享 venv:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
- 匠厂宿主安装/更新技能后,会将技能 `requirements.txt` 安装到共享 venv:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
||||||
- **不要**在业务代码中 `subprocess` / `pip install`;缺依赖由 `health` 报错,由宿主负责安装。
|
- **不要**在业务代码中 `subprocess` / `pip install`;缺依赖由 `health` 报错,由宿主负责安装。
|
||||||
- **版本约束尽量收窄**,降低多技能共享 venv 时的冲突风险。推荐范围写法:
|
- **版本约束尽量收窄**,降低多技能共享 venv 时的冲突风险。推荐范围写法:
|
||||||
@@ -487,7 +487,7 @@ metadata:
|
|||||||
|
|
||||||
- `cmd_run` 及主任务入口必须:`log.info("task_start ...")`、`log.info("task_log_saved ...")`;失败路径必须 `log.exception("task_failed ...")`。
|
- `cmd_run` 及主任务入口必须:`log.info("task_start ...")`、`log.info("task_log_saved ...")`;失败路径必须 `log.exception("task_failed ...")`。
|
||||||
- 外部 API、兄弟技能、RPA 操作须记录**开始 / 结束 / 耗时 / 状态**(`external_call_start` / `external_call_done elapsed_ms=...`)。
|
- 外部 API、兄弟技能、RPA 操作须记录**开始 / 结束 / 耗时 / 状态**(`external_call_start` / `external_call_done elapsed_ms=...`)。
|
||||||
- 长任务 / RPA 须配合 `activity.emit` 或 `RpaVideoSession.add_step` 输出用户可见进度。
|
- 长任务 / RPA 须配合 `activity.emit` 或 `RpaVideoSession.add_step` 输出用户可见进度;`cmd_run` 须 `job_context` + 各出口 `finish`(见 [`LOGGING.md`](LOGGING.md) §2.5)。
|
||||||
- 使用 `from util.logging_config import get_skill_logger`,**不要**用 `print` 替代 logger 做排障日志。
|
- 使用 `from util.logging_config import get_skill_logger`,**不要**用 `print` 替代 logger 做排障日志。
|
||||||
- **禁止**在日志中写入 password、token、cookie 等敏感明文(见 `LOGGING.md` §敏感信息红线)。
|
- **禁止**在日志中写入 password、token、cookie 等敏感明文(见 `LOGGING.md` §敏感信息红线)。
|
||||||
|
|
||||||
|
|||||||
@@ -56,10 +56,13 @@ OpenClaw 技能常在客户电脑上异步执行,且大量依赖 RPA、浏览
|
|||||||
|
|
||||||
| API | 用途 |
|
| API | 用途 |
|
||||||
|-----|------|
|
|-----|------|
|
||||||
| `emit` | 推送用户可读进度(不写 stdout) |
|
| `emit` | 推送用户可读进度(不写 stdout);进入步骤前自动步骤闸门(SRCP) |
|
||||||
| `step` | 结构化步骤 |
|
| `step` | 结构化步骤 |
|
||||||
| `finish` | 任务结束;**唯一**写单行 result JSON 到 stdout 的场景 |
|
| `finish` | 任务结束;**唯一**写单行 result JSON 到 stdout 的场景 |
|
||||||
| `rpa_step` | RPA 专用步骤文案 |
|
| `job_context` | 包裹 `cmd_run`;未捕获异常 / `JobStopped` 时自动 `finish` |
|
||||||
|
| `rpa_step` | RPA 专用步骤:闸门 + ▶/✓ emit |
|
||||||
|
| `interruptible_sleep` | RPA 等待(替代裸 `asyncio.sleep`),可暂停/停止 |
|
||||||
|
| `checkpoint` | 长循环内 consult control(一般由 kit 自动调用) |
|
||||||
|
|
||||||
**路径**:
|
**路径**:
|
||||||
|
|
||||||
@@ -72,6 +75,33 @@ OpenClaw 技能常在客户电脑上异步执行,且大量依赖 RPA、浏览
|
|||||||
- `emit` **不写 stdout**;长任务应持续 emit,避免用户以为卡死。
|
- `emit` **不写 stdout**;长任务应持续 emit,避免用户以为卡死。
|
||||||
- `finish` 才输出单行 result JSON 供宿主解析。
|
- `finish` 才输出单行 result JSON 供宿主解析。
|
||||||
- RPA 类技能:`RpaVideoSession.add_step` 会自动同步 activity(无需重复手写每步 emit)。
|
- RPA 类技能:`RpaVideoSession.add_step` 会自动同步 activity(无需重复手写每步 emit)。
|
||||||
|
- **禁止**自建 `scripts/util/progress.py` 或向 stdout 打印 `type:progress` JSON;进度只走 Run Journal。
|
||||||
|
- 宿主通过 `{job_id}.control.json` 下发暂停/继续/停止;技能侧由 platform-kit 在步骤闸门自动处理(见 §2.5)。
|
||||||
|
|
||||||
|
### 2.5 步骤控制(SRCP v1,platform-kit >= 1.2.0)
|
||||||
|
|
||||||
|
**权威行为定义在本文**;platform-kit README 为实现细节参考。
|
||||||
|
|
||||||
|
| 通道 | 方向 | 载体 |
|
||||||
|
|------|------|------|
|
||||||
|
| 进度 | 技能 → 宿主 | Run Journal(`emit` / `rpa_step` / `add_step`) |
|
||||||
|
| 结果 | 技能 → 宿主 | `finish()` → Journal 终态 + stdout 一行 result |
|
||||||
|
| 控制 | 宿主 → 技能 | `{JIANGCHANG_DATA_ROOT}/.jiangchang/runs/{job_id}.control.json` |
|
||||||
|
|
||||||
|
`control.json` 的 `command` 只认:`none` | `pause` | `resume` | `stop`。
|
||||||
|
|
||||||
|
技能作者三件事:
|
||||||
|
|
||||||
|
1. `cmd_run` 外包 `with job_context(skill=SKILL_SLUG):`
|
||||||
|
2. 关键步骤 `emit(...)` 或 `@rpa_step` / `video.add_step`
|
||||||
|
3. 每个出口 `finish(status=..., message=..., skill=SKILL_SLUG, **fields)` — **不要**手写多行 JSON 结果
|
||||||
|
|
||||||
|
RPA 等待用 `interruptible_sleep`,**不要**裸 `asyncio.sleep`(否则暂停响应滞后)。
|
||||||
|
|
||||||
|
暂停在**步骤边界**生效(当前 `@rpa_step` / `emit` 执行完后、下一步开始前),与影刀「当前指令完成后暂停」一致。
|
||||||
|
|
||||||
|
Journal 会写入 `type: lifecycle` 事件(`paused` / `resumed` / `stopping`),供宿主任务中心显示状态。
|
||||||
|
|
||||||
|
|
||||||
### 2.3 `task_logs`(任务结果审计)
|
### 2.3 `task_logs`(任务结果审计)
|
||||||
|
|
||||||
@@ -202,7 +232,7 @@ batch_progress current=7 total=20 target_id=store-001
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from util.logging_config import get_skill_logger
|
from util.logging_config import get_skill_logger
|
||||||
from jiangchang_skill_core.activity import emit
|
from jiangchang_skill_core.activity import emit, finish, job_context, rpa_step, interruptible_sleep
|
||||||
|
|
||||||
from util.constants import SKILL_SLUG
|
from util.constants import SKILL_SLUG
|
||||||
|
|
||||||
@@ -210,6 +240,7 @@ log = get_skill_logger()
|
|||||||
|
|
||||||
def cmd_run(target=None, input_id=None):
|
def cmd_run(target=None, input_id=None):
|
||||||
task_type = "your_task"
|
task_type = "your_task"
|
||||||
|
with job_context(skill=SKILL_SLUG):
|
||||||
log.info(
|
log.info(
|
||||||
"task_start task_type=%s target_id=%s input_id=%s",
|
"task_start task_type=%s target_id=%s input_id=%s",
|
||||||
task_type, target, input_id,
|
task_type, target, input_id,
|
||||||
@@ -219,10 +250,11 @@ def cmd_run(target=None, input_id=None):
|
|||||||
ok, reason = check_entitlement(SKILL_SLUG)
|
ok, reason = check_entitlement(SKILL_SLUG)
|
||||||
if not ok:
|
if not ok:
|
||||||
log.warning("entitlement_failed task_type=%s reason=%s", task_type, reason)
|
log.warning("entitlement_failed task_type=%s reason=%s", task_type, reason)
|
||||||
|
finish(status="failed", message=reason, skill=SKILL_SLUG, error_code="ENTITLEMENT_DENIED")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
t0 = time.monotonic()
|
t0 = time.monotonic()
|
||||||
# ... 外部调用 ...
|
# ... 外部调用 / RPA:@rpa_step 或 video.add_step;等待用 interruptible_sleep ...
|
||||||
elapsed_ms = int((time.monotonic() - t0) * 1000)
|
elapsed_ms = int((time.monotonic() - t0) * 1000)
|
||||||
log.info(
|
log.info(
|
||||||
"external_call_done system=%s operation=%s elapsed_ms=%d status=%s",
|
"external_call_done system=%s operation=%s elapsed_ms=%d status=%s",
|
||||||
@@ -231,7 +263,7 @@ def cmd_run(target=None, input_id=None):
|
|||||||
|
|
||||||
tlr.save_task_log(..., status="success", ...)
|
tlr.save_task_log(..., status="success", ...)
|
||||||
log.info("task_log_saved task_type=%s status=success", task_type)
|
log.info("task_log_saved task_type=%s status=success", task_type)
|
||||||
emit("任务完成", skill=SKILL_SLUG, stage="run")
|
finish(status="success", message="任务完成", skill=SKILL_SLUG)
|
||||||
return 0
|
return 0
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
log.exception(
|
||||||
@@ -240,6 +272,7 @@ def cmd_run(target=None, input_id=None):
|
|||||||
)
|
)
|
||||||
emit("任务失败,已记录诊断信息", type="warn", skill=SKILL_SLUG, stage="run")
|
emit("任务失败,已记录诊断信息", type="warn", skill=SKILL_SLUG, stage="run")
|
||||||
tlr.save_task_log(..., status="failed", error_msg="...", ...)
|
tlr.save_task_log(..., status="failed", error_msg="...", ...)
|
||||||
|
finish(status="failed", message="任务执行异常", skill=SKILL_SLUG)
|
||||||
return 1
|
return 1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
| POLICY-LOGGING-003 | 主任务入口须含 `log.info`/`logger.info`、`log.exception`/`logger.exception`,并写入 `save_task_log` | development/LOGGING.md | hard | 扫描 `scripts/service/task_service.py` | `tests/test_development_policy_guard.py::TestPolicyLogging003` |
|
| POLICY-LOGGING-003 | 主任务入口须含 `log.info`/`logger.info`、`log.exception`/`logger.exception`,并写入 `save_task_log` | development/LOGGING.md | hard | 扫描 `scripts/service/task_service.py` | `tests/test_development_policy_guard.py::TestPolicyLogging003` |
|
||||||
| POLICY-LOGGING-004 | 长任务 / RPA 模板须使用 Activity 或 RPA video step 输出进度 | development/LOGGING.md;development/RPA.md | hard | 扫描 `scripts/service/task_service.py` 含 `emit(` / `activity.emit` / `video.add_step` | `tests/test_development_policy_guard.py::TestPolicyLogging004` |
|
| POLICY-LOGGING-004 | 长任务 / RPA 模板须使用 Activity 或 RPA video step 输出进度 | development/LOGGING.md;development/RPA.md | hard | 扫描 `scripts/service/task_service.py` 含 `emit(` / `activity.emit` / `video.add_step` | `tests/test_development_policy_guard.py::TestPolicyLogging004` |
|
||||||
| POLICY-LOGGING-005 | 交付代码不得在 logging 调用行以 `key=value` 形式记录明显敏感字段 | development/LOGGING.md;development/CONFIG.md | hard | 扫描 `scripts/**/*.py` 的 logging 调用行(不含注释) | `tests/test_development_policy_guard.py::TestPolicyLogging005` |
|
| POLICY-LOGGING-005 | 交付代码不得在 logging 调用行以 `key=value` 形式记录明显敏感字段 | development/LOGGING.md;development/CONFIG.md | hard | 扫描 `scripts/**/*.py` 的 logging 调用行(不含注释) | `tests/test_development_policy_guard.py::TestPolicyLogging005` |
|
||||||
|
| POLICY-CONTROL-001 | 不得存在 `scripts/util/progress.py` 或自建 stdout 进度模块 | development/LOGGING.md §2.5;development/RPA.md §0.1 | hard | 文件不存在检查 | `tests/test_development_policy_guard.py::TestPolicyControl001` |
|
||||||
|
| POLICY-CONTROL-002 | `task_service.py` 须使用 `job_context(` 与 `finish(` | development/LOGGING.md §2.5、§7 | hard | 扫描 `scripts/service/task_service.py` | `tests/test_development_policy_guard.py::TestPolicyControl002` |
|
||||||
|
| POLICY-CONTROL-003 | `scripts/service/*.py` 不得裸 `asyncio.sleep`(RPA 等待须 `interruptible_sleep`) | development/RPA.md §0.1 | hard | 扫描 service 层 Python | `tests/test_development_policy_guard.py::TestPolicyControl003` |
|
||||||
|
| POLICY-DATA-PATH-001 | 技能拥有路径须经 `resolve_data_path` / `get_*_dir`;`.env.example` 禁止 `./` CWD 相对路径;业务代码禁止 `abspath(config.get(...))` | development/DATA_PATHS.md | hard | 扫描 `.env.example` 与 `scripts/**/*.py` | `tests/test_development_policy_guard.py::TestPolicyDataPath001` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -42,4 +46,4 @@
|
|||||||
| RPA 拟人操作、选择器纪律、HITL 超时 | development/RPA.md §0–§1 | 行为与 DOM 质量,无法静态扫描 |
|
| RPA 拟人操作、选择器纪律、HITL 超时 | development/RPA.md §0–§1 | 行为与 DOM 质量,无法静态扫描 |
|
||||||
| adapter 四档契约测试覆盖 timeout/unauthorized 等 | development/ADAPTER.md §contract tests | 需业务实现后人工补测 |
|
| adapter 四档契约测试覆盖 timeout/unauthorized 等 | development/ADAPTER.md §contract tests | 需业务实现后人工补测 |
|
||||||
| `SKILL.md` / `constants.SKILL_SLUG` 一致性 | development/DEVELOPMENT.md §16 | 已有 `tests/test_skill_metadata.py` |
|
| `SKILL.md` / `constants.SKILL_SLUG` 一致性 | development/DEVELOPMENT.md §16 | 已有 `tests/test_skill_metadata.py` |
|
||||||
| platform_kit_min_version >= 1.0.17 | development/RUNTIME.md | 已有 `tests/test_platform_import.py` |
|
| platform_kit_min_version >= 1.2.0 | development/RUNTIME.md | 已有 `tests/test_platform_import.py` |
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
6. [`ADAPTER.md`](ADAPTER.md) — 涉及外部系统对接时
|
6. [`ADAPTER.md`](ADAPTER.md) — 涉及外部系统对接时
|
||||||
7. [`RPA.md`](RPA.md) — 涉及浏览器 / 桌面 / 手机自动化时
|
7. [`RPA.md`](RPA.md) — 涉及浏览器 / 桌面 / 手机自动化时
|
||||||
8. [`CONFIG.md`](CONFIG.md) — `.env` 规范与 bootstrap 机制
|
8. [`CONFIG.md`](CONFIG.md) — `.env` 规范与 bootstrap 机制
|
||||||
9. [`RUNTIME.md`](RUNTIME.md) — 共享 runtime、数据路径、发布打包与编码约定
|
9. [`DATA_PATHS.md`](DATA_PATHS.md) — 下载/导入/导出等本地文件路径标准(涉及文件读写时必读)
|
||||||
|
10. [`RUNTIME.md`](RUNTIME.md) — 共享 runtime、数据路径、发布打包与编码约定
|
||||||
|
|
||||||
脚手架与 Git 防串库:[`../tools/README.md`](../tools/README.md)(`scaffold_skill.ps1`)。
|
脚手架与 Git 防串库:[`../tools/README.md`](../tools/README.md)(`scaffold_skill.ps1`)。
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,30 @@
|
|||||||
| **失败存证** | 失败必截图,合规场景全程录屏,统一存 `{数据目录}/rpa-artifacts/{batch_id}/{tag}_{ts}.png` |
|
| **失败存证** | 失败必截图,合规场景全程录屏,统一存 `{数据目录}/rpa-artifacts/{batch_id}/{tag}_{ts}.png` |
|
||||||
| **选择器纪律** | 语义选择器优先(id/name/text/aria);**F12 确认后再写,严禁凭记忆猜 DOM** |
|
| **选择器纪律** | 语义选择器优先(id/name/text/aria);**F12 确认后再写,严禁凭记忆猜 DOM** |
|
||||||
| **统一错误码** | `ERROR:REQUIRE_LOGIN` / `ERROR:CAPTCHA_NEED_HUMAN` / `ERROR:RATE_LIMITED` / `ERROR:LOGIN_TIMEOUT` 等,见下方错误码表 |
|
| **统一错误码** | `ERROR:REQUIRE_LOGIN` / `ERROR:CAPTCHA_NEED_HUMAN` / `ERROR:RATE_LIMITED` / `ERROR:LOGIN_TIMEOUT` 等,见下方错误码表 |
|
||||||
|
| **步骤可控制** | 每条 RPA 指令 = 一个 `@rpa_step` 或 `video.add_step`;等待用 `interruptible_sleep`;宿主通过 control.json 暂停/继续/停止(SRCP,见 [`LOGGING.md`](LOGGING.md) §2.5) |
|
||||||
| **幂等 / 断点续跑** | 批量操作记录"已处理到第几条",崩溃后能续跑、不重复提交 |
|
| **幂等 / 断点续跑** | 批量操作记录"已处理到第几条",崩溃后能续跑、不重复提交 |
|
||||||
|
|
||||||
> 三端各自实现一个会话抽象 `RpaSession`(launch / login / act / screenshot / close),上层 skill 不感知是浏览器还是手机。
|
> 三端各自实现一个会话抽象 `RpaSession`(launch / login / act / screenshot / close),上层 skill 不感知是浏览器还是手机。
|
||||||
|
|
||||||
|
### 0.1 步骤控制与进度(SRCP,platform-kit >= 1.2.0)
|
||||||
|
|
||||||
|
- **禁止** `scripts/util/progress.py` 或 `print({"type":"progress",...})`;进度只走 `emit` / Run Journal。
|
||||||
|
- **禁止** RPA 主路径裸 `asyncio.sleep`;用 `jiangchang_skill_core.activity.interruptible_sleep`。
|
||||||
|
- RPA 函数用 `@rpa_step("中文步骤名")` 拆分;或在 `RpaVideoSession` 内 `video.add_step("中文步骤")`。
|
||||||
|
- `cmd_run` 须 `with job_context(skill=SKILL_SLUG):`,所有出口 `finish(...)`。
|
||||||
|
- 暂停在步骤边界生效;浏览器会话暂停时不强制关闭,恢复后同进程继续。
|
||||||
|
|
||||||
|
```python
|
||||||
|
from jiangchang_skill_core.activity import emit, finish, job_context, interruptible_sleep, rpa_step
|
||||||
|
|
||||||
|
@rpa_step("打开登录页")
|
||||||
|
async def open_login(page):
|
||||||
|
await page.goto("https://example.com")
|
||||||
|
await interruptible_sleep(1.5)
|
||||||
|
```
|
||||||
|
|
||||||
|
规范权威定义:[`LOGGING.md`](LOGGING.md) §2.5。金样代码:[`scripts/service/task_service.py`](../scripts/service/task_service.py)。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 1. 浏览器(标准已成熟)
|
## 1. 浏览器(标准已成熟)
|
||||||
@@ -51,7 +71,7 @@
|
|||||||
6. **可以** `ignore_default_args=["--enable-automation"]`(platform-kit `launch_persistent_browser` 已处理)。
|
6. **可以** `ignore_default_args=["--enable-automation"]`(platform-kit `launch_persistent_browser` 已处理)。
|
||||||
7. **强风控平台**:优先真实点击、键盘、鼠标、地址栏、持久 profile;**不要**直接拼接搜索结果 URL 或 DOM 注入。
|
7. **强风控平台**:优先真实点击、键盘、鼠标、地址栏、持久 profile;**不要**直接拼接搜索结果 URL 或 DOM 注入。
|
||||||
|
|
||||||
指纹淡化(stealth)典型项:`navigator.webdriver=undefined`、`chrome.runtime`、`permissions.query`、`plugins`、`languages` 等。共享实现见 `jiangchang_skill_core.rpa`(platform-kit **>= 1.0.17**)。
|
指纹淡化(stealth)典型项:`navigator.webdriver=undefined`、`chrome.runtime`、`permissions.query`、`plugins`、`languages` 等。共享实现见 `jiangchang_skill_core.rpa`(platform-kit **>= 1.2.0**)。
|
||||||
|
|
||||||
**拟人操作**(必做):
|
**拟人操作**(必做):
|
||||||
|
|
||||||
@@ -124,7 +144,7 @@ from jiangchang_skill_core.rpa import (
|
|||||||
from jiangchang_skill_core.rpa.stealth import stealth_enabled, STEALTH_INIT_SCRIPT
|
from jiangchang_skill_core.rpa.stealth import stealth_enabled, STEALTH_INIT_SCRIPT
|
||||||
```
|
```
|
||||||
|
|
||||||
- `RpaVideoSession` 来自 platform-kit **>= 1.0.17**;ffmpeg、背景音乐、media-assets 由 platform-kit 统一解析;已提供前置/后置缓冲、字幕、TTS 旁白、背景音乐循环、结尾淡出。
|
- `RpaVideoSession` 来自 platform-kit **>= 1.2.0**;ffmpeg、背景音乐、media-assets 由 platform-kit 统一解析;已提供前置/后置缓冲、字幕、TTS 旁白、背景音乐循环、结尾淡出。
|
||||||
- `health` 对上述资源做只读诊断,不下载、不修复。
|
- `health` 对上述资源做只读诊断,不下载、不修复。
|
||||||
|
|
||||||
### 1.5 真实浏览器 RPA 示例(必读)
|
### 1.5 真实浏览器 RPA 示例(必读)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## 共享 Python Runtime
|
## 共享 Python Runtime
|
||||||
|
|
||||||
**skill-template** 及复制出的新技能,公共能力均来自宿主匠厂安装的共享 Python Runtime(`jiangchang-platform-kit>=1.0.17` 及其传递依赖,含 `playwright`)。`jiangchang_skill_core` **不得**在技能仓库内 vendored,应由共享 venv 的 site-packages 提供。
|
**skill-template** 及复制出的新技能,公共能力均来自宿主匠厂安装的共享 Python Runtime(`jiangchang-platform-kit>=1.2.0` 及其传递依赖,含 `playwright`)。`jiangchang_skill_core` **不得**在技能仓库内 vendored,应由共享 venv 的 site-packages 提供。
|
||||||
|
|
||||||
技能根目录 `requirements.txt` **只声明技能特有依赖**;**不要**重复声明 `jiangchang-platform-kit` 或 `playwright`。`SKILL.md` 的 `platform_kit_min_version` 是运行契约,**不是** pip 依赖声明。
|
技能根目录 `requirements.txt` **只声明技能特有依赖**;**不要**重复声明 `jiangchang-platform-kit` 或 `playwright`。`SKILL.md` 的 `platform_kit_min_version` 是运行契约,**不是** pip 依赖声明。
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ Windows:
|
|||||||
|
|
||||||
`<shared-python>` 通常位于 `{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。数据根由宿主注入;开发模式下也可能通过 `JIANGCHANG_DATA_ROOT` 解析(见 `jiangchang_skill_core.runtime_env`)。
|
`<shared-python>` 通常位于 `{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。数据根由宿主注入;开发模式下也可能通过 `JIANGCHANG_DATA_ROOT` 解析(见 `jiangchang_skill_core.runtime_env`)。
|
||||||
|
|
||||||
## Runtime 诊断(platform-kit 1.0.17+)
|
## Runtime 诊断(platform-kit 1.2.0+)
|
||||||
|
|
||||||
`health` 命令通过 **`jiangchang_skill_core.collect_runtime_diagnostics`** 输出共享 runtime 诊断,**不在技能内重复实现**。典型字段:
|
`health` 命令通过 **`jiangchang_skill_core.collect_runtime_diagnostics`** 输出共享 runtime 诊断,**不在技能内重复实现**。典型字段:
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ Windows:
|
|||||||
- 用户实际 `.env`:`{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{skill_slug}/.env`。
|
- 用户实际 `.env`:`{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{skill_slug}/.env`。
|
||||||
- `scripts/main.py` 与 `cli.app.main()` 启动时调用 `util.config_bootstrap.bootstrap_skill_config()`。
|
- `scripts/main.py` 与 `cli.app.main()` 启动时调用 `util.config_bootstrap.bootstrap_skill_config()`。
|
||||||
- 配置优先级:**进程环境变量** > **用户 `.env`** > **`.env.example` 默认值**。
|
- 配置优先级:**进程环境变量** > **用户 `.env`** > **`.env.example` 默认值**。
|
||||||
- 公共 `config` / `merge_missing_env_keys` 来自共享 runtime 的 `jiangchang-platform-kit>=1.0.17`,**不得** vendored `scripts/jiangchang_skill_core/`。
|
- 公共 `config` / `merge_missing_env_keys` 来自共享 runtime 的 `jiangchang-platform-kit>=1.2.0`,**不得** vendored `scripts/jiangchang_skill_core/`。
|
||||||
|
|
||||||
## media-assets / ffmpeg / 背景音乐
|
## media-assets / ffmpeg / 背景音乐
|
||||||
|
|
||||||
@@ -89,6 +89,8 @@ RPA 录屏成片(`RpaVideoSession`)、ffmpeg 路径、背景音乐探测均
|
|||||||
{...}/{skill_slug}.db
|
{...}/{skill_slug}.db
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**业务文件(下载、导入、导出、缓存等)** 须落在上述数据目录的标准子目录下,**不得**相对 workspace/CWD 写入。完整子目录树、env 覆盖规则、`resolve_data_path()` 用法见 **[`DATA_PATHS.md`](DATA_PATHS.md)**。
|
||||||
|
|
||||||
- 业务表使用英文 snake_case;中文表名/字段名写入 `_jiangchang_tables` / `_jiangchang_columns`(见 `references/SCHEMA.md`)。
|
- 业务表使用英文 snake_case;中文表名/字段名写入 `_jiangchang_tables` / `_jiangchang_columns`(见 `references/SCHEMA.md`)。
|
||||||
- 界面字段顺序由 `CREATE TABLE` 列定义顺序决定,**不要**维护 `display_order` 来调整顺序。
|
- 界面字段顺序由 `CREATE TABLE` 列定义顺序决定,**不要**维护 `display_order` 来调整顺序。
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
必跑套件要像一个紧张的守门员:**快、确定、离线**。典型覆盖:
|
必跑套件要像一个紧张的守门员:**快、确定、离线**。典型覆盖:
|
||||||
|
|
||||||
- CLI:导入 [`cli.app`](../scripts/cli/app.py) 走解析链路、`health`(runtime diagnostics)/ `version` / `logs` / `log-get` 冒烟;
|
- CLI:导入 [`cli.app`](../scripts/cli/app.py) 走解析链路、`health`(runtime diagnostics)/ `version` / `logs` / `log-get` 冒烟;
|
||||||
- 架构守护:无 `scripts/jiangchang_skill_core/`、`platform-kit>=1.0.17` 导入来源、文档/runtime 标准(见 `test_platform_import.py` 等);
|
- 架构守护:无 `scripts/jiangchang_skill_core/`、`platform-kit>=1.2.0` 导入来源、文档/runtime 标准(见 `test_platform_import.py` 等);
|
||||||
- **真实 subprocess**:[`tests/test_entrypoint_subprocess.py`](../tests/test_entrypoint_subprocess.py) 再调用一遍 `python scripts/main.py`,防路径漂移;
|
- **真实 subprocess**:[`tests/test_entrypoint_subprocess.py`](../tests/test_entrypoint_subprocess.py) 再调用一遍 `python scripts/main.py`,防路径漂移;
|
||||||
- 运行时:`runtime_paths` 与 **`JIANGCHANG_*` 隔离**;
|
- 运行时:`runtime_paths` 与 **`JIANGCHANG_*` 隔离**;
|
||||||
- `SKILL.md` YAML slug vs [`constants.SKILL_SLUG`](../scripts/util/constants.py);
|
- `SKILL.md` YAML slug vs [`constants.SKILL_SLUG`](../scripts/util/constants.py);
|
||||||
@@ -260,7 +260,7 @@ Golden fixture 流程同理([`tests/samples/test_golden_cases.py.sample`](../t
|
|||||||
|
|
||||||
- [ ] `requirements.txt` **不含** `jiangchang-platform-kit` / `playwright`
|
- [ ] `requirements.txt` **不含** `jiangchang-platform-kit` / `playwright`
|
||||||
- [ ] 无 `scripts/jiangchang_skill_core/` vendored 副本
|
- [ ] 无 `scripts/jiangchang_skill_core/` vendored 副本
|
||||||
- [ ] `platform_kit_min_version` **>= 1.0.17**(`SKILL.md` + `constants.py`)
|
- [ ] `platform_kit_min_version` **>= 1.2.0**(`SKILL.md` + `constants.py`)
|
||||||
- [ ] `health` 能输出 `platform_kit_version_ok`(或等价诊断行)
|
- [ ] `health` 能输出 `platform_kit_version_ok`(或等价诊断行)
|
||||||
- [ ] `config-path` 可输出用户 `.env` 路径 JSON
|
- [ ] `config-path` 可输出用户 `.env` 路径 JSON
|
||||||
- [ ] `pytest.ini` 存在且 `python_files` 只收集 `test_*.py` / `*_test.py`
|
- [ ] `pytest.ini` 存在且 `python_files` 只收集 `test_*.py` / `*_test.py`
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import uuid
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from jiangchang_skill_core import collect_runtime_diagnostics, config, format_runtime_health_lines
|
from jiangchang_skill_core import collect_runtime_diagnostics, config, format_runtime_health_lines
|
||||||
from jiangchang_skill_core.activity import emit
|
from jiangchang_skill_core.activity import JobStopped, emit, finish, job_context
|
||||||
from jiangchang_skill_core.rpa.video_session import RpaVideoSession
|
|
||||||
|
|
||||||
from db import task_logs_repository as tlr
|
from db import task_logs_repository as tlr
|
||||||
|
from jiangchang_skill_core.rpa.video_session import RpaVideoSession
|
||||||
from service.entitlement_service import check_entitlement
|
from service.entitlement_service import check_entitlement
|
||||||
from service.task_run_support import (
|
from service.task_run_support import (
|
||||||
_print_video_summary,
|
_print_video_summary,
|
||||||
@@ -65,6 +65,8 @@ def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int
|
|||||||
"""通用任务执行入口模板。复制后请实现真实业务逻辑。"""
|
"""通用任务执行入口模板。复制后请实现真实业务逻辑。"""
|
||||||
log = _get_task_logger()
|
log = _get_task_logger()
|
||||||
task_type = "demo"
|
task_type = "demo"
|
||||||
|
|
||||||
|
with job_context(skill=SKILL_SLUG):
|
||||||
log.info(
|
log.info(
|
||||||
"task_start task_type=%s target_id=%s input_id=%s",
|
"task_start task_type=%s target_id=%s input_id=%s",
|
||||||
task_type,
|
task_type,
|
||||||
@@ -92,6 +94,13 @@ def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int
|
|||||||
target,
|
target,
|
||||||
input_id,
|
input_id,
|
||||||
)
|
)
|
||||||
|
finish(
|
||||||
|
status="failed",
|
||||||
|
message=reason,
|
||||||
|
skill=SKILL_SLUG,
|
||||||
|
error_code="ENTITLEMENT_DENIED",
|
||||||
|
stage="auth",
|
||||||
|
)
|
||||||
print(f"❌ {reason}")
|
print(f"❌ {reason}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -124,8 +133,18 @@ def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int
|
|||||||
input_id,
|
input_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
finish(
|
||||||
|
status="failed",
|
||||||
|
message="模板仓库未实现真实业务",
|
||||||
|
skill=SKILL_SLUG,
|
||||||
|
template_demo=True,
|
||||||
|
target=target,
|
||||||
|
input_id=input_id,
|
||||||
|
)
|
||||||
print("❌ 这是模板仓库,请复制后在 scripts/service/task_service.py 中实现 cmd_run 的真实业务逻辑。")
|
print("❌ 这是模板仓库,请复制后在 scripts/service/task_service.py 中实现 cmd_run 的真实业务逻辑。")
|
||||||
return rc
|
return rc
|
||||||
|
except JobStopped:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
log.exception(
|
||||||
"task_failed task_type=%s target_id=%s input_id=%s",
|
"task_failed task_type=%s target_id=%s input_id=%s",
|
||||||
@@ -160,6 +179,12 @@ def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int
|
|||||||
target,
|
target,
|
||||||
input_id,
|
input_id,
|
||||||
)
|
)
|
||||||
|
finish(
|
||||||
|
status="failed",
|
||||||
|
message="任务执行异常,详见统一日志",
|
||||||
|
skill=SKILL_SLUG,
|
||||||
|
stage="run",
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""技能标识、版本与平台公共库约束(复制后请修改 slug/version/logger)。"""
|
"""技能标识、版本与平台公共库约束(复制后请修改 slug/version/logger)。"""
|
||||||
|
|
||||||
SKILL_SLUG = "your-skill-slug"
|
SKILL_SLUG = "your-skill-slug"
|
||||||
SKILL_VERSION = "1.0.32"
|
SKILL_VERSION = "1.0.39"
|
||||||
LOG_LOGGER_NAME = "openclaw.skill.your_skill_slug"
|
LOG_LOGGER_NAME = "openclaw.skill.your_skill_slug"
|
||||||
PLATFORM_KIT_MIN_VERSION = "1.0.17"
|
PLATFORM_KIT_MIN_VERSION = "1.2.0"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""数据根、技能目录、兄弟技能根路径。"""
|
"""数据根、技能目录、兄弟技能根路径与用户数据子目录解析。"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -10,6 +10,22 @@ from util.constants import SKILL_SLUG
|
|||||||
|
|
||||||
_SCRIPTS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
_SCRIPTS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
STANDARD_SUBDIR_DOWNLOADS = "downloads"
|
||||||
|
STANDARD_SUBDIR_IMPORTS = "imports"
|
||||||
|
STANDARD_SUBDIR_EXPORTS = "exports"
|
||||||
|
STANDARD_SUBDIR_UPLOADS = "uploads"
|
||||||
|
STANDARD_SUBDIR_CACHE = "cache"
|
||||||
|
STANDARD_SUBDIR_TEMP = "temp"
|
||||||
|
STANDARD_SUBDIR_RPA_ARTIFACTS = "rpa-artifacts"
|
||||||
|
STANDARD_SUBDIR_VIDEOS = "videos"
|
||||||
|
|
||||||
|
CONFIG_KEY_DOWNLOAD_DIR = "SKILL_DOWNLOAD_DIR"
|
||||||
|
CONFIG_KEY_IMPORT_DIR = "SKILL_IMPORT_DIR"
|
||||||
|
CONFIG_KEY_EXPORT_DIR = "SKILL_EXPORT_DIR"
|
||||||
|
CONFIG_KEY_UPLOAD_DIR = "SKILL_UPLOAD_DIR"
|
||||||
|
CONFIG_KEY_CACHE_DIR = "SKILL_CACHE_DIR"
|
||||||
|
CONFIG_KEY_TEMP_DIR = "SKILL_TEMP_DIR"
|
||||||
|
|
||||||
|
|
||||||
def get_skill_root() -> str:
|
def get_skill_root() -> str:
|
||||||
return os.path.dirname(_SCRIPTS_DIR)
|
return os.path.dirname(_SCRIPTS_DIR)
|
||||||
@@ -32,3 +48,98 @@ def get_skill_data_dir() -> str:
|
|||||||
def get_db_path(filename: str | None = None) -> str:
|
def get_db_path(filename: str | None = None) -> str:
|
||||||
name = filename or f"{SKILL_SLUG}.db"
|
name = filename or f"{SKILL_SLUG}.db"
|
||||||
return os.path.join(get_skill_data_dir(), name)
|
return os.path.join(get_skill_data_dir(), name)
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_subdir(value: str) -> str:
|
||||||
|
cleaned = value.strip().strip("/\\")
|
||||||
|
if not cleaned or cleaned.startswith(".."):
|
||||||
|
raise ValueError(f"invalid skill data subdir: {value!r}")
|
||||||
|
return cleaned.replace("/", os.sep).replace("\\", os.sep)
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_data_path(
|
||||||
|
config_key: str | None,
|
||||||
|
default_subdir: str,
|
||||||
|
*,
|
||||||
|
create: bool = True,
|
||||||
|
) -> str:
|
||||||
|
"""解析技能拥有路径:空配置 → 数据目录下 default_subdir;相对 → 相对数据目录;绝对 → 原样。"""
|
||||||
|
from jiangchang_skill_core import config
|
||||||
|
|
||||||
|
base = get_skill_data_dir()
|
||||||
|
raw = (config.get(config_key) or "").strip() if config_key else ""
|
||||||
|
if not raw:
|
||||||
|
path = os.path.join(base, _normalize_subdir(default_subdir))
|
||||||
|
elif os.path.isabs(raw):
|
||||||
|
path = os.path.abspath(os.path.expanduser(raw))
|
||||||
|
else:
|
||||||
|
path = os.path.join(base, _normalize_subdir(raw))
|
||||||
|
|
||||||
|
if create:
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_input_path(raw_path: str, *, create_parent: bool = False) -> str:
|
||||||
|
"""解析 CLI 输入路径:绝对路径原样;相对路径相对 {skill_data_dir}/imports/。"""
|
||||||
|
text = (raw_path or "").strip()
|
||||||
|
if not text:
|
||||||
|
return text
|
||||||
|
expanded = os.path.expanduser(text)
|
||||||
|
if os.path.isabs(expanded):
|
||||||
|
return os.path.abspath(expanded)
|
||||||
|
imports_dir = get_imports_dir(create=create_parent)
|
||||||
|
return os.path.abspath(os.path.join(imports_dir, os.path.normpath(expanded)))
|
||||||
|
|
||||||
|
|
||||||
|
def get_downloads_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_DOWNLOAD_DIR, STANDARD_SUBDIR_DOWNLOADS, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_imports_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_IMPORT_DIR, STANDARD_SUBDIR_IMPORTS, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_exports_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_EXPORT_DIR, STANDARD_SUBDIR_EXPORTS, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_uploads_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_UPLOAD_DIR, STANDARD_SUBDIR_UPLOADS, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_cache_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_CACHE_DIR, STANDARD_SUBDIR_CACHE, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_temp_dir(*, create: bool = True) -> str:
|
||||||
|
return resolve_data_path(CONFIG_KEY_TEMP_DIR, STANDARD_SUBDIR_TEMP, create=create)
|
||||||
|
|
||||||
|
|
||||||
|
def get_rpa_artifacts_dir(batch_id: str, *, create: bool = True) -> str:
|
||||||
|
batch = (batch_id or "").strip() or "default"
|
||||||
|
path = os.path.join(get_skill_data_dir(), STANDARD_SUBDIR_RPA_ARTIFACTS, batch)
|
||||||
|
if create:
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_videos_dir(*, create: bool = True) -> str:
|
||||||
|
path = os.path.join(get_skill_data_dir(), STANDARD_SUBDIR_VIDEOS)
|
||||||
|
if create:
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def list_resolved_data_paths() -> dict[str, str]:
|
||||||
|
"""供 health / config-path 输出已解析的数据子目录(不创建目录)。"""
|
||||||
|
return {
|
||||||
|
"skill_data_dir": get_skill_data_dir(),
|
||||||
|
"downloads_dir": get_downloads_dir(create=False),
|
||||||
|
"imports_dir": get_imports_dir(create=False),
|
||||||
|
"exports_dir": get_exports_dir(create=False),
|
||||||
|
"uploads_dir": get_uploads_dir(create=False),
|
||||||
|
"cache_dir": get_cache_dir(create=False),
|
||||||
|
"temp_dir": get_temp_dir(create=False),
|
||||||
|
"videos_dir": get_videos_dir(create=False),
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def get_skill_root() -> str:
|
|||||||
return _SKILL_ROOT
|
return _SKILL_ROOT
|
||||||
|
|
||||||
|
|
||||||
def platform_kit_version_patch(version: str = "1.0.17"):
|
def platform_kit_version_patch(version: str = "1.2.0"):
|
||||||
"""Mock installed jiangchang-platform-kit version for health/diagnostics tests."""
|
"""Mock installed jiangchang-platform-kit version for health/diagnostics tests."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ POLICY_IDS = (
|
|||||||
"POLICY-LOGGING-003",
|
"POLICY-LOGGING-003",
|
||||||
"POLICY-LOGGING-004",
|
"POLICY-LOGGING-004",
|
||||||
"POLICY-LOGGING-005",
|
"POLICY-LOGGING-005",
|
||||||
|
"POLICY-CONTROL-001",
|
||||||
|
"POLICY-CONTROL-002",
|
||||||
|
"POLICY-CONTROL-003",
|
||||||
|
"POLICY-DATA-PATH-001",
|
||||||
)
|
)
|
||||||
|
|
||||||
STRUCTURE_PATHS = (
|
STRUCTURE_PATHS = (
|
||||||
@@ -619,6 +623,117 @@ class TestPolicyLogging005(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPolicyControl001(unittest.TestCase):
|
||||||
|
def test_no_util_progress_module(self) -> None:
|
||||||
|
skill_root = get_skill_root()
|
||||||
|
path = os.path.join(skill_root, "scripts", "util", "progress.py")
|
||||||
|
self.assertFalse(
|
||||||
|
os.path.isfile(path),
|
||||||
|
msg=_policy_msg(
|
||||||
|
"POLICY-CONTROL-001",
|
||||||
|
"development/LOGGING.md §2.5; development/RPA.md §0.1",
|
||||||
|
"scripts/util/progress.py must not exist",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPolicyControl002(unittest.TestCase):
|
||||||
|
def test_task_service_uses_job_context_and_finish(self) -> None:
|
||||||
|
skill_root = get_skill_root()
|
||||||
|
path = os.path.join(skill_root, "scripts", "service", "task_service.py")
|
||||||
|
text = _read_text(path)
|
||||||
|
rel = _rel(skill_root, path)
|
||||||
|
missing: list[str] = []
|
||||||
|
if "job_context(" not in text:
|
||||||
|
missing.append("job_context(")
|
||||||
|
if "finish(" not in text:
|
||||||
|
missing.append("finish(")
|
||||||
|
self.assertEqual(
|
||||||
|
missing,
|
||||||
|
[],
|
||||||
|
msg=_policy_msg(
|
||||||
|
"POLICY-CONTROL-002",
|
||||||
|
"development/LOGGING.md §2.5、§7",
|
||||||
|
f"{rel} missing: " + ", ".join(missing),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPolicyControl003(unittest.TestCase):
|
||||||
|
def test_service_layer_has_no_bare_asyncio_sleep(self) -> None:
|
||||||
|
skill_root = get_skill_root()
|
||||||
|
offenders: list[str] = []
|
||||||
|
for path in _walk_files(skill_root, "scripts/service", suffix=".py"):
|
||||||
|
rel = _rel(skill_root, path)
|
||||||
|
for lineno, line in enumerate(_read_text(path).splitlines(), 1):
|
||||||
|
stripped = line.strip()
|
||||||
|
if not stripped or stripped.startswith("#"):
|
||||||
|
continue
|
||||||
|
if "asyncio.sleep" in stripped:
|
||||||
|
offenders.append(f"{rel}:{lineno}: {stripped}")
|
||||||
|
self.assertEqual(
|
||||||
|
offenders,
|
||||||
|
[],
|
||||||
|
msg=_policy_msg(
|
||||||
|
"POLICY-CONTROL-003",
|
||||||
|
"development/RPA.md §0.1",
|
||||||
|
"use interruptible_sleep instead:\n" + "\n".join(offenders),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPolicyDataPath001(unittest.TestCase):
|
||||||
|
def test_env_example_has_no_cwd_relative_paths(self) -> None:
|
||||||
|
path = os.path.join(get_skill_root(), ".env.example")
|
||||||
|
offenders: list[str] = []
|
||||||
|
with open(path, encoding="utf-8") as f:
|
||||||
|
for lineno, line in enumerate(f, 1):
|
||||||
|
stripped = line.strip()
|
||||||
|
if not stripped or stripped.startswith("#"):
|
||||||
|
continue
|
||||||
|
active = stripped.split("#", 1)[0].strip()
|
||||||
|
if re.search(r"=\s*\./", active):
|
||||||
|
offenders.append(f".env.example:{lineno}: {active}")
|
||||||
|
self.assertEqual(
|
||||||
|
offenders,
|
||||||
|
[],
|
||||||
|
msg=_policy_msg(
|
||||||
|
"POLICY-DATA-PATH-001",
|
||||||
|
"development/DATA_PATHS.md",
|
||||||
|
"\n".join(offenders) or "CWD-relative ./ paths in .env.example",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_runtime_paths_exposes_resolve_data_path(self) -> None:
|
||||||
|
import util.runtime_paths as rp
|
||||||
|
|
||||||
|
self.assertTrue(callable(getattr(rp, "resolve_data_path", None)))
|
||||||
|
self.assertTrue(callable(getattr(rp, "list_resolved_data_paths", None)))
|
||||||
|
|
||||||
|
def test_business_scripts_do_not_abspath_config_get(self) -> None:
|
||||||
|
skill_root = get_skill_root()
|
||||||
|
pattern = re.compile(r"os\.path\.abspath\s*\(\s*config\.get\b")
|
||||||
|
offenders: list[str] = []
|
||||||
|
for rel in _walk_files(skill_root, "scripts", suffix=".py"):
|
||||||
|
if rel.replace("\\", "/") == "scripts/util/runtime_paths.py":
|
||||||
|
continue
|
||||||
|
text = _read_text(os.path.join(skill_root, rel))
|
||||||
|
for lineno, line in enumerate(text.splitlines(), 1):
|
||||||
|
if line.strip().startswith("#"):
|
||||||
|
continue
|
||||||
|
if pattern.search(line):
|
||||||
|
offenders.append(f"{rel}:{lineno}: {line.strip()}")
|
||||||
|
self.assertEqual(
|
||||||
|
offenders,
|
||||||
|
[],
|
||||||
|
msg=_policy_msg(
|
||||||
|
"POLICY-DATA-PATH-001",
|
||||||
|
"development/DATA_PATHS.md",
|
||||||
|
"\n".join(offenders),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestPolicyDocs001(unittest.TestCase):
|
class TestPolicyDocs001(unittest.TestCase):
|
||||||
def test_policy_matrix_exists_and_lists_policy_ids(self) -> None:
|
def test_policy_matrix_exists_and_lists_policy_ids(self) -> None:
|
||||||
skill_root = get_skill_root()
|
skill_root = get_skill_root()
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class TestDocsStandards(unittest.TestCase):
|
|||||||
self.assertIn("--no-sandbox", text)
|
self.assertIn("--no-sandbox", text)
|
||||||
self.assertIn("--disable-blink-features=AutomationControlled", text)
|
self.assertIn("--disable-blink-features=AutomationControlled", text)
|
||||||
self.assertIn("RpaVideoSession", text)
|
self.assertIn("RpaVideoSession", text)
|
||||||
self.assertIn("1.0.17", text)
|
self.assertIn("1.2.0", text)
|
||||||
|
|
||||||
def test_rpa_md_forbids_rpa_helpers_import(self) -> None:
|
def test_rpa_md_forbids_rpa_helpers_import(self) -> None:
|
||||||
text = self._read("development/RPA.md")
|
text = self._read("development/RPA.md")
|
||||||
|
|||||||
@@ -83,16 +83,16 @@ class TestPlatformImportSource(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_platform_kit_min_version_is_1_0_14(self) -> None:
|
def test_platform_kit_min_version_is_1_2_0(self) -> None:
|
||||||
from jiangchang_skill_core import version_ge
|
from jiangchang_skill_core import version_ge
|
||||||
from util.constants import PLATFORM_KIT_MIN_VERSION
|
from util.constants import PLATFORM_KIT_MIN_VERSION
|
||||||
|
|
||||||
self.assertEqual(PLATFORM_KIT_MIN_VERSION, "1.0.17")
|
self.assertEqual(PLATFORM_KIT_MIN_VERSION, "1.2.0")
|
||||||
|
|
||||||
md_path = os.path.join(get_skill_root(), "SKILL.md")
|
md_path = os.path.join(get_skill_root(), "SKILL.md")
|
||||||
with open(md_path, encoding="utf-8") as f:
|
with open(md_path, encoding="utf-8") as f:
|
||||||
md = f.read()
|
md = f.read()
|
||||||
self.assertEqual(_parse_platform_kit_min_version(md), "1.0.17")
|
self.assertEqual(_parse_platform_kit_min_version(md), "1.2.0")
|
||||||
|
|
||||||
req_path = os.path.join(get_skill_root(), "requirements.txt")
|
req_path = os.path.join(get_skill_root(), "requirements.txt")
|
||||||
with open(req_path, encoding="utf-8") as f:
|
with open(req_path, encoding="utf-8") as f:
|
||||||
|
|||||||
@@ -82,6 +82,68 @@ class TestRuntimePaths(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.normpath(data_dir).startswith(os.path.normpath(tmp)))
|
self.assertTrue(os.path.normpath(data_dir).startswith(os.path.normpath(tmp)))
|
||||||
self.assertIn("_test", data_dir.replace("\\", "/"))
|
self.assertIn("_test", data_dir.replace("\\", "/"))
|
||||||
|
|
||||||
|
def test_resolve_data_path_defaults_under_skill_data_dir(self) -> None:
|
||||||
|
with IsolatedDataRoot() as tmp:
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
import util.runtime_paths as rp
|
||||||
|
|
||||||
|
importlib.reload(rp)
|
||||||
|
path = rp.resolve_data_path(None, "downloads", create=True)
|
||||||
|
norm = os.path.normcase(os.path.normpath(path))
|
||||||
|
norm_tmp = os.path.normcase(os.path.normpath(tmp))
|
||||||
|
self.assertTrue(norm.startswith(norm_tmp))
|
||||||
|
self.assertTrue(norm.endswith(os.path.normcase(os.path.join("downloads"))))
|
||||||
|
|
||||||
|
def test_resolve_data_path_relative_uses_data_dir_not_cwd(self) -> None:
|
||||||
|
with IsolatedDataRoot() as tmp:
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
import util.runtime_paths as rp
|
||||||
|
|
||||||
|
importlib.reload(rp)
|
||||||
|
os.environ["SKILL_DOWNLOAD_DIR"] = "downloads/videos"
|
||||||
|
from jiangchang_skill_core import config
|
||||||
|
|
||||||
|
config.reset_cache()
|
||||||
|
importlib.reload(rp)
|
||||||
|
path = rp.resolve_data_path("SKILL_DOWNLOAD_DIR", "downloads", create=False)
|
||||||
|
norm = os.path.normcase(os.path.normpath(path))
|
||||||
|
self.assertIn(os.path.normcase("downloads"), norm)
|
||||||
|
self.assertIn(os.path.normcase("videos"), norm)
|
||||||
|
self.assertTrue(norm.startswith(os.path.normcase(os.path.normpath(tmp))))
|
||||||
|
os.environ.pop("SKILL_DOWNLOAD_DIR", None)
|
||||||
|
config.reset_cache()
|
||||||
|
|
||||||
|
def test_resolve_input_path_relative_under_imports(self) -> None:
|
||||||
|
with IsolatedDataRoot() as tmp:
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
import util.runtime_paths as rp
|
||||||
|
|
||||||
|
importlib.reload(rp)
|
||||||
|
resolved = rp.resolve_input_path("urls.txt", create_parent=True)
|
||||||
|
norm = os.path.normcase(os.path.normpath(resolved))
|
||||||
|
self.assertIn(os.path.normcase("imports"), norm)
|
||||||
|
self.assertTrue(norm.startswith(os.path.normcase(os.path.normpath(tmp))))
|
||||||
|
|
||||||
|
def test_list_resolved_data_paths_keys(self) -> None:
|
||||||
|
with IsolatedDataRoot():
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
import util.runtime_paths as rp
|
||||||
|
|
||||||
|
importlib.reload(rp)
|
||||||
|
paths = rp.list_resolved_data_paths()
|
||||||
|
for key in (
|
||||||
|
"skill_data_dir",
|
||||||
|
"downloads_dir",
|
||||||
|
"imports_dir",
|
||||||
|
"exports_dir",
|
||||||
|
):
|
||||||
|
self.assertIn(key, paths)
|
||||||
|
self.assertTrue(paths[key])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ FORBIDDEN_PHRASES = (
|
|||||||
|
|
||||||
POSITIVE_MARKERS = (
|
POSITIVE_MARKERS = (
|
||||||
"jiangchang-platform-kit",
|
"jiangchang-platform-kit",
|
||||||
"1.0.17",
|
"1.2.0",
|
||||||
"共享 runtime",
|
"共享 runtime",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user