pi-agent-flow 1.0.3 → 1.0.5

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 (2) hide show
  1. package/flow.ts +42 -9
  2. package/package.json +1 -1
package/flow.ts CHANGED
@@ -104,13 +104,14 @@ function buildFlowArgs(
104
104
  intent: string,
105
105
  forkSessionPath: string | null,
106
106
  tieredModels?: { lite?: string; flash?: string; full?: string },
107
+ parentDepth: number = 0,
108
+ maxDepth: number = 0,
107
109
  ): string[] {
108
110
  const args: string[] = [
109
111
  "--mode",
110
112
  "json",
111
113
  ...inheritedCliArgs.extensionArgs,
112
114
  ...inheritedCliArgs.alwaysProxy,
113
- "-p",
114
115
  ];
115
116
 
116
117
  // Fork mode: always use --session
@@ -139,16 +140,46 @@ function buildFlowArgs(
139
140
  // No --append-system-prompt: child inherits parent's system prompt for cache hits.
140
141
  // Flow instructions go in the intent message instead.
141
142
 
142
- const flowDirectives =
143
- `--- flow directive ---\n` +
144
- `The conversation history above is background context — use it for reference, but your sole focus is the intent below, and try to execute EXACTLY as requested in the intent.\n` +
145
- `--- end flow directive ---`;
146
-
147
- const flowInstructions = flow.systemPrompt.trim()
148
- ? `\n\n--- system directive ---\n${flow.systemPrompt.trim()}\n--- end system directive ---`
143
+ const currentDepth = Math.max(0, Math.floor(parentDepth)) + 1;
144
+ const effectiveMaxDepth = Math.max(0, Math.floor(maxDepth));
145
+ const canDelegate = currentDepth < effectiveMaxDepth;
146
+ const availableTools = flow.tools?.join(", ") ?? "all";
147
+
148
+ // Phase 1: Context seal — sharp boundary declaring history sealed
149
+ const contextSeal =
150
+ `<context-seal>\n` +
151
+ `The conversation above is sealed — it is your session history for situational awareness only.\n` +
152
+ `Your task begins NOW. Do not respond to or continue anything from the history.\n` +
153
+ `</context-seal>`;
154
+
155
+ // Phase 2: Activation — role, tools, depth, delegation rules (dynamically generated)
156
+ const delegationRule = canDelegate
157
+ ? `You may delegate to sub-flows (depth ${currentDepth}/${effectiveMaxDepth}).`
158
+ : `You may NOT delegate to sub-flows (depth limit reached).`;
159
+
160
+ const activation =
161
+ `\n\n<activation flow="${flow.name}" depth="${currentDepth}" tools="${availableTools}">\n` +
162
+ `You are a [${flow.name}] agent operating at depth ${currentDepth}.\n` +
163
+ `Available tools: ${availableTools}.\n` +
164
+ `${delegationRule}\n` +
165
+ `Do not attempt to use any tool outside the available set — it will fail.\n` +
166
+ `</activation>`;
167
+
168
+ // Phase 3: Directive — the flow's system prompt (renamed from <system-directive>)
169
+ const directive = flow.systemPrompt.trim()
170
+ ? `\n\n<directive>\n${flow.systemPrompt.trim()}\n</directive>`
149
171
  : "";
150
172
 
151
- args.push(`${flowDirectives}${flowInstructions}\n\nIntent: ${intent}`);
173
+ // Phase 4: Mission — the intent wrapped with execution contract
174
+ const mission =
175
+ `\n\n<mission>\n` +
176
+ `${intent}\n` +
177
+ `\nExecute this mission. Use only your available tools. If blocked, report why — do not guess.\n` +
178
+ `Follow the output format specified in your directive.\n` +
179
+ `</mission>`;
180
+
181
+ // -p must immediately precede the prompt so the CLI parser binds it correctly
182
+ args.push("-p", `${contextSeal}${activation}${directive}${mission}`);
152
183
  return args;
153
184
  }
154
185
 
@@ -269,6 +300,8 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
269
300
  intent,
270
301
  forkSessionTmpPath,
271
302
  opts.tieredModels,
303
+ parentDepth,
304
+ maxDepth,
272
305
  );
273
306
  let wasAborted = false;
274
307
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-flow",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Flow-state delegation extension for Pi coding agent.",
5
5
  "type": "module",
6
6
  "main": "index.ts",