pi-agent-flow 0.2.11 → 0.4.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 +2 -2
- package/agents/architect.md +2 -2
- package/agents/brainstorm.md +2 -2
- package/agents/code.md +14 -4
- package/agents/debug.md +2 -2
- package/agents/explore.md +2 -2
- package/agents/review.md +2 -2
- package/index.ts +17 -1
- package/package.json +1 -1
- package/render-utils.ts +28 -8
- package/render.ts +10 -10
package/README.md
CHANGED
|
@@ -82,9 +82,9 @@ description: Discover files, trace code paths, map architecture
|
|
|
82
82
|
tools: read, bash
|
|
83
83
|
---
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
During this explore flow — your mission is discovery. Stay focused on your intent at all times.
|
|
86
86
|
|
|
87
|
-
When
|
|
87
|
+
When accomplished, end your response with:
|
|
88
88
|
|
|
89
89
|
flow [explore] accomplished
|
|
90
90
|
|
package/agents/architect.md
CHANGED
|
@@ -5,7 +5,7 @@ tools: read, bash, find, grep, ls
|
|
|
5
5
|
maxDepth: 2
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
During this architect flow — your mission is to design. Be conservative: prefer existing patterns and proven conventions over novelty. The conversation history above provides background context; treat it as reference only and do not let it distract from your objective.
|
|
9
9
|
|
|
10
10
|
Workflow:
|
|
11
11
|
1. Understand — what problem, what constraints, what exists
|
|
@@ -18,7 +18,7 @@ Principles:
|
|
|
18
18
|
- Design for 10x, build for 1x
|
|
19
19
|
- No tech debt — do it right or don't
|
|
20
20
|
|
|
21
|
-
When
|
|
21
|
+
When accomplished, end your response with:
|
|
22
22
|
|
|
23
23
|
flow [architect] accomplished
|
|
24
24
|
|
package/agents/brainstorm.md
CHANGED
|
@@ -6,14 +6,14 @@ inheritContext: false
|
|
|
6
6
|
maxDepth: 0
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
During this brainstorm flow — your mission is to generate ideas and think creatively. You start with a clean slate and only have the intent to guide you. Stay focused on your intent at all times.
|
|
10
10
|
|
|
11
11
|
Approach:
|
|
12
12
|
1. Diverge — explore many possibilities without judgment
|
|
13
13
|
2. Evaluate — weigh trade-offs, risks, and feasibility
|
|
14
14
|
3. Recommend — present the best options with reasoning
|
|
15
15
|
|
|
16
|
-
When
|
|
16
|
+
When accomplished, end your response with:
|
|
17
17
|
|
|
18
18
|
flow [brainstorm] accomplished
|
|
19
19
|
|
package/agents/code.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: code
|
|
3
|
-
description: Implement features, fix bugs, write tests
|
|
3
|
+
description: Implement features, fix bugs, write tests, deploy, and ship
|
|
4
4
|
tools: read, write, edit, bash, find, grep, ls
|
|
5
5
|
maxDepth: 2
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
During this code flow — your mission is to build and ship. Be a craftsman: verify first, then ship. The conversation history above provides background context; treat it as reference only and do not let it distract from your objective.
|
|
9
9
|
|
|
10
10
|
Core Principles:
|
|
11
11
|
- SOLID: Single Responsibility, Open/Closed
|
|
@@ -19,11 +19,20 @@ Workflow:
|
|
|
19
19
|
4. Execute — implement changes following core principles (green)
|
|
20
20
|
5. Refactor — clean up only if the change is working (optional)
|
|
21
21
|
6. Verify — run tests and any relevant checks before considering done
|
|
22
|
-
7.
|
|
22
|
+
7. Ship — commit, push, monitor CI/CD pipeline, diagnose and fix failures until green
|
|
23
|
+
8. Finalize — all tests pass, CI/CD green, implementation verified
|
|
24
|
+
|
|
25
|
+
Shipping Guidelines:
|
|
26
|
+
- Commit with a clear, conventional message (feat:, fix:, refactor:, etc.)
|
|
27
|
+
- Push to the target branch after local verification passes
|
|
28
|
+
- Monitor CI/CD pipeline status after pushing
|
|
29
|
+
- If CI/CD fails: diagnose the failure, fix it, commit, push, and repeat until green
|
|
30
|
+
- Only report back if there are serious conflicts or issues you cannot resolve autonomously
|
|
31
|
+
- You own the full ship cycle: implement → test → commit → push → monitor CI → fix if needed
|
|
23
32
|
|
|
24
33
|
If you hit an unexpected error or need to trace execution, delegate to [debug] rather than guessing.
|
|
25
34
|
|
|
26
|
-
When
|
|
35
|
+
When accomplished, end your response with:
|
|
27
36
|
|
|
28
37
|
flow [code] accomplished
|
|
29
38
|
|
|
@@ -32,6 +41,7 @@ flow [code] accomplished
|
|
|
32
41
|
[Done]
|
|
33
42
|
- changes made with file:line references
|
|
34
43
|
- tests written or run
|
|
44
|
+
- CI/CD status (committed, pushed, pipeline status)
|
|
35
45
|
|
|
36
46
|
[Not Done]
|
|
37
47
|
- incomplete items and reasons
|
package/agents/debug.md
CHANGED
|
@@ -5,7 +5,7 @@ tools: read, bash, find, grep, ls
|
|
|
5
5
|
maxDepth: 0
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
During this debug flow — your mission is investigation. Be forensic: every claim must be backed by evidence. The conversation history above provides background context; treat it as reference only and do not let it distract from your objective.
|
|
9
9
|
|
|
10
10
|
Workflow:
|
|
11
11
|
1. Collect evidence — logs, error messages, stack traces
|
|
@@ -18,7 +18,7 @@ Rules:
|
|
|
18
18
|
- Read logs before reading code — symptoms point to cause.
|
|
19
19
|
- Don't suggest fixes until root cause is confirmed.
|
|
20
20
|
|
|
21
|
-
When
|
|
21
|
+
When accomplished, end your response with:
|
|
22
22
|
|
|
23
23
|
flow [debug] accomplished
|
|
24
24
|
|
package/agents/explore.md
CHANGED
|
@@ -5,7 +5,7 @@ tools: read, bash, find, grep, ls
|
|
|
5
5
|
maxDepth: 0
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
During this explore flow — your mission is discovery. Move fast and stay surgical. The conversation history above provides background context; treat it as reference only and do not let it distract from your objective.
|
|
9
9
|
|
|
10
10
|
Rules:
|
|
11
11
|
- Use grep/find/ls before reading entire files — be efficient.
|
|
@@ -13,7 +13,7 @@ Rules:
|
|
|
13
13
|
- Show actual code/data, not excessive summaries.
|
|
14
14
|
- If not found, say so immediately — don't guess.
|
|
15
15
|
|
|
16
|
-
When
|
|
16
|
+
When accomplished, end your response with:
|
|
17
17
|
|
|
18
18
|
flow [explore] accomplished
|
|
19
19
|
|
package/agents/review.md
CHANGED
|
@@ -5,7 +5,7 @@ tools: read, bash, find, grep, ls
|
|
|
5
5
|
maxDepth: 2
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
During this review flow — your mission is to audit. Be adversarial: look for what others miss, but stay honest. The conversation history above provides background context; treat it as reference only and do not let it distract from your objective.
|
|
9
9
|
|
|
10
10
|
Focus Areas:
|
|
11
11
|
- Security — injection, auth bypass, exposed secrets
|
|
@@ -19,7 +19,7 @@ Rules:
|
|
|
19
19
|
- Do not modify source files — report findings with severity only
|
|
20
20
|
- If the audit reveals structural issues requiring redesign, recommend [architect] in [Next Steps]
|
|
21
21
|
|
|
22
|
-
When
|
|
22
|
+
When accomplished, end your response with:
|
|
23
23
|
|
|
24
24
|
flow [review] accomplished
|
|
25
25
|
|
package/index.ts
CHANGED
|
@@ -405,10 +405,26 @@ flow [type] accomplished
|
|
|
405
405
|
label: "Flow",
|
|
406
406
|
description: [
|
|
407
407
|
"Delegate work to flow states running in isolated pi processes.",
|
|
408
|
-
"Each flow receives a snapshot of your current session context.",
|
|
408
|
+
"Each flow receives a forked snapshot of your current session context.",
|
|
409
409
|
"All flows run in parallel — batch independent tasks into one call.",
|
|
410
410
|
"",
|
|
411
411
|
'Usage: { "flow": [{ "type": "explore", "intent": "..." }, ...] }',
|
|
412
|
+
"",
|
|
413
|
+
"Each flow type is a specialized agent configuration. Standard types:",
|
|
414
|
+
"\u2022 explore \u2014 Discovery, trace code paths, map architecture",
|
|
415
|
+
"\u2022 debug \u2014 Root-cause analysis, investigate errors and stack traces",
|
|
416
|
+
"\u2022 code \u2014 Implementation, tests, builds, deploy, git commit",
|
|
417
|
+
"\u2022 architect \u2014 Structural design, planning before building",
|
|
418
|
+
"\u2022 review \u2014 Read-only audit for security, quality, correctness",
|
|
419
|
+
"\u2022 brainstorm \u2014 Fresh ideas from a clean slate (no inherited context)",
|
|
420
|
+
"",
|
|
421
|
+
"Custom flows can be defined as .md files in .pi/agents/ (project)",
|
|
422
|
+
"or ~/.pi/agent/agents/ (user). They override bundled flows by name.",
|
|
423
|
+
"",
|
|
424
|
+
"Each flow returns: [Summary], [Done], [Not Done], [Next Steps]",
|
|
425
|
+
"",
|
|
426
|
+
"Guards: Max delegation depth and cycle prevention are enforced.",
|
|
427
|
+
"Blocked flows return an error with the reason.",
|
|
412
428
|
].join("\n"),
|
|
413
429
|
parameters: FlowParams,
|
|
414
430
|
|
package/package.json
CHANGED
package/render-utils.ts
CHANGED
|
@@ -92,6 +92,17 @@ export function visibleLength(text: string): number {
|
|
|
92
92
|
return text.replace(ANSI_RE, "").length;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Compute the remaining visible-character budget for a line,
|
|
97
|
+
* given the length of its prefix (indent + label + space).
|
|
98
|
+
* Respects `process.stdout.columns` with a floor of 40 and default of 80.
|
|
99
|
+
*/
|
|
100
|
+
export function getTruncationBudget(prefixLength: number): number {
|
|
101
|
+
const cols = process.stdout.columns ?? 80;
|
|
102
|
+
const width = Math.max(cols, 40);
|
|
103
|
+
return Math.max(width - prefixLength, 1);
|
|
104
|
+
}
|
|
105
|
+
|
|
95
106
|
/**
|
|
96
107
|
* Truncate an ANSI-colored string to at most `max` visible characters,
|
|
97
108
|
* preserving ANSI codes in the kept portions and appending a reset before
|
|
@@ -115,9 +126,12 @@ function truncateAnsi(text: string, max: number): string {
|
|
|
115
126
|
if (src[i] === "\x1b" && src[i + 1] === "[") {
|
|
116
127
|
const end = src.indexOf("m", i + 2);
|
|
117
128
|
if (end !== -1) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
const seq = src.slice(i, end + 1);
|
|
130
|
+
if (/^\x1b\[[0-9;]*m$/.test(seq)) {
|
|
131
|
+
raw += seq;
|
|
132
|
+
i = end + 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
137
|
raw += src[i];
|
|
@@ -139,9 +153,12 @@ function truncateAnsi(text: string, max: number): string {
|
|
|
139
153
|
if (src[i] === "m") {
|
|
140
154
|
const escStart = src.lastIndexOf("\x1b[", i);
|
|
141
155
|
if (escStart !== -1 && escStart < i) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
156
|
+
const seq = src.slice(escStart, i + 1);
|
|
157
|
+
if (/^\x1b\[[0-9;]*m$/.test(seq)) {
|
|
158
|
+
// This is an ANSI sequence — don't count, skip past it
|
|
159
|
+
i = escStart - 1;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
visible++;
|
|
@@ -173,8 +190,11 @@ export function tailText(text: string, max: number): string {
|
|
|
173
190
|
if (flat[i] === "m") {
|
|
174
191
|
const escStart = flat.lastIndexOf("\x1b[", i);
|
|
175
192
|
if (escStart !== -1 && escStart < i) {
|
|
176
|
-
|
|
177
|
-
|
|
193
|
+
const seq = flat.slice(escStart, i + 1);
|
|
194
|
+
if (/^\x1b\[[0-9;]*m$/.test(seq)) {
|
|
195
|
+
i = escStart - 1;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
178
198
|
}
|
|
179
199
|
}
|
|
180
200
|
visible++;
|
package/render.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
isFlowError,
|
|
23
23
|
isFlowSuccess,
|
|
24
24
|
} from "./types.js";
|
|
25
|
-
import { formatTokens, formatFixedTokens, formatFlowUsage, formatCompactStats, formatExpandedStats, formatFlowTypeName, truncateChars, tailText } from "./render-utils.js";
|
|
25
|
+
import { formatTokens, formatFixedTokens, formatFlowUsage, formatCompactStats, formatExpandedStats, formatFlowTypeName, truncateChars, tailText, getTruncationBudget } from "./render-utils.js";
|
|
26
26
|
|
|
27
27
|
function shortenPath(p: string): string {
|
|
28
28
|
const home = os.homedir();
|
|
@@ -234,23 +234,23 @@ function renderFlowCollapsed(
|
|
|
234
234
|
|
|
235
235
|
// dir: line (intent/objective)
|
|
236
236
|
if (r.intent) {
|
|
237
|
-
text += `\n${theme.fg("dim", "├─ dir:")} ${theme.fg("dim", truncateChars(r.intent,
|
|
237
|
+
text += `\n${theme.fg("dim", "├─ dir:")} ${theme.fg("dim", truncateChars(r.intent, getTruncationBudget(8)))}`;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// exe: line (last tool call)
|
|
241
241
|
const lastTool = getLastToolCall(r.messages);
|
|
242
242
|
if (lastTool) {
|
|
243
243
|
const exeStr = formatFlowToolCall(lastTool.name, lastTool.args, theme.fg.bind(theme));
|
|
244
|
-
text += `\n${theme.fg("dim", "├─ exe:")} ${truncateChars(exeStr,
|
|
244
|
+
text += `\n${theme.fg("dim", "├─ exe:")} ${truncateChars(exeStr, getTruncationBudget(8))}`;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// log: line (last assistant text or streaming)
|
|
248
248
|
if (flowOutput) {
|
|
249
|
-
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("dim", truncateChars(flowOutput,
|
|
249
|
+
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("dim", truncateChars(flowOutput, getTruncationBudget(8)))}`;
|
|
250
250
|
} else if (streamingText) {
|
|
251
|
-
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("dim", tailText(streamingText,
|
|
251
|
+
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("dim", tailText(streamingText, getTruncationBudget(8)))}`;
|
|
252
252
|
} else if (error && r.errorMessage) {
|
|
253
|
-
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("error", truncateChars(r.errorMessage,
|
|
253
|
+
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("error", truncateChars(r.errorMessage, getTruncationBudget(8)))}`;
|
|
254
254
|
} else {
|
|
255
255
|
text += `\n${theme.fg("dim", "└─ log:")} ${theme.fg("dim", "[n/a]")}`;
|
|
256
256
|
}
|
|
@@ -369,22 +369,22 @@ function renderActivityPanel(
|
|
|
369
369
|
|
|
370
370
|
// dir: line (intent/objective)
|
|
371
371
|
if (r.intent) {
|
|
372
|
-
container.addChild(new Text(`${theme.fg("dim", indent + "├─ dir:")} ${theme.fg("dim", truncateChars(r.intent,
|
|
372
|
+
container.addChild(new Text(`${theme.fg("dim", indent + "├─ dir:")} ${theme.fg("dim", truncateChars(r.intent, getTruncationBudget(11)))}`, 0, 0));
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
// exe: line (last tool call)
|
|
376
376
|
const lastTool = getLastToolCall(r.messages);
|
|
377
377
|
if (lastTool) {
|
|
378
378
|
const exeStr = formatFlowToolCall(lastTool.name, lastTool.args, theme.fg.bind(theme));
|
|
379
|
-
container.addChild(new Text(`${theme.fg("dim", indent + "├─ exe:")} ${truncateChars(exeStr,
|
|
379
|
+
container.addChild(new Text(`${theme.fg("dim", indent + "├─ exe:")} ${truncateChars(exeStr, getTruncationBudget(11))}`, 0, 0));
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
// log: line (last assistant text)
|
|
383
383
|
const lastText = getLastAssistantText(r.messages);
|
|
384
384
|
if (lastText) {
|
|
385
|
-
container.addChild(new Text(`${theme.fg("dim", indent + "└─ log:")} ${theme.fg("dim", truncateChars(lastText,
|
|
385
|
+
container.addChild(new Text(`${theme.fg("dim", indent + "└─ log:")} ${theme.fg("dim", truncateChars(lastText, getTruncationBudget(11)))}`, 0, 0));
|
|
386
386
|
} else if (error && r.errorMessage) {
|
|
387
|
-
container.addChild(new Text(`${theme.fg("dim", indent + "└─ log:")} ${theme.fg("error", truncateChars(r.errorMessage,
|
|
387
|
+
container.addChild(new Text(`${theme.fg("dim", indent + "└─ log:")} ${theme.fg("error", truncateChars(r.errorMessage, getTruncationBudget(11)))}`, 0, 0));
|
|
388
388
|
} else {
|
|
389
389
|
container.addChild(new Text(`${theme.fg("dim", indent + "└─ log:")} ${theme.fg("dim", "[n/a]")}`, 0, 0));
|
|
390
390
|
}
|