@topce/pizx 0.3.0 → 0.5.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 +90 -3
- package/dist/cli.js +151 -32
- package/dist/cli.js.map +4 -4
- package/dist/index.js +154 -33
- package/dist/index.js.map +4 -4
- package/package.json +12 -8
package/dist/index.js
CHANGED
|
@@ -113,6 +113,37 @@ function pickModel(preferred) {
|
|
|
113
113
|
return models[0];
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
// src/skill-loader.ts
|
|
117
|
+
import { readFile } from "node:fs/promises";
|
|
118
|
+
import { homedir as homedir2 } from "node:os";
|
|
119
|
+
import { join as join2 } from "node:path";
|
|
120
|
+
var SKILL_PATHS = [
|
|
121
|
+
".pi/skills",
|
|
122
|
+
".agents/skills",
|
|
123
|
+
"skills",
|
|
124
|
+
join2(homedir2(), ".pi", "agent", "skills"),
|
|
125
|
+
join2(homedir2(), ".codewhale", "skills"),
|
|
126
|
+
join2(homedir2(), ".claude", "skills")
|
|
127
|
+
];
|
|
128
|
+
async function loadSkillContent(name) {
|
|
129
|
+
for (const base of SKILL_PATHS) {
|
|
130
|
+
const candidate = join2(base, name, "SKILL.md");
|
|
131
|
+
try {
|
|
132
|
+
return await readFile(candidate, "utf-8");
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
async function loadSkillContents(names) {
|
|
139
|
+
const map = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const name of names) {
|
|
141
|
+
const content = await loadSkillContent(name);
|
|
142
|
+
if (content) map.set(name, content);
|
|
143
|
+
}
|
|
144
|
+
return map;
|
|
145
|
+
}
|
|
146
|
+
|
|
116
147
|
// src/patterns/types.ts
|
|
117
148
|
var PatternOutput = class {
|
|
118
149
|
constructor(text, startTime = Date.now(), endTime = Date.now()) {
|
|
@@ -243,18 +274,35 @@ async function confirmPhase(description, opts) {
|
|
|
243
274
|
async function ask(prompt, opts = {}) {
|
|
244
275
|
const model = pickModel(opts.model);
|
|
245
276
|
if (!model) throw new Error("pizx/patterns: No AI models configured. Run `pi auth login` first.");
|
|
277
|
+
let systemPrompt = opts.system;
|
|
278
|
+
if (opts.skills && opts.skills.length > 0) {
|
|
279
|
+
const skillMap = await loadSkillContents(opts.skills);
|
|
280
|
+
if (skillMap.size > 0) {
|
|
281
|
+
const skillBlocks = [];
|
|
282
|
+
for (const [name, content] of skillMap) {
|
|
283
|
+
skillBlocks.push(`Skill context (${name}):
|
|
284
|
+
${content}`);
|
|
285
|
+
}
|
|
286
|
+
const skillContext = skillBlocks.join("\n\n");
|
|
287
|
+
systemPrompt = systemPrompt ? `${systemPrompt}
|
|
288
|
+
|
|
289
|
+
${skillContext}` : skillContext;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
246
292
|
const t0 = Date.now();
|
|
247
293
|
const result = await completeSimple(
|
|
248
294
|
model,
|
|
249
295
|
{
|
|
250
|
-
systemPrompt
|
|
296
|
+
systemPrompt,
|
|
251
297
|
messages: [{ role: "user", content: prompt, timestamp: Date.now() }]
|
|
252
298
|
},
|
|
253
299
|
{
|
|
254
300
|
maxTokens: opts.maxTokens ?? 4096,
|
|
255
301
|
reasoning: opts.thinkingLevel ?? "medium",
|
|
302
|
+
thinkingBudgets: opts.thinkingBudgets,
|
|
256
303
|
timeoutMs: opts.timeoutMs,
|
|
257
|
-
maxRetries: opts.maxRetries
|
|
304
|
+
maxRetries: opts.maxRetries,
|
|
305
|
+
apiKey: opts.apiKey
|
|
258
306
|
}
|
|
259
307
|
);
|
|
260
308
|
const durationMs = Date.now() - t0;
|
|
@@ -791,9 +839,9 @@ var defaults4 = {
|
|
|
791
839
|
rounds: 1
|
|
792
840
|
};
|
|
793
841
|
var CritiqueRound = class {
|
|
794
|
-
constructor(content,
|
|
842
|
+
constructor(content, critique2, round) {
|
|
795
843
|
this.content = content;
|
|
796
|
-
this.critique =
|
|
844
|
+
this.critique = critique2;
|
|
797
845
|
this.round = round;
|
|
798
846
|
}
|
|
799
847
|
content;
|
|
@@ -857,12 +905,12 @@ Revise the content based on the critique.`,
|
|
|
857
905
|
}
|
|
858
906
|
if (!opts.quiet) process.stderr.write(` \u2192 Critiquing (round ${r + 1})...
|
|
859
907
|
`);
|
|
860
|
-
const
|
|
908
|
+
const critique2 = await ask(currentContent, {
|
|
861
909
|
...opts,
|
|
862
910
|
model: plannerModel,
|
|
863
911
|
system: mergeSystem(opts.system, CRITIQUE_SYSTEM)
|
|
864
912
|
});
|
|
865
|
-
critiqueRounds.push(new CritiqueRound(currentContent,
|
|
913
|
+
critiqueRounds.push(new CritiqueRound(currentContent, critique2, r));
|
|
866
914
|
}
|
|
867
915
|
const t1 = Date.now();
|
|
868
916
|
const finalContent = currentContent;
|
|
@@ -2353,21 +2401,21 @@ ${prompt}`, {
|
|
|
2353
2401
|
}
|
|
2354
2402
|
return { keys, roles: roles.slice(0, agentCount), assignments };
|
|
2355
2403
|
}
|
|
2356
|
-
function formatStore(
|
|
2357
|
-
const entries = Object.entries(
|
|
2404
|
+
function formatStore(store2) {
|
|
2405
|
+
const entries = Object.entries(store2).filter(([, v]) => v);
|
|
2358
2406
|
if (entries.length === 0) return "(empty \u2014 you are the first contributor)";
|
|
2359
2407
|
return entries.map(([k, v]) => `[${k}]: ${v}`).join("\n\n");
|
|
2360
2408
|
}
|
|
2361
|
-
function mergeEntry(
|
|
2362
|
-
if (
|
|
2363
|
-
|
|
2409
|
+
function mergeEntry(store2, key, content) {
|
|
2410
|
+
if (store2[key]) {
|
|
2411
|
+
store2[key] += `
|
|
2364
2412
|
|
|
2365
2413
|
${content}`;
|
|
2366
2414
|
} else {
|
|
2367
|
-
|
|
2415
|
+
store2[key] = content;
|
|
2368
2416
|
}
|
|
2369
2417
|
}
|
|
2370
|
-
async function executeRound(roles, assignments,
|
|
2418
|
+
async function executeRound(roles, assignments, store2, round, opts) {
|
|
2371
2419
|
const workerModel = opts.workerModel ?? opts.model;
|
|
2372
2420
|
const isWrite = round === 1;
|
|
2373
2421
|
const operation = isWrite ? "write" : "update";
|
|
@@ -2375,7 +2423,7 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2375
2423
|
roles.map(async (role) => {
|
|
2376
2424
|
const assignedKeys = assignments.get(role) ?? ["General"];
|
|
2377
2425
|
const keysStr = assignedKeys.join(", ");
|
|
2378
|
-
const storeText = formatStore(
|
|
2426
|
+
const storeText = formatStore(store2);
|
|
2379
2427
|
const systemPrompt = isWrite ? WRITE_SYSTEM(role, keysStr).replace("{store}", storeText) : UPDATE_SYSTEM(role, keysStr).replace("{store}", storeText);
|
|
2380
2428
|
const task = isWrite ? `Write your initial findings to your assigned keys: ${keysStr}` : `Review the shared context and update your entries for keys: ${keysStr}`;
|
|
2381
2429
|
const response = await ask(task, {
|
|
@@ -2387,7 +2435,7 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2387
2435
|
})
|
|
2388
2436
|
);
|
|
2389
2437
|
const entries = [];
|
|
2390
|
-
const newStore = { ...
|
|
2438
|
+
const newStore = { ...store2 };
|
|
2391
2439
|
for (const r of roundResults) {
|
|
2392
2440
|
if (r.status !== "fulfilled") continue;
|
|
2393
2441
|
const { role, response } = r.value;
|
|
@@ -2410,8 +2458,8 @@ async function executeRound(roles, assignments, store, round, opts) {
|
|
|
2410
2458
|
}
|
|
2411
2459
|
return { entries, store: newStore };
|
|
2412
2460
|
}
|
|
2413
|
-
async function consolidateStore(task,
|
|
2414
|
-
const storeText = formatStore(
|
|
2461
|
+
async function consolidateStore(task, store2, opts) {
|
|
2462
|
+
const storeText = formatStore(store2);
|
|
2415
2463
|
return ask(
|
|
2416
2464
|
`Original task: ${task}
|
|
2417
2465
|
|
|
@@ -2452,7 +2500,7 @@ async function execute14(pieces, args, opts) {
|
|
|
2452
2500
|
}
|
|
2453
2501
|
}
|
|
2454
2502
|
const allEntries = [];
|
|
2455
|
-
let
|
|
2503
|
+
let store2 = {};
|
|
2456
2504
|
for (let round = 1; round <= totalRounds; round++) {
|
|
2457
2505
|
const label = round === 1 ? "Writing" : "Updating";
|
|
2458
2506
|
if (!opts.quiet) process.stderr.write(` \u2192 Round ${round}/${totalRounds}: ${label}...
|
|
@@ -2460,15 +2508,15 @@ async function execute14(pieces, args, opts) {
|
|
|
2460
2508
|
const { entries, store: updatedStore } = await executeRound(
|
|
2461
2509
|
roles,
|
|
2462
2510
|
assignments,
|
|
2463
|
-
|
|
2511
|
+
store2,
|
|
2464
2512
|
round,
|
|
2465
2513
|
opts
|
|
2466
2514
|
);
|
|
2467
2515
|
allEntries.push(...entries);
|
|
2468
|
-
|
|
2516
|
+
store2 = updatedStore;
|
|
2469
2517
|
}
|
|
2470
2518
|
if (!opts.quiet) process.stderr.write(" \u2192 Consolidating store...\n");
|
|
2471
|
-
const synthesis = await consolidateStore(task,
|
|
2519
|
+
const synthesis = await consolidateStore(task, store2, { ...opts, plannerModel });
|
|
2472
2520
|
if (!opts.quiet && opts.qualityCheck) process.stderr.write(" \u2192 Quality review...\n");
|
|
2473
2521
|
const qualityReview = await runQualityReview(task, synthesis, opts);
|
|
2474
2522
|
const t1 = Date.now();
|
|
@@ -2479,7 +2527,7 @@ async function execute14(pieces, args, opts) {
|
|
|
2479
2527
|
`Entries: ${allEntries.length}`,
|
|
2480
2528
|
`Synthesis: ${synthesis}`
|
|
2481
2529
|
].join("\n\n");
|
|
2482
|
-
return new TauOutput(summary, allEntries,
|
|
2530
|
+
return new TauOutput(summary, allEntries, store2, synthesis, t0, t1, qualityReview);
|
|
2483
2531
|
}
|
|
2484
2532
|
var \u03A4 = createPatternTag(defaults14, execute14);
|
|
2485
2533
|
|
|
@@ -2520,10 +2568,10 @@ The conversation so far:
|
|
|
2520
2568
|
Respond as your role. Be specific, build on or challenge what others have said.
|
|
2521
2569
|
Keep your response under 200 words.`;
|
|
2522
2570
|
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.`;
|
|
2523
|
-
function buildThreadPrompt(role,
|
|
2571
|
+
function buildThreadPrompt(role, thread2) {
|
|
2524
2572
|
return THREAD_PROMPT.replace("{role}", role).replace(
|
|
2525
2573
|
"{thread}",
|
|
2526
|
-
|
|
2574
|
+
thread2 || "(This is the first message in the thread.)"
|
|
2527
2575
|
);
|
|
2528
2576
|
}
|
|
2529
2577
|
async function execute15(pieces, args, opts) {
|
|
@@ -2541,17 +2589,17 @@ async function execute15(pieces, args, opts) {
|
|
|
2541
2589
|
`);
|
|
2542
2590
|
}
|
|
2543
2591
|
const messages = [];
|
|
2544
|
-
let
|
|
2592
|
+
let thread2 = `Topic: ${topic}
|
|
2545
2593
|
`;
|
|
2546
2594
|
for (let turn = 1; turn <= maxTurns; turn++) {
|
|
2547
2595
|
if (!opts.quiet) process.stderr.write(` \u2192 Turn ${turn}/${maxTurns}
|
|
2548
2596
|
`);
|
|
2549
2597
|
for (let a = 0; a < roles.length; a++) {
|
|
2550
2598
|
const role = roles[a] ?? `Agent ${a + 1}`;
|
|
2551
|
-
const prompt = buildThreadPrompt(role,
|
|
2599
|
+
const prompt = buildThreadPrompt(role, thread2);
|
|
2552
2600
|
const response = await ask(prompt, { ...opts, model: workerModel });
|
|
2553
2601
|
messages.push(new ThreadMessage(role, turn, response));
|
|
2554
|
-
|
|
2602
|
+
thread2 += `
|
|
2555
2603
|
[${role}] (Turn ${turn}): ${response}
|
|
2556
2604
|
`;
|
|
2557
2605
|
}
|
|
@@ -2561,7 +2609,7 @@ async function execute15(pieces, args, opts) {
|
|
|
2561
2609
|
`Topic: ${topic}
|
|
2562
2610
|
|
|
2563
2611
|
Conversation thread:
|
|
2564
|
-
${
|
|
2612
|
+
${thread2}
|
|
2565
2613
|
|
|
2566
2614
|
Synthesize a clear, actionable conclusion.`,
|
|
2567
2615
|
{
|
|
@@ -2581,6 +2629,23 @@ Synthesize a clear, actionable conclusion.`,
|
|
|
2581
2629
|
}
|
|
2582
2630
|
var \u0398 = createPatternTag(defaults15, execute15);
|
|
2583
2631
|
|
|
2632
|
+
// src/patterns/index.ts
|
|
2633
|
+
var ralph = \u03A1;
|
|
2634
|
+
var fleet = \u03A6;
|
|
2635
|
+
var subagent = \u03A3;
|
|
2636
|
+
var debate = \u0394;
|
|
2637
|
+
var pipeline = \u039B;
|
|
2638
|
+
var critique = \u03A8;
|
|
2639
|
+
var orchestrator = \u03A9;
|
|
2640
|
+
var thread = \u0398;
|
|
2641
|
+
var memory = \u039C;
|
|
2642
|
+
var broadcast = \u0392;
|
|
2643
|
+
var adaptive = \u0391;
|
|
2644
|
+
var graph = \u0393;
|
|
2645
|
+
var team = \u039D;
|
|
2646
|
+
var learn = \u03A7;
|
|
2647
|
+
var store = \u03A4;
|
|
2648
|
+
|
|
2584
2649
|
// src/pi.ts
|
|
2585
2650
|
import {
|
|
2586
2651
|
streamSimple
|
|
@@ -2648,8 +2713,11 @@ var defaults16 = {
|
|
|
2648
2713
|
maxTokens: 4096
|
|
2649
2714
|
};
|
|
2650
2715
|
function makeContext(pieces, args, opts) {
|
|
2716
|
+
const systemParts = [];
|
|
2717
|
+
if (opts.system) systemParts.push(opts.system);
|
|
2718
|
+
if (opts.appendSystemPrompt) systemParts.push(opts.appendSystemPrompt);
|
|
2651
2719
|
return {
|
|
2652
|
-
systemPrompt:
|
|
2720
|
+
systemPrompt: systemParts.length > 0 ? systemParts.join("\n\n") : void 0,
|
|
2653
2721
|
messages: [
|
|
2654
2722
|
{
|
|
2655
2723
|
role: "user",
|
|
@@ -2663,8 +2731,10 @@ function makeOpts(opts) {
|
|
|
2663
2731
|
return {
|
|
2664
2732
|
maxTokens: opts.maxTokens,
|
|
2665
2733
|
reasoning: opts.thinkingLevel,
|
|
2734
|
+
thinkingBudgets: opts.thinkingBudgets,
|
|
2666
2735
|
timeoutMs: opts.timeoutMs,
|
|
2667
|
-
maxRetries: opts.maxRetries
|
|
2736
|
+
maxRetries: opts.maxRetries,
|
|
2737
|
+
apiKey: opts.apiKey
|
|
2668
2738
|
};
|
|
2669
2739
|
}
|
|
2670
2740
|
async function run(pieces, args, opts) {
|
|
@@ -2752,7 +2822,10 @@ function configurePi(opts) {
|
|
|
2752
2822
|
}
|
|
2753
2823
|
|
|
2754
2824
|
// src/pi-agent.ts
|
|
2755
|
-
import {
|
|
2825
|
+
import {
|
|
2826
|
+
createAgentSession as createAgentSession2,
|
|
2827
|
+
DefaultResourceLoader
|
|
2828
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2756
2829
|
var _agentDefaults = {
|
|
2757
2830
|
quiet: false,
|
|
2758
2831
|
maxTurns: 10
|
|
@@ -2784,14 +2857,43 @@ var AgentOutput = class {
|
|
|
2784
2857
|
var AgentPromise = class extends Promise {
|
|
2785
2858
|
};
|
|
2786
2859
|
var _sharedSession = null;
|
|
2860
|
+
function createLoader(opts) {
|
|
2861
|
+
const hasSystem = opts.system !== void 0;
|
|
2862
|
+
const hasAppend = opts.appendSystemPrompt !== void 0;
|
|
2863
|
+
const hasSkills = opts.skills && opts.skills.length > 0;
|
|
2864
|
+
if (!hasSystem && !hasAppend && !hasSkills) return void 0;
|
|
2865
|
+
return new DefaultResourceLoader({
|
|
2866
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
2867
|
+
agentDir: "",
|
|
2868
|
+
systemPrompt: opts.system,
|
|
2869
|
+
appendSystemPrompt: opts.appendSystemPrompt ? [opts.appendSystemPrompt] : void 0
|
|
2870
|
+
});
|
|
2871
|
+
}
|
|
2787
2872
|
async function getSession(opts) {
|
|
2788
2873
|
if (_sharedSession && !opts.model) return _sharedSession;
|
|
2789
2874
|
try {
|
|
2875
|
+
const loader = createLoader(opts);
|
|
2876
|
+
if (opts.skills && opts.skills.length > 0 && loader) {
|
|
2877
|
+
const skillMap = await loadSkillContents(opts.skills);
|
|
2878
|
+
const skillPaths = [];
|
|
2879
|
+
for (const [name] of skillMap) {
|
|
2880
|
+
for (const base of SKILL_PATHS) {
|
|
2881
|
+
skillPaths.push({
|
|
2882
|
+
path: `${base}/${name}`,
|
|
2883
|
+
metadata: { source: "pizx", scope: "project", origin: "top-level" }
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
if (skillPaths.length > 0) {
|
|
2888
|
+
loader.extendResources({ skillPaths });
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2790
2891
|
const result = await createAgentSession2({
|
|
2791
2892
|
cwd: opts.cwd,
|
|
2792
2893
|
thinkingLevel: opts.thinkingLevel,
|
|
2793
2894
|
tools: opts.tools,
|
|
2794
|
-
excludeTools: opts.excludeTools
|
|
2895
|
+
excludeTools: opts.excludeTools,
|
|
2896
|
+
resourceLoader: loader
|
|
2795
2897
|
});
|
|
2796
2898
|
_sharedSession = result.session;
|
|
2797
2899
|
return _sharedSession;
|
|
@@ -2890,19 +2992,38 @@ export {
|
|
|
2890
2992
|
OrchestratorWorkerResult,
|
|
2891
2993
|
PatternOutput,
|
|
2892
2994
|
PatternPromise,
|
|
2995
|
+
\u03A0 as Pi,
|
|
2893
2996
|
PiOutput,
|
|
2894
|
-
PiPromise,
|
|
2895
2997
|
PipelineOutput,
|
|
2896
2998
|
PipelineStageResult,
|
|
2897
2999
|
RalphOutput,
|
|
3000
|
+
SKILL_PATHS,
|
|
2898
3001
|
SubagentOutput,
|
|
2899
3002
|
SubagentResult,
|
|
2900
3003
|
ThreadMessage,
|
|
2901
3004
|
ThreadOutput,
|
|
3005
|
+
adaptive,
|
|
3006
|
+
broadcast,
|
|
2902
3007
|
closeAgent,
|
|
2903
3008
|
configureAgent,
|
|
2904
3009
|
configurePi,
|
|
2905
3010
|
createPatternTag,
|
|
3011
|
+
critique,
|
|
3012
|
+
debate,
|
|
3013
|
+
fleet,
|
|
3014
|
+
graph,
|
|
3015
|
+
learn,
|
|
3016
|
+
loadSkillContent,
|
|
3017
|
+
loadSkillContents,
|
|
3018
|
+
memory,
|
|
3019
|
+
orchestrator,
|
|
3020
|
+
\u03C0 as pi,
|
|
3021
|
+
pipeline,
|
|
3022
|
+
ralph,
|
|
3023
|
+
store,
|
|
3024
|
+
subagent,
|
|
3025
|
+
team,
|
|
3026
|
+
thread,
|
|
2906
3027
|
\u0391,
|
|
2907
3028
|
\u0392,
|
|
2908
3029
|
\u0393,
|