@zhushanwen/pi-subagent-workflow 7.3.4 → 8.0.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/README.md +39 -12
- package/agents/analyst.md +61 -0
- package/agents/coder.md +70 -0
- package/agents/debugger.md +67 -0
- package/agents/doc-reviewer.md +3 -3
- package/agents/explorer.md +50 -18
- package/agents/general-purpose.md +19 -8
- package/agents/orchestrator.md +37 -32
- package/agents/planner.md +45 -11
- package/agents/researcher.md +53 -11
- package/agents/reviewer.md +74 -0
- package/package.json +1 -1
- package/skills/workflow-script-format/SKILL.md +1 -1
- package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +1 -0
- package/src/execution/__tests__/agent-registry.test.ts +13 -11
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +10 -4
- package/src/execution/__tests__/before-agent-start-injection.test.ts +132 -0
- package/src/execution/__tests__/bg-notify-render.test.ts +15 -15
- package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +365 -0
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +190 -0
- package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +215 -0
- package/src/execution/__tests__/conversation-wiring.test.ts +198 -0
- package/src/execution/__tests__/crash-recovery.test.ts +8 -2
- package/src/execution/__tests__/delivery-methods.test.ts +385 -0
- package/src/execution/__tests__/epipe-fallback.test.ts +241 -0
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +49 -2
- package/src/execution/__tests__/execute-nesting.test.ts +20 -72
- package/src/execution/__tests__/execution-record.test.ts +199 -0
- package/src/execution/__tests__/finalize-record.test.ts +170 -14
- package/src/execution/__tests__/format.test.ts +131 -7
- package/src/execution/__tests__/gc-timer.test.ts +184 -0
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +254 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +25 -7
- package/src/execution/__tests__/index-session-start-identity.test.ts +371 -0
- package/src/execution/__tests__/index-session-start.test.ts +257 -5
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +211 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +337 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +116 -0
- package/src/execution/__tests__/list-component.test.ts +59 -5
- package/src/execution/__tests__/list-fields.test.ts +109 -0
- package/src/execution/__tests__/model-resolver.test.ts +38 -1
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +287 -0
- package/src/execution/__tests__/nested-visibility.test.ts +325 -0
- package/src/execution/__tests__/notifier-flush.test.ts +209 -7
- package/src/execution/__tests__/one-shot-upgrade.test.ts +205 -0
- package/src/execution/__tests__/parent-child-matrix.test.ts +336 -0
- package/src/execution/__tests__/record-store.test.ts +158 -52
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +11 -12
- package/src/execution/__tests__/recursive-visibility-env.test.ts +18 -20
- package/src/execution/__tests__/resource-policy.test.ts +109 -0
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +267 -0
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +253 -0
- package/src/execution/__tests__/run-spawn-edges.test.ts +18 -25
- package/src/execution/__tests__/run-spawn-integration.test.ts +29 -25
- package/src/execution/__tests__/run-spawn-resume.test.ts +322 -0
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +14 -11
- package/src/execution/__tests__/session-pending.test.ts +61 -2
- package/src/execution/__tests__/session-reconstructor.test.ts +4 -4
- package/src/execution/__tests__/session-runner-epipe.test.ts +178 -0
- package/src/execution/__tests__/session-runner-schema-env.test.ts +15 -21
- package/src/execution/__tests__/session-start-reaper.test.ts +10 -8
- package/src/execution/__tests__/spawn-args.test.ts +127 -49
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +1 -0
- package/src/execution/__tests__/spawned-children.test.ts +92 -0
- package/src/execution/__tests__/status-refactor.test.ts +345 -0
- package/src/execution/__tests__/stdin-writer.test.ts +97 -0
- package/src/execution/__tests__/subagent-service-message-close.test.ts +598 -0
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +180 -0
- package/src/execution/__tests__/subagent-service.test.ts +49 -11
- package/src/execution/__tests__/timeout-integration.test.ts +27 -13
- package/src/execution/__tests__/tool-action.test.ts +12 -10
- package/src/execution/__tests__/truncline-snapshot.test.ts +81 -0
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +194 -0
- package/src/execution/__tests__/worktree-manager.test.ts +292 -89
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +13 -12
- package/src/execution/argv-mirror.ts +21 -2
- package/src/execution/execution-record.ts +126 -9
- package/src/execution/finalize-record.ts +90 -13
- package/src/execution/host-mode.ts +1 -1
- package/src/execution/lifecycle-manager.ts +484 -0
- package/src/execution/lifecycle-predicates.ts +65 -0
- package/src/execution/manifest-store.ts +61 -16
- package/src/execution/model-resolver.ts +26 -5
- package/src/execution/notifier.ts +69 -12
- package/src/execution/pi-invocation.ts +21 -1
- package/src/execution/record-store.ts +554 -107
- package/src/execution/session-pending.ts +116 -45
- package/src/execution/session-reconstructor.ts +224 -7
- package/src/execution/session-runner.ts +290 -75
- package/src/execution/sessions-index.ts +304 -0
- package/src/execution/stdin-writer.ts +93 -7
- package/src/execution/stream-sink.ts +20 -3
- package/src/execution/subagent-service.ts +867 -138
- package/src/execution/turn-limiter.ts +14 -0
- package/src/execution/types.ts +204 -22
- package/src/execution/worktree-manager.ts +128 -49
- package/src/execution/worktree-registry.ts +13 -2
- package/src/index.ts +277 -19
- package/src/injectors/subagent-list-injector.ts +26 -8
- package/src/injectors/workflow-list-injector.ts +25 -8
- package/src/interface/__tests__/subagent-tool-prompt.test.ts +18 -5
- package/src/interface/__tests__/tool-render.test.ts +15 -13
- package/src/interface/bg-notify-render.ts +32 -8
- package/src/interface/command-actions.ts +26 -7
- package/src/interface/commands.ts +21 -22
- package/src/interface/format.ts +44 -17
- package/src/interface/gui-mappers.ts +6 -8
- package/src/interface/helpers.ts +170 -10
- package/src/interface/list-component.ts +53 -14
- package/src/interface/subagent-actions.ts +235 -17
- package/src/interface/subagent-tool.ts +82 -17
- package/src/interface/subagents.ts +2 -1
- package/src/interface/tool-render.ts +11 -24
- package/src/interface/tool-workflow.ts +20 -35
- package/src/interface/views/WorkflowsView.ts +89 -32
- package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +264 -0
- package/src/interface/views/__tests__/detail-content-session-file.test.ts +1 -1
- package/src/interface/views/format.ts +3 -3
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +325 -0
- package/src/orchestration/__tests__/args-validator.test.ts +1 -1
- package/src/orchestration/__tests__/config-loader.test.ts +38 -0
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +394 -4
- package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +4 -4
- package/src/orchestration/__tests__/execute-agent-call.test.ts +95 -0
- package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +657 -18
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -2
- package/src/orchestration/__tests__/lifecycle.test.ts +332 -149
- package/src/orchestration/__tests__/skill-discovery.test.ts +157 -0
- package/src/orchestration/__tests__/test-mocks.ts +191 -0
- package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +98 -0
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -2
- package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +110 -0
- package/src/orchestration/__tests__/workflows-e2e.test.ts +1 -1
- package/src/orchestration/agent-opts-resolver.ts +4 -1
- package/src/orchestration/args-validator.ts +2 -2
- package/src/orchestration/config-loader.ts +30 -1
- package/src/orchestration/error-recovery.ts +133 -29
- package/src/orchestration/execute-agent-call.ts +31 -7
- package/src/orchestration/jsonl-run-store.ts +287 -40
- package/src/orchestration/launcher.ts +7 -1
- package/src/orchestration/lifecycle.ts +135 -132
- package/src/orchestration/models/__tests__/trace.test.ts +408 -0
- package/src/orchestration/models/budget.ts +1 -1
- package/src/orchestration/models/run-runtime.ts +15 -17
- package/src/orchestration/models/run-spec.ts +2 -2
- package/src/orchestration/models/run-state.ts +3 -3
- package/src/orchestration/models/trace.ts +95 -15
- package/src/orchestration/models/types.ts +8 -9
- package/src/orchestration/models/workflow-run.ts +50 -71
- package/src/orchestration/models/workflow-script.ts +32 -1
- package/src/orchestration/skill-discovery.ts +30 -0
- package/src/orchestration/worker-handle.ts +1 -1
- package/src/orchestration/worker-host.ts +1 -1
- package/src/orchestration/worker-script-builder.ts +29 -10
- package/src/shared/__tests__/agent-ref.test.ts +34 -0
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +280 -0
- package/src/shared/__tests__/resource-discovery.test.ts +55 -0
- package/src/shared/__tests__/schema-jsonify.test.ts +81 -0
- package/src/shared/agent-ref.ts +16 -0
- package/src/shared/resource-discovery.ts +147 -58
- package/src/shared/schema-jsonify.ts +53 -0
- package/workflows/README.md +4 -4
- package/agents/code-reviewer.md +0 -47
- package/agents/context-builder.md +0 -21
- package/agents/oracle.md +0 -34
- package/agents/worker.md +0 -20
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// src/execution/__tests__/turn-limiter-semantics.test.ts
|
|
2
|
+
//
|
|
3
|
+
// SP-9: turn-limiter chatMode 语义——chatMode 下 maxTurns 每轮 reset(不跨轮累计)。
|
|
4
|
+
// 设计 D9 决策:续聊本质是无限轮,累计上限违背 G1。
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
|
|
8
|
+
import { createTurnLimiter } from "../turn-limiter.ts";
|
|
9
|
+
|
|
10
|
+
describe("SP-9: turn-limiter chatMode semantics (maxTurns reset per round)", () => {
|
|
11
|
+
describe("TC-1: chatMode 多轮后 maxTurns 每轮 reset(不累计)", () => {
|
|
12
|
+
it("reset 后 maxTurns 不累计——第二轮从 0 开始,不触发 steer/abort", () => {
|
|
13
|
+
const steer = vi.fn();
|
|
14
|
+
const abort = vi.fn();
|
|
15
|
+
const limiter = createTurnLimiter({ maxTurns: 3, graceTurns: 2, steer, abort });
|
|
16
|
+
|
|
17
|
+
// 第一轮:3 turns → steer(达到 maxTurns=3)
|
|
18
|
+
limiter.onTurnEnd(1);
|
|
19
|
+
limiter.onTurnEnd(2);
|
|
20
|
+
limiter.onTurnEnd(3);
|
|
21
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
22
|
+
expect(abort).not.toHaveBeenCalled();
|
|
23
|
+
|
|
24
|
+
// agent_settled → reset(模拟 chatMode 每轮 reset)
|
|
25
|
+
limiter.reset();
|
|
26
|
+
|
|
27
|
+
// 第二轮从 turnCount=0 开始(record.turnCount 由 session-runner 归零):
|
|
28
|
+
// 2 turns 不触发 steer(距离 maxTurns=3 还差 1)
|
|
29
|
+
limiter.onTurnEnd(1);
|
|
30
|
+
limiter.onTurnEnd(2);
|
|
31
|
+
// steer 仍然是 1 次(第一轮那次),第二轮未触发
|
|
32
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
33
|
+
expect(abort).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("reset 后第二轮同样达到 maxTurns 时仍触发 steer", () => {
|
|
37
|
+
const steer = vi.fn();
|
|
38
|
+
const abort = vi.fn();
|
|
39
|
+
const limiter = createTurnLimiter({ maxTurns: 2, graceTurns: 1, steer, abort });
|
|
40
|
+
|
|
41
|
+
// 第一轮:steer + grace + abort
|
|
42
|
+
limiter.onTurnEnd(1);
|
|
43
|
+
limiter.onTurnEnd(2); // steer
|
|
44
|
+
limiter.onTurnEnd(3); // abort
|
|
45
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
46
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
47
|
+
|
|
48
|
+
// reset(chatMode 新轮)
|
|
49
|
+
limiter.reset();
|
|
50
|
+
expect(limiter.didSteer).toBe(false);
|
|
51
|
+
expect(limiter.didAbort).toBe(false);
|
|
52
|
+
|
|
53
|
+
// 第二轮:同样走完 steer + grace 路径
|
|
54
|
+
limiter.onTurnEnd(1);
|
|
55
|
+
limiter.onTurnEnd(2); // steer again
|
|
56
|
+
expect(steer).toHaveBeenCalledTimes(2);
|
|
57
|
+
expect(abort).toHaveBeenCalledTimes(1); // 还没到 abort
|
|
58
|
+
|
|
59
|
+
limiter.onTurnEnd(3); // abort again
|
|
60
|
+
expect(abort).toHaveBeenCalledTimes(2);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("多轮连续 reset 后 limiter 始终可用", () => {
|
|
64
|
+
const steer = vi.fn();
|
|
65
|
+
const abort = vi.fn();
|
|
66
|
+
const limiter = createTurnLimiter({ maxTurns: 2, graceTurns: 0, steer, abort });
|
|
67
|
+
|
|
68
|
+
for (let round = 1; round <= 5; round++) {
|
|
69
|
+
limiter.onTurnEnd(1);
|
|
70
|
+
limiter.onTurnEnd(2); // steer + abort (graceTurns=0)
|
|
71
|
+
expect(steer).toHaveBeenCalledTimes(round);
|
|
72
|
+
expect(abort).toHaveBeenCalledTimes(round);
|
|
73
|
+
limiter.reset();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("TC-2: graceTurns 每轮 reset", () => {
|
|
79
|
+
it("reset 后 graceTurns 从 0 重新计数", () => {
|
|
80
|
+
const steer = vi.fn();
|
|
81
|
+
const abort = vi.fn();
|
|
82
|
+
const limiter = createTurnLimiter({ maxTurns: 2, graceTurns: 3, steer, abort });
|
|
83
|
+
|
|
84
|
+
// 第一轮:steer at turn 2,用掉 1 个 grace turn
|
|
85
|
+
limiter.onTurnEnd(1);
|
|
86
|
+
limiter.onTurnEnd(2); // steer
|
|
87
|
+
limiter.onTurnEnd(3); // grace turn 1
|
|
88
|
+
expect(abort).not.toHaveBeenCalled();
|
|
89
|
+
|
|
90
|
+
// reset(模拟 chatMode agent_settled)
|
|
91
|
+
limiter.reset();
|
|
92
|
+
|
|
93
|
+
// 第二轮:从 turn 1 开始,graceTurns 重新从 0 计数
|
|
94
|
+
limiter.onTurnEnd(1);
|
|
95
|
+
limiter.onTurnEnd(2); // steer again
|
|
96
|
+
limiter.onTurnEnd(3); // grace turn 1(重计)
|
|
97
|
+
limiter.onTurnEnd(4); // grace turn 2
|
|
98
|
+
limiter.onTurnEnd(5); // grace turn 3 → abort
|
|
99
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("reset 前未 steer 时 reset 后仍正常工作", () => {
|
|
103
|
+
const steer = vi.fn();
|
|
104
|
+
const abort = vi.fn();
|
|
105
|
+
const limiter = createTurnLimiter({ maxTurns: 5, graceTurns: 2, steer, abort });
|
|
106
|
+
|
|
107
|
+
// 第一轮:只走了 2 turns(未达 maxTurns)
|
|
108
|
+
limiter.onTurnEnd(1);
|
|
109
|
+
limiter.onTurnEnd(2);
|
|
110
|
+
expect(steer).not.toHaveBeenCalled();
|
|
111
|
+
|
|
112
|
+
limiter.reset();
|
|
113
|
+
|
|
114
|
+
// 第二轮:从 turn 1 开始,到 maxTurns=5 触发 steer
|
|
115
|
+
limiter.onTurnEnd(1);
|
|
116
|
+
limiter.onTurnEnd(2);
|
|
117
|
+
limiter.onTurnEnd(3);
|
|
118
|
+
limiter.onTurnEnd(4);
|
|
119
|
+
limiter.onTurnEnd(5); // steer
|
|
120
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
121
|
+
limiter.onTurnEnd(6);
|
|
122
|
+
limiter.onTurnEnd(7); // abort (5+2)
|
|
123
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("TC-3: 非 chatMode 行为不变(全程累计)", () => {
|
|
128
|
+
it("不调用 reset 时 turn-limiter 行为与原来完全一致", () => {
|
|
129
|
+
const steer = vi.fn();
|
|
130
|
+
const abort = vi.fn();
|
|
131
|
+
const limiter = createTurnLimiter({ maxTurns: 3, graceTurns: 2, steer, abort });
|
|
132
|
+
|
|
133
|
+
// 全程累计(非 chatMode,不 reset):3→steer,5→abort
|
|
134
|
+
limiter.onTurnEnd(1);
|
|
135
|
+
limiter.onTurnEnd(2);
|
|
136
|
+
limiter.onTurnEnd(3); // steer
|
|
137
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
138
|
+
limiter.onTurnEnd(4); // grace 1
|
|
139
|
+
limiter.onTurnEnd(5); // grace 2 → abort
|
|
140
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
141
|
+
expect(limiter.didSteer).toBe(true);
|
|
142
|
+
expect(limiter.didAbort).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("maxTurns=0(禁用)不因 reset 而误启用", () => {
|
|
146
|
+
const steer = vi.fn();
|
|
147
|
+
const abort = vi.fn();
|
|
148
|
+
const limiter = createTurnLimiter({ maxTurns: 0, graceTurns: 2, steer, abort });
|
|
149
|
+
|
|
150
|
+
limiter.onTurnEnd(100);
|
|
151
|
+
expect(steer).not.toHaveBeenCalled();
|
|
152
|
+
|
|
153
|
+
limiter.reset();
|
|
154
|
+
limiter.onTurnEnd(100);
|
|
155
|
+
// maxTurns=0(禁用),即使 reset 也不触发
|
|
156
|
+
expect(steer).not.toHaveBeenCalled();
|
|
157
|
+
expect(abort).not.toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("全程累计(不 reset)达到 maxTurns+graceTurns 后不再触发", () => {
|
|
161
|
+
const steer = vi.fn();
|
|
162
|
+
const abort = vi.fn();
|
|
163
|
+
const limiter = createTurnLimiter({ maxTurns: 2, graceTurns: 1, steer, abort });
|
|
164
|
+
|
|
165
|
+
limiter.onTurnEnd(1);
|
|
166
|
+
limiter.onTurnEnd(2); // steer
|
|
167
|
+
limiter.onTurnEnd(3); // abort
|
|
168
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
169
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
170
|
+
|
|
171
|
+
// 已 abort 后继续调用 onTurnEnd(不应再次触发)
|
|
172
|
+
limiter.onTurnEnd(4);
|
|
173
|
+
limiter.onTurnEnd(5);
|
|
174
|
+
expect(steer).toHaveBeenCalledTimes(1);
|
|
175
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("TC-4: reset 诊断属性", () => {
|
|
180
|
+
it("reset 清除 didSteer 和 didAbort 诊断标志", () => {
|
|
181
|
+
const steer = vi.fn();
|
|
182
|
+
const abort = vi.fn();
|
|
183
|
+
const limiter = createTurnLimiter({ maxTurns: 1, graceTurns: 0, steer, abort });
|
|
184
|
+
|
|
185
|
+
limiter.onTurnEnd(1); // steer + abort (graceTurns=0)
|
|
186
|
+
expect(limiter.didSteer).toBe(true);
|
|
187
|
+
expect(limiter.didAbort).toBe(true);
|
|
188
|
+
|
|
189
|
+
limiter.reset();
|
|
190
|
+
expect(limiter.didSteer).toBe(false);
|
|
191
|
+
expect(limiter.didAbort).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|