@topce/pizx 0.4.0 → 0.6.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/dist/cli.js CHANGED
@@ -101,6 +101,7 @@ function loadPiAuth() {
101
101
  // src/patterns/types.ts
102
102
  import { createInterface } from "node:readline";
103
103
  import { completeSimple } from "@earendil-works/pi-ai";
104
+ import { createAgentSession } from "@earendil-works/pi-coding-agent";
104
105
 
105
106
  // src/model-picker.ts
106
107
  import {
@@ -367,7 +368,8 @@ ${skillContext}` : skillContext;
367
368
  reasoning: opts.thinkingLevel ?? "medium",
368
369
  thinkingBudgets: opts.thinkingBudgets,
369
370
  timeoutMs: opts.timeoutMs,
370
- maxRetries: opts.maxRetries
371
+ maxRetries: opts.maxRetries,
372
+ apiKey: opts.apiKey
371
373
  }
372
374
  );
373
375
  const durationMs = Date.now() - t0;
@@ -392,6 +394,40 @@ ${skillContext}` : skillContext;
392
394
  }
393
395
  return text.trim();
394
396
  }
397
+ async function executeTask(prompt, opts = {}) {
398
+ if (opts.mode === "agent") {
399
+ return runAgentTask(prompt, opts);
400
+ }
401
+ return ask(prompt, opts);
402
+ }
403
+ async function runAgentTask(prompt, opts) {
404
+ const model = pickModel(opts.model);
405
+ if (!model) throw new Error("pizx/patterns: No AI models configured. Run `pi auth login` first.");
406
+ const tools = ["read", "bash", "edit", "write", "grep", "ls"];
407
+ const { session } = await createAgentSession({
408
+ tools,
409
+ ...model ? { model } : {}
410
+ });
411
+ try {
412
+ await session.sendUserMessage(prompt);
413
+ const messages = session.messages;
414
+ for (let i = messages.length - 1; i >= 0; i--) {
415
+ const msg = messages[i];
416
+ if (msg?.role !== "assistant") continue;
417
+ const c = "content" in msg ? msg.content : void 0;
418
+ if (typeof c === "string") return c.trim();
419
+ if (Array.isArray(c)) {
420
+ const texts = c.filter(
421
+ (block) => typeof block === "object" && block !== null && "type" in block && "text" in block
422
+ ).map((block) => block.text);
423
+ if (texts.length > 0) return texts.join("\n").trim();
424
+ }
425
+ }
426
+ return "";
427
+ } finally {
428
+ session.dispose();
429
+ }
430
+ }
395
431
  var QUALITY_REVIEW_SYSTEM = `You are a quality assurance reviewer. Evaluate the final deliverable against the original request.
396
432
 
397
433
  Output format:
@@ -495,7 +531,7 @@ async function execute(pieces, args, opts) {
495
531
  `);
496
532
  }
497
533
  if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
