@zhushanwen/pi-subagent-workflow 8.8.0 → 8.9.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.
Files changed (38) hide show
  1. package/package.json +9 -8
  2. package/skills/subagent-ext-config/SKILL.md +21 -1
  3. package/src/host/pi-host.ts +5 -4
  4. package/src/index.ts +145 -464
  5. package/src/injectors/__tests__/engine-awareness.test.ts +4 -2
  6. package/src/injectors/__tests__/engine-section-stability.test.ts +42 -29
  7. package/src/injectors/engine-awareness.ts +80 -4
  8. package/src/injectors/resource-list-injector.ts +209 -0
  9. package/src/injectors/subagent-list-injector.ts +30 -143
  10. package/src/injectors/workflow-list-injector.ts +23 -150
  11. package/src/interface/__tests__/detectors.test.ts +1 -1
  12. package/src/interface/__tests__/subagent-tool-path-guard.test.ts +42 -26
  13. package/src/interface/__tests__/subagent-tool-prompt.test.ts +15 -6
  14. package/src/interface/__tests__/tool-workflow-run-builtin-name.test.ts +1 -1
  15. package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +1 -1
  16. package/src/interface/bg-notify-render.ts +4 -4
  17. package/src/interface/commands.ts +115 -75
  18. package/src/interface/format.ts +339 -241
  19. package/src/interface/helpers.ts +2 -2
  20. package/src/interface/list-component.ts +163 -116
  21. package/src/interface/list-shared.ts +2 -2
  22. package/src/interface/list-view.ts +129 -72
  23. package/src/interface/subagent-actions.ts +5 -5
  24. package/src/interface/subagent-tool-schema.ts +21 -6
  25. package/src/interface/subagent-tool.ts +31 -29
  26. package/src/interface/subagents.ts +8 -7
  27. package/src/interface/tool-render.ts +2 -2
  28. package/src/interface/tool-workflow-script.ts +15 -14
  29. package/src/interface/tool-workflow.ts +14 -11
  30. package/src/interface/tui-kit.ts +305 -0
  31. package/src/interface/views/WorkflowsView.ts +267 -196
  32. package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
  33. package/src/interface/views/__tests__/detail-content-session-file.test.ts +7 -4
  34. package/src/interface/views/detail-content.ts +16 -14
  35. package/src/interface/views/view-constants.ts +19 -0
  36. package/src/jsonl-run-store.ts +11 -7
  37. package/src/session-lifecycle.ts +561 -0
  38. package/src/interface/views/format.ts +0 -281
@@ -12,29 +12,31 @@
12
12
 
13
13
  import { Key, matchesKey } from "@earendil-works/pi-tui";
14
14
 
15
- import { getAllToolCalls, projectLiveProgress } from "@zhushanwen/subagent-core/execution/execution-record.ts";
16
- import type { AgentEventLogEntry } from "@zhushanwen/subagent-core/execution/types.ts";
17
- import type { ExecutionTraceNode } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
18
- import type { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
15
+ import { getAllToolCalls, projectLiveProgress } from "@zhushanwen/subagent-core";
16
+ import type { AgentEventLogEntry } from "@zhushanwen/subagent-core";
17
+ import type { ExecutionTraceNode } from "@zhushanwen/subagent-core";
18
+ import type { WorkflowRun } from "@zhushanwen/subagent-core";
19
19
  import {
20
- BOX_BORDER_CHARS,
21
- BUDGET_TOKENS_DIVISOR,
22
20
  ELLIPSIS,
23
21
  formatActivityLine,
24
22
  formatElapsed,
25
23
  formatElapsedSeconds,
26
- formatEventLine,
27
24
  formatTokenStat,
25
+ formatTraceEventLine,
26
+ statusDotStr,
27
+ type ThemeLike,
28
+ } from "../format.ts";
29
+ import { PAGE_SCROLL_DEFAULT } from "../tui-kit.ts";
30
+ import {
31
+ BOX_BORDER_CHARS,
32
+ BUDGET_TOKENS_DIVISOR,
28
33
  MAX_TOOL_CALLS_DISPLAY,
29
34
  OUTPUT_TRUNCATE_BYTES,
30
- PAGE_SCROLL_DEFAULT,
31
35
  PROMPT_FOLD_LINES,
32
- statusDotStr,
33
- type ThemeLike,
34
- } from "./format.ts";
36
+ } from "./view-constants.ts";
35
37
 
36
- // ── 共享常量(BOX_BORDER_CHARS / BUDGET_TOKENS_DIVISOR / MAX_TOOL_CALLS_DISPLAY
37
- // 已上移到 format.ts,供 WorkflowsView + detail-content 共用,避免重复定义)──
38
+ // ── 共享常量(BOX_BORDER_CHARS / BUDGET_TOKENS_DIVISOR / MAX_TOOL_CALLS_DISPLAY 等)
39
+ // 落位 ./view-constants.ts(post-convergence C4:views 专属常量自 format.ts 沉回 views/)──
38
40
 
39
41
  /** 探测宽度:足够大避免截断折行影响行数统计(对齐 subagents DETAIL_LEN_PROBE_WIDTH)。 */
40
42
  const DETAIL_LEN_PROBE_WIDTH = 9999;
