@topce/pizx 0.1.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
@@ -1,19 +1,92 @@
1
1
  # pizx
2
2
 
3
- **zx fork with native Pi AI integration** — 15 template tags for shell scripting, AI text generation, coding agents, agentic patterns, communication, and orchestration topologies.
3
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/topce?style=social&logo=github)](https://github.com/sponsors/topce)
4
+
5
+ > **zx fork with native Pi AI integration** — 15 template tags for shell scripting, AI text generation, coding agents, agentic patterns, communication, and orchestration topologies.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ npm install @topce/pizx
11
+ pi auth login # one-time: configure Pi AI credentials
12
+ ```
13
+
14
+ Write a script (`hello.mjs`):
4
15
 
5
16
  ```js
6
17
  #!/usr/bin/env pizx
7
- const files = (await $`ls src/`).stdout.trim()
8
- const summary = await π`summarize these files: ${files}`
9
- await Π`fix TypeScript errors flagged in: ${summary}`
10
- await Ρ`iteratively improve error handling across src/`
11
- const plan = await Ω`design a comprehensive testing strategy for this project`
18
+
19
+ // Simple AI query
20
+ const answer = await π`what is the capital of France?`
21
+ echo(answer)
22
+
23
+ // Agent patterns
24
+ const files = await $`ls src/`
25
+ const summary = await π`summarize these files in one sentence: ${files}`
26
+ console.log(summary)
27
+ ```
28
+
29
+ Run it:
30
+
31
+ ```bash
32
+ chmod +x hello.mjs
33
+ ./hello.mjs
34
+
35
+ # Or:
36
+ pizx hello.mjs
37
+ ```
38
+
39
+ **New to pizx?** Start with the [Onboarding Guide](docs/onboarding.md).
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ npm install @topce/pizx
45
+ ```
46
+
47
+ **Prerequisites:**
48
+ - Node.js >= 22.19.0
49
+ - [Pi AI](https://github.com/earendil-works/pi-ai) installed and configured (`pi auth login`)
50
+ - Shell commands from [zx](https://github.com/google/zx) (`$`, `cd`, `echo`, `fetch`, etc.)
51
+
52
+ ## Writing Scripts
53
+
54
+ ### Shebang
55
+
56
+ ```js
57
+ #!/usr/bin/env pizx
58
+
59
+ const name = await question('What is your name? ')
60
+ const intro = await π`write a friendly greeting for ${name}`
61
+ echo(intro)
62
+ ```
63
+
64
+ ### Programmatic Import
65
+
66
+ ```js
67
+ import { $, π, Π, Ρ, Φ, Σ } from '@topce/pizx'
68
+
69
+ const output = await $`ls src/ | grep '.ts'`
70
+ console.log(output.stdout)
71
+
72
+ const review = await π`review this code for issues:\n${output.stdout}`
73
+ console.log(review.text)
74
+
75
+ // Use the coding agent to fix issues
76
+ await Π`fix the TypeScript errors in src/`
77
+ ```
78
+
79
+ ### CLI Quick Queries
80
+
81
+ ```bash
82
+ pizx -p "explain async/await in JavaScript"
83
+ pizx -p --model deepseek/deepseek-chat "summarize this code: @file.ts"
84
+ pizx --version
12
85
  ```
13
86
 
14
87
  ## Tags Reference
15
88
 
16
- Each tag has its own detailed documentation in [`docs/`](docs/):
89
+ Each tag has detailed documentation in [`docs/`](docs/):
17
90
 
18
91
  ### Core
19
92
 
@@ -53,7 +126,21 @@ Each tag has its own detailed documentation in [`docs/`](docs/):
53
126
  | `Χ` | Chi | Analyze traces → extract patterns | [docs/chi.md](docs/chi.md) |
54
127
  | `Τ` | Tau | Define schema → write → refine → consolidate | [docs/tau.md](docs/tau.md) |
55
128
 
56
- ## Per-Phase Model Selection
129
+ ## Architecture
130
+
131
+ See [docs/decisions/](docs/decisions/) for Architecture Decision Records covering the key design choices:
132
+
133
+ - [ADR-001: Template-Tag DSL](docs/decisions/ADR-001-template-tag-dsl.md) — Why patterns are template tags with curried option chaining
134
+ - [ADR-002: Shared Tag Factory](docs/decisions/ADR-002-shared-tag-factory.md) — How `createPatternTag` eliminates 450 lines of boilerplate
135
+ - [ADR-003: Quality Validation](docs/decisions/ADR-003-quality-validation.md) — The `qualityCheck` design and `runQualityReview` helper
136
+ - [ADR-004: Phase Logging](docs/decisions/ADR-004-phase-logging.md) — Structured audit trails via `phaseLog` on every output
137
+ - [ADR-005: Pattern Composition](docs/decisions/ADR-005-pattern-composition.md) — How `TaskDescriptor` enables nested patterns
138
+ - [ADR-006: Confirm Gates](docs/decisions/ADR-006-confirm-gates.md) — Human-in-the-loop approval via `confirm` option
139
+ - [ADR-007: System Propagation](docs/decisions/ADR-007-system-propagation.md) — How `mergeSystem` propagates user prompts
140
+
141
+ ## Advanced Features
142
+
143
+ ### Per-Phase Model Selection
57
144
 
58
145
  All patterns support `plannerModel` and `workerModel` for routing high-level reasoning vs execution to different models:
59
146
 
@@ -66,40 +153,245 @@ await Ω({
66
153
 
67
154
  Without per-phase models, patterns fall back to `model` → Pi default.
68
155
 
69
- ## Option Chaining
156
+ ### System Prompt Propagation
157
+
158
+ All patterns respect the `system` option. When you provide a custom system prompt, it is prepended to the pattern's default system prompt — your context is never silently discarded:
159
+
160
+ ```js
161
+ await Ω({ system: 'You are a senior security architect.' })`design an auth system`
162
+ // → "You are a senior security architect.\n\n[PLANNER_SYSTEM]"
163
+ ```
164
+
165
+ ### Quality Validation
166
+
167
+ All 15 patterns support an optional `qualityCheck` flag. When enabled, the pattern runs a post-execution LLM review that scores the final output (0.0–1.0), provides an assessment, and recommends improvements:
168
+
169
+ ```js
170
+ const result = await Ω({ qualityCheck: true })`design the system architecture`
171
+
172
+ if (result.qualityReview) {
173
+ console.log(`Quality score: ${result.qualityReview.score}`) // 0.0 – 1.0
174
+ console.log(result.qualityReview.assessment) // 1-2 sentence assessment
175
+ console.log(result.qualityReview.recommendation) // improvement suggestion
176
+ }
177
+ ```
178
+
179
+ ### Human-in-the-Loop (Confirm Gates)
180
+
181
+ Set `confirm: true` to pause before the main execution phase and ask for approval. The pattern displays a summary of what it's about to do and waits for `[Y/n]` on stdin:
182
+
183
+ ```js
184
+ await Ω({ confirm: true })`design the system`
185
+ // → "── Confirm ──"
186
+ // → "Execute 3 sub-task(s) as planned?"
187
+ // → " 1. Analyze requirements"
188
+ // → " 2. Design architecture"
189
+ // → " 3. Document decisions"
190
+ // → "Proceed? [Y/n] "
191
+ ```
192
+
193
+ Supported by: `Ω`, `Σ`, `Φ`, `Λ` (more patterns coming).
194
+
195
+ ### Option Chaining & Quiet Mode
70
196
 
71
- All patterns support option chaining and `.quiet` mode:
197
+ All tags support option chaining and `.quiet` mode to suppress output:
72
198
 
73
199
  ```js
200
+ await π({ model: 'anthropic/claude-sonnet-4-5' })`explain this algorithm`
201
+ await Π.quiet`fix the lint issues in src/`
74
202
  await Φ({ concurrency: 5 })`review all .ts files`
75
203
  await Σ.quiet`analyze security across the codebase`
76
204
  await Θ({ agents: 4, turns: 3 })`debate the architecture`
77
205
  await Γ({ graph: { nodes: [...], edges: [...] } })`execute workflow`
78
206
  ```
79
207
 
80
- ## Install
208
+ ### Timeout & Retry
81
209
 
82
- ```bash
83
- npm install @topce/pizx
210
+ All tags accept `timeoutMs` and `maxRetries` to control LLM call resilience. When unset, the provider SDK defaults apply (typically 10 min timeout, 2 retries).
211
+
212
+ ```js
213
+ // Per-pattern
214
+ await Φ({ timeoutMs: 30000, maxRetries: 2 })`review all .ts files`
215
+
216
+ // Per-call on π
217
+ await π({ timeoutMs: 15000 })`summarize this document`
218
+
219
+ // Global defaults
220
+ configurePi({ timeoutMs: 60000, maxRetries: 3 })
221
+ ```
222
+
223
+ ### Token, Cost & Phase Tracking
224
+
225
+ Every pattern output and π call includes an execution trace with token usage, cost, and a structured phase log. All collected automatically — no extra flags needed.
226
+
227
+ ```js
228
+ const result = await Ω`design a notification system`
229
+
230
+ // Per-call breakdown
231
+ for (const t of result.trace) {
232
+ console.log(`Call ${t.call}: ${t.modelId} — ${t.totalTokens} tokens, $${t.cost.toFixed(6)}`)
233
+ }
234
+
235
+ // Aggregates (on both PatternOutput and PiOutput)
236
+ console.log(`Total: ${result.totalTokens} tokens`)
237
+ console.log(`Cost: $${result.totalCost.toFixed(4)}`)
238
+ console.log(`Calls: ${result.callCount}`)
239
+
240
+ // Structured phase log — what happened during execution
241
+ for (const phase of result.phaseLog) {
242
+ console.log(`${phase.phase}: ${phase.durationMs}ms — ${phase.description}`)
243
+ }
244
+ // → "plan: 1234ms — Generated plan with 3 workers"
245
+ // → "dispatch: 5678ms — Executed 3 worker(s), 3 succeeded"
246
+ // → "synthesize: 901ms — Synthesized worker results"
247
+
248
+ // Works with π too
249
+ const answer = await π`explain quantum computing`
250
+ console.log(`Input: ${answer.inputTokens}, Output: ${answer.outputTokens}`)
251
+ console.log(`Cost: $${answer.totalCost.toFixed(6)}`)
252
+ ```
253
+
254
+ Each `CallTrace` entry includes: call index, model id, prompt/output previews, input/output/cache tokens, cost (USD), and duration.
255
+
256
+ ### Pattern Composition (Nesting)
257
+
258
+ Fleet and Pipeline accept `TaskDescriptor` — either a plain string (for a standard LLM call) or a function that invokes another pattern as a sub-task. See [docs/advanced-features.md](docs/advanced-features.md#pattern-composition-taskdescriptor) for details.
259
+
260
+ **Fleet with mixed tasks:**
261
+
262
+ ```js
263
+ await Φ({
264
+ tasks: [
265
+ 'analyze the frontend', // string: standard LLM call
266
+ () => Σ\`analyze the backend\`, // function: compose a Subagents pattern
267
+ () => Ψ\`review the API design\`, // function: compose a Critique pattern
268
+ ],
269
+ })`review everything`
270
+ ```
271
+
272
+ **Pipeline with composed stages:**
273
+
274
+ ```js
275
+ await Λ({
276
+ stages: [
277
+ 'generate product description', // string: standard LLM call
278
+ (prev) => Ψ\`critique this: ${prev}\`, // function: receives previous output
279
+ ],
280
+ })`generate → improve`
281
+ ```
282
+
283
+ ### Global Configuration
284
+
285
+ ```js
286
+ import { configurePi, configureAgent } from '@topce/pizx'
287
+
288
+ configurePi({ model: 'anthropic/claude-sonnet-4-5', maxTokens: 8000, timeoutMs: 60000 })
289
+ configureAgent({ maxTurns: 5, excludeTools: ['write'] })
290
+ ```
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`
84
320
  ```
85
321
 
86
- Requires Pi AI configured: `pi auth login`
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
+ ```
87
342
 
88
- ## CLI
343
+ ## CLI Reference
89
344
 
90
345
  ```bash
91
- pizx script.mjs # Run a pizx script
92
- pizx -p "prompt" # Quick pi-ai query
93
- pizx --version # Print version
346
+ pizx [options] <script> # Run a pizx script
347
+ pizx -p <prompt> # Quick pi-ai query
348
+ pizx --version # Print version
349
+ pizx --help # Print help
94
350
  ```
95
351
 
352
+ **Options:**
353
+ - `-p, --prompt <text>` — Run a quick pi-ai query (no script needed)
354
+ - `-m, --model <id>` — Specify AI model to use
355
+ - `--quiet` — Suppress output except errors
356
+ - `--shell <path>` — Shell to use (default: auto-detect)
357
+
96
358
  ## Commands
97
359
 
98
360
  ```bash
99
- npm run build # Build (JS + DTS)
100
- npm test # 95 unit tests
361
+ npm run build # Build (JS + DTS)
362
+ npm run check # Lint and format with Biome
363
+ npm test # 223 unit tests (no network)
364
+ npm run test:integration # Integration tests (requires Pi credentials)
365
+ npm run test:quality # Run qualityCheck example
366
+ npm run test:confirm # Run confirm gate example
367
+ npm run test:composition-fleet # Run pattern composition in Fleet example
368
+ npm run test:composition-pipeline # Run pattern composition in Pipeline example
369
+ npm run test:new-features # Run all 4 feature examples
370
+ npm run example:hello # Run hello example
371
+ npm run example:all # Run all pattern examples
101
372
  ```
102
373
 
374
+ ## Examples
375
+
376
+ See [`examples/`](examples/) for runnable examples of every pattern and feature:
377
+
378
+ ### Pattern Examples
379
+
380
+ - [`hello-pizx.mjs`](examples/hello-pizx.mjs) — Basic script with shell + AI
381
+ - [`basic-pi.mjs`](examples/basic-pi.mjs) — π text generation
382
+ - [`basic-capital-pi.mjs`](examples/basic-capital-pi.mjs) — Π coding agent
383
+ - [`pattern-ralph.mjs`](examples/pattern-ralph.mjs) — Ralph Loop
384
+ - [`pattern-fleet.mjs`](examples/pattern-fleet.mjs) — Fleet parallel execution
385
+ - [`pattern-debate.mjs`](examples/pattern-debate.mjs) — Multi-perspective debate
386
+ - ... and more for every pattern
387
+
388
+ ### New Feature Demos
389
+
390
+ - [`test-quality.mjs`](examples/test-quality.mjs) — `qualityCheck` + `system` + `phaseLog`
391
+ - [`test-confirm.mjs`](examples/test-confirm.mjs) — Human-in-the-loop approval gate
392
+ - [`test-composition-fleet.mjs`](examples/test-composition-fleet.mjs) — Pattern composition in Fleet
393
+ - [`test-composition-pipeline.mjs`](examples/test-composition-pipeline.mjs) — Pattern composition in Pipeline
394
+
103
395
  ## License
104
396
 
105
397
  MIT