@zhushanwen/pi-subagent-workflow 0.1.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/agents/context-builder.md +17 -0
- package/agents/general-purpose.md +16 -0
- package/agents/oracle.md +17 -0
- package/agents/planner.md +17 -0
- package/agents/researcher.md +17 -0
- package/agents/reviewer.md +17 -0
- package/agents/scout.md +17 -0
- package/agents/worker.md +16 -0
- package/examples/README.md +43 -0
- package/examples/chain.example.js +92 -0
- package/examples/map-reduce.example.js +99 -0
- package/examples/parallel.example.js +82 -0
- package/examples/scatter-gather.example.js +106 -0
- package/index.ts +1 -0
- package/package.json +66 -0
- package/skills/workflow-script-format/SKILL.md +328 -0
- package/src/execution/__tests__/agent-registry.test.ts +164 -0
- package/src/execution/__tests__/agent-result-mapper.test.ts +128 -0
- package/src/execution/__tests__/alive-store.test.ts +147 -0
- package/src/execution/__tests__/bg-notify-render.test.ts +256 -0
- package/src/execution/__tests__/concurrency-pool.test.ts +217 -0
- package/src/execution/__tests__/config.test.ts +110 -0
- package/src/execution/__tests__/crash-recovery.test.ts +311 -0
- package/src/execution/__tests__/execute-nesting.test.ts +359 -0
- package/src/execution/__tests__/execute-options-mapper.test.ts +138 -0
- package/src/execution/__tests__/execution-record.test.ts +959 -0
- package/src/execution/__tests__/finalized-marker.test.ts +82 -0
- package/src/execution/__tests__/format-schema-instruction.test.ts +135 -0
- package/src/execution/__tests__/format.test.ts +320 -0
- package/src/execution/__tests__/helpers/mock-extension-api.ts +30 -0
- package/src/execution/__tests__/list-component.test.ts +347 -0
- package/src/execution/__tests__/model-resolver.test.ts +356 -0
- package/src/execution/__tests__/output-collector.test.ts +61 -0
- package/src/execution/__tests__/path-encoding.test.ts +75 -0
- package/src/execution/__tests__/pi-invocation.test.ts +73 -0
- package/src/execution/__tests__/record-store.test.ts +545 -0
- package/src/execution/__tests__/run-spawn-edges.test.ts +439 -0
- package/src/execution/__tests__/run-spawn-integration.test.ts +897 -0
- package/src/execution/__tests__/sdk-contract.test.ts +272 -0
- package/src/execution/__tests__/session-context-resolver.test.ts +167 -0
- package/src/execution/__tests__/session-file-gc.test.ts +247 -0
- package/src/execution/__tests__/session-reconstructor.test.ts +359 -0
- package/src/execution/__tests__/session-runner-schema-env.test.ts +314 -0
- package/src/execution/__tests__/session-start-reaper.test.ts +227 -0
- package/src/execution/__tests__/spawn-args.test.ts +244 -0
- package/src/execution/__tests__/spawn-event-adapter.test.ts +167 -0
- package/src/execution/__tests__/subagent-service.test.ts +678 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +389 -0
- package/src/execution/__tests__/temp-prompt.test.ts +53 -0
- package/src/execution/__tests__/timeout-integration.test.ts +381 -0
- package/src/execution/__tests__/tombstone-store.test.ts +73 -0
- package/src/execution/__tests__/tool-action.test.ts +330 -0
- package/src/execution/__tests__/turn-limiter.test.ts +65 -0
- package/src/execution/__tests__/worktree-manager.test.ts +423 -0
- package/src/execution/__tests__/worktree-registry.test.ts +161 -0
- package/src/execution/agent-registry.ts +252 -0
- package/src/execution/agent-result-mapper.ts +84 -0
- package/src/execution/alive-store.ts +92 -0
- package/src/execution/best-effort.ts +30 -0
- package/src/execution/concurrency-pool.ts +84 -0
- package/src/execution/config.ts +73 -0
- package/src/execution/execute-options-mapper.ts +86 -0
- package/src/execution/execution-record.ts +778 -0
- package/src/execution/finalized-marker.ts +51 -0
- package/src/execution/model-config-service.ts +225 -0
- package/src/execution/model-resolver.ts +247 -0
- package/src/execution/notifier.ts +168 -0
- package/src/execution/output-collector.ts +88 -0
- package/src/execution/path-encoding.ts +34 -0
- package/src/execution/pi-invocation.ts +70 -0
- package/src/execution/record-store.ts +350 -0
- package/src/execution/session-context-resolver.ts +64 -0
- package/src/execution/session-file-gc.ts +98 -0
- package/src/execution/session-reconstructor.ts +450 -0
- package/src/execution/session-runner.ts +725 -0
- package/src/execution/spawn-event-adapter.ts +150 -0
- package/src/execution/subagent-service.ts +973 -0
- package/src/execution/subprocess-agent-runner.ts +108 -0
- package/src/execution/temp-prompt.ts +57 -0
- package/src/execution/tombstone-store.ts +72 -0
- package/src/execution/turn-limiter.ts +88 -0
- package/src/execution/types.ts +634 -0
- package/src/execution/worktree-manager.ts +285 -0
- package/src/execution/worktree-registry.ts +144 -0
- package/src/index.ts +454 -0
- package/src/interface/bg-notify-render.ts +286 -0
- package/src/interface/commands.ts +157 -0
- package/src/interface/format.ts +501 -0
- package/src/interface/gui-adapter.ts +136 -0
- package/src/interface/helpers.ts +110 -0
- package/src/interface/list-component.ts +643 -0
- package/src/interface/list-shared.ts +84 -0
- package/src/interface/list-view.ts +373 -0
- package/src/interface/reentry-guard.ts +30 -0
- package/src/interface/subagent-actions.ts +294 -0
- package/src/interface/subagent-tool.ts +294 -0
- package/src/interface/subagents.ts +30 -0
- package/src/interface/tool-render.ts +333 -0
- package/src/interface/tool-workflow-script.ts +351 -0
- package/src/interface/tool-workflow.ts +485 -0
- package/src/interface/views/WorkflowsView.ts +944 -0
- package/src/interface/views/detail-content.ts +298 -0
- package/src/interface/views/format.ts +320 -0
- package/src/orchestration/__tests__/concurrency-gate.test.ts +125 -0
- package/src/orchestration/__tests__/config-loader.test.ts +381 -0
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +332 -0
- package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +166 -0
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +248 -0
- package/src/orchestration/__tests__/lifecycle.test.ts +385 -0
- package/src/orchestration/__tests__/script-lint.test.ts +347 -0
- package/src/orchestration/__tests__/worker-script-builder.test.ts +42 -0
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +319 -0
- package/src/orchestration/agent-opts-resolver.ts +128 -0
- package/src/orchestration/concurrency-gate.ts +69 -0
- package/src/orchestration/config-loader.ts +313 -0
- package/src/orchestration/error-recovery.ts +578 -0
- package/src/orchestration/execute-agent-call.ts +174 -0
- package/src/orchestration/jsonl-run-store.ts +292 -0
- package/src/orchestration/launcher.ts +368 -0
- package/src/orchestration/lifecycle.ts +373 -0
- package/src/orchestration/models/__tests__/budget.test.ts +367 -0
- package/src/orchestration/models/agent-call.ts +76 -0
- package/src/orchestration/models/budget.ts +148 -0
- package/src/orchestration/models/ports.ts +165 -0
- package/src/orchestration/models/run-runtime.ts +91 -0
- package/src/orchestration/models/run-spec.ts +54 -0
- package/src/orchestration/models/run-state.ts +44 -0
- package/src/orchestration/models/trace.ts +102 -0
- package/src/orchestration/models/types.ts +242 -0
- package/src/orchestration/models/workflow-run.ts +275 -0
- package/src/orchestration/models/workflow-script-registry.ts +32 -0
- package/src/orchestration/models/workflow-script.ts +90 -0
- package/src/orchestration/node-ops.ts +192 -0
- package/src/orchestration/script-lint.ts +387 -0
- package/src/orchestration/skill-discovery.ts +60 -0
- package/src/orchestration/worker-handle.ts +115 -0
- package/src/orchestration/worker-host.ts +93 -0
- package/src/orchestration/worker-script-builder.ts +281 -0
- package/src/orchestration/workflow-files.ts +85 -0
- package/src/orchestration/workflow-script-registry-impl.ts +128 -0
- package/src/shared/__tests__/resource-discovery.test.ts +226 -0
- package/src/shared/agent-event.ts +13 -0
- package/src/shared/resource-discovery.ts +535 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Extension — Interface helpers
|
|
3
|
+
*
|
|
4
|
+
* notifyDone(pi, runId, run, notified) — run 完成时发 completion notification。
|
|
5
|
+
*
|
|
6
|
+
* 层归属:Interface(依赖 Pi SDK + Engine WorkflowRun 模型)。
|
|
7
|
+
*
|
|
8
|
+
* 参考:domain-models.md §D-12。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
12
|
+
|
|
13
|
+
import type { WorkflowRun } from "../orchestration/models/workflow-run.ts";
|
|
14
|
+
import {
|
|
15
|
+
guiComponent,
|
|
16
|
+
type GuiContext,
|
|
17
|
+
guiResult,
|
|
18
|
+
isGuiCapable,
|
|
19
|
+
} from "./gui-adapter.ts";
|
|
20
|
+
|
|
21
|
+
// ── 常量 ─────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
const JSON_INDENT = 2;
|
|
24
|
+
const MAX_RESULT_LENGTH = 8000;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* workflow 到达 done 终态时发送完成通知。
|
|
28
|
+
*
|
|
29
|
+
* 通过 pi.sendMessage 注入结果消息(含 __gui__ 结构化渲染数据),
|
|
30
|
+
* triggerTurn:true 唤醒 parent agent 处理结果。
|
|
31
|
+
*
|
|
32
|
+
* **去重**:notifiedRunIds Set 由调用方(factory/extension instance)持有,
|
|
33
|
+
* 同一 runId 只通知一次(跨 session_shutdown 等边界防重复)。
|
|
34
|
+
*
|
|
35
|
+
* @param pi ExtensionAPI(调 sendMessage)
|
|
36
|
+
* @param runId run 标识
|
|
37
|
+
* @param run WorkflowRun 聚合根(读 spec.scriptName + state.status + trace + scriptResult)
|
|
38
|
+
* @param notifiedRunIds 去重 Set(调用方持有,scope 到 factory 实例)
|
|
39
|
+
*/
|
|
40
|
+
export function notifyDone(
|
|
41
|
+
pi: ExtensionAPI,
|
|
42
|
+
runId: string,
|
|
43
|
+
run: WorkflowRun,
|
|
44
|
+
notifiedRunIds: Set<string>,
|
|
45
|
+
ctx?: GuiContext,
|
|
46
|
+
): void {
|
|
47
|
+
if (notifiedRunIds.has(runId)) return;
|
|
48
|
+
notifiedRunIds.add(runId);
|
|
49
|
+
|
|
50
|
+
const traceNodes = run.state.trace.toArray();
|
|
51
|
+
const name = run.spec.scriptName;
|
|
52
|
+
const status = `${run.state.status}${run.state.reason ? ` (${run.state.reason})` : ""}`;
|
|
53
|
+
|
|
54
|
+
// 构建消息内容
|
|
55
|
+
const parts: string[] = [];
|
|
56
|
+
parts.push(`Workflow '${name}' done: ${status}`);
|
|
57
|
+
|
|
58
|
+
if (run.state.scriptResult !== undefined && run.state.scriptResult !== null) {
|
|
59
|
+
const serialized = JSON.stringify(run.state.scriptResult, null, JSON_INDENT);
|
|
60
|
+
const truncated =
|
|
61
|
+
serialized.length > MAX_RESULT_LENGTH
|
|
62
|
+
? serialized.slice(0, MAX_RESULT_LENGTH) + "\n... (truncated)"
|
|
63
|
+
: serialized;
|
|
64
|
+
parts.push("");
|
|
65
|
+
parts.push("--- Script Result ---");
|
|
66
|
+
parts.push(truncated);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
parts.push("");
|
|
70
|
+
parts.push("--- Agent Trace ---");
|
|
71
|
+
for (const node of traceNodes) {
|
|
72
|
+
parts.push(`[${node.stepIndex}] ${node.agent}: ${node.status}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const content = parts.join("\n");
|
|
76
|
+
|
|
77
|
+
// deliverAs:"steer" + triggerTurn:true —— workflow 完成作为 steering 消息注入
|
|
78
|
+
// 并立即唤醒 parent agent 处理结果(与 subagent 的 followUp+triggerTurn 对称)
|
|
79
|
+
const details: Record<string, unknown> = {
|
|
80
|
+
runId,
|
|
81
|
+
name,
|
|
82
|
+
status: run.state.status,
|
|
83
|
+
reason: run.state.reason,
|
|
84
|
+
traceLength: traceNodes.length,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// GUI 协议:RPC 模式下附加结构化渲染数据
|
|
88
|
+
if (ctx && isGuiCapable(ctx)) {
|
|
89
|
+
details.__gui__ = guiResult(
|
|
90
|
+
guiComponent("workflow-runs", {
|
|
91
|
+
runs: [{
|
|
92
|
+
runId,
|
|
93
|
+
name,
|
|
94
|
+
status: run.state.status,
|
|
95
|
+
reason: run.state.reason,
|
|
96
|
+
}],
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pi.sendMessage(
|
|
102
|
+
{
|
|
103
|
+
customType: "workflow-result",
|
|
104
|
+
content,
|
|
105
|
+
display: true,
|
|
106
|
+
details,
|
|
107
|
+
},
|
|
108
|
+
{ triggerTurn: true, deliverAs: "steer" },
|
|
109
|
+
);
|
|
110
|
+
}
|