@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/README.md +156 -12
- package/dist/cli.js +148 -70
- package/dist/cli.js.map +4 -4
- package/dist/index.js +148 -71
- package/dist/index.js.map +4 -4
- package/package.json +12 -9
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "zx";
|
|
|
4
4
|
// src/patterns/types.ts
|
|
5
5
|
import { createInterface } from "node:readline";
|
|
6
6
|
import { completeSimple } from "@earendil-works/pi-ai";
|
|
7
|
+
import { createAgentSession } from "@earendil-works/pi-coding-agent";
|
|
7
8
|
|
|
8
9
|
// src/model-picker.ts
|
|
9
10
|
import {
|
|
@@ -301,7 +302,8 @@ ${skillContext}` : skillContext;
|
|
|
301
302
|
reasoning: opts.thinkingLevel ?? "medium",
|
|
302
303
|
thinkingBudgets: opts.thinkingBudgets,
|
|
303
304
|
timeoutMs: opts.timeoutMs,
|
|
304
|
-
maxRetries: opts.maxRetries
|
|
305
|
+
maxRetries: opts.maxRetries,
|
|
306
|
+
apiKey: opts.apiKey
|
|
305
307
|
}
|
|
306
308
|
);
|
|
307
309
|
const durationMs = Date.now() - t0;
|
|
@@ -326,6 +328,40 @@ ${skillContext}` : skillContext;
|
|
|
326
328
|
}
|
|
327
329
|
return text.trim();
|
|
328
330
|
}
|
|
331
|
+
async function executeTask(prompt, opts = {}) {
|
|
332
|
+
if (opts.mode === "agent") {
|
|
333
|
+
return runAgentTask(prompt, opts);
|
|
334
|
+
}
|
|
335
|
+
return ask(prompt, opts);
|
|
336
|
+
}
|
|
337
|
+
async function runAgentTask(prompt, opts) {
|
|
338
|
+
const model = pickModel(opts.model);
|
|
339
|
+
if (!model) throw new Error("pizx/patterns: No AI models configured. Run `pi auth login` first.");
|
|
340
|
+
const tools = ["read", "bash", "edit", "write", "grep", "ls"];
|
|
341
|
+
const { session } = await createAgentSession({
|
|
342
|
+
tools,
|
|
343
|
+
...model ? { model } : {}
|
|
344
|
+
});
|
|
345
|
+
try {
|
|
346
|
+
await session.sendUserMessage(prompt);
|
|
347
|
+
const messages = session.messages;
|
|
348
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
349
|
+
const msg = messages[i];
|
|
350
|
+
if (msg?.role !== "assistant") continue;
|
|
351
|
+
const c = "content" in msg ? msg.content : void 0;
|
|
352
|
+
if (typeof c === "string") return c.trim();
|
|
353
|
+
if (Array.isArray(c)) {
|
|
354
|
+
const texts = c.filter(
|
|
355
|
+
(block) => typeof block === "object" && block !== null && "type" in block && "text" in block
|
|
356
|
+
).map((block) => block.text);
|
|
357
|
+
if (texts.length > 0) return texts.join("\n").trim();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return "";
|
|
361
|
+
} finally {
|
|
362
|
+
session.dispose();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
329
365
|
var QUALITY_REVIEW_SYSTEM = `You are a quality assurance reviewer. Evaluate the final deliverable against the original request.
|
|
330
366
|
|
|
331
367
|
Output format:
|
|
@@ -429,7 +465,7 @@ async function execute(pieces, args, opts) {
|
|
|
429
465
|
`);
|
|
430
466
|
}
|
|
431
467
|
if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
|
|
432
|
-
const planText = await
|
|
468
|
+
const planText = await executeTask(goal, {
|
|
433
469
|
...opts,
|
|
434
470
|
model: plannerModel,
|
|
435
471
|
thinkingLevel: "high",
|
|
@@ -462,12 +498,12 @@ async function execute(pieces, args, opts) {
|
|
|
462
498
|
if (!opts.quiet)
|
|
463
499
|
process.stderr.write(` \u2192 Step ${executionStep}: ${currentStep.slice(0, 60)}...
|
|
464
500
|
`);
|
|
465
|
-
const result = await
|
|
501
|
+
const result = await executeTask(currentStep, {
|
|
466
502
|
...opts,
|
|
467
503
|
model: workerModel,
|
|
468
504
|
system: mergeSystem(opts.system, EXECUTE_SYSTEM)
|
|
469
505
|
});
|
|
470
|
-
const evaluation = await
|
|
506
|
+
const evaluation = await executeTask(
|
|
471
507
|
`Goal: ${goal}
|
|
472
508
|
Step executed: ${currentStep}
|
|
473
509
|
Result: ${result}
|
|
@@ -671,7 +707,7 @@ async function execute2(pieces, args, opts) {
|
|
|
671
707
|
const broadcastResults = await Promise.allSettled(
|
|
672
708
|
roles.map(async (role) => {
|
|
673
709
|
const prompt = WORKER_PROMPT.replace("{role}", role).replace("{question}", question);
|
|
674
|
-
const text = await
|
|
710
|
+
const text = await executeTask(prompt, { ...opts, model: workerModel });
|
|
675
711
|
return new BroadcastResponse(role, text, true);
|
|
676
712
|
})
|
|
677
713
|
);
|
|
@@ -687,7 +723,7 @@ async function execute2(pieces, args, opts) {
|
|
|
687
723
|
if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing responses...\n");
|
|
688
724
|
const responsesText = responses.map((wr) => `--- ${wr.role} ---
|
|
689
725
|
${wr.response}`).join("\n\n");
|
|
690
|
-
const synthesis = await
|
|
726
|
+
const synthesis = await executeTask(
|
|
691
727
|
`Original question:
|
|
692
728
|
${question}
|
|
693
729
|
|
|
@@ -808,7 +844,7 @@ async function execute3(pieces, args, opts) {
|
|
|
808
844
|
process.stderr.write(`\u03A7: Cross-Agent Learning \u2014 analyzing ${label}
|
|
809
845
|
`);
|
|
810
846
|
}
|
|
811
|
-
const response = await
|
|
847
|
+
const response = await executeTask(input, {
|
|
812
848
|
...opts,
|
|
813
849
|
model: plannerModel,
|
|
814
850
|
system: mergeSystem(opts.system, ANALYSIS_SYSTEM)
|
|
@@ -838,9 +874,9 @@ var defaults4 = {
|
|
|
838
874
|
rounds: 1
|
|
839
875
|
};
|
|
840
876
|
var CritiqueRound = class {
|
|
841
|
-
constructor(content,
|
|
877
|
+
constructor(content, critique2, round) {
|
|
842
878
|
this.content = content;
|
|
843
|
-
this.critique =
|
|
879
|
+
this.critique = critique2;
|
|
844
880
|
this.round = round;
|
|
845
881
|
}
|
|
846
882
|
content;
|
|
@@ -884,12 +920,16 @@ async function execute4(pieces, args, opts) {
|
|
|
884
920
|
for (let r = 0; r < rounds; r++) {
|
|
885
921
|
if (r === 0) {
|
|
886
922
|
if (!opts.quiet) process.stderr.write(" \u2192 Generating initial content...\n");
|
|
887
|
-
currentContent = await
|
|
923
|
+
currentContent = await executeTask(prompt, {
|
|
924
|
+
...opts,
|
|
925
|
+
model: workerModel,
|
|
926
|
+
system: opts.system
|
|
927
|
+
});
|
|
888
928
|
} else {
|
|
889
929
|
if (!opts.quiet) process.stderr.write(` \u2192 Improving (round ${r + 1})...
|
|
890
930
|
`);
|
|
891
931
|
const prevCritique = critiqueRounds[r - 1]?.critique ?? "";
|
|
892
|
-
currentContent = await
|
|
932
|
+
currentContent = await executeTask(
|
|
893
933
|
`Original request: ${prompt}
|
|
894
934
|
|
|
895
935
|
Critique:
|
|
@@ -904,12 +944,12 @@ Revise the content based on the critique.`,
|
|
|
904
944
|
}
|
|
905
945
|
if (!opts.quiet) process.stderr.write(` \u2192 Critiquing (round ${r + 1})...
|
|
906
946
|
`);
|
|
907
|
-
const
|
|
947
|
+
const critique2 = await executeTask(currentContent, {
|
|
908
948
|
...opts,
|
|
909
949
|
model: plannerModel,
|
|
910
950
|
system: mergeSystem(opts.system, CRITIQUE_SYSTEM)
|
|
911
951
|
});
|
|
912
|
-
critiqueRounds.push(new CritiqueRound(currentContent,
|
|
952
|
+
critiqueRounds.push(new CritiqueRound(currentContent, critique2, r));
|
|
913
953
|
}
|
|
914
954
|
const t1 = Date.now();
|
|
915
955
|
const finalContent = currentContent;
|
|
@@ -1035,7 +1075,7 @@ Refine your position. Address the counter-arguments directly. Strengthen your ar
|
|
|
1035
1075
|
`;
|
|
1036
1076
|
}
|
|
1037
1077
|
if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing perspectives...\n");
|
|
1038
|
-
const conclusion = await
|
|
1078
|
+
const conclusion = await executeTask(
|
|
1039
1079
|
`${debateHistory}
|
|
1040
1080
|
|
|
1041
1081
|
Synthesize a balanced conclusion from the full debate above. Weigh the evidence from all rounds.`,
|
|
@@ -1116,7 +1156,7 @@ function describeTask(task) {
|
|
|
1116
1156
|
return task;
|
|
1117
1157
|
}
|
|
1118
1158
|
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.`;
|
|
1119
|
-
async function
|
|
1159
|
+
async function executeFleetTask(task, opts, workerModel) {
|
|
1120
1160
|
if (typeof task === "function") {
|
|
1121
1161
|
try {
|
|
1122
1162
|
const text = await task("");
|
|
@@ -1127,7 +1167,7 @@ async function executeTask(task, opts, workerModel) {
|
|
|
1127
1167
|
}
|
|
1128
1168
|
const model = workerModel ?? opts.model;
|
|
1129
1169
|
try {
|
|
1130
|
-
const text = await
|
|
1170
|
+
const text = await executeTask(task, {
|
|
1131
1171
|
...opts,
|
|
1132
1172
|
model,
|
|
1133
1173
|
system: mergeSystem(opts.system, FLEET_SYSTEM)
|
|
@@ -1161,7 +1201,7 @@ async function execute6(pieces, args, opts) {
|
|
|
1161
1201
|
for (let i = 0; i < tasks.length; i += concurrency) {
|
|
1162
1202
|
const batch = tasks.slice(i, i + concurrency);
|
|
1163
1203
|
const batchResults = await Promise.allSettled(
|
|
1164
|
-
batch.map((task) =>
|
|
1204
|
+
batch.map((task) => executeFleetTask(task, opts, workerModel))
|
|
1165
1205
|
);
|
|
1166
1206
|
batchResults.forEach((r, idx) => {
|
|
1167
1207
|
if (r.status === "fulfilled") {
|
|
@@ -1308,7 +1348,7 @@ ${depResults}
|
|
|
1308
1348
|
Your task: ${node.task}`;
|
|
1309
1349
|
}
|
|
1310
1350
|
}
|
|
1311
|
-
const text = await
|
|
1351
|
+
const text = await executeTask(context, {
|
|
1312
1352
|
...opts,
|
|
1313
1353
|
model: workerModel,
|
|
1314
1354
|
system: mergeSystem(opts.system, NODE_SYSTEM)
|
|
@@ -1403,7 +1443,7 @@ async function execute8(pieces, args, opts) {
|
|
|
1403
1443
|
const roundResults = await Promise.allSettled(
|
|
1404
1444
|
roles.map(async (role) => {
|
|
1405
1445
|
const prompt = buildWriterPrompt(role, topic, blackboard);
|
|
1406
|
-
const text = await
|
|
1446
|
+
const text = await executeTask(prompt, { ...opts, model: workerModel });
|
|
1407
1447
|
return { role, text };
|
|
1408
1448
|
})
|
|
1409
1449
|
);
|
|
@@ -1417,7 +1457,7 @@ async function execute8(pieces, args, opts) {
|
|
|
1417
1457
|
}
|
|
1418
1458
|
}
|
|
1419
1459
|
if (!opts.quiet) process.stderr.write(" \u2192 Consolidating findings...\n");
|
|
1420
|
-
const synthesis = await
|
|
1460
|
+
const synthesis = await executeTask(
|
|
1421
1461
|
`Topic: ${topic}
|
|
1422
1462
|
|
|
1423
1463
|
Blackboard findings:
|
|
@@ -1508,7 +1548,7 @@ async function negotiateRoles(task, opts) {
|
|
|
1508
1548
|
const min = opts.minAgents ?? 2;
|
|
1509
1549
|
const max = opts.maxAgents ?? 5;
|
|
1510
1550
|
const prompt = NEGOTIATE_SYSTEM.replace("{min}", String(min)).replace("{max}", String(max));
|
|
1511
|
-
const response = await
|
|
1551
|
+
const response = await executeTask(`Task: ${task}
|
|
1512
1552
|
|
|
1513
1553
|
${prompt}`, {
|
|
1514
1554
|
...opts,
|
|
@@ -1540,7 +1580,7 @@ async function decideWorkflow(roles, task, opts) {
|
|
|
1540
1580
|
if (roles.length <= 1)
|
|
1541
1581
|
return { workflow: "parallel", reasoning: "Single role \u2014 no dependencies." };
|
|
1542
1582
|
const rolesText = roles.map((r, i) => `${i + 1}. ${r.name}: ${r.goal}`).join("\n");
|
|
1543
|
-
const response = await
|
|
1583
|
+
const response = await executeTask(
|
|
1544
1584
|
`Task: ${task}
|
|
1545
1585
|
|
|
1546
1586
|
Roles:
|
|
@@ -1570,7 +1610,7 @@ async function executeRoles(roles, task, workflow, opts) {
|
|
|
1570
1610
|
if (workflow === "sequential") {
|
|
1571
1611
|
let context = task;
|
|
1572
1612
|
for (const role of roles) {
|
|
1573
|
-
const output = await
|
|
1613
|
+
const output = await executeTask(context, {
|
|
1574
1614
|
...opts,
|
|
1575
1615
|
model: workerModel,
|
|
1576
1616
|
system: mergeSystem(opts.system, EXECUTE_SYSTEM2(role))
|
|
@@ -1738,7 +1778,7 @@ async function execute10(pieces, args, opts) {
|
|
|
1738
1778
|
}
|
|
1739
1779
|
if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
|
|
1740
1780
|
const planStart = Date.now();
|
|
1741
|
-
const planText = await
|
|
1781
|
+
const planText = await executeTask(request, {
|
|
1742
1782
|
...opts,
|
|
1743
1783
|
model: plannerModel,
|
|
1744
1784
|
thinkingLevel: "high",
|
|
@@ -1803,7 +1843,7 @@ async function execute10(pieces, args, opts) {
|
|
|
1803
1843
|
const workerTexts = workerResults.map((wr, i) => `Task ${i + 1}: ${wr.task}
|
|
1804
1844
|
Result: ${wr.output}`).join("\n\n");
|
|
1805
1845
|
const synthStart = Date.now();
|
|
1806
|
-
const synthesis = await
|
|
1846
|
+
const synthesis = await executeTask(
|
|
1807
1847
|
`Original request:
|
|
1808
1848
|
${request}
|
|
1809
1849
|
|
|
@@ -1954,7 +1994,7 @@ async function execute11(pieces, args, opts) {
|
|
|
1954
1994
|
} else {
|
|
1955
1995
|
const prompt = customPrompt ?? generateStagePrompt(stage, currentInput, i === 0);
|
|
1956
1996
|
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.`;
|
|
1957
|
-
output = await
|
|
1997
|
+
output = await executeTask(prompt, {
|
|
1958
1998
|
...opts,
|
|
1959
1999
|
model: workerModel,
|
|
1960
2000
|
system: mergeSystem(opts.system, systemMessage)
|
|
@@ -1976,7 +2016,7 @@ ${sr.output.slice(0, 200)}${sr.output.length > 200 ? "..." : ""}`
|
|
|
1976
2016
|
var \u039B = createPatternTag(defaults11, execute11);
|
|
1977
2017
|
|
|
1978
2018
|
// src/patterns/ralph.ts
|
|
1979
|
-
import { createAgentSession } from "@earendil-works/pi-coding-agent";
|
|
2019
|
+
import { createAgentSession as createAgentSession2 } from "@earendil-works/pi-coding-agent";
|
|
1980
2020
|
var defaults12 = {
|
|
1981
2021
|
maxIterations: 5,
|
|
1982
2022
|
useTools: true,
|
|
@@ -2002,7 +2042,7 @@ async function executeWithTools(goal, opts) {
|
|
|
2002
2042
|
`pizx/\u03A1: model not found: "${opts.model}". Run \`pi models\` to see available models.`
|
|
2003
2043
|
);
|
|
2004
2044
|
}
|
|
2005
|
-
const { session } = await
|
|
2045
|
+
const { session } = await createAgentSession2({
|
|
2006
2046
|
tools: ["read", "bash", "edit", "write", "grep", "ls"],
|
|
2007
2047
|
...agentModel ? { model: agentModel } : {}
|
|
2008
2048
|
});
|
|
@@ -2052,13 +2092,13 @@ async function execute12(pieces, args, opts) {
|
|
|
2052
2092
|
`);
|
|
2053
2093
|
}
|
|
2054
2094
|
if (!opts.quiet) process.stderr.write(" \u2192 Analyzing...\n");
|
|
2055
|
-
const analysis = await
|
|
2095
|
+
const analysis = await executeTask(currentGoal, {
|
|
2056
2096
|
...opts,
|
|
2057
2097
|
model: plannerModel,
|
|
2058
2098
|
system: mergeSystem(opts.system, ANALYSIS_SYSTEM2)
|
|
2059
2099
|
});
|
|
2060
2100
|
if (!opts.quiet) process.stderr.write(" \u2192 Planning...\n");
|
|
2061
|
-
const plan = await
|
|
2101
|
+
const plan = await executeTask(
|
|
2062
2102
|
`Goal: ${currentGoal}
|
|
2063
2103
|
|
|
2064
2104
|
Analysis: ${analysis}
|
|
@@ -2073,7 +2113,7 @@ ${plan}
|
|
|
2073
2113
|
Goal: ${currentGoal}`, {
|
|
2074
2114
|
...opts,
|
|
2075
2115
|
model: workerModel
|
|
2076
|
-
}) : await
|
|
2116
|
+
}) : await executeTask(`Implement this plan:
|
|
2077
2117
|
${plan}
|
|
2078
2118
|
|
|
2079
2119
|
Goal: ${currentGoal}`, {
|
|
@@ -2081,19 +2121,22 @@ Goal: ${currentGoal}`, {
|
|
|
2081
2121
|
model: workerModel
|
|
2082
2122
|
});
|
|
2083
2123
|
if (!opts.quiet) process.stderr.write(" \u2192 Reviewing...\n");
|
|
2084
|
-
const review = await
|
|
2124
|
+
const review = await executeTask(
|
|
2125
|
+
`Plan:
|
|
2085
2126
|
${plan}
|
|
2086
2127
|
|
|
2087
2128
|
Result:
|
|
2088
2129
|
${result}
|
|
2089
2130
|
|
|
2090
|
-
Review the implementation.`,
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2131
|
+
Review the implementation.`,
|
|
2132
|
+
{
|
|
2133
|
+
...opts,
|
|
2134
|
+
model: plannerModel,
|
|
2135
|
+
maxTokens: 1024,
|
|
2136
|
+
thinkingLevel: "high",
|
|
2137
|
+
system: mergeSystem(opts.system, REVIEW_SYSTEM)
|
|
2138
|
+
}
|
|
2139
|
+
);
|
|
2097
2140
|
const shouldContinue = review.includes("ITERATE") && !review.includes("DONE");
|
|
2098
2141
|
iterations.push({
|
|
2099
2142
|
iteration,
|
|
@@ -2162,7 +2205,7 @@ var DECOMPOSE_SYSTEM = `You are a task decomposition specialist. Break down comp
|
|
|
2162
2205
|
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.`;
|
|
2163
2206
|
async function decomposeTask(task, opts) {
|
|
2164
2207
|
if (opts.subdomains && opts.subdomains.length > 0) return opts.subdomains;
|
|
2165
|
-
const result = await
|
|
2208
|
+
const result = await executeTask(
|
|
2166
2209
|
`Decompose this task into ${opts.maxSubTasks ?? 4} independent sub-tasks that can be worked on in parallel:
|
|
2167
2210
|
|
|
2168
2211
|
${task}
|
|
@@ -2252,7 +2295,7 @@ async function execute13(pieces, args, opts) {
|
|
|
2252
2295
|
const subResultsText = subResults.map((sr, i) => `Sub-task ${i + 1}: ${sr.subTask}
|
|
2253
2296
|
Result: ${sr.text}`).join("\n\n");
|
|
2254
2297
|
const synthStart = Date.now();
|
|
2255
|
-
const synthesis = await
|
|
2298
|
+
const synthesis = await executeTask(
|
|
2256
2299
|
`Original task:
|
|
2257
2300
|
${task}
|
|
2258
2301
|
|
|
@@ -2370,7 +2413,7 @@ var CONSOLIDATE_SYSTEM = `You are a research director. Consolidate the structure
|
|
|
2370
2413
|
async function defineSchema(task, opts) {
|
|
2371
2414
|
const agentCount = opts.agents ?? 3;
|
|
2372
2415
|
const prompt = SCHEMA_SYSTEM.replace("{agentCount}", String(agentCount));
|
|
2373
|
-
const response = await
|
|
2416
|
+
const response = await executeTask(`Task: ${task}
|
|
2374
2417
|
|
|
2375
2418
|
${prompt}`, {
|
|
2376
2419
|
...opts,
|
|
@@ -2400,21 +2443,21 @@ ${prompt}`, {
|
|
|
2400
2443
|
}
|
|
2401
2444
|
return { keys, roles: roles.slice(0, agentCount), assignments };
|
|
2402
2445
|
}
|
|
2403
|
-
function formatStore(
|
|
2404
|
-
const entries = Object.entries(
|
|
2446
|
+
function formatStore(store2) {
|
|
2447
|
+
const entries = Object.entries(store2).filter(([, v]) => v);
|
|
2405
2448
|
if (entries.length === 0) return "(empty \u2014 you are the first contributor)";
|
|
2406
2449
|
return entries.map(([k, v]) => `[${k}]: ${v}`).join("\n\n");
|
|
2407
2450
|
}
|
|
2408
|
-
function mergeEntry(
|
|
2409
|
-
if (
|
|
2410
|
-
|
|
2451
|
+
function mergeEntry(store2, key, content) {
|
|
2452
|
+
if (store2[key]) {
|
|
2453
|
+
store2[key] += `
|
|
2411
2454
|
|
|
2412
2455
|
${content}`;
|
|
2413
2456
|
} else {
|
|
2414
|
-
|
|
2457
|
+
store2[key] = content;
|
|
2415
2458
|
}
|
|
2416
2459
|
}
|
|
2417
|
-
async function executeRound(roles, assignments,
|
|
2460
|
+
async function executeRound(roles, assignments, store2, round, opts) {
|
|
2418
2461
|
const workerModel = opts.workerModel ?? opts.model;
|
|
2419
2462
|
const isWrite = round === 1;
|
|
2420
2463
|
const operation = isWrite ? "write" : "update";
|
|
@@ -2422,10 +2465,10 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2422
2465
|
roles.map(async (role) => {
|
|
2423
2466
|
const assignedKeys = assignments.get(role) ?? ["General"];
|
|
2424
2467
|
const keysStr = assignedKeys.join(", ");
|
|
2425
|
-
const storeText = formatStore(
|
|
2468
|
+
const storeText = formatStore(store2);
|
|
2426
2469
|
const systemPrompt = isWrite ? WRITE_SYSTEM(role, keysStr).replace("{store}", storeText) : UPDATE_SYSTEM(role, keysStr).replace("{store}", storeText);
|
|
2427
2470
|
const task = isWrite ? `Write your initial findings to your assigned keys: ${keysStr}` : `Review the shared context and update your entries for keys: ${keysStr}`;
|
|
2428
|
-
const response = await
|
|
2471
|
+
const response = await executeTask(task, {
|
|
2429
2472
|
...opts,
|
|
2430
2473
|
model: workerModel,
|
|
2431
2474
|
system: mergeSystem(opts.system, systemPrompt)
|
|
@@ -2434,7 +2477,7 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2434
2477
|
})
|
|
2435
2478
|
);
|
|
2436
2479
|
const entries = [];
|
|
2437
|
-
const newStore = { ...
|
|
2480
|
+
const newStore = { ...store2 };
|
|
2438
2481
|
for (const r of roundResults) {
|
|
2439
2482
|
if (r.status !== "fulfilled") continue;
|
|
2440
2483
|
const { role, response } = r.value;
|
|
@@ -2457,8 +2500,8 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2457
2500
|
}
|
|
2458
2501
|
return { entries, store: newStore };
|
|
2459
2502
|
}
|
|
2460
|
-
async function consolidateStore(task,
|
|
2461
|
-
const storeText = formatStore(
|
|
2503
|
+
async function consolidateStore(task, store2, opts) {
|
|
2504
|
+
const storeText = formatStore(store2);
|
|
2462
2505
|
return ask(
|
|
2463
2506
|
`Original task: ${task}
|
|
2464
2507
|
|
|
@@ -2499,7 +2542,7 @@ async function execute14(pieces, args, opts) {
|
|
|
2499
2542
|
}
|
|
2500
2543
|
}
|
|
2501
2544
|
const allEntries = [];
|
|
2502
|
-
let
|
|
2545
|
+
let store2 = {};
|
|
2503
2546
|
for (let round = 1; round <= totalRounds; round++) {
|
|
2504
2547
|
const label = round === 1 ? "Writing" : "Updating";
|
|
2505
2548
|
if (!opts.quiet) process.stderr.write(` \u2192 Round ${round}/${totalRounds}: ${label}...
|
|
@@ -2507,15 +2550,15 @@ async function execute14(pieces, args, opts) {
|
|
|
2507
2550
|
const { entries, store: updatedStore } = await executeRound(
|
|
2508
2551
|
roles,
|
|
2509
2552
|
assignments,
|
|
2510
|
-
|
|
2553
|
+
store2,
|
|
2511
2554
|
round,
|
|
2512
2555
|
opts
|
|
2513
2556
|
);
|
|
2514
2557
|
allEntries.push(...entries);
|
|
2515
|
-
|
|
2558
|
+
store2 = updatedStore;
|
|
2516
2559
|
}
|
|
2517
2560
|
if (!opts.quiet) process.stderr.write(" \u2192 Consolidating store...\n");
|
|
2518
|
-
const synthesis = await consolidateStore(task,
|
|
2561
|
+
const synthesis = await consolidateStore(task, store2, { ...opts, plannerModel });
|
|
2519
2562
|
if (!opts.quiet && opts.qualityCheck) process.stderr.write(" \u2192 Quality review...\n");
|
|
2520
2563
|
const qualityReview = await runQualityReview(task, synthesis, opts);
|
|
2521
2564
|
const t1 = Date.now();
|
|
@@ -2526,7 +2569,7 @@ async function execute14(pieces, args, opts) {
|
|
|
2526
2569
|
`Entries: ${allEntries.length}`,
|
|
2527
2570
|
`Synthesis: ${synthesis}`
|
|
2528
2571
|
].join("\n\n");
|
|
2529
|
-
return new TauOutput(summary, allEntries,
|
|
2572
|
+
return new TauOutput(summary, allEntries, store2, synthesis, t0, t1, qualityReview);
|
|
2530
2573
|
}
|
|
2531
2574
|
var \u03A4 = createPatternTag(defaults14, execute14);
|
|
2532
2575
|
|
|
@@ -2567,10 +2610,10 @@ The conversation so far:
|
|
|
2567
2610
|
Respond as your role. Be specific, build on or challenge what others have said.
|
|
2568
2611
|
Keep your response under 200 words.`;
|
|
2569
2612
|
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.`;
|
|
2570
|
-
function buildThreadPrompt(role,
|
|
2613
|
+
function buildThreadPrompt(role, thread2) {
|
|
2571
2614
|
return THREAD_PROMPT.replace("{role}", role).replace(
|
|
2572
2615
|
"{thread}",
|
|
2573
|
-
|
|
2616
|
+
thread2 || "(This is the first message in the thread.)"
|
|
2574
2617
|
);
|
|
2575
2618
|
}
|
|
2576
2619
|
async function execute15(pieces, args, opts) {
|
|
@@ -2588,27 +2631,27 @@ async function execute15(pieces, args, opts) {
|
|
|
2588
2631
|
`);
|
|
2589
2632
|
}
|
|
2590
2633
|
const messages = [];
|
|
2591
|
-
let
|
|
2634
|
+
let thread2 = `Topic: ${topic}
|
|
2592
2635
|
`;
|
|
2593
2636
|
for (let turn = 1; turn <= maxTurns; turn++) {
|
|
2594
2637
|
if (!opts.quiet) process.stderr.write(` \u2192 Turn ${turn}/${maxTurns}
|
|
2595
2638
|
`);
|
|
2596
2639
|
for (let a = 0; a < roles.length; a++) {
|
|
2597
2640
|
const role = roles[a] ?? `Agent ${a + 1}`;
|
|
2598
|
-
const prompt = buildThreadPrompt(role,
|
|
2599
|
-
const response = await
|
|
2641
|
+
const prompt = buildThreadPrompt(role, thread2);
|
|
2642
|
+
const response = await executeTask(prompt, { ...opts, model: workerModel });
|
|
2600
2643
|
messages.push(new ThreadMessage(role, turn, response));
|
|
2601
|
-
|
|
2644
|
+
thread2 += `
|
|
2602
2645
|
[${role}] (Turn ${turn}): ${response}
|
|
2603
2646
|
`;
|
|
2604
2647
|
}
|
|
2605
2648
|
}
|
|
2606
2649
|
if (!opts.quiet) process.stderr.write(" \u2192 Synthesizing conclusion...\n");
|
|
2607
|
-
const conclusion = await
|
|
2650
|
+
const conclusion = await executeTask(
|
|
2608
2651
|
`Topic: ${topic}
|
|
2609
2652
|
|
|
2610
2653
|
Conversation thread:
|
|
2611
|
-
${
|
|
2654
|
+
${thread2}
|
|
2612
2655
|
|
|
2613
2656
|
Synthesize a clear, actionable conclusion.`,
|
|
2614
2657
|
{
|
|
@@ -2628,6 +2671,23 @@ Synthesize a clear, actionable conclusion.`,
|
|
|
2628
2671
|
}
|
|
2629
2672
|
var \u0398 = createPatternTag(defaults15, execute15);
|
|
2630
2673
|
|
|
2674
|
+
// src/patterns/index.ts
|
|
2675
|
+
var ralph = \u03A1;
|
|
2676
|
+
var fleet = \u03A6;
|
|
2677
|
+
var subagent = \u03A3;
|
|
2678
|
+
var debate = \u0394;
|
|
2679
|
+
var pipeline = \u039B;
|
|
2680
|
+
var critique = \u03A8;
|
|
2681
|
+
var orchestrator = \u03A9;
|
|
2682
|
+
var thread = \u0398;
|
|
2683
|
+
var memory = \u039C;
|
|
2684
|
+
var broadcast = \u0392;
|
|
2685
|
+
var adaptive = \u0391;
|
|
2686
|
+
var graph = \u0393;
|
|
2687
|
+
var team = \u039D;
|
|
2688
|
+
var learn = \u03A7;
|
|
2689
|
+
var store = \u03A4;
|
|
2690
|
+
|
|
2631
2691
|
// src/pi.ts
|
|
2632
2692
|
import {
|
|
2633
2693
|
streamSimple
|
|
@@ -2715,7 +2775,8 @@ function makeOpts(opts) {
|
|
|
2715
2775
|
reasoning: opts.thinkingLevel,
|
|
2716
2776
|
thinkingBudgets: opts.thinkingBudgets,
|
|
2717
2777
|
timeoutMs: opts.timeoutMs,
|
|
2718
|
-
maxRetries: opts.maxRetries
|
|
2778
|
+
maxRetries: opts.maxRetries,
|
|
2779
|
+
apiKey: opts.apiKey
|
|
2719
2780
|
};
|
|
2720
2781
|
}
|
|
2721
2782
|
async function run(pieces, args, opts) {
|
|
@@ -2804,7 +2865,7 @@ function configurePi(opts) {
|
|
|
2804
2865
|
|
|
2805
2866
|
// src/pi-agent.ts
|
|
2806
2867
|
import {
|
|
2807
|
-
createAgentSession as
|
|
2868
|
+
createAgentSession as createAgentSession3,
|
|
2808
2869
|
DefaultResourceLoader
|
|
2809
2870
|
} from "@earendil-works/pi-coding-agent";
|
|
2810
2871
|
var _agentDefaults = {
|
|
@@ -2869,7 +2930,7 @@ async function getSession(opts) {
|
|
|
2869
2930
|
loader.extendResources({ skillPaths });
|
|
2870
2931
|
}
|
|
2871
2932
|
}
|
|
2872
|
-
const result = await
|
|
2933
|
+
const result = await createAgentSession3({
|
|
2873
2934
|
cwd: opts.cwd,
|
|
2874
2935
|
thinkingLevel: opts.thinkingLevel,
|
|
2875
2936
|
tools: opts.tools,
|
|
@@ -2973,8 +3034,8 @@ export {
|
|
|
2973
3034
|
OrchestratorWorkerResult,
|
|
2974
3035
|
PatternOutput,
|
|
2975
3036
|
PatternPromise,
|
|
3037
|
+
\u03A0 as Pi,
|
|
2976
3038
|
PiOutput,
|
|
2977
|
-
PiPromise,
|
|
2978
3039
|
PipelineOutput,
|
|
2979
3040
|
PipelineStageResult,
|
|
2980
3041
|
RalphOutput,
|
|
@@ -2983,12 +3044,28 @@ export {
|
|
|
2983
3044
|
SubagentResult,
|
|
2984
3045
|
ThreadMessage,
|
|
2985
3046
|
ThreadOutput,
|
|
3047
|
+
adaptive,
|
|
3048
|
+
broadcast,
|
|
2986
3049
|
closeAgent,
|
|
2987
3050
|
configureAgent,
|
|
2988
3051
|
configurePi,
|
|
2989
3052
|
createPatternTag,
|
|
3053
|
+
critique,
|
|
3054
|
+
debate,
|
|
3055
|
+
fleet,
|
|
3056
|
+
graph,
|
|
3057
|
+
learn,
|
|
2990
3058
|
loadSkillContent,
|
|
2991
3059
|
loadSkillContents,
|
|
3060
|
+
memory,
|
|
3061
|
+
orchestrator,
|
|
3062
|
+
\u03C0 as pi,
|
|
3063
|
+
pipeline,
|
|
3064
|
+
ralph,
|
|
3065
|
+
store,
|
|
3066
|
+
subagent,
|
|
3067
|
+
team,
|
|
3068
|
+
thread,
|
|
2992
3069
|
\u0391,
|
|
2993
3070
|
\u0392,
|
|
2994
3071
|
\u0393,
|