pi-agent-flow 1.8.39 → 2.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.
Files changed (291) hide show
  1. package/README.md +33 -37
  2. package/agents/audit.md +18 -22
  3. package/agents/build.md +20 -22
  4. package/agents/craft.md +20 -27
  5. package/agents/debug.md +21 -28
  6. package/agents/ideas.md +18 -101
  7. package/agents/scout.md +15 -19
  8. package/dist/batch/batch-bash.d.ts +2 -2
  9. package/dist/batch/batch-bash.d.ts.map +1 -1
  10. package/dist/batch/batch-bash.js +3 -3
  11. package/dist/batch/batch-bash.js.map +1 -1
  12. package/dist/batch/constants.d.ts +19 -5
  13. package/dist/batch/constants.d.ts.map +1 -1
  14. package/dist/batch/constants.js +4 -3
  15. package/dist/batch/constants.js.map +1 -1
  16. package/dist/batch/execute.d.ts +0 -1
  17. package/dist/batch/execute.d.ts.map +1 -1
  18. package/dist/batch/execute.js +101 -10
  19. package/dist/batch/execute.js.map +1 -1
  20. package/dist/batch/fuzzy-edit.d.ts +0 -6
  21. package/dist/batch/fuzzy-edit.d.ts.map +1 -1
  22. package/dist/batch/fuzzy-edit.js +1 -1
  23. package/dist/batch/fuzzy-edit.js.map +1 -1
  24. package/dist/batch/index.d.ts.map +1 -1
  25. package/dist/batch/index.js +87 -16
  26. package/dist/batch/index.js.map +1 -1
  27. package/dist/batch/render.d.ts +0 -1
  28. package/dist/batch/render.d.ts.map +1 -1
  29. package/dist/batch/render.js +7 -101
  30. package/dist/batch/render.js.map +1 -1
  31. package/dist/batch/summary.d.ts +5 -0
  32. package/dist/batch/summary.d.ts.map +1 -0
  33. package/dist/batch/summary.js +101 -0
  34. package/dist/batch/summary.js.map +1 -0
  35. package/dist/{config.d.ts → config/config.d.ts} +34 -2
  36. package/dist/config/config.d.ts.map +1 -0
  37. package/dist/{config.js → config/config.js} +157 -9
  38. package/dist/config/config.js.map +1 -0
  39. package/dist/config/log.d.ts +27 -0
  40. package/dist/config/log.d.ts.map +1 -0
  41. package/dist/config/log.js +104 -0
  42. package/dist/config/log.js.map +1 -0
  43. package/dist/{settings-resolver.d.ts → config/settings-resolver.d.ts} +9 -2
  44. package/dist/config/settings-resolver.d.ts.map +1 -0
  45. package/dist/config/settings-resolver.js +275 -0
  46. package/dist/config/settings-resolver.js.map +1 -0
  47. package/dist/core/agents.d.ts.map +1 -0
  48. package/dist/{agents.js → core/agents.js} +11 -10
  49. package/dist/core/agents.js.map +1 -0
  50. package/dist/core/delegation.d.ts +24 -0
  51. package/dist/core/delegation.d.ts.map +1 -0
  52. package/dist/core/delegation.js +55 -0
  53. package/dist/core/delegation.js.map +1 -0
  54. package/dist/core/depth.d.ts.map +1 -0
  55. package/dist/{depth.js → core/depth.js} +9 -8
  56. package/dist/core/depth.js.map +1 -0
  57. package/dist/{executor.d.ts → core/executor.d.ts} +13 -3
  58. package/dist/core/executor.d.ts.map +1 -0
  59. package/dist/{executor.js → core/executor.js} +79 -15
  60. package/dist/core/executor.js.map +1 -0
  61. package/dist/{flow.d.ts → core/flow.d.ts} +4 -1
  62. package/dist/core/flow.d.ts.map +1 -0
  63. package/dist/{flow.js → core/flow.js} +179 -25
  64. package/dist/core/flow.js.map +1 -0
  65. package/dist/{session-mode.d.ts → core/session-mode.d.ts} +2 -1
  66. package/dist/core/session-mode.d.ts.map +1 -0
  67. package/dist/{session-mode.js → core/session-mode.js} +1 -1
  68. package/dist/core/session-mode.js.map +1 -0
  69. package/dist/core/session-registry.d.ts +16 -0
  70. package/dist/core/session-registry.d.ts.map +1 -0
  71. package/dist/core/session-registry.js +30 -0
  72. package/dist/core/session-registry.js.map +1 -0
  73. package/dist/core/transitions.d.ts.map +1 -0
  74. package/dist/{transitions.js → core/transitions.js} +1 -1
  75. package/dist/core/transitions.js.map +1 -0
  76. package/dist/flow/command.d.ts +8 -0
  77. package/dist/flow/command.d.ts.map +1 -0
  78. package/dist/flow/command.js +189 -0
  79. package/dist/flow/command.js.map +1 -0
  80. package/dist/flow/continuation.d.ts +16 -0
  81. package/dist/flow/continuation.d.ts.map +1 -0
  82. package/dist/flow/continuation.js +151 -0
  83. package/dist/flow/continuation.js.map +1 -0
  84. package/dist/flow/index.d.ts +15 -0
  85. package/dist/flow/index.d.ts.map +1 -0
  86. package/dist/flow/index.js +22 -0
  87. package/dist/flow/index.js.map +1 -0
  88. package/dist/flow/settings-command.d.ts +51 -0
  89. package/dist/flow/settings-command.d.ts.map +1 -0
  90. package/dist/flow/settings-command.js +851 -0
  91. package/dist/flow/settings-command.js.map +1 -0
  92. package/dist/flow/store.d.ts +26 -0
  93. package/dist/flow/store.d.ts.map +1 -0
  94. package/dist/flow/store.js +158 -0
  95. package/dist/flow/store.js.map +1 -0
  96. package/dist/flow/template-strings.d.ts +8 -0
  97. package/dist/flow/template-strings.d.ts.map +1 -0
  98. package/dist/flow/template-strings.js +39 -0
  99. package/dist/flow/template-strings.js.map +1 -0
  100. package/dist/flow/types.d.ts +55 -0
  101. package/dist/flow/types.d.ts.map +1 -0
  102. package/dist/flow/types.js +5 -0
  103. package/dist/flow/types.js.map +1 -0
  104. package/dist/flow/warp-command.d.ts +9 -0
  105. package/dist/flow/warp-command.d.ts.map +1 -0
  106. package/dist/flow/warp-command.js +405 -0
  107. package/dist/flow/warp-command.js.map +1 -0
  108. package/dist/index.d.ts +3 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +115 -32
  111. package/dist/index.js.map +1 -1
  112. package/dist/{notify-state.d.ts → notify/notify-state.d.ts} +2 -1
  113. package/dist/notify/notify-state.d.ts.map +1 -0
  114. package/dist/notify/notify-state.js.map +1 -0
  115. package/dist/notify/notify.d.ts.map +1 -0
  116. package/dist/{notify.js → notify/notify.js} +3 -2
  117. package/dist/notify/notify.js.map +1 -0
  118. package/dist/{cli-args.d.ts → snapshot/cli-args.d.ts} +4 -2
  119. package/dist/snapshot/cli-args.d.ts.map +1 -0
  120. package/dist/{cli-args.js → snapshot/cli-args.js} +10 -1
  121. package/dist/snapshot/cli-args.js.map +1 -0
  122. package/dist/snapshot/index.d.ts +2 -0
  123. package/dist/snapshot/index.d.ts.map +1 -0
  124. package/dist/snapshot/index.js +2 -0
  125. package/dist/snapshot/index.js.map +1 -0
  126. package/dist/{reasoning-strip.d.ts → snapshot/reasoning-strip.d.ts} +0 -4
  127. package/dist/snapshot/reasoning-strip.d.ts.map +1 -0
  128. package/dist/{reasoning-strip.js → snapshot/reasoning-strip.js} +2 -2
  129. package/dist/snapshot/reasoning-strip.js.map +1 -0
  130. package/dist/{runner-events.d.ts → snapshot/runner-events.d.ts} +13 -1
  131. package/dist/snapshot/runner-events.d.ts.map +1 -0
  132. package/dist/{runner-events.js → snapshot/runner-events.js} +16 -4
  133. package/dist/snapshot/runner-events.js.map +1 -0
  134. package/dist/{snapshot.d.ts → snapshot/snapshot.d.ts} +29 -3
  135. package/dist/snapshot/snapshot.d.ts.map +1 -0
  136. package/dist/{snapshot.js → snapshot/snapshot.js} +347 -39
  137. package/dist/snapshot/snapshot.js.map +1 -0
  138. package/dist/{structured-output.d.ts → snapshot/structured-output.d.ts} +1 -1
  139. package/dist/snapshot/structured-output.d.ts.map +1 -0
  140. package/dist/{structured-output.js → snapshot/structured-output.js} +13 -0
  141. package/dist/snapshot/structured-output.js.map +1 -0
  142. package/dist/{flow-prompt.d.ts → steering/flow-prompt.d.ts} +2 -2
  143. package/dist/steering/flow-prompt.d.ts.map +1 -0
  144. package/dist/{flow-prompt.js → steering/flow-prompt.js} +3 -3
  145. package/dist/steering/flow-prompt.js.map +1 -0
  146. package/dist/{sliding-prompt.d.ts → steering/sliding-prompt.d.ts} +8 -7
  147. package/dist/steering/sliding-prompt.d.ts.map +1 -0
  148. package/dist/{sliding-prompt.js → steering/sliding-prompt.js} +15 -64
  149. package/dist/steering/sliding-prompt.js.map +1 -0
  150. package/dist/{tool-utils.d.ts → steering/tool-utils.d.ts} +1 -0
  151. package/dist/steering/tool-utils.d.ts.map +1 -0
  152. package/dist/{tool-utils.js → steering/tool-utils.js} +10 -3
  153. package/dist/steering/tool-utils.js.map +1 -0
  154. package/dist/{ask-user.d.ts → tools/ask-user.d.ts} +3 -15
  155. package/dist/tools/ask-user.d.ts.map +1 -0
  156. package/dist/tools/ask-user.js +778 -0
  157. package/dist/tools/ask-user.js.map +1 -0
  158. package/dist/{timed-bash.d.ts → tools/timed-bash.d.ts} +2 -7
  159. package/dist/tools/timed-bash.d.ts.map +1 -0
  160. package/dist/{timed-bash.js → tools/timed-bash.js} +2 -2
  161. package/dist/tools/timed-bash.js.map +1 -0
  162. package/dist/{web-tool.d.ts → tools/web-tool.d.ts} +1 -1
  163. package/dist/tools/web-tool.d.ts.map +1 -0
  164. package/dist/{web-tool.js → tools/web-tool.js} +8 -7
  165. package/dist/tools/web-tool.js.map +1 -0
  166. package/dist/tui/flow-colors.d.ts +55 -0
  167. package/dist/tui/flow-colors.d.ts.map +1 -0
  168. package/dist/tui/flow-colors.js +22 -0
  169. package/dist/tui/flow-colors.js.map +1 -0
  170. package/dist/{render-utils.d.ts → tui/render-utils.d.ts} +1 -1
  171. package/dist/tui/render-utils.d.ts.map +1 -0
  172. package/dist/{render-utils.js → tui/render-utils.js} +3 -3
  173. package/dist/tui/render-utils.js.map +1 -0
  174. package/dist/tui/render.d.ts +21 -0
  175. package/dist/tui/render.d.ts.map +1 -0
  176. package/dist/tui/render.js +813 -0
  177. package/dist/tui/render.js.map +1 -0
  178. package/dist/tui/scramble/algorithm.d.ts +7 -0
  179. package/dist/tui/scramble/algorithm.d.ts.map +1 -0
  180. package/dist/tui/scramble/algorithm.js +227 -0
  181. package/dist/tui/scramble/algorithm.js.map +1 -0
  182. package/dist/tui/scramble/constants.d.ts +99 -0
  183. package/dist/tui/scramble/constants.d.ts.map +1 -0
  184. package/dist/tui/scramble/constants.js +101 -0
  185. package/dist/tui/scramble/constants.js.map +1 -0
  186. package/dist/tui/scramble/index.d.ts +6 -0
  187. package/dist/tui/scramble/index.d.ts.map +1 -0
  188. package/dist/tui/scramble/index.js +6 -0
  189. package/dist/tui/scramble/index.js.map +1 -0
  190. package/dist/tui/scramble/manager.d.ts +48 -0
  191. package/dist/tui/scramble/manager.d.ts.map +1 -0
  192. package/dist/tui/scramble/manager.js +959 -0
  193. package/dist/tui/scramble/manager.js.map +1 -0
  194. package/dist/tui/scramble/utils.d.ts +18 -0
  195. package/dist/tui/scramble/utils.d.ts.map +1 -0
  196. package/dist/tui/scramble/utils.js +145 -0
  197. package/dist/tui/scramble/utils.js.map +1 -0
  198. package/dist/tui/single-select-layout.d.ts +17 -0
  199. package/dist/tui/single-select-layout.d.ts.map +1 -0
  200. package/dist/{single-select-layout.js → tui/single-select-layout.js} +8 -25
  201. package/dist/tui/single-select-layout.js.map +1 -0
  202. package/dist/types/flow.d.ts +110 -0
  203. package/dist/types/flow.d.ts.map +1 -0
  204. package/dist/{types.js → types/flow.js} +3 -54
  205. package/dist/types/flow.js.map +1 -0
  206. package/dist/types/index.d.ts +8 -0
  207. package/dist/types/index.d.ts.map +1 -0
  208. package/dist/types/index.js +7 -0
  209. package/dist/types/index.js.map +1 -0
  210. package/dist/types/output.d.ts +104 -0
  211. package/dist/types/output.d.ts.map +1 -0
  212. package/dist/types/output.js +5 -0
  213. package/dist/types/output.js.map +1 -0
  214. package/dist/types/ui.d.ts +24 -0
  215. package/dist/types/ui.d.ts.map +1 -0
  216. package/dist/types/ui.js +55 -0
  217. package/dist/types/ui.js.map +1 -0
  218. package/package.json +7 -4
  219. package/dist/agents.d.ts.map +0 -1
  220. package/dist/agents.js.map +0 -1
  221. package/dist/ask-user.d.ts.map +0 -1
  222. package/dist/ask-user.js +0 -1405
  223. package/dist/ask-user.js.map +0 -1
  224. package/dist/batch.d.ts +0 -12
  225. package/dist/batch.d.ts.map +0 -1
  226. package/dist/batch.js +0 -11
  227. package/dist/batch.js.map +0 -1
  228. package/dist/cli-args.d.ts.map +0 -1
  229. package/dist/cli-args.js.map +0 -1
  230. package/dist/config.d.ts.map +0 -1
  231. package/dist/config.js.map +0 -1
  232. package/dist/depth.d.ts.map +0 -1
  233. package/dist/depth.js.map +0 -1
  234. package/dist/executor.d.ts.map +0 -1
  235. package/dist/executor.js.map +0 -1
  236. package/dist/flow-prompt.d.ts.map +0 -1
  237. package/dist/flow-prompt.js.map +0 -1
  238. package/dist/flow.d.ts.map +0 -1
  239. package/dist/flow.js.map +0 -1
  240. package/dist/notify-state.d.ts.map +0 -1
  241. package/dist/notify-state.js.map +0 -1
  242. package/dist/notify.d.ts.map +0 -1
  243. package/dist/notify.js.map +0 -1
  244. package/dist/reasoning-strip.d.ts.map +0 -1
  245. package/dist/reasoning-strip.js.map +0 -1
  246. package/dist/render-utils.d.ts.map +0 -1
  247. package/dist/render-utils.js.map +0 -1
  248. package/dist/render.d.ts +0 -24
  249. package/dist/render.d.ts.map +0 -1
  250. package/dist/render.js +0 -592
  251. package/dist/render.js.map +0 -1
  252. package/dist/runner-events.d.ts.map +0 -1
  253. package/dist/runner-events.js.map +0 -1
  254. package/dist/scramble.d.ts +0 -171
  255. package/dist/scramble.d.ts.map +0 -1
  256. package/dist/scramble.js +0 -2261
  257. package/dist/scramble.js.map +0 -1
  258. package/dist/session-mode.d.ts.map +0 -1
  259. package/dist/session-mode.js.map +0 -1
  260. package/dist/settings-resolver.d.ts.map +0 -1
  261. package/dist/settings-resolver.js +0 -148
  262. package/dist/settings-resolver.js.map +0 -1
  263. package/dist/single-select-layout.d.ts +0 -20
  264. package/dist/single-select-layout.d.ts.map +0 -1
  265. package/dist/single-select-layout.js.map +0 -1
  266. package/dist/sliding-prompt.d.ts.map +0 -1
  267. package/dist/sliding-prompt.js.map +0 -1
  268. package/dist/snapshot.d.ts.map +0 -1
  269. package/dist/snapshot.js.map +0 -1
  270. package/dist/spec-mode.d.ts +0 -13
  271. package/dist/spec-mode.d.ts.map +0 -1
  272. package/dist/spec-mode.js +0 -90
  273. package/dist/spec-mode.js.map +0 -1
  274. package/dist/structured-output.d.ts.map +0 -1
  275. package/dist/structured-output.js.map +0 -1
  276. package/dist/timed-bash.d.ts.map +0 -1
  277. package/dist/timed-bash.js.map +0 -1
  278. package/dist/tool-utils.d.ts.map +0 -1
  279. package/dist/tool-utils.js.map +0 -1
  280. package/dist/transitions.d.ts.map +0 -1
  281. package/dist/transitions.js.map +0 -1
  282. package/dist/types.d.ts +0 -208
  283. package/dist/types.d.ts.map +0 -1
  284. package/dist/types.js.map +0 -1
  285. package/dist/web-tool.d.ts.map +0 -1
  286. package/dist/web-tool.js.map +0 -1
  287. /package/dist/{agents.d.ts → core/agents.d.ts} +0 -0
  288. /package/dist/{depth.d.ts → core/depth.d.ts} +0 -0
  289. /package/dist/{transitions.d.ts → core/transitions.d.ts} +0 -0
  290. /package/dist/{notify-state.js → notify/notify-state.js} +0 -0
  291. /package/dist/{notify.d.ts → notify/notify.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/core/executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAM/D,OAAO,EAA8E,KAAK,sBAAsB,EAA0B,MAAM,qBAAqB,CAAC;AACtK,OAAO,EAAqD,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK7G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMpD,MAAM,WAAW,gBAAgB;IAChC,mCAAmC;IACnC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,2CAA2C;IAC3C,aAAa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Error, isFlowComplete, emptyFlowUsage } from "./types.js";
