@xynogen/pix-skills 0.4.6 → 0.4.8
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 +3 -1
- package/package.json +1 -1
- package/skills/subagent.md +212 -0
- package/skills/toon.md +101 -0
- package/src/index.ts +1 -1
- package/src/once.ts +19 -9
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Pi coding agent extension — skill loader tool + skills bundle.
|
|
|
7
7
|
| Resource | Type | Description |
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| `read_skills` | tool | Browse and load bundled skills. No args → list all. `name` only → description. `name + full=true` → full instructions. |
|
|
10
|
-
| `skills/` | skills |
|
|
10
|
+
| `skills/` | skills | 26 bundled skills (auto-loaded by pi at startup — names + descriptions in system prompt) |
|
|
11
11
|
|
|
12
12
|
## How it works
|
|
13
13
|
|
|
@@ -50,8 +50,10 @@ All skills are model-invocable — pi auto-loads each one on description match.
|
|
|
50
50
|
| `task` | Task orchestration and ambiguity resolution |
|
|
51
51
|
| `test` | Test execution, analysis, and failure resolution via TDD |
|
|
52
52
|
| `tldr` | Maximum-density technical summary, zero filler |
|
|
53
|
+
| `toon` | Handle information-dense JSON with jq + TOON compression |
|
|
53
54
|
| `ui` | UI/UX design and implementation guidance for frontends |
|
|
54
55
|
| `verify` | Verification before completion — confirm it's actually fixed |
|
|
56
|
+
| `subagent` | Plan, decompose, and fan out independent units to cheaper parallel subagent workers |
|
|
55
57
|
|
|
56
58
|
## Usage
|
|
57
59
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: subagent
|
|
3
|
+
description: Plan a task, break it into small independent units, and fan them out in parallel to cheaper/less-capable subagent models for faster, cheaper, more efficient execution. Use when a task is large enough to split into parts that do not depend on each other and a strong model is overkill for each part.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Parallel Delegate
|
|
7
|
+
|
|
8
|
+
Plan first, decompose into small independent units, then fan those units out to
|
|
9
|
+
**cheaper** subagent models running **in parallel**. A capable orchestrator (you)
|
|
10
|
+
keeps the plan, the decisions, and the final integration. Cheap workers do the
|
|
11
|
+
bulk grunt work concurrently. Net effect: faster wall-clock, lower cost, less of
|
|
12
|
+
the expensive model's tokens spent on mechanical work.
|
|
13
|
+
|
|
14
|
+
This skill is for the **parent orchestrator only**. Children receive concrete,
|
|
15
|
+
self-contained tasks — they do not plan, do not decompose further, and do not
|
|
16
|
+
launch their own subagents.
|
|
17
|
+
|
|
18
|
+
## When to use
|
|
19
|
+
|
|
20
|
+
Use when **all** of these hold:
|
|
21
|
+
|
|
22
|
+
- The task splits into **2+ units that do not depend on each other** (no unit
|
|
23
|
+
needs another unit's output mid-flight).
|
|
24
|
+
- Each unit is **mechanical enough** that a smaller model can do it reliably
|
|
25
|
+
given a precise spec (boilerplate, repetitive edits across files, test
|
|
26
|
+
scaffolding, format conversions, doc stubs, per-module refactors).
|
|
27
|
+
- The shared decisions (architecture, contracts, naming) can be **fixed up
|
|
28
|
+
front** by the orchestrator so workers don't have to make them.
|
|
29
|
+
|
|
30
|
+
Do **not** use when:
|
|
31
|
+
|
|
32
|
+
- Units share a write target (same file/region) — that needs a single writer,
|
|
33
|
+
not a swarm. Use the single-writer pattern or `worktree: true`.
|
|
34
|
+
- The work is genuinely hard reasoning end-to-end — a cheap model will produce
|
|
35
|
+
slop you pay to fix.
|
|
36
|
+
- The pieces are tightly coupled and must be done in sequence — use a chain.
|
|
37
|
+
|
|
38
|
+
## The flow
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
1. PLAN → decide architecture, contracts, naming, acceptance up front
|
|
42
|
+
2. DECOMPOSE → split into N independent, fully-specified units
|
|
43
|
+
3. FAN OUT → subagent({ tasks:[...], concurrency }) with a cheap model per task
|
|
44
|
+
4. INTEGRATE → orchestrator wires units together, resolves seams, runs the gate
|
|
45
|
+
5. VERIFY → lint + typecheck + tests; fix seams the cheap workers couldn't
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 1. Plan
|
|
49
|
+
|
|
50
|
+
For simple/medium tasks, plan inline using the `plan` skill's discipline: fix the
|
|
51
|
+
exact file paths, the shared contracts (types, function signatures, interfaces),
|
|
52
|
+
the naming, and the acceptance criteria **before** splitting. The whole point is
|
|
53
|
+
that workers inherit decisions instead of inventing them.
|
|
54
|
+
|
|
55
|
+
For large/complex tasks, delegate planning to the builtin `planner` first, get
|
|
56
|
+
the plan, then decompose it:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
subagent({ agent: "planner", task: "Plan: <task>. Emphasize independent, parallelizable units." })
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 2. Decompose
|
|
63
|
+
|
|
64
|
+
Split the plan into units that satisfy the independence test:
|
|
65
|
+
|
|
66
|
+
- **No cross-unit dependency** — a unit must be completable with only the spec
|
|
67
|
+
the orchestrator hands it, never another running unit's output.
|
|
68
|
+
- **No shared write target** — two units must not edit the same file/region.
|
|
69
|
+
- **Self-contained spec** — each unit's task string carries everything: exact
|
|
70
|
+
paths, the shared contract it must conform to, the expected output shape, and
|
|
71
|
+
how to validate locally.
|
|
72
|
+
|
|
73
|
+
If a unit fails the test, either merge it back, sequence it (chain), or keep it
|
|
74
|
+
on the orchestrator.
|
|
75
|
+
|
|
76
|
+
### 3. Fan out to cheap models
|
|
77
|
+
|
|
78
|
+
Use top-level parallel tasks with a per-task `model` override pointing at a
|
|
79
|
+
cheaper/smaller model.
|
|
80
|
+
|
|
81
|
+
**Resolve the cheap model at call time — never hardcode it.** The active model is
|
|
82
|
+
dynamic: the user can switch it mid-chat, and the orchestrator's own model is
|
|
83
|
+
whatever is current. So before fanning out:
|
|
84
|
+
|
|
85
|
+
1. If the user named a cheap model for the workers, use that.
|
|
86
|
+
2. Otherwise pick a cheaper sibling of the **current** model (smaller/mini/flash
|
|
87
|
+
tier of the same or a comparable provider).
|
|
88
|
+
3. If no clearly-cheaper option is obvious, **ask** which model to delegate to
|
|
89
|
+
rather than guessing — the wrong pick wastes the run.
|
|
90
|
+
|
|
91
|
+
The per-task `model` override is the right mechanism precisely because the main
|
|
92
|
+
model can change: the override pins each worker to the chosen cheap model
|
|
93
|
+
regardless of what the orchestrator is running at that moment. Examples below use
|
|
94
|
+
`<cheap-model>` as a placeholder — substitute the resolved model.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
subagent({
|
|
98
|
+
tasks: [
|
|
99
|
+
{ agent: "worker", model: "<cheap-model>", task: "<full self-contained spec for unit A>", output: "units/a.md", outputMode: "file-only" },
|
|
100
|
+
{ agent: "worker", model: "<cheap-model>", task: "<full self-contained spec for unit B>", output: "units/b.md", outputMode: "file-only" },
|
|
101
|
+
{ agent: "worker", model: "<cheap-model>", task: "<full self-contained spec for unit C>", output: "units/c.md", outputMode: "file-only" }
|
|
102
|
+
],
|
|
103
|
+
concurrency: 3,
|
|
104
|
+
async: true
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Rules for the fan-out:
|
|
109
|
+
|
|
110
|
+
- **One cheap model per task** via `model`. Keep the orchestrator on the strong
|
|
111
|
+
model; only the workers get downgraded.
|
|
112
|
+
- **`concurrency`** caps how many run at once. Default 3–4; raise it for many
|
|
113
|
+
tiny units, lower it if the units are heavy.
|
|
114
|
+
- **`async: true`** so the main chat stays unblocked. While workers run, the
|
|
115
|
+
orchestrator does integration prep, not parallel edits to the same files.
|
|
116
|
+
- **Distinct `output` paths** — concurrent children must never write the same
|
|
117
|
+
file. Use `outputMode: "file-only"` for large outputs so the parent result
|
|
118
|
+
stays compact.
|
|
119
|
+
- **No shared worktree writes.** If units genuinely must edit the repo
|
|
120
|
+
concurrently, isolate each with `worktree: true` instead of letting them
|
|
121
|
+
collide.
|
|
122
|
+
|
|
123
|
+
#### Cheap-worker prompt contract
|
|
124
|
+
|
|
125
|
+
Because the worker is less capable, the spec must be **tighter**, not looser.
|
|
126
|
+
Each task string should carry:
|
|
127
|
+
|
|
128
|
+
- **Goal** — the one concrete artifact this unit produces.
|
|
129
|
+
- **Contract** — the exact types/signatures/paths it must conform to (copied in,
|
|
130
|
+
not referenced from parent history — children don't see it).
|
|
131
|
+
- **Constraints** — what not to touch; "edit only `<paths>`"; no scope creep.
|
|
132
|
+
- **Validation** — the local check to run and the expected result.
|
|
133
|
+
- **Output** — the exact shape to return (file written, summary format).
|
|
134
|
+
|
|
135
|
+
Add structured `acceptance` for write units so the runtime runs a bounded
|
|
136
|
+
self-check before reporting done:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
{
|
|
140
|
+
agent: "worker",
|
|
141
|
+
model: "<cheap-model>",
|
|
142
|
+
task: "<full spec>",
|
|
143
|
+
acceptance: {
|
|
144
|
+
criteria: ["Conforms to the given contract", "Edits only the named files", "Local check passes"],
|
|
145
|
+
evidence: ["changed-files", "validation-output"],
|
|
146
|
+
verify: [{ id: "check", command: "<targeted test/lint command>" }],
|
|
147
|
+
stopRules: ["Do not edit files outside the named paths", "Stop and report if the contract is ambiguous"],
|
|
148
|
+
maxFinalizationTurns: 2
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 4. Integrate
|
|
154
|
+
|
|
155
|
+
When the workers finish, the **orchestrator** (strong model) does the joins that
|
|
156
|
+
cheap models are bad at: reconciling seams between units, fixing contract drift,
|
|
157
|
+
wiring the pieces into the whole, and removing any slop. This is where the
|
|
158
|
+
expensive model earns its cost — on the 10% that's hard, not the 90% that's
|
|
159
|
+
mechanical.
|
|
160
|
+
|
|
161
|
+
If a worker produced something off-contract, prefer to fix it inline rather than
|
|
162
|
+
re-spawning, unless the miss is large and clean to redo.
|
|
163
|
+
|
|
164
|
+
### 5. Verify
|
|
165
|
+
|
|
166
|
+
Run the repo's quality gate on the integrated result — never trust the sum of
|
|
167
|
+
green per-unit checks to mean the whole is green:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
lint → typecheck → tests
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Fix the cross-unit failures (the seams) yourself. A unit passing in isolation
|
|
174
|
+
does not mean it composes correctly.
|
|
175
|
+
|
|
176
|
+
## Worked shape: repetitive edit across modules
|
|
177
|
+
|
|
178
|
+
Task: "Add the same new field + validation to 6 independent API handlers."
|
|
179
|
+
|
|
180
|
+
1. **Plan** — fix the field name, type, validation rule, and error message once.
|
|
181
|
+
2. **Decompose** — 6 units, one per handler file, each fully independent.
|
|
182
|
+
3. **Fan out** — 6 `worker` tasks at a cheap model, `concurrency: 4`, each told
|
|
183
|
+
the exact field/type/rule and "edit only `handlers/<name>.ts`".
|
|
184
|
+
4. **Integrate** — orchestrator checks the shared validation helper is consistent
|
|
185
|
+
across all 6, dedupes if they each inlined it.
|
|
186
|
+
5. **Verify** — full test suite; fix any handler that drifted from the contract.
|
|
187
|
+
|
|
188
|
+
## Cost / efficiency notes
|
|
189
|
+
|
|
190
|
+
- The win is **decomposition quality**, not raw parallelism. Bad splits create
|
|
191
|
+
coupling that the orchestrator pays to untangle, erasing the savings.
|
|
192
|
+
- Cheap models need **more spec, less latitude**. The orchestrator spends its
|
|
193
|
+
tokens on a precise plan once, then amortizes it across N cheap runs.
|
|
194
|
+
- Parallelism cuts **wall-clock**; cheap models cut **cost**. You get both only
|
|
195
|
+
when units are truly independent and truly mechanical.
|
|
196
|
+
- If you find yourself re-spawning workers to fix their output repeatedly, the
|
|
197
|
+
unit was too hard for the cheap model — pull it back to the orchestrator or a
|
|
198
|
+
capable `worker`.
|
|
199
|
+
|
|
200
|
+
## Constraints
|
|
201
|
+
|
|
202
|
+
- **Parent owns orchestration.** Children get concrete tasks; they do not plan,
|
|
203
|
+
decompose, or spawn subagents.
|
|
204
|
+
- **Single writer per target.** Independent files or isolated worktrees only —
|
|
205
|
+
never concurrent writes to the same region.
|
|
206
|
+
- **Self-contained specs.** Children don't inherit parent history; copy every
|
|
207
|
+
contract detail into the task string.
|
|
208
|
+
- **Strong model integrates and verifies.** Cheap models do bulk units; the
|
|
209
|
+
orchestrator owns the seams and the final gate.
|
|
210
|
+
- **Resolve the worker model at call time.** The active model can change
|
|
211
|
+
mid-chat; pick the cheap model per fan-out via the per-task `model` override,
|
|
212
|
+
never a hardcoded default. Ask if no clearly-cheaper option is obvious.
|
package/skills/toon.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: toon
|
|
3
|
+
description: Manipulate information-dense JSON efficiently with jq + TOON. Use when fetching/reading large or repetitive JSON (LLM schemas, OpenAPI specs, API responses, datasets, config dumps) into context. Query/reshape with jq, compress to TOON to cut tokens, decode back to JSON only when a strict contract needs it.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TOON + jq: Dense JSON Workflow
|
|
7
|
+
|
|
8
|
+
## Goal
|
|
9
|
+
Carry only the JSON slice you need, in the cheapest encoding. Query with `jq`,
|
|
10
|
+
compress with `toon`, and round-trip back to JSON **only** when a contract
|
|
11
|
+
requires strict JSON.
|
|
12
|
+
|
|
13
|
+
TOON (Token-Oriented Object Notation, https://github.com/toon-format/spec) is a
|
|
14
|
+
line-oriented encoding of the JSON data model. Uniform arrays of objects declare
|
|
15
|
+
their keys once and stream bare rows, so token cost drops sharply on tabular and
|
|
16
|
+
dense data.
|
|
17
|
+
|
|
18
|
+
## The pipeline
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Fetch → reshape → compress (most common)
|
|
22
|
+
curl -s https://api.example.com/models | jq '.data' | toon
|
|
23
|
+
|
|
24
|
+
# Local file, show token savings
|
|
25
|
+
cat openapi.json | jq '.paths' | toon --stats
|
|
26
|
+
|
|
27
|
+
# Just compress, no query
|
|
28
|
+
cat data.json | toon
|
|
29
|
+
|
|
30
|
+
# Convert TOON back to JSON (strict contract / downstream parser)
|
|
31
|
+
echo "$TOON_BLOB" | toon -d
|
|
32
|
+
cat data.toon | toon --decode
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`toon` auto-detects direction from input. Force it with `-e` (encode JSON→TOON)
|
|
36
|
+
or `-d` (decode TOON→JSON).
|
|
37
|
+
|
|
38
|
+
### Useful flags
|
|
39
|
+
- `--stats` — print token/byte statistics for the conversion
|
|
40
|
+
- `--delimiter=,|\t|"|"` — array delimiter (comma default; tab/pipe can tokenize better)
|
|
41
|
+
- `--keyFolding=safe` — collapse single-key nesting chains
|
|
42
|
+
- `--no-strict` — lenient decode
|
|
43
|
+
|
|
44
|
+
## Decide before you compress
|
|
45
|
+
|
|
46
|
+
TOON is not always smaller. Pick based on shape:
|
|
47
|
+
|
|
48
|
+
| Shape | Action | Why |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| Uniform array of objects (same keys, primitive values) | **TOON** | Sweet spot — keys declared once, rows streamed; savings scale with rows × fields |
|
|
51
|
+
| Flat object / primitive array | **TOON** | Drops quotes and braces |
|
|
52
|
+
| Shallow nesting | **TOON** | Indentation cheaper than braces at low depth |
|
|
53
|
+
| Deeply nested / non-uniform | **JSON** | Indentation cost grows; compact JSON can win |
|
|
54
|
+
| Array of arrays | **JSON** | TOON's one structurally-worse case (explicit list markers + inner headers) |
|
|
55
|
+
| API contract / payload to send or store | **JSON** | Must stay valid JSON for the consumer |
|
|
56
|
+
|
|
57
|
+
Rule of thumb: **TOON for reading dense data into context. JSON for contracts.**
|
|
58
|
+
|
|
59
|
+
## When NOT to use TOON
|
|
60
|
+
- Anything sent to or stored by an API that expects JSON.
|
|
61
|
+
- Data a downstream tool/parser must consume as strict JSON.
|
|
62
|
+
- Deeply nested config trees or highly irregular structures.
|
|
63
|
+
- Tiny payloads where the conversion overhead isn't worth it.
|
|
64
|
+
|
|
65
|
+
In those cases, still use `jq` to slice down to what you need — just skip the
|
|
66
|
+
`| toon` step.
|
|
67
|
+
|
|
68
|
+
## Worked examples
|
|
69
|
+
|
|
70
|
+
LLM model list (uniform array → great TOON candidate):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
curl -s https://api.example.com/v1/models | jq '.data | map({id, owned_by, context})' | toon
|
|
74
|
+
```
|
|
75
|
+
```
|
|
76
|
+
[3]{id,owned_by,context}:
|
|
77
|
+
gpt-x,acme,128000
|
|
78
|
+
gpt-y,acme,200000
|
|
79
|
+
gpt-z,acme,1000000
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
OpenAPI paths summary (reshape first, then compress):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
cat openapi.json \
|
|
86
|
+
| jq '[.paths | to_entries[] | {path: .key, methods: (.value | keys)}]' \
|
|
87
|
+
| toon --stats
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Round-trip back to JSON for an API call:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
RESHAPED=$(cat payload.toon | toon -d)
|
|
94
|
+
curl -s -X POST https://api.example.com/ingest -d "$RESHAPED"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Checklist
|
|
98
|
+
1. **Query** — narrow with `jq` to the exact slice needed.
|
|
99
|
+
2. **Decide** — uniform/tabular/shallow → TOON; nested/array-of-arrays/contract → JSON.
|
|
100
|
+
3. **Compress** — `| toon` (add `--stats` to confirm savings).
|
|
101
|
+
4. **Round-trip** — `toon -d` only when strict JSON is required downstream.
|
package/src/index.ts
CHANGED
|
@@ -254,7 +254,7 @@ function registerResourcesDiscover(pi: ExtensionAPI): void {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
export default function (pi: ExtensionAPI): void {
|
|
257
|
-
once("pix-skills", () => {
|
|
257
|
+
once(pi, "pix-skills", () => {
|
|
258
258
|
registerSkillLoader(pi);
|
|
259
259
|
registerResourcesDiscover(pi);
|
|
260
260
|
});
|
package/src/once.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Per-instance idempotency guard for extension activation.
|
|
3
3
|
*
|
|
4
|
-
* pix-core (the meta-package) invokes this package's factory
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* pix-core (the meta-package) invokes this package's factory, and a standalone
|
|
5
|
+
* install makes Pi invoke it again — sometimes against the SAME `pi`. We must
|
|
6
|
+
* dedupe that. But Pi rebuilds the extension runtime on /new, /resume, /fork,
|
|
7
|
+
* and /reload, handing the factory a BRAND-NEW `pi`; that must re-register.
|
|
8
|
+
*
|
|
9
|
+
* Keying the registry on the `pi` instance satisfies both: same instance =>
|
|
10
|
+
* skip, new instance => run. The registry lives on globalThis because jiti
|
|
11
|
+
* (`moduleCache: false`) re-evaluates this module on every load pass, so a
|
|
12
|
+
* module-scoped WeakMap would not be shared between the aggregator pass and the
|
|
13
|
+
* standalone pass within a single session.
|
|
9
14
|
*/
|
|
10
|
-
export function once(key: string, fn: () => void): void {
|
|
11
|
-
const g = globalThis as {
|
|
12
|
-
const
|
|
15
|
+
export function once(pi: object, key: string, fn: () => void): void {
|
|
16
|
+
const g = globalThis as { __pixOnce?: WeakMap<object, Set<string>> };
|
|
17
|
+
const registry = (g.__pixOnce ??= new WeakMap<object, Set<string>>());
|
|
18
|
+
let loaded = registry.get(pi);
|
|
19
|
+
if (!loaded) {
|
|
20
|
+
loaded = new Set<string>();
|
|
21
|
+
registry.set(pi, loaded);
|
|
22
|
+
}
|
|
13
23
|
if (loaded.has(key)) return;
|
|
14
24
|
loaded.add(key);
|
|
15
25
|
fn();
|