pi-agent-flow 1.8.1 → 1.8.3

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 (154) hide show
  1. package/README.md +4 -30
  2. package/agents/audit.md +1 -2
  3. package/agents/build.md +1 -0
  4. package/agents/craft.md +12 -8
  5. package/agents/debug.md +2 -2
  6. package/agents/ideas.md +1 -0
  7. package/agents/scout.md +1 -0
  8. package/dist/agents.d.ts +41 -0
  9. package/dist/agents.d.ts.map +1 -0
  10. package/dist/agents.js +283 -0
  11. package/dist/agents.js.map +1 -0
  12. package/dist/batch/batch-bash.d.ts +87 -0
  13. package/dist/batch/batch-bash.d.ts.map +1 -0
  14. package/dist/batch/batch-bash.js +369 -0
  15. package/dist/batch/batch-bash.js.map +1 -0
  16. package/dist/batch/constants.d.ts +100 -0
  17. package/dist/batch/constants.d.ts.map +1 -0
  18. package/dist/batch/constants.js +15 -0
  19. package/dist/batch/constants.js.map +1 -0
  20. package/dist/batch/execute.d.ts +21 -0
  21. package/dist/batch/execute.d.ts.map +1 -0
  22. package/dist/batch/execute.js +440 -0
  23. package/dist/batch/execute.js.map +1 -0
  24. package/dist/batch/fuzzy-edit.d.ts +29 -0
  25. package/dist/batch/fuzzy-edit.d.ts.map +1 -0
  26. package/dist/batch/fuzzy-edit.js +257 -0
  27. package/dist/batch/fuzzy-edit.js.map +1 -0
  28. package/dist/batch/index.d.ts +85 -0
  29. package/dist/batch/index.d.ts.map +1 -0
  30. package/dist/batch/index.js +422 -0
  31. package/dist/batch/index.js.map +1 -0
  32. package/dist/batch/render.d.ts +14 -0
  33. package/dist/batch/render.d.ts.map +1 -0
  34. package/dist/batch/render.js +74 -0
  35. package/dist/batch/render.js.map +1 -0
  36. package/dist/batch/symbols.d.ts +9 -0
  37. package/dist/batch/symbols.d.ts.map +1 -0
  38. package/dist/batch/symbols.js +310 -0
  39. package/dist/batch/symbols.js.map +1 -0
  40. package/dist/batch.d.ts +12 -0
  41. package/dist/batch.d.ts.map +1 -0
  42. package/dist/batch.js +11 -0
  43. package/dist/batch.js.map +1 -0
  44. package/dist/cli-args.d.ts +27 -0
  45. package/dist/cli-args.d.ts.map +1 -0
  46. package/dist/cli-args.js +265 -0
  47. package/dist/cli-args.js.map +1 -0
  48. package/dist/config.d.ts +58 -0
  49. package/dist/config.d.ts.map +1 -0
  50. package/dist/config.js +296 -0
  51. package/dist/config.js.map +1 -0
  52. package/dist/depth.d.ts +25 -0
  53. package/dist/depth.d.ts.map +1 -0
  54. package/dist/depth.js +160 -0
  55. package/dist/depth.js.map +1 -0
  56. package/dist/executor.d.ts +87 -0
  57. package/dist/executor.d.ts.map +1 -0
  58. package/dist/executor.js +295 -0
  59. package/dist/executor.js.map +1 -0
  60. package/dist/flow-prompt.d.ts +23 -0
  61. package/dist/flow-prompt.d.ts.map +1 -0
  62. package/dist/flow-prompt.js +99 -0
  63. package/dist/flow-prompt.js.map +1 -0
  64. package/dist/flow.d.ts +76 -0
  65. package/dist/flow.d.ts.map +1 -0
  66. package/dist/flow.js +704 -0
  67. package/dist/flow.js.map +1 -0
  68. package/dist/index.d.ts +10 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +327 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/reasoning-strip.d.ts +26 -0
  73. package/dist/reasoning-strip.d.ts.map +1 -0
  74. package/dist/reasoning-strip.js +58 -0
  75. package/dist/reasoning-strip.js.map +1 -0
  76. package/dist/render-utils.d.ts +42 -0
  77. package/dist/render-utils.d.ts.map +1 -0
  78. package/dist/render-utils.js +182 -0
  79. package/dist/render-utils.js.map +1 -0
  80. package/dist/render.d.ts +24 -0
  81. package/dist/render.d.ts.map +1 -0
  82. package/dist/render.js +409 -0
  83. package/dist/render.js.map +1 -0
  84. package/dist/runner-events.d.ts +59 -0
  85. package/dist/runner-events.d.ts.map +1 -0
  86. package/dist/runner-events.js +539 -0
  87. package/dist/runner-events.js.map +1 -0
  88. package/dist/session-mode.d.ts +10 -0
  89. package/dist/session-mode.d.ts.map +1 -0
  90. package/dist/session-mode.js +25 -0
  91. package/dist/session-mode.js.map +1 -0
  92. package/dist/settings-resolver.d.ts +28 -0
  93. package/dist/settings-resolver.d.ts.map +1 -0
  94. package/dist/settings-resolver.js +148 -0
  95. package/dist/settings-resolver.js.map +1 -0
  96. package/dist/sliding-prompt.d.ts +40 -0
  97. package/dist/sliding-prompt.d.ts.map +1 -0
  98. package/dist/sliding-prompt.js +121 -0
  99. package/dist/sliding-prompt.js.map +1 -0
  100. package/dist/snapshot.d.ts +29 -0
  101. package/dist/snapshot.d.ts.map +1 -0
  102. package/dist/snapshot.js +199 -0
  103. package/dist/snapshot.js.map +1 -0
  104. package/dist/structured-output.d.ts +36 -0
  105. package/dist/structured-output.d.ts.map +1 -0
  106. package/dist/structured-output.js +244 -0
  107. package/dist/structured-output.js.map +1 -0
  108. package/dist/timed-bash.d.ts +45 -0
  109. package/dist/timed-bash.d.ts.map +1 -0
  110. package/dist/timed-bash.js +219 -0
  111. package/dist/timed-bash.js.map +1 -0
  112. package/dist/tool-utils.d.ts +20 -0
  113. package/dist/tool-utils.d.ts.map +1 -0
  114. package/dist/tool-utils.js +38 -0
  115. package/dist/tool-utils.js.map +1 -0
  116. package/dist/transitions.d.ts +39 -0
  117. package/dist/transitions.d.ts.map +1 -0
  118. package/dist/transitions.js +59 -0
  119. package/dist/transitions.js.map +1 -0
  120. package/dist/types.d.ts +207 -0
  121. package/dist/types.d.ts.map +1 -0
  122. package/dist/types.js +143 -0
  123. package/dist/types.js.map +1 -0
  124. package/dist/web-tool.d.ts +35 -0
  125. package/dist/web-tool.d.ts.map +1 -0
  126. package/dist/web-tool.js +545 -0
  127. package/dist/web-tool.js.map +1 -0
  128. package/package.json +7 -5
  129. package/src/agents.ts +0 -299
  130. package/src/ambient.d.ts +0 -107
  131. package/src/batch/batch-bash.ts +0 -443
  132. package/src/batch/constants.ts +0 -128
  133. package/src/batch/execute.ts +0 -551
  134. package/src/batch/fuzzy-edit.ts +0 -323
  135. package/src/batch/index.ts +0 -494
  136. package/src/batch/render.ts +0 -81
  137. package/src/batch/symbols.ts +0 -341
  138. package/src/batch.ts +0 -28
  139. package/src/cli-args.ts +0 -315
  140. package/src/config.ts +0 -391
  141. package/src/executor.ts +0 -445
  142. package/src/flow.ts +0 -834
  143. package/src/hooks.ts +0 -294
  144. package/src/index.ts +0 -1132
  145. package/src/render-utils.ts +0 -205
  146. package/src/render.ts +0 -524
  147. package/src/runner-events.ts +0 -692
  148. package/src/session-mode.ts +0 -33
  149. package/src/sliding-prompt.ts +0 -144
  150. package/src/structured-output.ts +0 -195
  151. package/src/timed-bash.ts +0 -270
  152. package/src/transitions.ts +0 -86
  153. package/src/types.ts +0 -386
  154. package/src/web-tool.ts +0 -663
