@maplezzk/pi-dynamic-workflows 1.1.2 → 1.2.0

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.
package/SKILL.md ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: configure-pi-dynamic-workflows
3
+ description: "配置与排查 pi-dynamic-workflows 的执行后端和异步模式。Use when configuring workflow backend, async mode, or subagent integration."
4
+ ---
5
+
6
+ # 配置 pi-dynamic-workflows
7
+
8
+ ## 诊断
9
+
10
+ 读取实际 Pi agent 目录下的 `extensions/pi-dynamic-workflows/config.json`,并检查 `PI_WORKFLOW_BACKEND`、`PI_WORKFLOW_ASYNC`。优先级是 JSON 配置 > 环境变量 > 默认值。
11
+
12
+ ## 修改
13
+
14
+ 优先在 Pi 中运行 `/config:workflow`:
15
+
16
+ - `backend: "workflow"` 使用内置进程内 agent;
17
+ - `backend: "subagent"` 要求 `pi-interactive-subagents` 已安装并加载;
18
+ - `async: true` 让 workflow 后台执行并显示实时状态。
19
+
20
+ `/workflow-config` 和 `/pi-workflow-config` 仅为兼容别名。不要在没有 subagent 扩展时选择 `subagent`,也不要用环境变量覆盖后误以为 JSON 未生效。
21
+
22
+ ## 验证
23
+
24
+ 运行一个最小 workflow,至少包含静态 `meta.phases`、一次 `phase()` 和一次带 JSON Schema 的 `agent()`。若使用 `subagent` 后端,确认 `globalThis.__pi_subagents` 能力已注入;缺失时明确报告配置依赖错误,不静默切回内置后端。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maplezzk/pi-dynamic-workflows",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Claude-Code-style dynamic workflow orchestration for Pi. Fork of michaelliv/pi-dynamic-workflows.",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -13,7 +13,8 @@
13
13
  "locales",
14
14
  "types",
15
15
  "README.md",
16
- "README.zh-CN.md"
16
+ "README.zh-CN.md",
17
+ "SKILL.md"
17
18
  ],
18
19
  "scripts": {
19
20
  "test": "tsx --test tests/*.test.ts",
@@ -25,6 +26,9 @@
25
26
  "extensions": [
26
27
  "./index.ts",
27
28
  "../pi-extensions-i18n/index.ts"
29
+ ],
30
+ "skills": [
31
+ "./SKILL.md"
28
32
  ]
29
33
  },
30
34
  "engines": {
@@ -56,7 +60,7 @@
56
60
  ],
57
61
  "dependencies": {
58
62
  "acorn": "^8.16.0",
59
- "pi-extensions-i18n": "^0.3.1"
63
+ "pi-extensions-i18n": "^0.4.0"
60
64
  },
61
65
  "peerDependencies": {
62
66
  "@earendil-works/pi-ai": ">=0.80.0 <0.81.0",
package/src/workflow.ts CHANGED
@@ -203,7 +203,7 @@ export async function runWorkflow<T = unknown>(
203
203
  };
204
204
 
205
205
  const context = vm.createContext({
206
- agent,
206
+ __agent: agent,
207
207
  parallel,
208
208
  pipeline,
209
209
  log,
@@ -230,7 +230,21 @@ export async function runWorkflow<T = unknown>(
230
230
  Promise,
231
231
  });
232
232
 
233
- const wrapped = `(async () => {\n${body}\n})()`;
233
+ // A host Promise receives a context-local wrapper when it crosses into vm.
234
+ // Track that wrapper in the vm realm itself so a fire-and-forget agent() that
235
+ // later rejects (notably during cancellation) cannot become an unhandled
236
+ // rejection and terminate Pi. Returning the original promise preserves normal
237
+ // await/rejection semantics for workflow scripts.
238
+ const wrapped = `(async (__workflowAgent) => {
239
+ const trackedAgent = (...args) => {
240
+ const promise = __workflowAgent(...args)
241
+ void promise.catch(() => {})
242
+ return promise
243
+ }
244
+ return await (async (agent) => {
245
+ ${body}
246
+ })(trackedAgent)
247
+ })(__agent)`;
234
248
  const result = await new vm.Script(wrapped, { filename: `${meta.name || "workflow"}.js` }).runInContext(context);
235
249
  await Promise.allSettled([...pendingAgentRuns]);
236
250
  assertStructuredCloneable(result, "workflow result");