@dev-sergeev/datalab-kit 0.1.4 → 0.1.6

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +47 -4
  3. package/THIRD_PARTY_NOTICES.md +3 -0
  4. package/dist/datalab-provider.d.ts +2 -0
  5. package/dist/datalab-provider.js +45 -0
  6. package/dist/extension.js +4 -0
  7. package/dist/skills.d.ts +2 -0
  8. package/dist/skills.js +54 -0
  9. package/docs/adr/0003-datalab-environment-provider.md +11 -0
  10. package/package.json +36 -9
  11. package/skills/init/SKILL.md +31 -0
  12. package/skills/skill-creator/LICENSE.txt +202 -0
  13. package/skills/skill-creator/SKILL.md +610 -0
  14. package/skills/skill-creator/agents/analyzer.md +291 -0
  15. package/skills/skill-creator/agents/comparator.md +213 -0
  16. package/skills/skill-creator/agents/grader.md +234 -0
  17. package/skills/skill-creator/assets/eval_review.html +146 -0
  18. package/skills/skill-creator/eval-viewer/generate_review.py +453 -0
  19. package/skills/skill-creator/eval-viewer/viewer.html +1329 -0
  20. package/skills/skill-creator/references/schemas.md +521 -0
  21. package/skills/skill-creator/scripts/aggregate_benchmark.py +415 -0
  22. package/skills/skill-creator/scripts/generate_report.py +329 -0
  23. package/skills/skill-creator/scripts/improve_description.py +225 -0
  24. package/skills/skill-creator/scripts/package_skill.py +136 -0
  25. package/skills/skill-creator/scripts/pi_runtime.py +177 -0
  26. package/skills/skill-creator/scripts/quick_validate.py +107 -0
  27. package/skills/skill-creator/scripts/run_eval.py +215 -0
  28. package/skills/skill-creator/scripts/run_loop.py +334 -0
  29. package/skills/skill-creator/scripts/utils.py +41 -0
  30. package/node_modules/node-addon-api/common 2.gypi +0 -21
  31. package/node_modules/node-addon-api/except 2.gypi +0 -25
  32. package/node_modules/node-addon-api/napi 2.h +0 -3463
  33. package/node_modules/node-addon-api/napi-inl 2.h +0 -7250
  34. package/node_modules/node-addon-api/napi-inl.deprecated 2.h +0 -186
  35. package/node_modules/node-addon-api/node_addon_api 2.gyp +0 -42
  36. package/node_modules/node-addon-api/node_api 2.gyp +0 -9
  37. package/node_modules/node-addon-api/noexcept 2.gypi +0 -26
  38. package/node_modules/pi-toggle-skills/toggle-skills 2.ts +0 -316
  39. package/node_modules/pi-toggle-skills/vitest.config 2.ts +0 -15
  40. package/node_modules/sprintf-js/.npmignore 2 +0 -1
  41. package/node_modules/sprintf-js/LICENSE 2 +0 -24
  42. package/node_modules/sprintf-js/README 2.md +0 -88
  43. package/node_modules/sprintf-js/bower 2.json +0 -14
  44. package/node_modules/sprintf-js/gruntfile 2.js +0 -36
  45. package/node_modules/sprintf-js/package 2.json +0 -22
  46. package/node_modules/tree-sitter-bash/tree-sitter-bash 2.wasm +0 -0
  47. package/node_modules/typebox/license 2 +0 -23
  48. package/node_modules/typebox/package 2.json +0 -87
  49. package/node_modules/typebox/readme 2.md +0 -370
  50. package/node_modules/zod/compile 2.cjs +0 -96
  51. package/node_modules/zod/compile 2.js +0 -52
  52. package/node_modules/zod/index 2.cjs +0 -52
  53. package/node_modules/zod/index 2.js +0 -7
  54. /package/{node_modules/node-addon-api/nothing 2.c → skills/skill-creator/scripts/__init__.py} +0 -0