8
+ import { isFlowSuccess, isFlowError, isFlowComplete, emptyFlowUsage } from "../types/flow.js";
9
9
  import { getTransitionAdvice } from "./transitions.js";
10
10
  import { mapFlowConcurrent, runFlow } from "./flow.js";
11
- import { getFlowSummaryText } from "./runner-events.js";
12
- import { normalizeFlowModeName, resolveFlowModelCandidates, selectFlowModelStrategy } from "./config.js";
11
+ import { getFlowSummaryText } from "../snapshot/runner-events.js";
12
+ import { normalizeFlowModeName, resolveFlowModelCandidates, selectFlowModelStrategy } from "../config/config.js";
13
13
  import { getAgentSessionTimeoutMs, resolveAgentSessionMode } from "./session-mode.js";
14
- import { setFlowComplete } from "./notify-state.js";
14
+ import { setFlowComplete } from "../notify/notify-state.js";
15
+ import { setLiveText } from '../tui/scramble/index.js';
16
+ import { logWarn } from '../config/log.js';
17
+ import { markFlowCompleted } from '../flow/index.js';
15
18
  // ---------------------------------------------------------------------------
16
19
  // Helpers
17
20
  // ---------------------------------------------------------------------------
@@ -43,12 +46,25 @@ async function confirmProjectFlowsIfNeeded(projectFlows, projectFlowsDir, hasUI,
43
46
  // ---------------------------------------------------------------------------
44
47
  // Cache limits
45
48
  // ---------------------------------------------------------------------------
46
- const FLOW_RESULT_CACHE_MAX_ENTRIES = 50;
49
+ function resolveCacheMaxEntries() {
50
+ if (typeof process === "undefined")
51
+ return 100;
52
+ const env = process.env.PI_FLOW_CACHE_MAX_ENTRIES;
53
+ if (!env)
54
+ return 100;
55
+ const parsed = parseInt(env, 10);
56
+ if (Number.isNaN(parsed) || parsed < 1)
57
+ return 100;
58
+ return parsed;
59
+ }
60
+ const FLOW_RESULT_CACHE_MAX_ENTRIES = resolveCacheMaxEntries();
47
61
  /** Evict oldest entries from the cache when it exceeds the cap. */
48
- function evictCacheOverflow(cache) {
62
+ export function evictCacheOverflow(cache) {
49
63
  if (cache.size <= FLOW_RESULT_CACHE_MAX_ENTRIES)
50
64
  return;
51
65
  const excess = cache.size - FLOW_RESULT_CACHE_MAX_ENTRIES;
66
+ logWarn(`[pi-agent-flow] Flow result cache overflow: evicting ${excess} oldest entries. ` +
67
+ `Raising PI_FLOW_CACHE_MAX_ENTRIES (currently ${FLOW_RESULT_CACHE_MAX_ENTRIES}) may help for long sessions.`);
52
68
  const keys = cache.keys();
53
69
  for (let i = 0; i < excess; i++) {
54
70
  const next = keys.next();
@@ -83,7 +99,7 @@ function shouldFailover(result) {
83
99
  * project confirmation, parallel execution with model failover, and telemetry.
84
100
  */
85
101
  export async function executeFlows(deps, params, toolCallId) {
86
- const { flows, currentDepth, maxDepth, ancestorFlowStack, preventCycles, toolOptimize, structuredOutput, cwd, loadedFlowModelConfigs, maxConcurrency, defaultSessionMode, signal, onUpdate, makeDetails, getFlag, tierOverrideResolver, fallbackModel, forkSessionSnapshotJsonl, flowResultCache, projectFlowsDir, hasUI, uiConfirm, onFlowMetrics, confirmProjectFlows, } = deps;
102
+ const { flows, currentDepth, maxDepth, ancestorFlowStack, preventCycles, toolOptimize, structuredOutput, cwd, loadedFlowModelConfigs, maxConcurrency, defaultSessionMode, signal, onUpdate, makeDetails, getFlag, tierOverrideResolver, fallbackModel, forkSessionSnapshotJsonl, flowResultCache, projectFlowsDir, hasUI, uiConfirm, onFlowMetrics, confirmProjectFlows, goalContext, } = deps;
87
103
  const requested = new Set(params.map((f) => f.type.toLowerCase()));
88
104
  // Cycle check
89
105
  if (preventCycles) {
@@ -116,7 +132,7 @@ export async function executeFlows(deps, params, toolCallId) {
116
132
  const cliFlowMode = normalizeFlowModeName(getFlag("flow-mode"));
117
133
  const cliFlowModelConfig = normalizeFlowModeName(getFlag("flow-model-config"));
118
134
  if (cliFlowMode !== undefined && cliFlowModelConfig !== undefined && cliFlowMode !== cliFlowModelConfig) {
119
- console.warn(`[pi-agent-flow] Both --flow-mode "${cliFlowMode}" and --flow-model-config "${cliFlowModelConfig}" were provided. Using --flow-mode.`);
135
+ logWarn(`[pi-agent-flow] Both --flow-mode "${cliFlowMode}" and --flow-model-config "${cliFlowModelConfig}" were provided. Using --flow-mode.`);
120
136
  }
121
137
  const selectedFlowModelConfig = selectFlowModelStrategy(loadedFlowModelConfigs.configs, cliFlowMode ?? cliFlowModelConfig ?? loadedFlowModelConfigs.selectedName);
122
138
  // Pre-allocate results array
@@ -135,14 +151,29 @@ export async function executeFlows(deps, params, toolCallId) {
135
151
  };
136
152
  }
137
153
  // Streaming progress
138
- let lastStreamingText = "";
139
154
  let lastEmittedSignature;
140
155
  const emitProgress = (streamingText) => {
156
+ const activeStreamingText = allResults
157
+ .filter((r) => r.exitCode === -1)
158
+ .map((r) => r.streamingText)
159
+ .filter((text) => Boolean(text))
160
+ .at(-1);
161
+ const text = streamingText ?? activeStreamingText ?? "";
162
+ // (debug trace removed — was writing to /tmp/pi-flow-debug.log on every emitProgress call)
163
+ // Update live text store FIRST — always
164
+ const key = toolCallId || 'collapsed';
165
+ setLiveText(key, text);
166
+ setLiveText('collapsed', text);
167
+ for (let i = 0; i < allResults.length; i++) {
168
+ const r = allResults[i];
169
+ if (r.streamingText) {
170
+ setLiveText(`${key}#${i}`, r.streamingText);
171
+ setLiveText(`collapsed#${i}`, r.streamingText);
172
+ }
173
+ }
174
+ // Now check onUpdate for host callback
141
175
  if (!onUpdate)
142
176
  return;
143
- if (streamingText !== undefined)
144
- lastStreamingText = streamingText;
145
- const text = lastStreamingText || "";
146
177
  const signature = text +
147
178
  "|" +
148
179
  allResults
@@ -159,10 +190,10 @@ export async function executeFlows(deps, params, toolCallId) {
159
190
  onUpdate({
160
191
  content: [{ type: "text", text }],
161
192
  details: makeDetails([...allResults]),
193
+ _toolCallId: toolCallId,
162
194
  });
163
195
  };
164
- if (onUpdate)
165
- emitProgress();
196
+ emitProgress();
166
197
  // Execute all flows in parallel
167
198
  const executionStart = Date.now();
168
199
  const results = await mapFlowConcurrent(params, maxConcurrency, async (item, index) => {
@@ -220,10 +251,17 @@ export async function executeFlows(deps, params, toolCallId) {
220
251
  structuredOutput,
221
252
  sessionMode,
222
253
  model: candidateModel,
254
+ goalContext: deps.goalContext,
223
255
  signal,
224
256
  onUpdate: (partial) => {
225
257
  if (partial.details?.results[0]) {
226
258
  allResults[index] = partial.details.results[0];
259
+ // Update per-flow live text
260
+ const flowText = partial.content?.[0]?.text;
261
+ if (flowText !== undefined) {
262
+ setLiveText(`${toolCallId || 'collapsed'}#${index}`, flowText);
263
+ setLiveText(`collapsed#${index}`, flowText); // ← predictable fallback
264
+ }
227
265
  emitProgress(partial.content?.[0]?.text);
228
266
  }
229
267
  },
@@ -267,19 +305,44 @@ export async function executeFlows(deps, params, toolCallId) {
267
305
  if (lastResult) {
268
306
  setFlowComplete(lastResult.type, lastResult.acceptance, results.length - 1, results.length);
269
307
  }
308
+ // Mark flow completion for the continuation hold — gives the user
309
+ // time to read the result before the next flow auto-spawns.
310
+ markFlowCompleted(deps.sessionManager.getSessionId());
311
+ // Goal continuation callback
312
+ if (deps.goalContinuationCallback) {
313
+ await deps.goalContinuationCallback(results);
314
+ }
270
315
  // Cache flow results
271
316
  for (const result of results) {
272
317
  const so = result.structuredOutput;
273
- if (!so)
318
+ if (!so) {
319
+ logWarn(`[pi-agent-flow] Flow result for toolCallId=${toolCallId} type=${result.type} has no structuredOutput — cache entry skipped. This means child flows will see placeholder text instead of compressed results.`);
274
320
  continue;
321
+ }
275
322
  const compressed = {
276
323
  type: result.type,
277
324
  status: isFlowError(result) ? "failed" : "accomplished",
278
325
  };
326
+ if (result.intent)
327
+ compressed.intent = result.intent;
328
+ if (result.aim)
329
+ compressed.aim = result.aim;
330
+ if (so.summary)
331
+ compressed.summary = so.summary;
279
332
  if (so.files.length > 0)
280
333
  compressed.files = so.files;
334
+ if (so.actions.length > 0)
335
+ compressed.actions = so.actions;
281
336
  if (so.commands.length > 0)
282
337
  compressed.commands = so.commands;
338
+ if (so.notDone.length > 0)
339
+ compressed.notDone = so.notDone;
340
+ if (so.nextSteps.length > 0)
341
+ compressed.nextSteps = so.nextSteps;
342
+ if (so.reasoning.length > 0)
343
+ compressed.reasoning = so.reasoning;
344
+ if (so.notes.length > 0)
345
+ compressed.notes = so.notes;
283
346
  if (result.errorMessage)
284
347
  compressed.error = result.errorMessage;
285
348
  const existing = flowResultCache.get(toolCallId) ?? [];
@@ -305,6 +368,7 @@ export async function executeFlows(deps, params, toolCallId) {
305
368
  text: `Flow: ${successCount}/${results.length} completed\n\n${flowReports.join("\n\n---\n\n")}${advisorBlock}`,
306
369
  }],
307
370
  details: makeDetails(results),
371
+ _toolCallId: toolCallId,
308
372
  };
309
373
  }
310
374
  //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/core/executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAiB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,uBAAuB,EAAuD,MAAM,qBAAqB,CAAC;AACtK,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAyB,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAiFrD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,sBAAsB,CAC9B,cAA2B,EAC3B,iBAA2B;IAE3B,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,IAAI,iBAAiB,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C;IACD,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAEpC,oBAAoB;IACpB,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACpE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC;QAC1D,OAAO,SAAS,CAAC,CAAC,IAAI,KAAK,MAAM,OAAO,MAAM,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,yDAAyD;IACzD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC;QACvC,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;IAEN,OAAO;QACN,OAAO,EAAE,CAAC;gBACT,IAAI,EAAE,MAAe;gBACrB,IAAI,EAAE,SAAS,YAAY,IAAI,OAAO,CAAC,MAAM,iBAAiB,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,YAAY,EAAE;aAC9G,CAAC;QACF,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;QAC7B,WAAW,EAAE,UAAU;KACvB,CAAC;AACH,CAAC"}
@@ -6,8 +6,9 @@
6
6
  */
7
7
  import type { AgentToolResult } from "@mariozechner/pi-agent-core";
8
8
  import { type FlowConfig } from "./agents.js";
9
- import { type SingleResult, type FlowDetails } from "./types.js";
9
+ import { type SingleResult, type FlowDetails } from "../types/flow.js";
10
10
  import { type AgentSessionMode } from "./session-mode.js";
11
+ import type { GoalContext } from "../flow/types.js";
11
12
  /** Register a child process group for cleanup on shutdown. */
12
13
  export declare function registerChildGroup(pid: number, name: string): void;
13
14
  /** Unregister a completed/stopped child process group. */
@@ -62,6 +63,8 @@ export interface RunFlowOptions {
62
63
  makeDetails: (results: SingleResult[]) => FlowDetails;
63
64
  /** Child-flow session mode. Default: "default" (600s). */
64
65
  sessionMode?: AgentSessionMode;
66
+ /** Optional flow goal context to inject into the child prompt. */
67
+ goalContext?: GoalContext;
65
68
  }
66
69
  /**
67
70
  * Spawn a single flow process with forked session context.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/core/flow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,aAAa,CAAC;AAG3D,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,WAAW,EAIhB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAwD,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAChH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA2CpD,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIlE;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEtD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAsB9C;AAED,KAAK,kBAAkB,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;AA2J1E;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,EAC/B,YAAY,EAAE,OAAO,GACnB,MAAM,EAAE,GAAG,SAAS,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K,EAAE,GAAG,EAAE,EACZ,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC7C,OAAO,CAAC,IAAI,EAAE,CAAC,CAgBjB"}
@@ -8,10 +8,12 @@ import { spawn } from "node:child_process";
8
8
  import * as fs from "node:fs";
9
9
  import * as os from "node:os";
10
10
  import * as path from "node:path";
11
- import { getInheritedCliArgs } from "./cli-args.js";
12
- import { processFlowJsonLine, drainStreamingText, drainStreamingEstimate, drainCtxEstimate, updateSmoothedTps, drainSmoothedTps } from "./runner-events.js";
13
- import { emptyFlowUsage, getFlowOutput, normalizeFlowResult, } from "./types.js";
14
- import { extractStructuredOutput, generateCommandsFromHistory } from "./structured-output.js";
11
+ import { getFlowTier } from "./agents.js";
12
+ import { getInheritedCliArgs } from "../snapshot/cli-args.js";
13
+ import { processFlowJsonLine, drainStreamingText, drainStreamingEstimate, drainCtxEstimate, updateSmoothedTps, drainSmoothedTps } from "../snapshot/runner-events.js";
14
+ import { emptyFlowUsage, getFlowOutput, normalizeFlowResult, } from "../types/flow.js";
15
+ import { extractStructuredOutput, generateCommandsFromHistory } from "../snapshot/structured-output.js";
16
+ import { logWarn, logError } from '../config/log.js';
15
17
  import { DEFAULT_AGENT_SESSION_MODE, getAgentSessionTimeoutMs } from "./session-mode.js";
16
18
  const isWindows = process.platform === "win32";
17
19
  const SIGKILL_TIMEOUT_MS = 5000;
@@ -22,10 +24,14 @@ const FLOW_FINAL_URGE_MS = 135 * 1000; // final urge 135 s (2m15s) before kill (
22
24
  const REPORTING_GRACE_MS = 90_000; // grace period after timeout for agent to report findings (increased from 10s to 90s)
23
25
  const FLOW_TOOL_SUMMARY_GRACE_MS = FLOW_FINAL_URGE_MS; // bash/tool abort lead time so the agent can summarize
24
26
  import { FLOW_DEPTH_ENV, FLOW_MAX_DEPTH_ENV, FLOW_STACK_ENV, FLOW_PREVENT_CYCLES_ENV, FLOW_TOOL_OPTIMIZE_ENV, } from "./depth.js";
27
+ import { computeDelegationState, buildGuardLine, buildDelegationRule, buildFlowListSection, buildLineage, buildParentLineageHint, computeChildPropagation, } from "./delegation.js";
25
28
  const FLOW_DEADLINE_ENV = "PI_FLOW_DEADLINE_MS";
26
29
  const FLOW_TOOL_SUMMARY_GRACE_ENV = "PI_FLOW_TOOL_SUMMARY_GRACE_MS";
27
30
  const PI_OFFLINE_ENV = "PI_OFFLINE";
28
31
  const FLOW_REMINDER_FILE_ENV = "PI_FLOW_REMINDER_FILE";
32
+ const FLOW_DUMP_SNAPSHOT_ENV = "PI_FLOW_DUMP_SNAPSHOT";
33
+ const packageJsonPath = path.join(path.dirname(new URL(import.meta.url).pathname), "../..", "package.json");
34
+ const { version: pipelineVersion } = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
29
35
  // ---------------------------------------------------------------------------
30
36
  // Global child process group tracking for signal propagation
31
37
  // ---------------------------------------------------------------------------
@@ -135,6 +141,64 @@ function cleanupFlowTempDir(dir) {
135
141
  }
136
142
  }
137
143
  // ---------------------------------------------------------------------------
144
+ // Dump path helpers
145
+ // ---------------------------------------------------------------------------
146
+ function makeUniqueDumpPath(basePath, flowName) {
147
+ const ext = path.extname(basePath);
148
+ const base = ext ? basePath.slice(0, -ext.length) : basePath;
149
+ const timestamp = Date.now();
150
+ const safeFlowName = flowName.replace(/[^\w.-]+/g, "_");
151
+ return `${base}.${safeFlowName}.${timestamp}.md`;
152
+ }
153
+ function makeUniqueDumpTxtPath(mdPath) {
154
+ return mdPath.replace(/\.md$/, ".txt");
155
+ }
156
+ function atomicWriteFileSync(targetPath, data) {
157
+ const dir = path.dirname(targetPath);
158
+ const tmpPath = path.join(dir, `.tmp-${path.basename(targetPath)}.${Date.now()}`);
159
+ fs.writeFileSync(tmpPath, data, { encoding: "utf-8", mode: 0o600 });
160
+ fs.renameSync(tmpPath, targetPath);
161
+ }
162
+ // ---------------------------------------------------------------------------
163
+ // Dump TTL cleanup
164
+ // ---------------------------------------------------------------------------
165
+ /**
166
+ * Delete stale dump files from the dump directory.
167
+ * Called once at the start of each dump block to prevent unbounded accumulation.
168
+ * Silently skips on any error (defensive).
169
+ */
170
+ function cleanupStaleDumps(dumpPath, maxAgeHours = 168) {
171
+ try {
172
+ const dir = path.dirname(dumpPath);
173
+ const baseName = path.basename(dumpPath);
174
+ const ext = path.extname(baseName);
175
+ const base = ext ? baseName.slice(0, -ext.length) : baseName;
176
+ const entries = fs.readdirSync(dir);
177
+ const nowMs = Date.now();
178
+ const maxAgeMs = maxAgeHours * 60 * 60 * 1000;
179
+ let deleted = 0;
180
+ for (const entry of entries) {
181
+ // Match both pi-dump.* and snapshot-dump.* families, plus .txt twins
182
+ const isLegacyDump = entry.startsWith("snapshot-dump");
183
+ if (!entry.startsWith(base) && !isLegacyDump)
184
+ continue;
185
+ const entryPath = path.join(dir, entry);
186
+ try {
187
+ const stats = fs.statSync(entryPath);
188
+ if (nowMs - stats.mtimeMs > maxAgeMs) {
189
+ fs.unlinkSync(entryPath);
190
+ deleted++;
191
+ }
192
+ }
193
+ catch { /* ignore per-entry errors */ }
194
+ }
195
+ if (deleted > 0) {
196
+ logError(`[pi-agent-flow] Cleaned ${deleted} stale dump file(s) from ${dir}`);
197
+ }
198
+ }
199
+ catch { /* ignore all errors silently */ }
200
+ }
201
+ // ---------------------------------------------------------------------------
138
202
  // Reminder file helpers
139
203
  // ---------------------------------------------------------------------------
140
204
  /**
@@ -171,7 +235,7 @@ export function getOptimizedTools(flowTools, toolOptimize) {
171
235
  ? filtered
172
236
  : [...filtered, "batch"];
173
237
  }
174
- function buildFlowArgs(flow, intent, forkSessionPath, model, parentDepth = 0, maxDepth = 0, toolOptimize = false, structuredOutput = true, sessionMode = DEFAULT_AGENT_SESSION_MODE, sessionTimeoutMs = getAgentSessionTimeoutMs(sessionMode), acceptance) {
238
+ function buildFlowArgs(flow, intent, forkSessionPath, model, parentDepth = 0, maxDepth = 0, toolOptimize = false, structuredOutput = true, sessionMode = DEFAULT_AGENT_SESSION_MODE, sessionTimeoutMs = getAgentSessionTimeoutMs(sessionMode), acceptance, discoveredFlows = [], parentFlowStack = [], preventCycles = true, goalContext, cwd) {
175
239
  const args = [
176
240
  "--mode",
177
241
  "json",
@@ -212,17 +276,17 @@ function buildFlowArgs(flow, intent, forkSessionPath, model, parentDepth = 0, ma
212
276
  args.push("--thinking", thinking);
213
277
  // Compute delegation depth before building tool list — children that can
214
278
  // delegate need the "flow" tool in their available set.
215
- const currentDepth = Math.max(0, Math.floor(parentDepth)) + 1;
216
- const effectiveMaxDepth = Math.max(0, Math.floor(maxDepth));
217
- const canDelegate = currentDepth < effectiveMaxDepth;
218
- // Child flows get their configured tools from flow.tools, optimized by
219
- // getOptimizedTools. When toolOptimize is on and the child can delegate,
220
- // include "flow" so it can spawn sub-flows.
279
+ const { currentDepth, effectiveMaxDepth, canDelegate } = computeDelegationState(parentDepth, maxDepth);
280
+ // Default tools for child flows. Legacy read/write/edit are NOT registered
281
+ // for children only batch (which includes read/write ops) is available.
282
+ // The flow's frontmatter `tools` field overrides this default when set.
221
283
  const defaultTools = toolOptimize
222
284
  ? canDelegate
223
285
  ? ["batch", "bash", "flow", "web"]
224
286
  : ["batch", "bash", "web"]
225
- : ["read", "write", "edit", "batch", "bash", "flow", "web"];
287
+ : canDelegate
288
+ ? ["batch", "bash", "flow", "web"]
289
+ : ["batch", "bash", "web"];
226
290
  // getOptimizedTools replaces legacy read/write/edit with batch when
227
291
  // toolOptimize is on. If the flow's frontmatter explicitly lists "flow",
228
292
  // it passes through; otherwise the defaultTools above handle it.
@@ -245,17 +309,26 @@ function buildFlowArgs(flow, intent, forkSessionPath, model, parentDepth = 0, ma
245
309
  `Your task begins NOW. Do not respond to or continue anything from the history.\n` +
246
310
  `</context-seal>`;
247
311
  // Phase 2: Activation — role, tools, depth, delegation rules (dynamically generated)
248
- const delegationRule = canDelegate
249
- ? `You may delegate to sub-flows (depth ${currentDepth}/${effectiveMaxDepth}).`
250
- : `You may NOT delegate to sub-flows (depth limit reached).`;
312
+ const guardLine = buildGuardLine(currentDepth, effectiveMaxDepth, preventCycles, parentFlowStack);
313
+ const delegationRule = buildDelegationRule(canDelegate, guardLine);
314
+ const flowListSection = buildFlowListSection(canDelegate, discoveredFlows);
251
315
  const timeBudgetHint = sessionTimeoutMs > 0
252
316
  ? `Session mode: ${sessionMode}. Time budget: ${Math.round(sessionTimeoutMs / 1000)}s total. Long-running tools may be interrupted near the deadline to preserve final-summary time; if a tool reports [Flow timeout], stop tool use and output structured findings immediately.\n`
253
317
  : "";
254
- const activation = `\n\n<activation flow="${flow.name}" depth="${currentDepth}" tools="${availableTools}">\n` +
318
+ const effectiveTier = flow.tier ?? getFlowTier(flow.name);
319
+ const lineage = buildLineage(flow.name, parentFlowStack);
320
+ const parentLineageHint = buildParentLineageHint(parentFlowStack);
321
+ const projectHint = cwd && fs.existsSync(path.join(cwd, "CLAUDE.md"))
322
+ ? `Project index available at CLAUDE.md (read for architecture context if needed).\n`
323
+ : "";
324
+ const activation = `\n\n<activation flow="${flow.name}" depth="${currentDepth}" tools="${availableTools}" tier="${effectiveTier}" lineage="${lineage}">\n` +
255
325
  `You are a [${flow.name}] agent operating at depth ${currentDepth}.\n` +
256
326
  `Available tools: ${availableTools}.\n` +
257
327
  `${delegationRule}\n` +
328
+ `${flowListSection}` +
329
+ `${parentLineageHint}` +
258
330
  `${timeBudgetHint}` +
331
+ `${projectHint}` +
259
332
  `Do not attempt to use any tool outside the available set — it will fail.\n` +
260
333
  `</activation>`;
261
334
  // Phase 3: Directive — the flow's system prompt (renamed from <system-directive>)
@@ -275,8 +348,12 @@ function buildFlowArgs(flow, intent, forkSessionPath, model, parentDepth = 0, ma
275
348
  `\nExecute this mission. Use only your available tools. If blocked, report why — do not guess.\n` +
276
349
  `Follow the output format specified in your directive.\n` +
277
350
  `</mission>`;
351
+ // Phase 4.5: Flow goal context (optional)
352
+ const goalSection = goalContext?.objective
353
+ ? `\n\n<flow>\nObjective: ${goalContext.objective}\n${goalContext.acceptance ? `Acceptance: ${goalContext.acceptance}\n` : ""}${goalContext.maxFlows !== undefined ? `Progress: ${goalContext.flowCount ?? 0}/${goalContext.maxFlows} flows used.\n` : ""}</flow>`
354
+ : "";
278
355
  // -p must immediately precede the prompt so the CLI parser binds it correctly
279
- args.push("-p", `${contextSeal}${activation}${directive}${mission}`);
356
+ args.push("-p", `${contextSeal}${activation}${directive}${mission}${goalSection}`);
280
357
  return args;
281
358
  }
282
359
  /**
@@ -327,6 +404,7 @@ export async function runFlow(opts) {
327
404
  const streamingDelta = drainStreamingText(result);
328
405
  if (streamingDelta)
329
406
  liveStreamingText += streamingDelta;
407
+ // Live text is stored per-toolCallId by the executor's emitProgress, not here.
330
408
  const estimatedTokens = drainStreamingEstimate(result);
331
409
  if (result.usage.output !== lastActualOutputTokens) {
332
410
  lastActualOutputTokens = result.usage.output;
@@ -364,16 +442,76 @@ export async function runFlow(opts) {
364
442
  reminderFilePath = path.join(reminderTmpDir, "reminder.txt");
365
443
  }
366
444
  try {
367
- const piArgs = buildFlowArgs(flow, intent, forkSessionTmpPath, model, parentDepth, maxDepth, toolOptimize, structuredOutput, effectiveSessionMode, effectiveTimeout, opts.acceptance);
445
+ const piArgs = buildFlowArgs(flow, intent, forkSessionTmpPath, model, parentDepth, maxDepth, toolOptimize, structuredOutput, effectiveSessionMode, effectiveTimeout, opts.acceptance, flows, parentFlowStack, preventCycles, opts.goalContext, cwd);
446
+ // Dump verbatim child payload to disk for debugging when requested.
447
+ const dumpPath = process.env[FLOW_DUMP_SNAPSHOT_ENV] || inheritedCliArgs.dumpPath;
448
+ if (dumpPath) {
449
+ const maxAgeHours = Number(process.env.PI_FLOW_DUMP_MAX_AGE_HOURS);
450
+ cleanupStaleDumps(dumpPath, Number.isFinite(maxAgeHours) && maxAgeHours > 0 ? maxAgeHours : 168);
451
+ const promptIndex = piArgs.indexOf("-p");
452
+ const prompt = promptIndex >= 0 ? piArgs[promptIndex + 1] : "";
453
+ // Extract compression stats and applied passes from the trailing JSONL entry if present.
454
+ let compressionStats = "";
455
+ let passesApplied = [];
456
+ if (forkSessionSnapshotJsonl) {
457
+ const lines = forkSessionSnapshotJsonl.trimEnd().split("\n");
458
+ const lastLine = lines[lines.length - 1];
459
+ try {
460
+ const lastEntry = JSON.parse(lastLine);
461
+ if (lastEntry?.type === "compression-stats") {
462
+ compressionStats = `\n\n## Compression Stats\n\n- Pre-sanitization: ${lastEntry.preBytes} bytes\n- Post-sanitization: ${lastEntry.postBytes} bytes\n- Reduction: ${lastEntry.reductionPercent}%`;
463
+ passesApplied = Array.isArray(lastEntry.passesApplied) ? lastEntry.passesApplied : [];
464
+ }
465
+ }
466
+ catch { /* ignore */ }
467
+ }
468
+ const effectiveTier = flow.tier ?? getFlowTier(flow.name);
469
+ const passesList = passesApplied.length > 0 ? passesApplied.join(", ") : forkSessionSnapshotJsonl ? "sanitizeForkSnapshot (see src/snapshot.ts)" : "(none — cold start)";
470
+ const sanitizationHeader = `<!-- pi-agent-flow dump | State: post-sanitization | Passes: ${passesList} | Flow: ${flow.name} | Tier: ${effectiveTier} | Pipeline: ${pipelineVersion} | Generated: ${new Date().toISOString()} -->`;
471
+ const markdownParts = [
472
+ sanitizationHeader,
473
+ ``,
474
+ ];
475
+ if (forkSessionSnapshotJsonl) {
476
+ markdownParts.push(`## Session Snapshot (JSONL)`, ``, ...forkSessionSnapshotJsonl.split("\n"), ``);
477
+ }
478
+ markdownParts.push(`## Activation Prompt (-p)`, ``, prompt, compressionStats);
479
+ const markdown = markdownParts.join("\n");
480
+ const uniqueDumpPath = makeUniqueDumpPath(dumpPath, flow.name);
481
+ const uniqueTxtPath = makeUniqueDumpTxtPath(uniqueDumpPath);
482
+ try {
483
+ atomicWriteFileSync(uniqueDumpPath, markdown);
484
+ atomicWriteFileSync(uniqueTxtPath, prompt);
485
+ logError(`[pi-agent-flow] Snapshot dumped to ${uniqueDumpPath}`);
486
+ }
487
+ catch (err) {
488
+ logError(`[pi-agent-flow] Snapshot dump FAILED: ${err}`);
489
+ }
490
+ }
368
491
  let wasAborted = false;
369
492
  const exitCode = await new Promise((resolve) => {
370
- const nextDepth = Math.max(0, Math.floor(parentDepth)) + 1;
371
- const propagatedMaxDepth = Math.max(0, Math.floor(maxDepth));
372
- const propagatedStack = [...parentFlowStack, normalizedFlowName];
493
+ const { nextDepth, propagatedMaxDepth, propagatedStack } = computeChildPropagation(parentDepth, maxDepth, parentFlowStack, normalizedFlowName);
373
494
  const proportionalGraceMs = Math.floor(effectiveTimeout * 0.1);
374
495
  const minimumGraceMs = effectiveTimeout >= 10_000 ? 1_000 : Math.floor(effectiveTimeout / 2);
375
496
  const toolSummaryGraceMs = Math.min(FLOW_TOOL_SUMMARY_GRACE_MS, Math.max(0, effectiveTimeout), Math.max(minimumGraceMs, proportionalGraceMs));
376
497
  const { command, prefixArgs } = resolveFlowSpawn();
498
+ if (dumpPath) {
499
+ const distDir = path.dirname(new URL(import.meta.url).pathname);
500
+ const srcDir = path.join(distDir, "..", "src");
501
+ const checkStale = (srcFile, distFile) => {
502
+ try {
503
+ const srcMtime = fs.statSync(path.join(srcDir, srcFile)).mtimeMs;
504
+ const distMtime = fs.statSync(path.join(distDir, distFile)).mtimeMs;
505
+ return srcMtime > distMtime;
506
+ }
507
+ catch {
508
+ return false;
509
+ }
510
+ };
511
+ if (checkStale("snapshot.ts", "snapshot.js") || checkStale("flow.ts", "flow.js")) {
512
+ logWarn("⚠️ Source newer than dist — run npm run build for accurate dumps");
513
+ }
514
+ }
377
515
  const proc = spawn(command, [...prefixArgs, ...piArgs], {
378
516
  cwd: taskCwd ?? cwd,
379
517
  shell: false,
@@ -424,6 +562,7 @@ export async function runFlow(opts) {
424
562
  let timeoutFired = false;
425
563
  let semanticCompletionTimer;
426
564
  let countdownTimer;
565
+ let renderTimer;
427
566
  let finishKillTimer;
428
567
  const clearSemanticCompletionTimer = () => {
429
568
  if (semanticCompletionTimer) {
@@ -437,6 +576,12 @@ export async function runFlow(opts) {
437
576
  countdownTimer = undefined;
438
577
  }
439
578
  };
579
+ const clearRenderTimer = () => {
580
+ if (renderTimer) {
581
+ clearInterval(renderTimer);
582
+ renderTimer = undefined;
583
+ }
584
+ };
440
585
  const terminateChild = () => {
441
586
  endStdin();
442
587
  if (isWindows) {
@@ -490,6 +635,7 @@ export async function runFlow(opts) {
490
635
  endStdin();
491
636
  clearSemanticCompletionTimer();
492
637
  clearCountdownTimer();
638
+ clearRenderTimer();
493
639
  if (signal && abortHandler) {
494
640
  signal.removeEventListener("abort", abortHandler);
495
641
  }
@@ -543,13 +689,21 @@ export async function runFlow(opts) {
543
689
  };
544
690
  proc.stdout.on("data", onStdoutData);
545
691
  proc.stderr.on("data", onStderrData);
546
- if (onUpdate && effectiveTimeout > 0) {
547
- countdownTimer = setInterval(() => {
692
+ if (onUpdate) {
693
+ renderTimer = setInterval(() => {
548
694
  if (didClose || settled)
549
695
  return;
550
696
  emitUpdate();
551
- }, 1000);
552
- countdownTimer.unref();
697
+ }, 200);
698
+ renderTimer.unref();
699
+ if (effectiveTimeout > 0) {
700
+ countdownTimer = setInterval(() => {
701
+ if (didClose || settled)
702
+ return;
703
+ emitUpdate();
704
+ }, 1000);
705
+ countdownTimer.unref();
706
+ }
553
707
  }
554
708
  proc.on("close", (code) => {
555
709
  didClose = true;