@topce/pizx 0.3.0 → 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 CHANGED
@@ -289,6 +289,57 @@ configurePi({ model: 'anthropic/claude-sonnet-4-5', maxTokens: 8000, timeoutMs:
289
289
  configureAgent({ maxTurns: 5, excludeTools: ['write'] })
290
290
  ```
291
291
 
292
+ ### System Prompt Overrides
293
+
294
+ All tags accept `system` (replaces default) and `appendSystemPrompt` (appended after system).
295
+
296
+ ```js
297
+ // π: custom system prompt
298
+ await π({ system: 'You are a security auditor' })`review this code`
299
+
300
+ // Π: set system prompt and append extra instructions
301
+ await Π({ system: 'You are a test engineer', appendSystemPrompt: 'Write tests first' })`add tests for auth`
302
+
303
+ // Patterns: inject system context via mergeSystem
304
+ await Ω({ system: 'Prioritize security over performance' })`design login flow`
305
+ ```
306
+
307
+ ### Thinking Budgets
308
+
309
+ Fine-grained token budgets per reasoning level. Passes through to providers via `thinkingBudgets`.
310
+
311
+ ```js
312
+ // Per-call
313
+ await π({ thinkingBudgets: { medium: 16384, high: 65536 } })`analyze`
314
+
315
+ // Global default
316
+ configurePi({ thinkingBudgets: { medium: 20480, high: 131072 } })
317
+
318
+ // Patterns support it too
319
+ await Ω({ thinkingBudgets: { high: 65536 } })`deep analysis task`
320
+ ```
321
+
322
+ ### Skill Integration
323
+
324
+ Load Pi agent skills from disk and inject them as system context. Skills are discovered from the same paths as `skill.sh`: `.pi/skills`, `.agents/skills`, `~/.pi/agent/skills`, etc.
325
+
326
+ ```js
327
+ import { loadSkillContent, loadSkillContents } from '@topce/pizx'
328
+
329
+ // Load a single skill
330
+ const codeStyle = await loadSkillContent('code-simplification')
331
+ if (codeStyle) {
332
+ await π({ system: codeStyle })`refactor auth.ts`
333
+ }
334
+
335
+ // Load multiple skills
336
+ const skills = await loadSkillContents(['test-driven-development', 'spec-driven-development'])
337
+
338
+ // Π and all patterns accept skills option
339
+ await Π({ skills: ['code-simplification'] })`clean up this file`
340
+ await Ω({ skills: ['spec-driven-development', 'incremental-implementation'] })`build the feature`
341
+ ```
342
+
292
343
  ## CLI Reference
293
344
 
294
345
  ```bash
package/dist/cli.js CHANGED
@@ -179,6 +179,37 @@ function pickModel(preferred) {
179
179
  return models[0];
180
180
  }
181
181
 
182
+ // src/skill-loader.ts
183
+ import { readFile } from "node:fs/promises";
184
+ import { homedir as homedir3 } from "node:os";
185
+ import { join as join3 } from "node:path";
186
+ var SKILL_PATHS = [
187
+ ".pi/skills",
188
+ ".agents/skills",
189
+ "skills",
190
+ join3(homedir3(), ".pi", "agent", "skills"),
191
+ join3(homedir3(), ".codewhale", "skills"),
192
+ join3(homedir3(), ".claude", "skills")
193
+ ];
194
+ async function loadSkillContent(name) {
195
+ for (const base of SKILL_PATHS) {
196
+ const candidate = join3(base, name, "SKILL.md");
197
+ try {
198
+ return await readFile(candidate, "utf-8");
199
+ } catch {
200
+ }
201
+ }
202
+ return void 0;
203
+ }
204
+ async function loadSkillContents(names) {
205
+ const map = /* @__PURE__ */ new Map();
206
+ for (const name of names) {
207
+ const content = await loadSkillContent(name);
208
+ if (content) map.set(name, content);
209
+ }
210
+ return map;
211
+ }
212
+
182
213
  // src/patterns/types.ts
183
214
  var PatternOutput = class {
184
215
  constructor(text, startTime = Date.now(), endTime = Date.now()) {
@@ -309,16 +340,32 @@ async function confirmPhase(description, opts) {
309
340
  async function ask(prompt, opts = {}) {
310
341
  const model = pickModel(opts.model);
311
342
  if (!model) throw new Error("pizx/patterns: No AI models configured. Run `pi auth login` first.");
343
+ let systemPrompt = opts.system;
344
+ if (opts.skills && opts.skills.length > 0) {
345
+ const skillMap = await loadSkillContents(opts.skills);
346
+ if (skillMap.size > 0) {
347
+ const skillBlocks = [];
348
+ for (const [name, content] of skillMap) {
349
+ skillBlocks.push(`Skill context (${name}):
350
+ ${content}`);
351
+ }
352
+ const skillContext = skillBlocks.join("\n\n");
353
+ systemPrompt = systemPrompt ? `${systemPrompt}
354
+
355
+ ${skillContext}` : skillContext;
356
+ }
357
+ }
312
358
  const t0 = Date.now();
313
359
  const result = await completeSimple(
314
360
  model,
315
361
  {
316
- systemPrompt: opts.system,
362
+ systemPrompt,
317
363
  messages: [{ role: "user", content: prompt, timestamp: Date.now() }]
318
364
  },
319
365
  {
320
366
  maxTokens: opts.maxTokens ?? 4096,
321
367
  reasoning: opts.thinkingLevel ?? "medium",
368
+ thinkingBudgets: opts.thinkingBudgets,
322
369
  timeoutMs: opts.timeoutMs,
323
370
  maxRetries: opts.maxRetries
324
371
  }
@@ -2709,8 +2756,11 @@ var defaults16 = {
2709
2756
  maxTokens: 4096
2710
2757
  };
2711
2758
  function makeContext(pieces, args, opts) {
2759
+ const systemParts = [];
2760
+ if (opts.system) systemParts.push(opts.system);
2761
+ if (opts.appendSystemPrompt) systemParts.push(opts.appendSystemPrompt);
2712
2762
  return {
2713
- systemPrompt: opts.system,
2763
+ systemPrompt: systemParts.length > 0 ? systemParts.join("\n\n") : void 0,
2714
2764
  messages: [
2715
2765
  {
2716
2766
  role: "user",
@@ -2724,6 +2774,7 @@ function makeOpts(opts) {
2724
2774
  return {
2725
2775
  maxTokens: opts.maxTokens,
2726
2776
  reasoning: opts.thinkingLevel,
2777
+ thinkingBudgets: opts.thinkingBudgets,
2727
2778
  timeoutMs: opts.timeoutMs,
2728
2779
  maxRetries: opts.maxRetries
2729
2780
  };
@@ -2810,7 +2861,10 @@ function makePi(opts = {}) {
2810
2861
  var \u03C0 = makePi();
2811
2862
 
2812
2863
  // src/pi-agent.ts
2813
- import { createAgentSession as createAgentSession2 } from "@earendil-works/pi-coding-agent";
2864
+ import {
2865
+ createAgentSession as createAgentSession2,
2866
+ DefaultResourceLoader
2867
+ } from "@earendil-works/pi-coding-agent";
2814
2868
  var _agentDefaults = {
2815
2869
  quiet: false,
2816
2870
  maxTurns: 10
@@ -2842,14 +2896,43 @@ var AgentOutput = class {
2842
2896
  var AgentPromise = class extends Promise {
2843
2897
  };
2844
2898
  var _sharedSession = null;
2899
+ function createLoader(opts) {
2900
+ const hasSystem = opts.system !== void 0;
2901
+ const hasAppend = opts.appendSystemPrompt !== void 0;
2902
+ const hasSkills = opts.skills && opts.skills.length > 0;
2903
+ if (!hasSystem && !hasAppend && !hasSkills) return void 0;
2904
+ return new DefaultResourceLoader({
2905
+ cwd: opts.cwd ?? process.cwd(),
2906
+ agentDir: "",
2907
+ systemPrompt: opts.system,
2908
+ appendSystemPrompt: opts.appendSystemPrompt ? [opts.appendSystemPrompt] : void 0
2909
+ });
2910
+ }
2845
2911
  async function getSession(opts) {
2846
2912
  if (_sharedSession && !opts.model) return _sharedSession;
2847
2913
  try {
2914
+ const loader = createLoader(opts);
2915
+ if (opts.skills && opts.skills.length > 0 && loader) {
2916
+ const skillMap = await loadSkillContents(opts.skills);
2917
+ const skillPaths = [];
2918
+ for (const [name] of skillMap) {
2919
+ for (const base of SKILL_PATHS) {
2920
+ skillPaths.push({
2921
+ path: `${base}/${name}`,
2922
+ metadata: { source: "pizx", scope: "project", origin: "top-level" }
2923
+ });
2924
+ }
2925
+ }
2926
+ if (skillPaths.length > 0) {
2927
+ loader.extendResources({ skillPaths });
2928
+ }
2929
+ }
2848
2930
  const result = await createAgentSession2({
2849
2931
  cwd: opts.cwd,
2850
2932
  thinkingLevel: opts.thinkingLevel,
2851
2933
  tools: opts.tools,
2852
- excludeTools: opts.excludeTools
2934
+ excludeTools: opts.excludeTools,
2935
+ resourceLoader: loader
2853
2936
  });
2854
2937
  _sharedSession = result.session;
2855
2938
  return _sharedSession;