@@ -0,0 +1,610 @@
1
+ ---
2
+ name: skill-creator
3
+ description: Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
4
+ ---
5
+
6
+ # Skill Creator
7
+
8
+ > **Datalab Kit Pi adaptation — modified from Anthropic's original.**
9
+ > Source: [anthropics/skills, `skills/skill-creator`](https://github.com/anthropics/skills/tree/dbd4588f9e1033efb41dad4bef2f7947c8993d44/skills/skill-creator),
10
+ > revision `dbd4588f9e1033efb41dad4bef2f7947c8993d44`.
11
+ > Licensed under [Apache-2.0](LICENSE.txt). The runtime, paths, evaluation isolation,
12
+ > telemetry guidance, and delivery instructions below have been changed for Pi.
13
+
14
+ ## Pi setup and writable paths
15
+
16
+ This workflow runs entirely through Pi. The Python utilities require **Python 3.10+**
17
+ and **PyYAML**; install PyYAML in the Python environment used for the commands
18
+ (for example, `python3 -m pip install PyYAML`, preferably in a virtual environment).
19
+ Pi must already be installed and authenticated for the selected provider. This
20
+ package supplies skills, not the Pi executable. Use `PI_EXECUTABLE_PATH` when set;
21
+ otherwise find `pi` on `PATH`. Model arguments accept Pi's `provider/model` syntax.
22
+
23
+ Resolve `<creator-root>` to the absolute directory containing this SKILL.md.
24
+ Read its supporting files there, but **never write generated files into that
25
+ directory**: npm installations may be read-only and upgrades replace their files.
26
+ Choose a writable, user-visible workspace, normally
27
+ `<current-project>/<skill-name>-workspace/`, or a user-selected writable directory.
28
+ Keep iterations, snapshots, trigger evals, reports, archives, and temporary files
29
+ there. If updating a package-provided or otherwise read-only skill, first copy the
30
+ whole skill to `<workspace>/candidate/<original-name>/` and edit that copy.
31
+ Preserve the existing directory name and frontmatter `name` when updating.
32
+
33
+ For a **new skill**, an explicit destination supplied by the user takes priority.
34
+ Otherwise use Pi's global agent directory: nonempty `PI_CODING_AGENT_DIR`
35
+ (expand `~` and resolve a relative value against the current directory), or
36
+ `~/.pi/agent`; the destination is `<agent-dir>/skills/<skill-name>/`.
37
+ Create only the new skill's directory; do not overwrite Pi settings or unrelated
38
+ skills. Stage a candidate in the workspace when practical, then copy the completed
39
+ skill to its destination. A new Pi session or `/reload` discovers installed skills.
40
+ Pi's native invocation is `/skill:<name>`; this kit also provides `/skill-creator`.
41
+
42
+ Run Python module commands **from the workspace**, with the creator root on the
43
+ module search path and bytecode writes disabled:
44
+
45
+ ```bash
46
+ export PYTHONPATH="<creator-root>${PYTHONPATH:+:$PYTHONPATH}"
47
+ export PYTHONDONTWRITEBYTECODE=1
48
+ ```
49
+
50
+ All paths in commands below should be absolute. These environment settings let
51
+ `python3 -m scripts.<module>` work without changing into the installed package.
52
+ Use explicit output paths inside the workspace whenever a command accepts one.
53
+
54
+ The bundled `@gotgenes/pi-subagents` extension supplies `subagent`,
55
+ `get_subagent_result`, and `steer_subagent`. Its agent types are not the files in
56
+ this skill's `agents/` directory: those files are task instructions to read, not
57
+ registered agent definitions. For grading, comparison, analysis, and orchestration:
58
+
59
+ ```text
60
+ subagent({
61
+ subagent_type: "general-purpose",
62
+ description: "Grade spreadsheet evaluation",
63
+ prompt: "Read <creator-root>/agents/grader.md. Expectations: [...]. Transcript: <absolute-path>. Outputs: <absolute-path>. Save grading.json beside outputs.",
64
+ inherit_context: false,
65
+ run_in_background: true
66
+ })
67
+ ```
68
+
69
+ Use the returned ID with
70
+ `get_subagent_result({agent_id: "<id>", wait: true, verbose: true})` when the
71
+ result is needed. Background runs notify on completion; do useful work meanwhile.
72
+ Set `model: "<provider/model>"` only when needed and keep executor models the
73
+ same across comparison arms. Do not invent a `tasks`, `agentScope`, `cwd`, or
74
+ `skills` spawn parameter: this extension has none. Children can see the parent's
75
+ skills, so functional evals require the fresh, isolated Pi sessions described
76
+ below, not simply a request to a child to "ignore" the candidate.
77
+
78
+ A skill for creating new skills and iteratively improving them.
79
+
80
+ At a high level, the process of creating a skill goes like this:
81
+
82
+ - Decide what you want the skill to do and roughly how it should do it
83
+ - Write a draft of the skill
84
+ - Create a few test prompts and run Pi with access to the skill on them
85
+ - Help the user evaluate the results both qualitatively and quantitatively
86
+ - While the runs happen in the background, draft some quantitative evals if there aren't any (if there are some, you can either use as is or modify if you feel something needs to change about them). Then explain them to the user (or if they already existed, explain the ones that already exist)
87
+ - Use the `eval-viewer/generate_review.py` script to show the user the results for them to look at, and also let them look at the quantitative metrics
88
+ - Rewrite the skill based on feedback from the user's evaluation of the results (and also if there are any glaring flaws that become apparent from the quantitative benchmarks)
89
+ - Repeat until you're satisfied
90
+ - Expand the test set and try again at larger scale
91
+
92
+ Your job when using this skill is to figure out where the user is in this process and then jump in and help them progress through these stages. So for instance, maybe they're like "I want to make a skill for X". You can help narrow down what they mean, write a draft, write the test cases, figure out how they want to evaluate, run all the prompts, and repeat.
93
+
94
+ On the other hand, maybe they already have a draft of the skill. In this case you can go straight to the eval/iterate part of the loop.
95
+
96
+ Of course, you should always be flexible and if the user is like "I don't need to run a bunch of evaluations, just vibe with me", you can do that instead.
97
+
98
+ Then after the skill is done (but again, the order is flexible), you can also run the skill description improver, which we have a whole separate script for, to optimize the triggering of the skill.
99
+
100
+ Cool? Cool.
101
+
102
+ ## Communicating with the user
103
+
104
+ The skill creator is liable to be used by people across a wide range of familiarity with coding jargon. Some users are opening a terminal for the first time; others are experienced developers.
105
+
106
+ So please pay attention to context cues to understand how to phrase your communication! In the default case, just to give you some idea:
107
+
108
+ - "evaluation" and "benchmark" are borderline, but OK
109
+ - for "JSON" and "assertion" you want to see serious cues from the user that they know what those things are before using them without explaining them
110
+
111
+ It's OK to briefly explain terms if you're in doubt, and feel free to clarify terms with a short definition if you're unsure if the user will get it.
112
+
113
+ ---
114
+
115
+ ## Creating a skill
116
+
117
+ ### Capture Intent
118
+
119
+ Start by understanding the user's intent. The current conversation might already contain a workflow the user wants to capture (e.g., they say "turn this into a skill"). If so, extract answers from the conversation history first — the tools used, the sequence of steps, corrections the user made, input/output formats observed. The user may need to fill the gaps, and should confirm before proceeding to the next step.
120
+
121
+ 1. What should this skill enable Pi to do?
122
+ 2. When should this skill trigger? (what user phrases/contexts)
123
+ 3. What's the expected output format?
124
+ 4. Should we set up test cases to verify the skill works? Skills with objectively verifiable outputs (file transforms, data extraction, code generation, fixed workflow steps) benefit from test cases. Skills with subjective outputs (writing style, art) often don't need them. Suggest the appropriate default based on the skill type, but let the user decide.
125
+
126
+ ### Interview and Research
127
+
128
+ Proactively ask questions about edge cases, input/output formats, example files, success criteria, and dependencies. Wait to write test prompts until you've got this part ironed out.
129
+
130
+ Check available MCPs - if useful for research (searching docs, finding similar skills, looking up best practices), research in parallel via subagents if available, otherwise inline. Come prepared with context to reduce burden on the user.
131
+
132
+ ### Write the SKILL.md
133
+
134
+ Based on the user interview, fill in these components:
135
+
136
+ - **name**: Skill identifier
137
+ - **description**: When to trigger, what it does. This is the primary triggering mechanism — include both what the skill does AND specific contexts for when to use it. All "when to use" info goes here, not in the body. Models sometimes undertrigger skills; make the description explicit about relevant tasks and adjacent wording without promising unrelated capabilities. For example, explain that a dashboard skill applies to data visualization and internal metrics even when the user does not explicitly ask for a "dashboard".
138
+ - **compatibility**: Required tools, dependencies (optional, rarely needed)
139
+ - **the rest of the skill :)**
140
+
141
+ ### Skill Writing Guide
142
+
143
+ #### Anatomy of a Skill
144
+
145
+ ```
146
+ skill-name/
147
+ ├── SKILL.md (required)
148
+ │ ├── YAML frontmatter (name, description required)
149
+ │ └── Markdown instructions
150
+ └── Bundled Resources (optional)
151
+ ├── scripts/ - Executable code for deterministic/repetitive tasks
152
+ ├── references/ - Docs loaded into context as needed
153
+ └── assets/ - Files used in output (templates, icons, fonts)
154
+ ```
155
+
156
+ #### Progressive Disclosure
157
+
158
+ Skills use a three-level loading system:
159
+ 1. **Metadata** (name + description) - Always in context (~100 words)
160
+ 2. **SKILL.md body** - In context whenever skill triggers (<500 lines ideal)
161
+ 3. **Bundled resources** - As needed (unlimited, scripts can execute without loading)
162
+
163
+ These word counts are approximate and you can feel free to go longer if needed.
164
+
165
+ **Key patterns:**
166
+ - Keep SKILL.md under 500 lines; if you're approaching this limit, add an additional layer of hierarchy along with clear pointers about where the model using the skill should go next to follow up.
167
+ - Reference files clearly from SKILL.md with guidance on when to read them
168
+ - For large reference files (>300 lines), include a table of contents
169
+
170
+ **Domain organization**: When a skill supports multiple domains/frameworks, organize by variant:
171
+ ```
172
+ cloud-deploy/
173
+ ├── SKILL.md (workflow + selection)
174
+ └── references/
175
+ ├── aws.md
176
+ ├── gcp.md
177
+ └── azure.md
178
+ ```
179
+ Pi reads only the relevant reference file.
180
+
181
+ #### Principle of Lack of Surprise
182
+
183
+ This goes without saying, but skills must not contain malware, exploit code, or any content that could compromise system security. A skill's contents should not surprise the user in their intent if described. Don't go along with requests to create misleading skills or skills designed to facilitate unauthorized access, data exfiltration, or other malicious activities. Things like a "roleplay as an XYZ" are OK though.
184
+
185
+ #### Writing Patterns
186
+
187
+ Prefer using the imperative form in instructions.
188
+
189
+ **Defining output formats** - You can do it like this:
190
+ ```markdown
191
+ ## Report structure
192
+ ALWAYS use this exact template:
193
+ # [Title]
194
+ ## Executive summary
195
+ ## Key findings
196
+ ## Recommendations
197
+ ```
198
+
199
+ **Examples pattern** - It's useful to include examples. You can format them like this (but if "Input" and "Output" are in the examples you might want to deviate a little):
200
+ ```markdown
201
+ ## Commit message format
202
+ **Example 1:**
203
+ Input: Added user authentication with JWT tokens
204
+ Output: feat(auth): implement JWT-based authentication
205
+ ```
206
+
207
+ ### Writing Style
208
+
209
+ Try to explain to the model why things are important in lieu of heavy-handed musty MUSTs. Use theory of mind and try to make the skill general and not super-narrow to specific examples. Start by writing a draft and then look at it with fresh eyes and improve it.
210
+
211
+ ### Test Cases
212
+
213
+ After writing the skill draft, come up with 2-3 realistic test prompts — the kind of thing a real user would actually say. Share them with the user: [you don't have to use this exact language] "Here are a few test cases I'd like to try. Do these look right, or do you want to add more?" Then run them.
214
+
215
+ Save test cases to `evals/evals.json` inside the writable candidate skill, never inside the installed creator package. Don't write assertions yet — just the prompts. You'll draft assertions in the next step while the runs are in progress.
216
+
217
+ ```json
218
+ {
219
+ "skill_name": "example-skill",
220
+ "evals": [
221
+ {
222
+ "id": 1,
223
+ "prompt": "User's task prompt",
224
+ "expected_output": "Description of expected result",
225
+ "files": []
226
+ }
227
+ ]
228
+ }
229
+ ```
230
+
231
+ See [references/schemas.md](references/schemas.md) for the full schema. Store the assertion strings in `expectations` in evals.json and copy them to `assertions` in each run's eval_metadata.json; these names serve different consumers.
232
+
233
+ ## Running and evaluating test cases
234
+
235
+ This section is one continuous sequence — don't stop partway through. Do NOT use `/skill-test` or any other testing skill.
236
+
237
+ Put results in the writable `<workspace>/` chosen above, not beside a package-managed skill. Organize results by iteration (`iteration-1/`, `iteration-2/`, etc.), then by descriptive test directory (`eval-0-table-extraction/`, for example). Create directories as needed. Use separate inputs, execution cwd, and outputs for each arm so runs cannot overwrite or learn from one another's files.
238
+
239
+ ### Step 1: Spawn with-skill AND baseline runs together
240
+
241
+ For each test case launch two independent executions in the same batch. Use
242
+ background `general-purpose` subagents to orchestrate them, with
243
+ `inherit_context: false`. Each orchestrator launches a **fresh Pi CLI process**
244
+ from its own writable run directory, rather than performing the task itself:
245
+
246
+ ```bash
247
+ "${PI_EXECUTABLE_PATH:-pi}" --print --mode json --no-session \
248
+ --no-skills --no-prompt-templates --no-themes \
249
+ --no-context-files --no-approve --model "<provider/model>" \
250
+ --system-prompt '' --append-system-prompt '' \
251
+ --skill "<absolute-candidate-path>/SKILL.md" \
252
+ "<task prompt, absolute input paths, absolute output directory; first read the supplied skill and follow it>" \
253
+ > "<run-dir>/transcript.jsonl" 2> "<run-dir>/stderr.log"
254
+ ```
255
+
256
+ `--no-skills` disables discovery while the explicit `--skill` adds only the
257
+ candidate. Disable project context and prompt templates, and pass empty
258
+ `--system-prompt` and `--append-system-prompt` values to suppress discovered
259
+ SYSTEM.md/APPEND_SYSTEM.md while retaining Pi's built-in base prompt.
260
+ `--no-context-files` alone does not suppress those system-prompt files.
261
+ This keeps normal creator instructions and globally installed skills out of
262
+ both arms. Keep configured
263
+ extensions enabled: the selected provider (including DataLab/GigaChat) may be
264
+ registered by an extension. Preserve the user's `PI_CODING_AGENT_DIR`, settings,
265
+ and authentication; do not manufacture a separate agent home or fall back to
266
+ another provider. Use identical extensions and tools in both arms, record any
267
+ extension-specific prompt/context additions, and do not claim stronger isolation
268
+ than the actual configuration provides. `--no-approve` declines project resource
269
+ trust for this controlled run; it is not a filesystem sandbox.
270
+
271
+ **With-skill:** use the writable candidate and save deliverables to
272
+ `<workspace>/iteration-N/eval-ID-name/with_skill/run-1/outputs/`.
273
+
274
+ **Baseline:**
275
+ - Creating a new skill: omit `--skill` and the instruction to read it; use the
276
+ identical task, inputs, model, and tools. Save to `without_skill/run-1/outputs/`.
277
+ - Improving a skill: snapshot the entire original skill before editing at
278
+ `<workspace>/skill-snapshot/<name>/`; use that snapshot with `--skill`.
279
+ Still name this comparison arm `without_skill/run-1/` for aggregation/viewer
280
+ compatibility, and record that it is the **old skill**, not a no-skill run.
281
+
282
+ The orchestrator should save raw JSONL, stderr, exit status, timing, and the final
283
+ assistant text (as an output file when the requested deliverable is prose).
284
+ Preserve failed runs and distinguish execution failure from an assertion failure.
285
+ Do not pass assertions, expected answers, grading rules, previous outputs, or
286
+ creator conversation to the execution process. Supply only the task, inputs,
287
+ output location, and candidate instructions for that arm. Restrict file writes
288
+ to the run directory where the task permits; Pi is not a filesystem sandbox.
289
+
290
+ Keep the `run-1/` layer even when running each prompt just once: aggregation
291
+ discovers `run-*` directories, not `with_skill/grading.json` directly. Repeated
292
+ runs use `run-2/`, `run-3/`, and so on in both comparison arms.
293
+
294
+ Write an `eval_metadata.json` for each test case (assertions can be empty for now). Give each eval a descriptive name based on what it's testing — not just "eval-0". Use this name for the directory too. If this iteration uses new or modified eval prompts, create these files for each new eval directory — don't assume they carry over from previous iterations.
295
+
296
+ ```json
297
+ {
298
+ "eval_id": 0,
299
+ "eval_name": "descriptive-name-here",
300
+ "prompt": "The user's task prompt",
301
+ "assertions": []
302
+ }
303
+ ```
304
+
305
+ ### Step 2: While runs are in progress, draft assertions
306
+
307
+ Don't just wait for the runs to finish — you can use this time productively. Draft quantitative assertions for each test case and explain them to the user. If assertions already exist in `evals/evals.json`, review them and explain what they check.
308
+
309
+ Good assertions are objectively verifiable and have descriptive names — they should read clearly in the benchmark viewer so someone glancing at the results immediately understands what each one checks. Subjective skills (writing style, design quality) are better evaluated qualitatively — don't force assertions onto things that need human judgment.
310
+
311
+ Update the `eval_metadata.json` files and `evals/evals.json` with the assertions once drafted. Also explain to the user what they'll see in the viewer — both the qualitative outputs and the quantitative benchmark.
312
+
313
+ ### Step 3: As runs complete, capture timing data
314
+
315
+ Measure the **executor process**, not the orchestration subagent. Wrap each Pi
316
+ launch with Python's `time.monotonic()` (or an equivalent monotonic clock) and
317
+ save the elapsed milliseconds and seconds in `<run-dir>/timing.json`.
318
+ Pi JSONL `message_end` events contain completed messages: sum available
319
+ `message.usage.totalTokens` across assistant messages for `total_tokens`.
320
+ Only include usage from the executor, not the orchestrator or grader.
321
+
322
+ ```json
323
+ {
324
+ "total_tokens": 84852,
325
+ "duration_ms": 23332,
326
+ "total_duration_seconds": 23.332
327
+ }
328
+ ```
329
+
330
+ Those numbers are illustrative, not defaults. If a provider omits token usage,
331
+ omit `total_tokens` and explain the missing measurement; never estimate tokens
332
+ from character counts or insert zero for unavailable telemetry. Tool counts can
333
+ be derived from actual `tool_execution_end` events, not inferred from prose.
334
+ The subagent extension's human-readable summaries can be rounded, and its
335
+ lifetime token accounting differs from Pi's provider usage. Do not assume a
336
+ notification has numeric `total_tokens`/`duration_ms`. Raw JSONL and saved timing
337
+ remain available for later grading and analysis.
338
+
339
+ ### Step 4: Grade, aggregate, and launch the viewer
340
+
341
+ Once all runs are done:
342
+
343
+ 1. **Grade each run** — spawn a `general-purpose` subagent whose prompt tells it to read [agents/grader.md](agents/grader.md), supplies the assertion strings and absolute transcript/output paths, and asks it to save `grading.json` beside `outputs/`. Or grade inline. The expectations array must use `text`, `passed`, and `evidence` — the viewer depends on these exact names. For programmatically checkable assertions, write and run a checker rather than eyeballing. Do not fabricate missing metrics.
344
+
345
+ 2. **Aggregate into benchmark** — from the writable workspace, with the Python environment above:
346
+ ```bash
347
+ python3 -m scripts.aggregate_benchmark <workspace>/iteration-N --skill-name <name>
348
+ ```
349
+ This produces `benchmark.json` and `benchmark.md` in the iteration directory, comparing pass rates, measured time, and available tokens with mean ± standard deviation. Use the layout and field names in [references/schemas.md](references/schemas.md), especially `with_skill` and `without_skill`. Repeat each case multiple times in separate `run-N/` directories when measuring variance; one observation cannot establish stability. Missing telemetry is not zero usage.
350
+ Put each with_skill version before its baseline counterpart.
351
+
352
+ 3. **Do an analyst pass** — read the benchmark data and surface patterns the aggregate stats might hide. See `agents/analyzer.md` (the "Analyzing Benchmark Results" section) for what to look for — things like assertions that always pass regardless of skill (non-discriminating), high-variance evals (possibly flaky), and time/token tradeoffs.
353
+
354
+ 4. **Launch the viewer** with both qualitative outputs and quantitative data:
355
+ ```bash
356
+ nohup python3 <creator-root>/eval-viewer/generate_review.py \
357
+ <workspace>/iteration-N \
358
+ --skill-name "my-skill" \
359
+ --benchmark <workspace>/iteration-N/benchmark.json \
360
+ > /dev/null 2>&1 &
361
+ VIEWER_PID=$!
362
+ ```
363
+ For iteration 2+, also pass `--previous-workspace <workspace>/iteration-<N-1>`.
364
+
365
+ **Remote or headless Pi:** If a local browser cannot be opened, add `--static <workspace>/iteration-N/review.html` to generate a standalone HTML file instead of a server. Give the user that file to open. "Submit All Reviews" downloads `feedback.json`; copy the downloaded file into the iteration directory before the next iteration. Do not skip the viewer or baseline because there is no display.
366
+
367
+ Note: please use generate_review.py to create the viewer; there's no need to write custom HTML.
368
+
369
+ 5. **Tell the user** where the viewer is running or where its static HTML file is saved. Only say it opened in a browser if that actually happened. Explain the two tabs: "Outputs" for per-case feedback and "Benchmark" for the quantitative comparison. Ask them to return when finished reviewing.
370
+
371
+ ### What the user sees in the viewer
372
+
373
+ The "Outputs" tab shows one test case at a time:
374
+ - **Prompt**: the task that was given
375
+ - **Output**: the files the skill produced, rendered inline where possible
376
+ - **Previous Output** (iteration 2+): collapsed section showing last iteration's output
377
+ - **Formal Grades** (if grading was run): collapsed section showing assertion pass/fail
378
+ - **Feedback**: a textbox that auto-saves as they type
379
+ - **Previous Feedback** (iteration 2+): their comments from last time, shown below the textbox
380
+
381
+ The "Benchmark" tab shows the stats summary: pass rates, timing, and token usage for each configuration, with per-eval breakdowns and analyst observations.
382
+
383
+ Navigation is via prev/next buttons or arrow keys. When done, they click "Submit All Reviews" which saves all feedback to `feedback.json`.
384
+
385
+ ### Step 5: Read the feedback
386
+
387
+ When the user tells you they're done, read `feedback.json`:
388
+
389
+ ```json
390
+ {
391
+ "reviews": [
392
+ {"run_id": "eval-0-with_skill", "feedback": "the chart is missing axis labels", "timestamp": "..."},
393
+ {"run_id": "eval-1-with_skill", "feedback": "", "timestamp": "..."},
394
+ {"run_id": "eval-2-with_skill", "feedback": "perfect, love this", "timestamp": "..."}
395
+ ],
396
+ "status": "complete"
397
+ }
398
+ ```
399
+
400
+ Empty feedback means the user thought it was fine. Focus your improvements on the test cases where the user had specific complaints.
401
+
402
+ Kill the viewer server when you're done with it:
403
+
404
+ ```bash
405
+ kill $VIEWER_PID 2>/dev/null
406
+ ```
407
+
408
+ ---
409
+
410
+ ## Improving the skill
411
+
412
+ This is the heart of the loop. You've run the test cases, the user has reviewed the results, and now you need to make the skill better based on their feedback.
413
+
414
+ ### How to think about improvements
415
+
416
+ 1. **Generalize from the feedback.** The big picture thing that's happening here is that we're trying to create skills that can be used a million times (maybe literally, maybe even more who knows) across many different prompts. Here you and the user are iterating on only a few examples over and over again because it helps move faster. The user knows these examples in and out and it's quick for them to assess new outputs. But if the skill you and the user are codeveloping works only for those examples, it's useless. Rather than put in fiddly overfitty changes, or oppressively constrictive MUSTs, if there's some stubborn issue, you might try branching out and using different metaphors, or recommending different patterns of working. It's relatively cheap to try and maybe you'll land on something great.
417
+
418
+ 2. **Keep the prompt lean.** Remove things that aren't pulling their weight. Make sure to read the transcripts, not just the final outputs — if it looks like the skill is making the model waste a bunch of time doing things that are unproductive, you can try getting rid of the parts of the skill that are making it do that and seeing what happens.
419
+
420
+ 3. **Explain the why.** Try hard to explain the **why** behind everything you're asking the model to do. Today's LLMs are *smart*. They have good theory of mind and when given a good harness can go beyond rote instructions and really make things happen. Even if the feedback from the user is terse or frustrated, try to actually understand the task and why the user is writing what they wrote, and what they actually wrote, and then transmit this understanding into the instructions. If you find yourself writing ALWAYS or NEVER in all caps, or using super rigid structures, that's a yellow flag — if possible, reframe and explain the reasoning so that the model understands why the thing you're asking for is important. That's a more humane, powerful, and effective approach.
421
+
422
+ 4. **Look for repeated work across test cases.** Read the transcripts from the test runs and notice if the subagents all independently wrote similar helper scripts or took the same multi-step approach to something. If all 3 test cases resulted in the subagent writing a `create_docx.py` or a `build_chart.py`, that's a strong signal the skill should bundle that script. Write it once, put it in `scripts/`, and tell the skill to use it. This saves every future invocation from reinventing the wheel.
423
+
424
+ This task is pretty important (we are trying to create billions a year in economic value here!) and your thinking time is not the blocker; take your time and really mull things over. I'd suggest writing a draft revision and then looking at it anew and making improvements. Really do your best to get into the head of the user and understand what they want and need.
425
+
426
+ ### The iteration loop
427
+
428
+ After improving the skill:
429
+
430
+ 1. Apply your improvements to the skill
431
+ 2. Rerun all test cases into a new `iteration-<N+1>/` directory, including baseline runs. If you're creating a new skill, the baseline is always `without_skill` (no skill) — that stays the same across iterations. If you're improving an existing skill, use your judgment on what makes sense as the baseline: the original version the user came in with, or the previous iteration.
432
+ 3. Launch the reviewer with `--previous-workspace` pointing at the previous iteration
433
+ 4. Wait for the user to review and tell you they're done
434
+ 5. Read the new feedback, improve again, repeat
435
+
436
+ Keep going until:
437
+ - The user says they're happy
438
+ - The feedback is all empty (everything looks good)
439
+ - You're not making meaningful progress
440
+
441
+ ---
442
+
443
+ ## Advanced: Blind comparison
444
+
445
+ For situations where you want a more rigorous comparison between two versions of a skill (e.g., the user asks "is the new version actually better?"), there's a blind comparison system. Read `agents/comparator.md` and `agents/analyzer.md` for the details. The basic idea is: give two outputs to an independent agent without telling it which is which, and let it judge quality. Then analyze why the winner won.
446
+
447
+ Use fresh `general-purpose` comparator and analyzer subagents with `inherit_context: false`. Randomize which result is A or B and stage copies under neutral paths in `<workspace>/blind/`; strip configuration labels from filenames and metadata given to the comparator. Supply the task and optional expectations, but neither skill identity nor the A/B mapping. Save comparison.json, then give only the analyzer the mapping, skill paths, and execution transcripts. On a TIE, report the tie and analyze differences without inventing a winner. This is optional; the human review loop is usually sufficient.
448
+
449
+ ---
450
+
451
+ ## Description Optimization
452
+
453
+ The description field in SKILL.md frontmatter is the primary mechanism that determines whether Pi reads a skill. After creating or improving a skill, offer to optimize the description for better triggering accuracy. This measures **selection**, not whether the selected skill completes the task successfully.
454
+
455
+ ### Step 1: Generate trigger eval queries
456
+
457
+ Create 20 eval queries — a mix of should-trigger and should-not-trigger. Save as JSON:
458
+
459
+ ```json
460
+ [
461
+ {"query": "the user prompt", "should_trigger": true},
462
+ {"query": "another prompt", "should_trigger": false}
463
+ ]
464
+ ```
465
+
466
+ The queries must be realistic requests a Pi user would actually type, not abstract tasks: include file paths, job context, column names, company names, or URLs where relevant. Mix lengths, informal phrasing, and near-misses. The user gets a chance to review them.
467
+
468
+ Bad: `"Format this data"`, `"Extract text from PDF"`, `"Create a chart"`
469
+
470
+ Good: `"ok so my boss just sent me this xlsx file (its in my downloads, called something like 'Q4 sales final FINAL v2.xlsx') and she wants me to add a column that shows the profit margin as a percentage. The revenue is in column C and costs are in column D i think"`
471
+
472
+ For the **should-trigger** queries (8-10), think about coverage. You want different phrasings of the same intent — some formal, some casual. Include cases where the user doesn't explicitly name the skill or file type but clearly needs it. Throw in some uncommon use cases and cases where this skill competes with another but should win.
473
+
474
+ For the **should-not-trigger** queries (8-10), the most valuable ones are the near-misses — queries that share keywords or concepts with the skill but actually need something different. Think adjacent domains, ambiguous phrasing where a naive keyword match would trigger but shouldn't, and cases where the query touches on something the skill does but in a context where another tool is more appropriate.
475
+
476
+ The key thing to avoid: don't make should-not-trigger queries obviously irrelevant. "Write a fibonacci function" as a negative test for a PDF skill is too easy — it doesn't test anything. The negative cases should be genuinely tricky.
477
+
478
+ ### Step 2: Review with user
479
+
480
+ Present the eval set to the user for review using the HTML template:
481
+
482
+ 1. Read [assets/eval_review.html](assets/eval_review.html).
483
+ 2. Replace `__EVAL_DATA_PLACEHOLDER__` with the JSON array, `__SKILL_NAME_PLACEHOLDER__` with the name, and `__SKILL_DESCRIPTION_PLACEHOLDER__` with the current description. Escape values for their HTML/JavaScript context; in particular escape `<` in embedded JSON so a query cannot end a script tag.
484
+ 3. Write `<workspace>/trigger-eval-review.html` and open it using the platform's browser opener when available, or give the user the path to open locally.
485
+ 4. The user edits queries, toggles should-trigger, adds/removes entries, and clicks "Export Eval Set".
486
+ 5. Read the actual downloaded JSON file the user exported, then save it as `<workspace>/trigger-eval.json`. Browser download paths vary; do not assume `~/Downloads/eval_set.json` is the exported file.
487
+
488
+ This step matters — bad eval queries lead to bad descriptions.
489
+
490
+ ### Step 3: Run the optimization loop
491
+
492
+ Tell the user that this runs repeated independent Pi queries and consumes model
493
+ usage. Save the reviewed eval set in the workspace. First, the standalone trigger
494
+ evaluation can establish a baseline:
495
+
496
+ ```bash
497
+ python3 -m scripts.run_eval \
498
+ --eval-set <workspace>/trigger-eval.json \
499
+ --skill-path <absolute-candidate-path> \
500
+ --model <provider/model>
501
+ ```
502
+
503
+ Then run the full optimization loop from the workspace:
504
+
505
+ ```bash
506
+ python3 -m scripts.run_loop \
507
+ --eval-set <workspace>/trigger-eval.json \
508
+ --skill-path <absolute-candidate-path> \
509
+ --model <provider/model> \
510
+ --max-iterations 5 \
511
+ --results-dir <workspace>/description-optimization \
512
+ --report <workspace>/description-optimization.html \
513
+ --verbose
514
+ ```
515
+
516
+ Use the actual Pi model selection, not a guessed model ID; the user may choose a
517
+ different authenticated provider/model. Run in the background when supported,
518
+ save logs in the workspace, and report observed iteration results.
519
+ By default, the loop splits queries into 60% training and 40% held-out testing
520
+ (`--holdout 0.4`), runs each query three times, and chooses `best_description`
521
+ by held-out score rather than training score. It evaluates descriptions through
522
+ Pi and asks Pi for evidence-based improvements, retaining the HTML report and
523
+ JSON results. Do not replace actual trigger reads with a model's self-report.
524
+ Trigger evaluation uses only `read` in a temporary cwd and observes an exact
525
+ read of the candidate SKILL.md; it does not execute the skill's full workflow.
526
+ Errors and timeouts are failed evaluations, not successful non-triggers.
527
+ The scripts retain configured provider extensions and authentication while
528
+ disabling discovered skills, prompt templates, themes, context files, and custom
529
+ SYSTEM.md/APPEND_SYSTEM.md discovery; Pi's built-in base prompt remains.
530
+ Description improvement runs Pi with `--no-tools`. If an extension injects
531
+ additional prompt/context, note that condition when interpreting trigger scores.
532
+ Keep generated results outside the installed package. The report path above
533
+ can be opened locally in a headless environment; `--report none` disables only
534
+ HTML report generation. See each module's `--help` for tuning flags.
535
+
536
+ ### How skill triggering works
537
+
538
+ Pi presents discovered skills as a catalogue of names, descriptions, and paths.
539
+ The model decides whether to read a SKILL.md using Pi's `read` tool. Trigger
540
+ evaluation detects an actual read of the candidate, not a claim in response text.
541
+ An explicit `/skill:<name>` invocation is different: it intentionally loads the
542
+ skill and is not a test of description-driven selection.
543
+
544
+ Use substantive queries for which the skill adds value, including negative
545
+ near-misses. Do not hard-code a supposed rule that simple requests never trigger:
546
+ selection depends on the model, catalogue, and description. Controlled evaluations
547
+ isolate the candidate; real installed skill catalogues may produce different rates.
548
+
549
+ ### Step 4: Apply the result
550
+
551
+ Take `best_description` from the JSON output and update the skill's SKILL.md frontmatter. Show the user before/after and report the scores.
552
+
553
+ ---
554
+
555
+ ### Validate, install, and package
556
+
557
+ Validate the completed writable candidate with the bundled validator:
558
+
559
+ ```bash
560
+ python3 -m scripts.quick_validate <absolute-candidate-path>
561
+ ```
562
+
563
+ Copy the skill directory (SKILL.md plus required scripts, references, and assets)
564
+ to the user-specified destination, or the global Pi skills path described above.
565
+ For updates, preserve the original name and avoid editing an npm-managed copy
566
+ in place. Tell the user the actual installation path and to start a new Pi
567
+ session or use `/reload`.
568
+
569
+ When the user wants a portable archive, package it from the workspace:
570
+
571
+ ```bash
572
+ python3 -m scripts.package_skill <absolute-candidate-path> <workspace>/dist
573
+ ```
574
+
575
+ The `.skill` file is a ZIP archive for sharing, **not** a `pi install` package.
576
+ To use it in Pi, extract its top-level skill directory into the chosen Pi skills
577
+ directory, then reload. Return the archive's real path without assuming a
578
+ `present_files` tool exists. Do not include evaluation workspaces, private inputs,
579
+ credentials, or unrelated generated output in the archive. Validate and review
580
+ the final contents before handing it over.
581
+
582
+ ---
583
+
584
+ ## Reference files
585
+
586
+ The agents/ directory contains instructions for specialized subagents. Read them when you need to spawn the relevant subagent.
587
+
588
+ - `agents/grader.md` — How to evaluate assertions against outputs
589
+ - `agents/comparator.md` — How to do blind A/B comparison between two outputs
590
+ - `agents/analyzer.md` — How to analyze why one version beat another
591
+
592
+ The references/ directory has additional documentation:
593
+ - `references/schemas.md` — JSON structures for evals.json, grading.json, etc.
594
+
595
+ ---
596
+
597
+ Repeating one more time the core loop here for emphasis:
598
+
599
+ - Figure out what the skill is about
600
+ - Draft or edit the skill
601
+ - Run isolated Pi executions with the candidate and the appropriate baseline
602
+ - With the user, evaluate the outputs:
603
+ - Create benchmark.json and run `eval-viewer/generate_review.py` to help the user review them
604
+ - Run quantitative evals
605
+ - Repeat until you and the user are satisfied
606
+ - Package the final skill and return it to the user.
607
+
608
+ Keep the human review, quantitative benchmark, and description-trigger evaluation
609
+ distinct: they answer different questions. Preserve the upstream loop's real
610
+ executions and evidence rather than substituting self-assessment.