@zhushanwen/pi-subagent-workflow 8.7.0 → 8.8.1
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 +5 -11
- package/package.json +8 -11
- package/skills/workflow-script-format/SKILL.md +32 -13
- package/src/host/__tests__/pi-host.test.ts +23 -2
- package/src/host/pi-host.ts +61 -6
- package/src/index.ts +155 -528
- package/src/injectors/__tests__/engine-awareness.test.ts +5 -3
- package/src/injectors/__tests__/engine-section-stability.test.ts +48 -33
- package/src/injectors/__tests__/model-list-injector.test.ts +18 -21
- package/src/injectors/__tests__/subagent-list-injector.test.ts +54 -14
- package/src/injectors/__tests__/workflow-list-injector.test.ts +26 -12
- package/src/injectors/engine-awareness.ts +80 -8
- package/src/injectors/model-list-injector.ts +15 -58
- package/src/injectors/resource-list-injector.ts +209 -0
- package/src/injectors/subagent-list-injector.ts +53 -224
- package/src/injectors/workflow-list-injector.ts +36 -196
- package/src/interface/__tests__/detectors.test.ts +46 -35
- package/src/interface/__tests__/subagent-tool-path-guard.test.ts +42 -26
- package/src/interface/__tests__/subagent-tool-prompt.test.ts +14 -3
- package/src/interface/__tests__/tool-workflow-run-builtin-name.test.ts +216 -0
- package/src/interface/__tests__/tool-workflow-script-generate.test.ts +17 -6
- package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +38 -2
- package/src/interface/bg-notify-render.ts +7 -17
- package/src/interface/command-actions.ts +5 -15
- package/src/interface/commands.ts +116 -76
- package/src/interface/format.ts +354 -245
- package/src/interface/gui-mappers.ts +18 -22
- package/src/interface/helpers.ts +9 -130
- package/src/interface/list-component.ts +164 -117
- package/src/interface/list-shared.ts +3 -3
- package/src/interface/list-view.ts +130 -73
- package/src/interface/subagent-actions.ts +50 -675
- package/src/interface/subagent-tool-schema.ts +7 -9
- package/src/interface/subagent-tool.ts +5 -4
- package/src/interface/subagents.ts +9 -8
- package/src/interface/tool-render.ts +5 -15
- package/src/interface/tool-workflow-script.ts +34 -75
- package/src/interface/tool-workflow.ts +62 -96
- package/src/interface/tui-kit.ts +305 -0
- package/src/interface/views/WorkflowsView.ts +270 -207
- package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
- package/src/interface/views/__tests__/detail-content-session-file.test.ts +7 -4
- package/src/interface/views/detail-content.ts +16 -14
- package/src/interface/views/view-constants.ts +19 -0
- package/src/jsonl-run-store.ts +144 -228
- package/agents/analyst.md +0 -61
- package/agents/coder.md +0 -70
- package/agents/debugger.md +0 -67
- package/agents/doc-reviewer.md +0 -50
- package/agents/explorer.md +0 -64
- package/agents/general-purpose.md +0 -32
- package/agents/orchestrator.md +0 -63
- package/agents/planner.md +0 -54
- package/agents/researcher.md +0 -65
- package/agents/reviewer.md +0 -74
- package/src/interface/views/format.ts +0 -320
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow View — Pure formatting functions (FR-4)
|
|
3
|
-
*
|
|
4
|
-
* Stateless functions extracted from WorkflowsView for testability.
|
|
5
|
-
* All functions are pure: no Pi runtime, no side effects.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
9
|
-
|
|
10
|
-
import type { AgentEventLogEntry } from "@zhushanwen/subagent-core/execution/types.ts";
|
|
11
|
-
import type { ExecutionTraceNode, ToolCallEntry } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
|
|
12
|
-
import type { DoneReason, RunStatus } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
|
|
13
|
-
import { displayAgentName } from "@zhushanwen/subagent-core/shared/agent-ref.ts";
|
|
14
|
-
|
|
15
|
-
// ── Constants ─────────────────────────────────────────────────
|
|
16
|
-
|
|
17
|
-
export const SIDEBAR_WIDTH = 24;
|
|
18
|
-
export const PROMPT_FOLD_LINES = 3;
|
|
19
|
-
export const OUTPUT_TRUNCATE_BYTES = 100_000;
|
|
20
|
-
export const ELLIPSIS = "\u2026"; // U+2026
|
|
21
|
-
|
|
22
|
-
// L2 详情滚动常量(对齐 subagents list-view.ts)。
|
|
23
|
-
/** terminal.rows 读不到时的翻页兜底步长(防 NaN)。 */
|
|
24
|
-
export const PAGE_SCROLL_DEFAULT = 10;
|
|
25
|
-
/** tui.terminal.rows 兜底行数(duck-type 失败时,对齐 subagents TERM_ROWS_FALLBACK)。 */
|
|
26
|
-
export const TERM_ROWS_FALLBACK = 24;
|
|
27
|
-
|
|
28
|
-
// 跨 view 共享的布局常量(WorkflowsView + detail-content 都用)。
|
|
29
|
-
/** box 左右边框字符宽度(│ x 2),用于内容行截断预算。 */
|
|
30
|
-
export const BOX_BORDER_CHARS = 2;
|
|
31
|
-
/** token 数 → k 单位的除数。 */
|
|
32
|
-
export const BUDGET_TOKENS_DIVISOR = 1000;
|
|
33
|
-
/** Activity 区最多显示的 tool call 条数。 */
|
|
34
|
-
export const MAX_TOOL_CALLS_DISPLAY = 3;
|
|
35
|
-
|
|
36
|
-
// 时间换算(模块私有常量)。
|
|
37
|
-
const MS_PER_SEC = 1000;
|
|
38
|
-
const SECS_PER_MIN = 60;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 可显示的状态文本集合。
|
|
42
|
-
*
|
|
43
|
-
* 包含 RunStatus("running"|"done" 不直接显示,转 reason)+ DoneReason
|
|
44
|
-
* (completed/failed/aborted/budget_limited/time_limited)+ ExecutionTraceNode.status
|
|
45
|
-
* (含 "pending"——trace 节点的初始态)。
|
|
46
|
-
*
|
|
47
|
-
* 收窄自 string → 显式联合,编译器会在新增 status 时强制 switch 补齐分支。
|
|
48
|
-
*/
|
|
49
|
-
type StatusText =
|
|
50
|
-
| RunStatus
|
|
51
|
-
| DoneReason
|
|
52
|
-
| "pending";
|
|
53
|
-
|
|
54
|
-
// ── Theme interface (avoids importing Pi runtime) ─────────────
|
|
55
|
-
|
|
56
|
-
export interface ThemeLike {
|
|
57
|
-
fg(token: string, text: string): string;
|
|
58
|
-
bold(text: string): string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ── Status helpers ────────────────────────────────────────────
|
|
62
|
-
|
|
63
|
-
/** status → 语义颜色 token(用于给任意文本染色,不含符号)。 */
|
|
64
|
-
function statusColorToken(
|
|
65
|
-
status: StatusText,
|
|
66
|
-
): "success" | "warning" | "error" | "muted" {
|
|
67
|
-
switch (status) {
|
|
68
|
-
case "completed": return "success";
|
|
69
|
-
case "running": return "warning";
|
|
70
|
-
case "failed": case "aborted": return "error";
|
|
71
|
-
default: return "muted";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function statusDotStr(
|
|
76
|
-
status: StatusText,
|
|
77
|
-
theme: ThemeLike,
|
|
78
|
-
): string {
|
|
79
|
-
return theme.fg(statusColorToken(status), "●");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Format a status badge with color for the header area. */
|
|
83
|
-
export function formatStatusBadge(
|
|
84
|
-
status: StatusText,
|
|
85
|
-
theme: ThemeLike,
|
|
86
|
-
): string {
|
|
87
|
-
switch (status) {
|
|
88
|
-
case "running": return theme.fg("warning", "\u25CF running");
|
|
89
|
-
case "completed": return theme.fg("success", "\u2713 completed");
|
|
90
|
-
case "failed": return theme.fg("error", "\u2717 failed");
|
|
91
|
-
case "aborted": return theme.fg("error", "\u2717 aborted");
|
|
92
|
-
case "budget_limited": return theme.fg("error", "\u26A0 budget");
|
|
93
|
-
case "time_limited": return theme.fg("error", "\u26A0 timeout");
|
|
94
|
-
default: return theme.fg("muted", status);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ── Pure formatting functions ─────────────────────────────────
|
|
99
|
-
|
|
100
|
-
/** Group trace nodes by phase. Nodes without phase go to "(no phase)". */
|
|
101
|
-
function groupByPhase(nodes: ExecutionTraceNode[]): Map<string, ExecutionTraceNode[]> {
|
|
102
|
-
const map = new Map<string, ExecutionTraceNode[]>();
|
|
103
|
-
for (const node of nodes) {
|
|
104
|
-
const phase = node.phase || "(default)";
|
|
105
|
-
let arr = map.get(phase);
|
|
106
|
-
if (!arr) {
|
|
107
|
-
arr = [];
|
|
108
|
-
map.set(phase, arr);
|
|
109
|
-
}
|
|
110
|
-
arr.push(node);
|
|
111
|
-
}
|
|
112
|
-
// Sort within each phase by stepIndex ascending (FR-3.2)
|
|
113
|
-
for (const arr of map.values()) {
|
|
114
|
-
arr.sort((a, b) => a.stepIndex - b.stepIndex);
|
|
115
|
-
}
|
|
116
|
-
return map;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Format elapsed time string from startedAt. */
|
|
120
|
-
export function formatElapsed(startedAt?: string, now: number = Date.now()): string {
|
|
121
|
-
if (!startedAt) return "-";
|
|
122
|
-
const ms = now - new Date(startedAt).getTime();
|
|
123
|
-
if (ms < MS_PER_SEC) return "0s";
|
|
124
|
-
const secs = Math.floor(ms / MS_PER_SEC);
|
|
125
|
-
if (secs < SECS_PER_MIN) return `${secs}s`;
|
|
126
|
-
const mins = Math.floor(secs / SECS_PER_MIN);
|
|
127
|
-
const remSecs = secs % SECS_PER_MIN;
|
|
128
|
-
return `${mins}m${remSecs}s`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Format elapsed time from integer seconds(live 路径用)。
|
|
133
|
-
* 与 formatElapsed 输出格式一致,但输入是 computeElapsedSeconds 的秒数(非时间戳)。
|
|
134
|
-
*/
|
|
135
|
-
export function formatElapsedSeconds(seconds: number): string {
|
|
136
|
-
if (seconds < 1) return "0s";
|
|
137
|
-
if (seconds < SECS_PER_MIN) return `${seconds}s`;
|
|
138
|
-
const mins = Math.floor(seconds / SECS_PER_MIN);
|
|
139
|
-
const remSecs = seconds % SECS_PER_MIN;
|
|
140
|
-
return `${mins}m${remSecs}s`;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Format a live eventLog entry(live 路径 Activity 区用)。
|
|
145
|
-
*
|
|
146
|
-
* tool_start → "→ {label}"
|
|
147
|
-
* tool_end → "← {label}"(done)/ "✗ {label}"(failed)
|
|
148
|
-
* turn_end → "∘ {label}"(turn 摘要)
|
|
149
|
-
* error → "✗ {label}"
|
|
150
|
-
*
|
|
151
|
-
* 对齐 subagents formatEventLine 的视觉风格,但用 workflow 的 ThemeLike(无 spinner)。
|
|
152
|
-
*/
|
|
153
|
-
export function formatEventLine(entry: AgentEventLogEntry, theme: ThemeLike): string {
|
|
154
|
-
switch (entry.type) {
|
|
155
|
-
case "tool_start":
|
|
156
|
-
return `→ ${entry.label}`;
|
|
157
|
-
case "tool_end":
|
|
158
|
-
return entry.status === "failed"
|
|
159
|
-
? theme.fg("error", `✗ ${entry.label}`)
|
|
160
|
-
: `✓ ${entry.label}`;
|
|
161
|
-
case "turn_end":
|
|
162
|
-
return theme.fg("dim", `∘ ${entry.label}`);
|
|
163
|
-
case "error":
|
|
164
|
-
return theme.fg("error", `✗ ${entry.label}`);
|
|
165
|
-
default:
|
|
166
|
-
return entry.label;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Format token + tool call statistics. */
|
|
171
|
-
export function formatTokenStat(
|
|
172
|
-
usage?: { input: number; output: number },
|
|
173
|
-
toolCalls?: ToolCallEntry[],
|
|
174
|
-
elapsed?: string,
|
|
175
|
-
): string {
|
|
176
|
-
const tokens = usage ? usage.input + usage.output : 0;
|
|
177
|
-
const tools = toolCalls?.length ?? 0;
|
|
178
|
-
const base = `${tokens} tok · ${tools} tool calls`;
|
|
179
|
-
return elapsed ? `${base} · ${elapsed}` : base;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* renderResult 的文本兜底:从 result.content[0] 提取纯文本。
|
|
184
|
-
* 多处 tool 的 renderResult 曾各自内联此逻辑,提取后统一调用。
|
|
185
|
-
*/
|
|
186
|
-
export function renderTextFallback(
|
|
187
|
-
result: { content?: Array<{ type: string; text?: string }> },
|
|
188
|
-
): string {
|
|
189
|
-
const first = result.content?.[0];
|
|
190
|
-
return first?.type === "text" ? (first.text ?? "") : "";
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Format a single activity line: ToolName(argsPreview). */
|
|
194
|
-
export function formatActivityLine(entry: ToolCallEntry, maxWidth: number): string {
|
|
195
|
-
// 语义阈值与开销:低于此宽度只显名称;括号占 2 字符 (name)。
|
|
196
|
-
const MIN_ACTIVITY_WIDTH = 10;
|
|
197
|
-
const PARENS_OVERHEAD = 2;
|
|
198
|
-
if (maxWidth < MIN_ACTIVITY_WIDTH) return entry.name;
|
|
199
|
-
const argsBudget = maxWidth - entry.name.length - PARENS_OVERHEAD;
|
|
200
|
-
if (argsBudget <= 0) return truncateToWidth(entry.name, maxWidth);
|
|
201
|
-
const truncated = entry.input.length > argsBudget
|
|
202
|
-
? entry.input.slice(0, argsBudget - 1) + ELLIPSIS
|
|
203
|
-
: entry.input;
|
|
204
|
-
return `${entry.name}(${truncated})`;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// ── ANSI helpers ──────────────────────────────────────────────
|
|
208
|
-
|
|
209
|
-
/** Measure visible width of a string (strips ANSI escapes, handles CJK/emoji).
|
|
210
|
-
* Delegates to pi-tui's visibleWidth for accurate width calculation.
|
|
211
|
-
*/
|
|
212
|
-
export function visibleLen(s: string): number {
|
|
213
|
-
return visibleWidth(s);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Pad an ANSI-escaped string to a target *visible* width.
|
|
217
|
-
* 只 pad 不截断:超宽时原样返回(调用方负责先截断)。
|
|
218
|
-
* 对齐 subagents 的 padToVisible 语义。
|
|
219
|
-
*/
|
|
220
|
-
export function padVisible(s: string, width: number): string {
|
|
221
|
-
const vl = visibleLen(s);
|
|
222
|
-
if (vl >= width) return s;
|
|
223
|
-
return s + " ".repeat(width - vl);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* 分段着色版填充:title 和 fill 都已着色(含 ANSI),拼接时各自 ANSI 延续。
|
|
228
|
-
* 解决 ANSI 嵌套失色:若用 fg("c1", fill(title, "─", n)),
|
|
229
|
-
* title 内的 \x1b[0m 会重置外层 c1,导致 title 之后的 ─ 失去 c1。
|
|
230
|
-
* 改成 title + fill.repeat(后),fill 整段保持自己的 ANSI,不依赖外层包裹。
|
|
231
|
-
*
|
|
232
|
-
* 对齐 subagents format.ts segFillColored(同源移植)。
|
|
233
|
-
*/
|
|
234
|
-
export function segFillColored(
|
|
235
|
-
titleStyled: string | undefined,
|
|
236
|
-
fillStyled: string,
|
|
237
|
-
width: number,
|
|
238
|
-
): string {
|
|
239
|
-
if (width <= 0) return "";
|
|
240
|
-
const fillW = visibleLen(fillStyled);
|
|
241
|
-
if (!titleStyled || fillW === 0) {
|
|
242
|
-
return fillStyled.repeat(width);
|
|
243
|
-
}
|
|
244
|
-
const tw = visibleLen(titleStyled);
|
|
245
|
-
if (tw >= width) return truncateToWidth(titleStyled, width);
|
|
246
|
-
const fillCount = width - tw;
|
|
247
|
-
return titleStyled + fillStyled.repeat(fillCount);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// ── Phase group (filters empty phases) ────────────────────────
|
|
251
|
-
|
|
252
|
-
export interface PhaseGroup {
|
|
253
|
-
name: string;
|
|
254
|
-
nodes: ExecutionTraceNode[];
|
|
255
|
-
doneCount: number;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** The fallback phase name when node has no explicit phase. */
|
|
259
|
-
const NO_PHASE = "(default)";
|
|
260
|
-
|
|
261
|
-
/** Build phase groups. Nodes without a phase are placed in an unnamed group. */
|
|
262
|
-
export function buildPhaseGroups(nodes: ExecutionTraceNode[]): PhaseGroup[] {
|
|
263
|
-
const map = groupByPhase(nodes);
|
|
264
|
-
const result: PhaseGroup[] = [];
|
|
265
|
-
for (const [name, phaseNodes] of map) {
|
|
266
|
-
if (phaseNodes.length > 0) {
|
|
267
|
-
result.push({
|
|
268
|
-
name: name === NO_PHASE ? "" : name,
|
|
269
|
-
nodes: phaseNodes,
|
|
270
|
-
doneCount: phaseNodes.filter((n) => n.status === "completed").length,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return result;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// ── Sidebar phase line formatter ─────────────────────────────
|
|
278
|
-
|
|
279
|
-
export function formatPhaseLine(
|
|
280
|
-
pg: PhaseGroup,
|
|
281
|
-
idx: number,
|
|
282
|
-
isSelected: boolean,
|
|
283
|
-
theme: ThemeLike,
|
|
284
|
-
maxWidth: number,
|
|
285
|
-
): string {
|
|
286
|
-
const pointer = isSelected ? "❯ " : " ";
|
|
287
|
-
const dot = statusDotStr(pg.doneCount === pg.nodes.length ? "completed" : "running", theme);
|
|
288
|
-
const name = pg.name || "(unnamed)";
|
|
289
|
-
const label = `${idx + 1} ${name} ${pg.doneCount}/${pg.nodes.length}`;
|
|
290
|
-
// pointer(2) + dot(1) + space(1)
|
|
291
|
-
const PHASE_PREFIX_WIDTH = 4;
|
|
292
|
-
const budget = maxWidth - PHASE_PREFIX_WIDTH;
|
|
293
|
-
const truncated = visibleLen(label) > budget
|
|
294
|
-
? truncateToWidth(label, budget - 1) + ELLIPSIS
|
|
295
|
-
: label;
|
|
296
|
-
return `${pointer}${dot} ${truncated}`;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// ── Agent one-liner for overview right panel ──────────────────
|
|
300
|
-
|
|
301
|
-
const TOKEN_K = 1000;
|
|
302
|
-
|
|
303
|
-
export function formatAgentOneLiner(node: ExecutionTraceNode, theme: ThemeLike): string {
|
|
304
|
-
const dot = statusDotStr(node.status, theme);
|
|
305
|
-
const elapsed = formatElapsed(
|
|
306
|
-
node.startedAt,
|
|
307
|
-
node.completedAt ? new Date(node.completedAt).getTime() : Date.now(),
|
|
308
|
-
);
|
|
309
|
-
const tok = node.result?.usage;
|
|
310
|
-
const tokStr = tok
|
|
311
|
-
? `${Math.round((tok.input + tok.output) / TOKEN_K)}k tok`
|
|
312
|
-
: "";
|
|
313
|
-
const tcCount = node.result?.toolCalls?.length ?? 0;
|
|
314
|
-
const parts = [dot, displayAgentName(node.agent), node.model];
|
|
315
|
-
if (tokStr) parts.push(`${tokStr} · ${tcCount} tools`);
|
|
316
|
-
parts.push(elapsed);
|
|
317
|
-
return parts.join(" ");
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|