add skill activity stream and job runtime foundation (v1.1.0)
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 17s
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 17s
Introduce SAS v1 emit/finish/journal API, sibling CLI bridge, RPA video session integration, and tests for the host Job Runner activity timeline. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
67
README.md
67
README.md
@@ -12,7 +12,7 @@ pip install jiangchang-platform-kit --index-url https://git.jc2009.com/api/packa
|
||||
|
||||
## 3. 包含的模块
|
||||
|
||||
- **jiangchang_skill_core**:权益 HTTP 客户端、`enforce_entitlement`、统一文件日志、`JIANGCHANG_*` 数据根与技能根路径解析、共享媒体资源(`media_assets`)等,供 Skill CLI / 服务进程使用。
|
||||
- **jiangchang_skill_core**:权益 HTTP 客户端、`enforce_entitlement`、统一文件日志、`JIANGCHANG_*` 数据根与技能根路径解析、**Skill Activity Stream / Job 运行时**(`emit` / `finish` / Run Journal)、兄弟技能 CLI 桥(`sibling_bridge`)、共享媒体资源(`media_assets`)等,供 Skill CLI / 服务进程使用。
|
||||
- **jiangchang_desktop_sdk**:匠厂桌面应用自动化客户端(基于 CDP + Playwright 同步 API)。**本包不声明 Playwright 依赖**;请在运行环境中自行安装 Playwright,以便 `import playwright` 可用。
|
||||
|
||||
## 4. 快速开始
|
||||
@@ -78,6 +78,71 @@ assert_skill_env_file(ctx, ["API_KEY"])
|
||||
send_prompt_via_composer(page, "第一行\n第二行")
|
||||
```
|
||||
|
||||
## Skill Activity Stream / Job 运行时
|
||||
|
||||
长任务(批量生成、RPA)需要把**逐步进度**推到匠厂宿主 UI,而不能依赖 Agent 轮询或 OpenClaw stdout patch。`jiangchang_skill_core.activity` 提供 **Skill Activity Stream (SAS) v1** 契约:
|
||||
|
||||
| API | 作用 |
|
||||
|-----|------|
|
||||
| `emit(text, ...)` | 写 Run Journal(`activity` / `progress` / `warn` / `debug`) |
|
||||
| `step(text)` | `emit(type='activity')` 别名 |
|
||||
| `finish(status=..., **fields)` | 写终态事件 + **唯一**向 stdout 输出单行 result JSON |
|
||||
| `rpa_step(name)` | 装饰器:进入/成功/失败自动 emit |
|
||||
| `job_context(...)` | 可选包裹 main;异常时自动 `finish(failed)` |
|
||||
|
||||
### Run Journal 路径(宿主 tail 此文件)
|
||||
|
||||
```
|
||||
{JIANGCHANG_DATA_ROOT}/.jiangchang/runs/{job_id}.jsonl
|
||||
```
|
||||
|
||||
- `job_id`:优先 `JIANGCHANG_JOB_ID`,否则进程内 `uuid4().hex`(首次 emit 时生成并缓存)
|
||||
- `JIANGCHANG_RUN_MODE`:`job` | `cli`(默认 `cli`),首行 meta 事件记录
|
||||
- NDJSON,UTF-8,append-only,每行 flush
|
||||
- `debug` 类型仅当 `JIANGCHANG_ACTIVITY_DEBUG=1` 时写入
|
||||
|
||||
### 与 Agent / OpenClaw 的分工
|
||||
|
||||
- **`emit()` / journal**:永不 print 到 stdout,避免 bash tool 结果淹没 Agent context
|
||||
- **`finish()`**:唯一允许向 stdout 写业务结果的 API;单行 compact JSON,`status` + 摘要字段,默认 ≤4096 字符
|
||||
- 技能里手写 `print("OK")`、pretty JSON 应逐步改为 `finish()`;RPA 步骤用 `emit("打开浏览器")` 或 `@rpa_step`
|
||||
|
||||
### GEO batch 示例
|
||||
|
||||
```python
|
||||
from jiangchang_skill_core.activity import emit, finish
|
||||
|
||||
for i, item in enumerate(items, 1):
|
||||
emit(f"生成 {item['title']}", type="progress", current=i, total=len(items), skill="geo-batch")
|
||||
# ... business logic ...
|
||||
|
||||
finish(status="success", skill="geo-batch", generated=len(items))
|
||||
```
|
||||
|
||||
### RPA 步骤示例
|
||||
|
||||
```python
|
||||
from jiangchang_skill_core.activity import emit, rpa_step
|
||||
|
||||
@rpa_step("打开浏览器")
|
||||
def open_browser(page):
|
||||
page.goto("https://example.com")
|
||||
|
||||
emit("手动步骤说明", skill="publish-toutiao", stage="rpa")
|
||||
```
|
||||
|
||||
`RpaVideoSession.add_step()` 在录屏字幕之外默认同步 `emit(..., stage="rpa.video")`;可通过 `emit_activity=False` 关闭。
|
||||
|
||||
### 兄弟技能 CLI 桥
|
||||
|
||||
```python
|
||||
from jiangchang_skill_core import call_sibling_json, get_sibling_main_path
|
||||
|
||||
accounts = call_sibling_json("account-manager", ["list", "all"])
|
||||
```
|
||||
|
||||
同步 `subprocess.run`,`capture_output=True`,自动带上 `subprocess_env_with_trace()`。
|
||||
|
||||
## 共享媒体资源
|
||||
|
||||
`jiangchang_skill_core.media_assets` 提供共享媒体资源解析能力。默认会从:
|
||||
|
||||
Reference in New Issue
Block a user