498
- const planText = await ask(goal, {
534
+ const planText = await executeTask(goal, {
499
535
  ...opts,
500
536
  model: plannerModel,
501
537
  thinkingLevel: "high",
@@ -528,12 +564,12 @@ async function execute(pieces, args, opts) {
528
564
  if (!opts.quiet)
529
565
  process.stderr.write(` \u2192 Step ${executionStep}: ${currentStep.slice(0, 60)}...
530
566
  `);
531
- const result = await ask(currentStep, {
567
+ const result = await executeTask(currentStep, {
532
568
  ...opts,
533
569
  model: workerModel,
534
570
  system: mergeSystem(opts.system, EXECUTE_SYSTEM)
535
571
  });
536
- const evaluation = await ask(
572
+ const evaluation = await executeTask(
537
573
  `Goal: ${goal}
538
574
  Step executed: ${currentStep}
539
575
  Result: ${result}
@@ -737,7 +773,7 @@ async function execute2(pieces, args, opts) {
737
773
  const broadcastResults = await Promise.allSettled(
738
774
  roles.map(async (role) => {
739
775
  const prompt = WORKER_PROMPT.replace("{role}", role).replace("{question}", question);
740
- const text = await ask(prompt, { ...opts, model: workerModel });
776
+ const text = await executeTask(prompt, { ...opts, model: workerModel });
741
777
  return new BroadcastResponse(role, text, true);
742
778
  })
743
779
  );
@@ -753,7 +789,7 @@ async function execute2(pieces, args, opts) {
753
789
  if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing responses...\n");
754
790
  const responsesText = responses.map((wr) => `--- ${wr.role} ---
755
791
  ${wr.response}`).join("\n\n");
756
- const synthesis = await ask(
792
+ const synthesis = await executeTask(
757
793
  `Original question:
758
794
  ${question}
759
795
 
@@ -874,7 +910,7 @@ async function execute3(pieces, args, opts) {
874
910
  process.stderr.write(`\u03A7: Cross-Agent Learning \u2014 analyzing ${label}
875
911
  `);
876
912
  }
877
- const response = await ask(input, {
913
+ const response = await executeTask(input, {
878
914
  ...opts,
879
915
  model: plannerModel,
880
916
  system: mergeSystem(opts.system, ANALYSIS_SYSTEM)
@@ -904,9 +940,9 @@ var defaults4 = {
904
940
  rounds: 1
905
941
  };
906
942
  var CritiqueRound = class {
907
- constructor(content, critique, round) {
943
+ constructor(content, critique2, round) {
908
944
  this.content = content;
909
- this.critique = critique;
945
+ this.critique = critique2;
910
946
  this.round = round;
911
947
  }
912
948
  content;
@@ -950,12 +986,16 @@ async function execute4(pieces, args, opts) {
950
986
  for (let r = 0; r < rounds; r++) {
951
987
  if (r === 0) {
952
988
  if (!opts.quiet) process.stderr.write(" \u2192 Generating initial content...\n");
953
- currentContent = await ask(prompt, { ...opts, model: workerModel, system: opts.system });
989
+ currentContent = await executeTask(prompt, {
990
+ ...opts,
991
+ model: workerModel,
992
+ system: opts.system
993
+ });
954
994
  } else {
955
995
  if (!opts.quiet) process.stderr.write(` \u2192 Improving (round ${r + 1})...
956
996
  `);
957
997
  const prevCritique = critiqueRounds[r - 1]?.critique ?? "";
958
- currentContent = await ask(
998
+ currentContent = await executeTask(
959
999
  `Original request: ${prompt}
960
1000
 
961
1001
  Critique:
@@ -970,12 +1010,12 @@ Revise the content based on the critique.`,
970
1010
  }
971
1011
  if (!opts.quiet) process.stderr.write(` \u2192 Critiquing (round ${r + 1})...
972
1012
  `);
973
- const critique = await ask(currentContent, {
1013
+ const critique2 = await executeTask(currentContent, {
974
1014
  ...opts,
975
1015
  model: plannerModel,
976
1016
  system: mergeSystem(opts.system, CRITIQUE_SYSTEM)
977
1017
  });
978
- critiqueRounds.push(new CritiqueRound(currentContent, critique, r));
1018
+ critiqueRounds.push(new CritiqueRound(currentContent, critique2, r));
979
1019
  }
980
1020
  const t1 = Date.now();
981
1021
  const finalContent = currentContent;
@@ -1101,7 +1141,7 @@ Refine your position. Address the counter-arguments directly. Strengthen your ar
1101
1141
  `;
1102
1142
  }
1103
1143
  if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing perspectives...\n");
1104
- const conclusion = await ask(
1144
+ const conclusion = await executeTask(
1105
1145
  `${debateHistory}
1106
1146
 
1107
1147
  Synthesize a balanced conclusion from the full debate above. Weigh the evidence from all rounds.`,
@@ -1177,7 +1217,7 @@ function describeTask(task) {
1177
1217
  return task;
1178
1218
  }
1179
1219
  var FLEET_SYSTEM = `You are a focused task specialist. Complete the assigned task concisely and accurately. Output only the result \u2014 no commentary about being an AI.`;
1180
- async function executeTask(task, opts, workerModel) {
1220
+ async function executeFleetTask(task, opts, workerModel) {
1181
1221
  if (typeof task === "function") {
1182
1222
  try {
1183
1223
  const text = await task("");
@@ -1188,7 +1228,7 @@ async function executeTask(task, opts, workerModel) {
1188
1228
  }
1189
1229
  const model = workerModel ?? opts.model;
1190
1230
  try {
1191
- const text = await ask(task, {
1231
+ const text = await executeTask(task, {
1192
1232
  ...opts,
1193
1233
  model,
1194
1234
  system: mergeSystem(opts.system, FLEET_SYSTEM)
@@ -1222,7 +1262,7 @@ async function execute6(pieces, args, opts) {
1222
1262
  for (let i = 0; i < tasks.length; i += concurrency) {
1223
1263
  const batch = tasks.slice(i, i + concurrency);
1224
1264
  const batchResults = await Promise.allSettled(
1225
- batch.map((task) => executeTask(task, opts, workerModel))
1265
+ batch.map((task) => executeFleetTask(task, opts, workerModel))
1226
1266
  );
1227
1267
  batchResults.forEach((r, idx) => {
1228
1268
  if (r.status === "fulfilled") {
@@ -1369,7 +1409,7 @@ ${depResults}
1369
1409
  Your task: ${node.task}`;
1370
1410
  }
1371
1411
  }
1372
- const text = await ask(context, {
1412
+ const text = await executeTask(context, {
1373
1413
  ...opts,
1374
1414
  model: workerModel,
1375
1415
  system: mergeSystem(opts.system, NODE_SYSTEM)
@@ -1464,7 +1504,7 @@ async function execute8(pieces, args, opts) {
1464
1504
  const roundResults = await Promise.allSettled(
1465
1505
  roles.map(async (role) => {
1466
1506
  const prompt = buildWriterPrompt(role, topic, blackboard);
1467
- const text = await ask(prompt, { ...opts, model: workerModel });
1507
+ const text = await executeTask(prompt, { ...opts, model: workerModel });
1468
1508
  return { role, text };
1469
1509
  })
1470
1510
  );
@@ -1478,7 +1518,7 @@ async function execute8(pieces, args, opts) {
1478
1518
  }
1479
1519
  }
1480
1520
  if (!opts.quiet) process.stderr.write(" \u2192 Consolidating findings...\n");
1481
- const synthesis = await ask(
1521
+ const synthesis = await executeTask(
1482
1522
  `Topic: ${topic}
1483
1523
 
1484
1524
  Blackboard findings:
@@ -1569,7 +1609,7 @@ async function negotiateRoles(task, opts) {
1569
1609
  const min = opts.minAgents ?? 2;
1570
1610
  const max = opts.maxAgents ?? 5;
1571
1611
  const prompt = NEGOTIATE_SYSTEM.replace("{min}", String(min)).replace("{max}", String(max));
1572
- const response = await ask(`Task: ${task}
1612
+ const response = await executeTask(`Task: ${task}
1573
1613
 
1574
1614
  ${prompt}`, {
1575
1615
  ...opts,
@@ -1601,7 +1641,7 @@ async function decideWorkflow(roles, task, opts) {
1601
1641
  if (roles.length <= 1)
1602
1642
  return { workflow: "parallel", reasoning: "Single role \u2014 no dependencies." };
1603
1643
  const rolesText = roles.map((r, i) => `${i + 1}. ${r.name}: ${r.goal}`).join("\n");
1604
- const response = await ask(
1644
+ const response = await executeTask(
1605
1645
  `Task: ${task}
1606
1646
 
1607
1647
  Roles:
@@ -1631,7 +1671,7 @@ async function executeRoles(roles, task, workflow, opts) {
1631
1671
  if (workflow === "sequential") {
1632
1672
  let context = task;
1633
1673
  for (const role of roles) {
1634
- const output = await ask(context, {
1674
+ const output = await executeTask(context, {
1635
1675
  ...opts,
1636
1676
  model: workerModel,
1637
1677
  system: mergeSystem(opts.system, EXECUTE_SYSTEM2(role))
@@ -1799,7 +1839,7 @@ async function execute10(pieces, args, opts) {
1799
1839
  }
1800
1840
  if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
1801
1841
  const planStart = Date.now();
1802
- const planText = await ask(request, {
1842
+ const planText = await executeTask(request, {
1803
1843
  ...opts,
1804
1844
  model: plannerModel,
1805
1845
  thinkingLevel: "high",
@@ -1864,7 +1904,7 @@ async function execute10(pieces, args, opts) {
1864
1904
  const workerTexts = workerResults.map((wr, i) => `Task ${i + 1}: ${wr.task}
1865
1905
  Result: ${wr.output}`).join("\n\n");
1866
1906
  const synthStart = Date.now();
1867
- const synthesis = await ask(
1907
+ const synthesis = await executeTask(
1868
1908
  `Original request:
1869
1909
  ${request}
1870
1910
 
@@ -2015,7 +2055,7 @@ async function execute11(pieces, args, opts) {
2015
2055
  } else {
2016
2056
  const prompt = customPrompt ?? generateStagePrompt(stage, currentInput, i === 0);
2017
2057
  const systemMessage = i === 0 ? `You are a specialist executing stage ${i + 1}: ${stage}. Focus only on this stage's output.` : `You are a specialist executing stage ${i + 1}: ${stage}. Process the previous stage's output according to your instructions. Maintain all important information from previous stages.`;
2018
- output = await ask(prompt, {
2058
+ output = await executeTask(prompt, {
2019
2059
  ...opts,
2020
2060
  model: workerModel,
2021
2061
  system: mergeSystem(opts.system, systemMessage)
@@ -2037,7 +2077,7 @@ ${sr.output.slice(0, 200)}${sr.output.length > 200 ? "..." : ""}`
2037
2077
  var \u039B = createPatternTag(defaults11, execute11);
2038
2078
 
2039
2079
  // src/patterns/ralph.ts
2040
- import { createAgentSession } from "@earendil-works/pi-coding-agent";
2080
+ import { createAgentSession as createAgentSession2 } from "@earendil-works/pi-coding-agent";
2041
2081
  var defaults12 = {
2042
2082
  maxIterations: 5,
2043
2083
  useTools: true,
@@ -2063,7 +2103,7 @@ async function executeWithTools(goal, opts) {
2063
2103
  `pizx/\u03A1: model not found: "${opts.model}". Run \`pi models\` to see available models.`
2064
2104
  );
2065
2105
  }
2066
- const { session } = await createAgentSession({
2106
+ const { session } = await createAgentSession2({
2067
2107
  tools: ["read", "bash", "edit", "write", "grep", "ls"],
2068
2108
  ...agentModel ? { model: agentModel } : {}
2069
2109
  });
@@ -2113,13 +2153,13 @@ async function execute12(pieces, args, opts) {
2113
2153
  `);
2114
2154
  }
2115
2155
  if (!opts.quiet) process.stderr.write(" \u2192 Analyzing...\n");
2116
- const analysis = await ask(currentGoal, {
2156
+ const analysis = await executeTask(currentGoal, {
2117
2157
  ...opts,
2118
2158
  model: plannerModel,
2119
2159
  system: mergeSystem(opts.system, ANALYSIS_SYSTEM2)
2120
2160
  });
2121
2161
  if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
2122
- const plan = await ask(
2162
+ const plan = await executeTask(
2123
2163
  `Goal: ${currentGoal}
2124
2164
 
2125
2165
  Analysis: ${analysis}
@@ -2134,7 +2174,7 @@ ${plan}
2134
2174
  Goal: ${currentGoal}`, {
2135
2175
  ...opts,
2136
2176
  model: workerModel
2137
- }) : await ask(`Implement this plan:
2177
+ }) : await executeTask(`Implement this plan:
2138
2178
  ${plan}
2139
2179
 
2140
2180
  Goal: ${currentGoal}`, {
@@ -2142,19 +2182,22 @@ Goal: ${currentGoal}`, {
2142
2182
  model: workerModel
2143
2183
  });
2144
2184
  if (!opts.quiet) process.stderr.write(" \u2192 Reviewing...\n");
2145
- const review = await ask(`Plan:
2185
+ const review = await executeTask(
2186
+ `Plan:
2146
2187
  ${plan}
2147
2188
 
2148
2189
  Result:
2149
2190
  ${result}
2150
2191
 
2151
- Review the implementation.`, {
2152
- ...opts,
2153
- model: plannerModel,
2154
- maxTokens: 1024,
2155
- thinkingLevel: "high",
2156
- system: mergeSystem(opts.system, REVIEW_SYSTEM)
2157
- });
2192
+ Review the implementation.`,
2193
+ {
2194
+ ...opts,
2195
+ model: plannerModel,
2196
+ maxTokens: 1024,
2197
+ thinkingLevel: "high",
2198
+ system: mergeSystem(opts.system, REVIEW_SYSTEM)
2199
+ }
2200
+ );
2158
2201
  const shouldContinue = review.includes("ITERATE") && !review.includes("DONE");
2159
2202
  iterations.push({
2160
2203
  iteration,
@@ -2223,7 +2266,7 @@ var DECOMPOSE_SYSTEM = `You are a task decomposition specialist. Break down comp
2223
2266
  var SYNTHESIS_SYSTEM5 = `You are a synthesis specialist. Combine the results from multiple sub-agent analyses into a coherent, comprehensive answer. Identify patterns, conflicts, and gaps.`;
2224
2267
  async function decomposeTask(task, opts) {
2225
2268
  if (opts.subdomains && opts.subdomains.length > 0) return opts.subdomains;
2226
- const result = await ask(
2269
+ const result = await executeTask(
2227
2270
  `Decompose this task into ${opts.maxSubTasks ?? 4} independent sub-tasks that can be worked on in parallel:
2228
2271
 
2229
2272
  ${task}
@@ -2313,7 +2356,7 @@ async function execute13(pieces, args, opts) {
2313
2356
  const subResultsText = subResults.map((sr, i) => `Sub-task ${i + 1}: ${sr.subTask}
2314
2357
  Result: ${sr.text}`).join("\n\n");
2315
2358
  const synthStart = Date.now();
2316
- const synthesis = await ask(
2359
+ const synthesis = await executeTask(
2317
2360
  `Original task:
2318
2361
  ${task}
2319
2362
 
@@ -2431,7 +2474,7 @@ var CONSOLIDATE_SYSTEM = `You are a research director. Consolidate the structure
2431
2474
  async function defineSchema(task, opts) {
2432
2475
  const agentCount = opts.agents ?? 3;
2433
2476
  const prompt = SCHEMA_SYSTEM.replace("{agentCount}", String(agentCount));
2434
- const response = await ask(`Task: ${task}
2477
+ const response = await executeTask(`Task: ${task}
2435
2478
 
2436
2479
  ${prompt}`, {
2437
2480
  ...opts,
@@ -2461,21 +2504,21 @@ ${prompt}`, {
2461
2504
  }
2462
2505
  return { keys, roles: roles.slice(0, agentCount), assignments };
2463
2506
  }
2464
- function formatStore(store) {
2465
- const entries = Object.entries(store).filter(([, v]) => v);
2507
+ function formatStore(store2) {
2508
+ const entries = Object.entries(store2).filter(([, v]) => v);
2466
2509
  if (entries.length === 0) return "(empty \u2014 you are the first contributor)";
2467
2510
  return entries.map(([k, v]) => `[${k}]: ${v}`).join("\n\n");
2468
2511
  }
2469
- function mergeEntry(store, key, content) {
2470
- if (store[key]) {
2471
- store[key] += `
2512
+ function mergeEntry(store2, key, content) {
2513
+ if (store2[key]) {
2514
+ store2[key] += `
2472
2515
 
2473
2516
  ${content}`;
2474
2517
  } else {
2475
- store[key] = content;
2518
+ store2[key] = content;
2476
2519
  }
2477
2520
  }
2478
- async function executeRound(roles, assignments, store, round, opts) {
2521
+ async function executeRound(roles, assignments, store2, round, opts) {
2479
2522
  const workerModel = opts.workerModel ?? opts.model;
2480
2523
  const isWrite = round === 1;
2481
2524
  const operation = isWrite ? "write" : "update";
@@ -2483,10 +2526,10 @@ async function executeRound(roles, assignments, store, round, opts) {
2483
2526
  roles.map(async (role) => {
2484
2527
  const assignedKeys = assignments.get(role) ?? ["General"];
2485
2528
  const keysStr = assignedKeys.join(", ");
2486
- const storeText = formatStore(store);
2529
+ const storeText = formatStore(store2);
2487
2530
  const systemPrompt = isWrite ? WRITE_SYSTEM(role, keysStr).replace("{store}", storeText) : UPDATE_SYSTEM(role, keysStr).replace("{store}", storeText);
2488
2531
  const task = isWrite ? `Write your initial findings to your assigned keys: ${keysStr}` : `Review the shared context and update your entries for keys: ${keysStr}`;
2489
- const response = await ask(task, {
2532
+ const response = await executeTask(task, {
2490
2533
  ...opts,
2491
2534
  model: workerModel,
2492
2535
  system: mergeSystem(opts.system, systemPrompt)
@@ -2495,7 +2538,7 @@ async function executeRound(roles, assignments, store, round, opts) {
2495
2538
  })
2496
2539
  );
2497
2540
  const entries = [];
2498
- const newStore = { ...store };
2541
+ const newStore = { ...store2 };
2499
2542
  for (const r of roundResults) {
2500
2543
  if (r.status !== "fulfilled") continue;
2501
2544
  const { role, response } = r.value;
@@ -2518,8 +2561,8 @@ async function executeRound(roles, assignments, store, round, opts) {
2518
2561
  }
2519
2562
  return { entries, store: newStore };
2520
2563
  }
2521
- async function consolidateStore(task, store, opts) {
2522
- const storeText = formatStore(store);
2564
+ async function consolidateStore(task, store2, opts) {
2565
+ const storeText = formatStore(store2);
2523
2566
  return ask(
2524
2567
  `Original task: ${task}
2525
2568
 
@@ -2560,7 +2603,7 @@ async function execute14(pieces, args, opts) {
2560
2603
  }
2561
2604
  }
2562
2605
  const allEntries = [];
2563
- let store = {};
2606
+ let store2 = {};
2564
2607
  for (let round = 1; round <= totalRounds; round++) {
2565
2608
  const label = round === 1 ? "Writing" : "Updating";
2566
2609
  if (!opts.quiet) process.stderr.write(` \u2192 Round ${round}/${totalRounds}: ${label}...
@@ -2568,15 +2611,15 @@ async function execute14(pieces, args, opts) {
2568
2611
  const { entries, store: updatedStore } = await executeRound(
2569
2612
  roles,
2570
2613
  assignments,
2571
- store,
2614
+ store2,
2572
2615
  round,
2573
2616
  opts
2574
2617
  );
2575
2618
  allEntries.push(...entries);
2576
- store = updatedStore;
2619
+ store2 = updatedStore;
2577
2620
  }
2578
2621
  if (!opts.quiet) process.stderr.write(" \u2192 Consolidating store...\n");
2579
- const synthesis = await consolidateStore(task, store, { ...opts, plannerModel });
2622
+ const synthesis = await consolidateStore(task, store2, { ...opts, plannerModel });
2580
2623
  if (!opts.quiet && opts.qualityCheck) process.stderr.write(" \u2192 Quality review...\n");
2581
2624
  const qualityReview = await runQualityReview(task, synthesis, opts);
2582
2625
  const t1 = Date.now();
@@ -2587,7 +2630,7 @@ async function execute14(pieces, args, opts) {
2587
2630
  `Entries: ${allEntries.length}`,
2588
2631
  `Synthesis: ${synthesis}`
2589
2632
  ].join("\n\n");
2590
- return new TauOutput(summary, allEntries, store, synthesis, t0, t1, qualityReview);
2633
+ return new TauOutput(summary, allEntries, store2, synthesis, t0, t1, qualityReview);
2591
2634
  }
2592
2635
  var \u03A4 = createPatternTag(defaults14, execute14);
2593
2636
 
@@ -2628,10 +2671,10 @@ The conversation so far:
2628
2671
  Respond as your role. Be specific, build on or challenge what others have said.
2629
2672
  Keep your response under 200 words.`;
2630
2673
  var SYNTHESIS_SYSTEM6 = `You are a neutral facilitator. Synthesize the multi-agent conversation thread into a clear, actionable conclusion. Weigh the evidence, resolve conflicts, and present the best path forward.`;
2631
- function buildThreadPrompt(role, thread) {
2674
+ function buildThreadPrompt(role, thread2) {
2632
2675
  return THREAD_PROMPT.replace("{role}", role).replace(
2633
2676
  "{thread}",
2634
- thread || "(This is the first message in the thread.)"
2677
+ thread2 || "(This is the first message in the thread.)"
2635
2678
  );
2636
2679
  }
2637
2680
  async function execute15(pieces, args, opts) {
@@ -2649,27 +2692,27 @@ async function execute15(pieces, args, opts) {
2649
2692
  `);
2650
2693
  }
2651
2694
  const messages = [];
2652
- let thread = `Topic: ${topic}
2695
+ let thread2 = `Topic: ${topic}
2653
2696
  `;
2654
2697
  for (let turn = 1; turn <= maxTurns; turn++) {
2655
2698
  if (!opts.quiet) process.stderr.write(` \u2192 Turn ${turn}/${maxTurns}
2656
2699
  `);
2657
2700
  for (let a = 0; a < roles.length; a++) {
2658
2701
  const role = roles[a] ?? `Agent ${a + 1}`;
2659
- const prompt = buildThreadPrompt(role, thread);
2660
- const response = await ask(prompt, { ...opts, model: workerModel });
2702
+ const prompt = buildThreadPrompt(role, thread2);
2703
+ const response = await executeTask(prompt, { ...opts, model: workerModel });
2661
2704
  messages.push(new ThreadMessage(role, turn, response));
2662
- thread += `
2705
+ thread2 += `
2663
2706
  [${role}] (Turn ${turn}): ${response}
2664
2707
  `;
2665
2708
  }
2666
2709
  }
2667
2710
  if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing conclusion...\n");
2668
- const conclusion = await ask(
2711
+ const conclusion = await executeTask(
2669
2712
  `Topic: ${topic}
2670
2713
 
2671
2714
  Conversation thread:
2672
- ${thread}
2715
+ ${thread2}
2673
2716
 
2674
2717
  Synthesize a clear, actionable conclusion.`,
2675
2718
  {
@@ -2689,6 +2732,23 @@ Synthesize a clear, actionable conclusion.`,
2689
2732
  }
2690
2733
  var \u0398 = createPatternTag(defaults15, execute15);
2691
2734
 
2735
+ // src/patterns/index.ts
2736
+ var ralph = \u03A1;
2737
+ var fleet = \u03A6;
2738
+ var subagent = \u03A3;
2739
+ var debate = \u0394;
2740
+ var pipeline = \u039B;
2741
+ var critique = \u03A8;
2742
+ var orchestrator = \u03A9;
2743
+ var thread = \u0398;
2744
+ var memory = \u039C;
2745
+ var broadcast = \u0392;
2746
+ var adaptive = \u0391;
2747
+ var graph = \u0393;
2748
+ var team = \u039D;
2749
+ var learn = \u03A7;
2750
+ var store = \u03A4;
2751
+
2692
2752
  // src/pi.ts
2693
2753
  import {
2694
2754
  streamSimple
@@ -2776,7 +2836,8 @@ function makeOpts(opts) {
2776
2836
  reasoning: opts.thinkingLevel,
2777
2837
  thinkingBudgets: opts.thinkingBudgets,
2778
2838
  timeoutMs: opts.timeoutMs,
2779
- maxRetries: opts.maxRetries
2839
+ maxRetries: opts.maxRetries,
2840
+ apiKey: opts.apiKey
2780
2841
  };
2781
2842
  }
2782
2843
  async function run(pieces, args, opts) {
@@ -2862,7 +2923,7 @@ var \u03C0 = makePi();
2862
2923
 
2863
2924
  // src/pi-agent.ts
2864
2925
  import {
2865
- createAgentSession as createAgentSession2,
2926
+ createAgentSession as createAgentSession3,
2866
2927
  DefaultResourceLoader
2867
2928
  } from "@earendil-works/pi-coding-agent";
2868
2929
  var _agentDefaults = {
@@ -2927,7 +2988,7 @@ async function getSession(opts) {
2927
2988
  loader.extendResources({ skillPaths });
2928
2989
  }
2929
2990
  }
2930
- const result = await createAgentSession2({
2991
+ const result = await createAgentSession3({
2931
2992
  cwd: opts.cwd,
2932
2993
  thinkingLevel: opts.thinkingLevel,
2933
2994
  tools: opts.tools,
@@ -3147,6 +3208,23 @@ async function runScriptMode(scriptPath) {
3147
3208
  g.\u0392 = \u0392;
3148
3209
  g.\u0391 = \u0391;
3149
3210
  g.\u0393 = \u0393;
3211
+ g.pi = \u03C0;
3212
+ g.Pi = \u03A0;
3213
+ g.ralph = ralph;
3214
+ g.fleet = fleet;
3215
+ g.subagent = subagent;
3216
+ g.debate = debate;
3217
+ g.pipeline = pipeline;
3218
+ g.critique = critique;
3219
+ g.orchestrator = orchestrator;
3220
+ g.thread = thread;
3221
+ g.memory = memory;
3222
+ g.broadcast = broadcast;
3223
+ g.adaptive = adaptive;
3224
+ g.graph = graph;
3225
+ g.team = team;
3226
+ g.learn = learn;
3227
+ g.store = store;
3150
3228
  const { createRequire: createRequire2 } = await import("node:module");
3151
3229
  const __filename = absPath;
3152
3230
  const __dirname = path.dirname(absPath);