@@ -232,7 +234,7 @@ function renderActivitySection(
232
234
  const start = eventLog.length - showCount;
233
235
  for (let i = start; i < eventLog.length; i++) {
234
236
  const entry = eventLog[i] as AgentEventLogEntry;
235
- rightLines.push(theme.fg("dim", ` ${formatEventLine(entry, theme)}`.slice(0, mainWidth - BOX_BORDER_CHARS)));
237
+ rightLines.push(theme.fg("dim", ` ${formatTraceEventLine(entry, theme)}`.slice(0, mainWidth - BOX_BORDER_CHARS)));
236
238
  }
237
239
  if (totalCount === 0 && !live.currentActivity) {
238
240
  rightLines.push(theme.fg("dim", " (starting...)"));
@@ -0,0 +1,19 @@
1
+ // src/interface/views/view-constants.ts
2
+ //
3
+ // workflow 全屏视图族专属布局常量(WorkflowsView + detail-content 消费)。
4
+ // 自 interface/format.ts 沉回 views/(post-convergence C4:format.ts 只保留
5
+ // 跨视图族共享的格式化函数,views 专属常量就近落位消费方目录)。
6
+ // ELLIPSIS 留在 format.ts(formatActivityLine/formatPhaseLine 亦消费,非 views 专属)。
7
+
8
+ /** 左侧 sidebar 宽度(WorkflowsView 布局)。 */
9
+ export const SIDEBAR_WIDTH = 24;
10
+ /** prompt 区折叠时显示的行数(detail-content L2)。 */
11
+ export const PROMPT_FOLD_LINES = 3;
12
+ /** result 正文渲染的截断预算(字节,detail-content L2)。 */
13
+ export const OUTPUT_TRUNCATE_BYTES = 100_000;
14
+ /** box 左右边框字符宽度(│ x 2),用于内容行截断预算。 */
15
+ export const BOX_BORDER_CHARS = 2;
16
+ /** token 数 → k 单位的除数。 */
17
+ export const BUDGET_TOKENS_DIVISOR = 1000;
18
+ /** Activity 区最多显示的 tool call 条数。 */
19
+ export const MAX_TOOL_CALLS_DISPLAY = 3;
@@ -73,19 +73,23 @@ import * as fs from "node:fs";
73
73
  import * as path from "node:path";
74
74
 
75
75
  import type { CustomEntry, ExtensionAPI, ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";
76
+ // DEFAULT_SAVE_MIN_INTERVAL_MS / DEFAULT_STATE_MAX_RUNS 保留深路径:core barrel
77
+ // 刻意不导出(exports 面即 semver 契约,见 subagent-core src/index.ts 头注),壳侧
78
+ // barrel 消费(DEFAULT_* 已进 core barrel——u-2c 删 ./* 通配后深路径 tsc 不可解析)
76
79
  import {
77
80
  DEFAULT_SAVE_MIN_INTERVAL_MS,
78
81
  DEFAULT_STATE_MAX_RUNS,
79
- } from "@zhushanwen/subagent-core/orchestration/file-run-store.ts";
80
- import { getLogger } from "@zhushanwen/subagent-core/core/logger.ts";
82
+ } from "@zhushanwen/subagent-core";
83
+ import { getLogger } from "@zhushanwen/subagent-core";
81
84
 
82
- import { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
85
+ import { WorkflowRun } from "@zhushanwen/subagent-core";
83
86
  import {
84
87
  SNAPSHOT_VERSION,
85
88
  fromRunSnapshot,
86
89
  toRunSnapshot,
87
90
  type RunSnapshot,
88
- } from "@zhushanwen/subagent-core/orchestration/run-snapshot.ts";
91
+ } from "@zhushanwen/subagent-core";
92
+ import { toErrorMessage } from "@zhushanwen/pi-ext-guards";
89
93
 
90
94
  // ── Workflow-record self-describing entry (W17, D4) ─────────
91
95
 
@@ -158,7 +162,7 @@ function collectRecordRun(entry: CustomEntry, entryIndex: number, recordRuns: Ma
158
162
  }
159
163
  // D-5: 版本不匹配 = old snapshot format / future version — skip silently
160
164
  } catch (err) {
161
- const reason = err instanceof Error ? err.message : String(err);
165
+ const reason = toErrorMessage(err);
162
166
  logger.warn(
163
167
  `[subagent-workflow] workflow-record entry #${entryIndex} corrupted, skipped run rebuild: ${reason}`,
164
168
  );
@@ -232,7 +236,7 @@ async function pruneStateFilesBeyondCap(stateDir: string, maxRuns: number): Prom
232
236
  names = await fs.promises.readdir(stateDir);
233
237
  } catch (err) {
234
238
  if (!isEnoentError(err)) {
235
- const reason = err instanceof Error ? err.message : String(err);
239
+ const reason = toErrorMessage(err);
236
240
  logger.warn(`[subagent-workflow] state retention: readdir ${stateDir} failed: ${reason}`);
237
241
  }
238
242
  return;
@@ -258,7 +262,7 @@ async function pruneStateFilesBeyondCap(stateDir: string, maxRuns: number): Prom
258
262
  logger.debug(`[subagent-workflow] state retention: pruned ${victim.full}`);
259
263
  } catch (err) {
260
264
  if (isEnoentError(err)) continue; // 并发删除已达成目标
261
- const reason = err instanceof Error ? err.message : String(err);
265
+ const reason = toErrorMessage(err);
262
266
  logger.warn(`[subagent-workflow] state retention: failed to delete ${victim.full}: ${reason}`);
263
267
  }
264
268
  }