@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,86 @@
|
|
|
1
|
+
// src/execution/execute-options-mapper.ts
|
|
2
|
+
//
|
|
3
|
+
// D-A2: AgentCallOpts → ExecuteOptions 映射(adapter 职责)
|
|
4
|
+
// D-A9: per-call timeoutMs 合并进 AbortSignal
|
|
5
|
+
//
|
|
6
|
+
// 接线层级:[模块内直调] —— SAR.run 内调。
|
|
7
|
+
|
|
8
|
+
import type { AgentCallOpts } from "../orchestration/models/types.ts";
|
|
9
|
+
import type { ModelInfo } from "./model-resolver.ts";
|
|
10
|
+
import type { ExecuteOptions } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* D-A2: AgentCallOpts → ExecuteOptions 映射。
|
|
14
|
+
*
|
|
15
|
+
* adapter 职责——SubagentService 的 ExecuteOptions 是稳定内部契约,不为 workflow 的
|
|
16
|
+
* AgentCallOpts 做适配(映射归调用方 SAR)。
|
|
17
|
+
*
|
|
18
|
+
* 映射规则:
|
|
19
|
+
* prompt → task
|
|
20
|
+
* agent → agent
|
|
21
|
+
* schema → schema
|
|
22
|
+
* schemaEnv → schemaEnv(D-A6 bridge)
|
|
23
|
+
* cwd → cwd
|
|
24
|
+
* model → model ?? ctxModel(D-008 填底)
|
|
25
|
+
* skillPath → skillPath
|
|
26
|
+
*
|
|
27
|
+
* 忽略字段(委托后由 executeAndAwait 内部机制替代):
|
|
28
|
+
* systemPromptFiles —— resolveIdentity 从 agentConfig.systemPrompt 读
|
|
29
|
+
* timeoutMs —— mergeTimeoutSignal 单独处理
|
|
30
|
+
* scene/description —— subagents 不消费
|
|
31
|
+
*/
|
|
32
|
+
export function mapToExecuteOptions(
|
|
33
|
+
opts: AgentCallOpts,
|
|
34
|
+
ctxModel?: ModelInfo,
|
|
35
|
+
): ExecuteOptions {
|
|
36
|
+
return {
|
|
37
|
+
task: opts.prompt,
|
|
38
|
+
agent: opts.agent,
|
|
39
|
+
schema: opts.schema,
|
|
40
|
+
schemaEnv: opts.schemaEnv,
|
|
41
|
+
cwd: opts.cwd,
|
|
42
|
+
model: opts.model ?? ctxModel?.id,
|
|
43
|
+
skillPath: opts.skillPath,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* D-A9: per-call timeoutMs 合并进 AbortSignal。
|
|
49
|
+
*
|
|
50
|
+
* 墙钟 timeoutMs(per-call)+ 外部 signal(run 级 abort)都生效。
|
|
51
|
+
* 缺此合并则 agent({timeoutMs:5000}) 静默无效(BC-9)。
|
|
52
|
+
*
|
|
53
|
+
* @param signal 外部 signal(workflow run 级 controller.signal)
|
|
54
|
+
* @param timeoutMs per-call 墙钟超时;undefined/<=0 → 不设超时,原样返回 signal
|
|
55
|
+
* @returns 合并后的 signal(timeoutMs 或外部 signal 任一 abort 都触发)
|
|
56
|
+
*/
|
|
57
|
+
export function mergeTimeoutSignal(
|
|
58
|
+
signal: AbortSignal,
|
|
59
|
+
timeoutMs?: number,
|
|
60
|
+
): AbortSignal {
|
|
61
|
+
if (!timeoutMs || timeoutMs <= 0) {
|
|
62
|
+
return signal;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
67
|
+
timer.unref();
|
|
68
|
+
|
|
69
|
+
const onExternalAbort = (): void => controller.abort();
|
|
70
|
+
if (signal.aborted) {
|
|
71
|
+
controller.abort();
|
|
72
|
+
} else {
|
|
73
|
+
signal.addEventListener("abort", onExternalAbort, { once: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
controller.signal.addEventListener(
|
|
77
|
+
"abort",
|
|
78
|
+
() => {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
if (!signal.aborted) signal.removeEventListener("abort", onExternalAbort);
|
|
81
|
+
},
|
|
82
|
+
{ once: true },
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return controller.signal;
|
|
86
|
+
}
|