package/src/hooks.ts DELETED
@@ -1,294 +0,0 @@
1
- /**
2
- * Post-flow hook registry.
3
- *
4
- * Hooks inject advisory messages into flow tool results after execution.
5
- * Built-in hooks fire automatically; user hooks can be registered via `registerHook()`.
6
- */
7
-
8
- import {
9
- type PostFlowHook,
10
- type AutoTransition,
11
- type SingleResult,
12
- isFlowSuccess,
13
- } from "./types.js";
14
-
15
- // ---------------------------------------------------------------------------
16
- // Module-scoped hook registry
17
- // ---------------------------------------------------------------------------
18
-
19
- const hooks: PostFlowHook[] = [];
20
-
21
- /**
22
- * Register or replace a hook by name.
23
- * If a hook with the same name already exists, it is replaced.
24
- */
25
- export function registerHook(hook: PostFlowHook): void {
26
- const idx = hooks.findIndex((h) => h.name === hook.name);
27
- if (idx >= 0) hooks[idx] = hook;
28
- else hooks.push(hook);
29
- }
30
-
31
- /**
32
- * Unregister a hook by name.
33
- * Returns true if a hook was removed, false if no hook with that name existed.
34
- */
35
- export function unregisterHook(name: string): boolean {
36
- const idx = hooks.findIndex((h) => h.name === name);
37
- if (idx < 0) return false;
38
- hooks.splice(idx, 1);
39
- return true;
40
- }
41
-
42
- export interface RunHooksResult {
43
- /** Advisory messages sorted by priority. */
44
- advisors: string[];
45
- /** Auto-transitions collected from hooks. */
46
- autoTransitions: AutoTransition[];
47
- }
48
-
49
- /**
50
- * Run all registered hooks against the given flow results.
51
- * Returns advisory strings sorted by priority and auto-transitions.
52
- */
53
- export function runHooks(
54
- params: Array<{ type: string; intent: string }>,
55
- results: SingleResult[],
56
- ): string[] {
57
- const raw = runHooksDetailed(params, results);
58
- return raw.advisors;
59
- }
60
-
61
- /**
62
- * Run all hooks and return both advisors and auto-transitions.
63
- *
64
- * Each hook action is wrapped in try/catch so one bad hook cannot crash
65
- * the pipeline. Failures are reported as advisory warnings.
66
- */
67
- export function runHooksDetailed(
68
- params: Array<{ type: string; intent: string }>,
69
- results: SingleResult[],
70
- ): RunHooksResult {
71
- const messages: Array<{ priority: number; content: string }> = [];
72
- const transitions: AutoTransition[] = [];
73
-
74
- for (const hook of hooks) {
75
- const triggerTypes = new Set(
76
- hook.trigger.flowTypes.map((t) => t.toLowerCase()),
77
- );
78
- const onlyOnSuccess = hook.trigger.onlyOnSuccess !== false;
79
-
80
- const matching = results.filter((r) => triggerTypes.has(r.type));
81
- if (matching.length === 0) continue;
82
- if (onlyOnSuccess && !matching.every((r) => isFlowSuccess(r))) continue;
83
-
84
- try {
85
- const result = hook.action({ results: matching, params });
86
- if (result) {
87
- messages.push({ priority: result.priority ?? 0, content: result.content });
88
- if (result.autoTransition) {
89
- transitions.push(result.autoTransition);
90
- }
91
- }
92
- } catch (err) {
93
- const errorMessage = err instanceof Error ? err.message : String(err);
94
- messages.push({
95
- priority: 999,
96
- content: `Hook "${hook.name}" failed: ${errorMessage}`,
97
- });
98
- }
99
- }
100
-
101
- messages.sort((a, b) => a.priority - b.priority);
102
- return {
103
- advisors: messages.map((m) => m.content),
104
- autoTransitions: transitions,
105
- };
106
- }
107
-
108
- /**
109
- * Get a snapshot of all registered hooks. For introspection and plugin API.
110
- */
111
- export function getRegisteredHooks(): PostFlowHook[] {
112
- return [...hooks];
113
- }
114
-
115
- /**
116
- * Clear all registered hooks. For testing only.
117
- */
118
- export function clearHooks(): void {
119
- hooks.length = 0;
120
- }
121
-
122
- // ---------------------------------------------------------------------------
123
- // Built-in hooks — success transitions
124
- // ---------------------------------------------------------------------------
125
-
126
- /** Suggest audit flow after a successful build flow. */
127
- registerHook({
128
- name: "pi-agent-flow/build-to-audit",
129
- trigger: { flowTypes: ["build"], onlyOnSuccess: true },
130
- action: (ctx) => {
131
- const auditWasRequested = ctx.params.some(
132
- (p) => p.type.toLowerCase() === "audit",
133
- );
134
- if (auditWasRequested) return null;
135
-
136
- return {
137
- content:
138
- "Consider running a [audit] flow to audit the changes for security, correctness, and code quality.",
139
- priority: 10,
140
- };
141
- },
142
- });
143
-
144
- /** Suggest build flow after a successful debug flow. */
145
- registerHook({
146
- name: "pi-agent-flow/debug-to-build",
147
- trigger: { flowTypes: ["debug"], onlyOnSuccess: true },
148
- action: (ctx) => {
149
- const buildWasRequested = ctx.params.some(
150
- (p) => p.type.toLowerCase() === "build",
151
- );
152
- if (buildWasRequested) return null;
153
-
154
- return {
155
- content:
156
- "The root cause has been identified. Consider running a [build] flow to implement the fix.",
157
- priority: 10,
158
- };
159
- },
160
- });
161
-
162
- /** Suggest scout flow after a successful audit flow. */
163
- registerHook({
164
- name: "pi-agent-flow/audit-to-scout",
165
- trigger: { flowTypes: ["audit"], onlyOnSuccess: true },
166
- action: (ctx) => {
167
- const scoutWasRequested = ctx.params.some(
168
- (p) => p.type.toLowerCase() === "scout",
169
- );
170
- if (scoutWasRequested) return null;
171
-
172
- return {
173
- content:
174
- "Audit complete. Consider running a [scout] flow to trace the audit findings across the codebase.",
175
- priority: 15,
176
- };
177
- },
178
- });
179
-
180
- /** Suggest build or debug flow after a successful scout flow. */
181
- registerHook({
182
- name: "pi-agent-flow/scout-to-build",
183
- trigger: { flowTypes: ["scout"], onlyOnSuccess: true },
184
- action: (ctx) => {
185
- const alreadyRequested = ctx.params.some(
186
- (p) => ["build", "debug"].includes(p.type.toLowerCase()),
187
- );
188
- if (alreadyRequested) return null;
189
-
190
- return {
191
- content:
192
- "Context mapped. Consider running a [build] flow to implement changes, or [debug] if investigating an issue.",
193
- priority: 20,
194
- };
195
- },
196
- });
197
-
198
- /** Suggest build flow after a successful craft flow. */
199
- registerHook({
200
- name: "pi-agent-flow/craft-to-build",
201
- trigger: { flowTypes: ["craft"], onlyOnSuccess: true },
202
- action: (ctx) => {
203
- const buildWasRequested = ctx.params.some(
204
- (p) => p.type.toLowerCase() === "build",
205
- );
206
- if (buildWasRequested) return null;
207
-
208
- return {
209
- content:
210
- "Plan ready. Consider running a [build] flow to implement the design.",
211
- priority: 10,
212
- };
213
- },
214
- });
215
-
216
- /** Suggest craft or build flow after a successful ideas flow. */
217
- registerHook({
218
- name: "pi-agent-flow/ideas-to-craft",
219
- trigger: { flowTypes: ["ideas"], onlyOnSuccess: true },
220
- action: (ctx) => {
221
- const alreadyRequested = ctx.params.some(
222
- (p) => ["craft", "build"].includes(p.type.toLowerCase()),
223
- );
224
- if (alreadyRequested) return null;
225
-
226
- return {
227
- content:
228
- "Ideas explored. Consider running a [craft] flow to design the approach, or [build] to implement directly.",
229
- priority: 15,
230
- };
231
- },
232
- });
233
-
234
- /** Suggest audit flow after a successful debug flow. */
235
- registerHook({
236
- name: "pi-agent-flow/debug-to-audit",
237
- trigger: { flowTypes: ["debug"], onlyOnSuccess: true },
238
- action: (ctx) => {
239
- const auditWasRequested = ctx.params.some(
240
- (p) => p.type.toLowerCase() === "audit",
241
- );
242
- if (auditWasRequested) return null;
243
-
244
- return {
245
- content:
246
- "Root cause identified. Consider running an [audit] flow to verify the fix area for related issues.",
247
- priority: 20,
248
- };
249
- },
250
- });
251
-
252
- // ---------------------------------------------------------------------------
253
- // Built-in hooks — failure transitions
254
- // ---------------------------------------------------------------------------
255
-
256
- /** Suggest debug flow after a failed build flow. */
257
- registerHook({
258
- name: "pi-agent-flow/build-to-debug-on-failure",
259
- trigger: { flowTypes: ["build"], onlyOnSuccess: false },
260
- action: (ctx) => {
261
- const allSucceeded = ctx.results.every((r) => isFlowSuccess(r));
262
- if (allSucceeded) return null;
263
- const debugWasRequested = ctx.params.some(
264
- (p) => p.type.toLowerCase() === "debug",
265
- );
266
- if (debugWasRequested) return null;
267
-
268
- return {
269
- content:
270
- "Build failed. Consider running a [debug] flow to investigate the root cause.",
271
- priority: 10,
272
- };
273
- },
274
- });
275
-
276
- /** Suggest build flow after a failed audit flow (found issues). */
277
- registerHook({
278
- name: "pi-agent-flow/audit-to-build-on-failure",
279
- trigger: { flowTypes: ["audit"], onlyOnSuccess: false },
280
- action: (ctx) => {
281
- const allSucceeded = ctx.results.every((r) => isFlowSuccess(r));
282
- if (allSucceeded) return null;
283
- const buildWasRequested = ctx.params.some(
284
- (p) => p.type.toLowerCase() === "build",
285
- );
286
- if (buildWasRequested) return null;
287
-
288
- return {
289
- content:
290
- "Audit found issues. Consider running a [build] flow to fix them.",
291
- priority: 10,
292
- };
293
- },
294
- });