pi-uva-hva 1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -0
  3. package/index.ts +1235 -0
  4. package/package.json +34 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # Pi extension (uva-hva-agentic-tools)
2
+
3
+ > Part of [uva-hva-agentic-tools](../README.md). This is the Pi guide; for other
4
+ > tools see [Claude Code](../claude-code/README.md),
5
+ > [VS Code](../vscode/README.md), [OpenCode](../opencode/README.md),
6
+ > [Aider](../aider/README.md), [Kilo Code](../kilo-code/README.md),
7
+ > [Factory Droid](../factory-droid/README.md), or
8
+ > [Odysseus](../odysseus/README.md).
9
+
10
+ A [Pi](https://pi.dev) coding-agent provider extension for the University of
11
+ Amsterdam / Amsterdam University of Applied Sciences LiteLLM proxies
12
+ (`https://llmproxy.uva.nl/v1`, `https://llmproxy.hva.nl/v1`).
13
+
14
+ Get every UvA/HvA model working in Pi in under a minute, without editing Pi's config
15
+ files. Load the extension, run `/login`, pick your proxy, paste your API key, and
16
+ it auto-discovers all available models so you can select one straight from
17
+ `/models`. Your base URL and key are saved, so the next launch just reconnects.
18
+ Reasoning models come pre-tuned (thinking on at medium),
19
+ and tool-heavy agent turns that would otherwise silently come back empty on this
20
+ proxy just work. That's the whole setup; everything below is optional detail.
21
+
22
+ ## Install
23
+
24
+ You need Pi installed and a UvA/HvA proxy API key.
25
+
26
+ ### 1. Load the extension
27
+
28
+ Pick one:
29
+
30
+ - From npm (easiest): add `"npm:pi-uva-hva"` to the `packages` array in
31
+ `~/.pi/agent/settings.json` (or run `pi install npm:pi-uva-hva`). Pi installs
32
+ it on the next launch, no clone needed:
33
+ ```jsonc
34
+ {
35
+ "packages": [
36
+ "npm:pi-uva-hva"
37
+ ]
38
+ }
39
+ ```
40
+ - From a local clone: clone the repo and point at the `pi/` folder instead:
41
+ ```jsonc
42
+ {
43
+ "packages": [
44
+ "/path/to/uva-hva-agentic-tools/pi"
45
+ ]
46
+ }
47
+ ```
48
+ - Try it once: `pi -e /path/to/uva-hva-agentic-tools/pi`
49
+ - Auto-load folder: copy `index.ts` to `~/.pi/agent/extensions/`.
50
+
51
+ ### 2. Connect with `/login`
52
+
53
+ Start Pi and run:
54
+
55
+ ```
56
+ /login
57
+ ```
58
+
59
+ Choose "UvA / HvA proxy", pick a base URL (UvA / HvA / custom), and paste
60
+ your API key. The extension discovers every model and saves your base URL + key
61
+ to `~/.pi/agent/openai-responses-uva.json`, so the next launch reconnects with
62
+ nothing re-entered. `/uva-login` runs the same flow.
63
+
64
+ > Prefer env vars? Set `UVA_API_KEY` (and optionally `UVA_BASE_URL`) instead of
65
+ > `/login`. Both work.
66
+
67
+ ### 3. Pick a model
68
+
69
+ ```
70
+ /models # select any discovered model
71
+ ```
72
+
73
+ Reasoning models default to thinking ON at medium. You can raise or lower a
74
+ model's default in `/configure-models`, or set the level per run from the CLI:
75
+
76
+ ```bash
77
+ pi --provider uva --model gpt-5.6-sol --thinking high -p "hello"
78
+ ```
79
+
80
+ ## Configuration
81
+
82
+ `/login` is the easy path; everything is also configurable via environment
83
+ variables (all optional):
84
+
85
+ | Variable | Default | Purpose |
86
+ | --- | --- | --- |
87
+ | `UVA_API_KEY` | - | API key, if you prefer env over `/login`. |
88
+ | `UVA_BASE_URL` | `https://llmproxy.uva.nl/v1` | Proxy base URL (must end at the `/v1` root). |
89
+ | `UVA_PROVIDER_ID` | `uva` | Provider id shown in `/models` and `--provider`. |
90
+ | `UVA_CREDENTIALS_FILE` | `~/.pi/agent/openai-responses-uva.json` | Override the saved-credentials path. |
91
+ | `UVA_NO_AUTO_THINKING` | - | Set to disable the medium thinking default. |
92
+ | `UVA_MODEL_OVERRIDES_FILE` | - | Path to a JSON file overriding per-model capabilities (below). |
93
+
94
+ ### Per-model overrides
95
+
96
+ Capabilities come from the proxy metadata (with a name-table fallback). To pin a
97
+ value yourself there are two ways.
98
+
99
+ Interactive menu (easiest): run `/configure-models`. Pick a model, then set
100
+ its context window and max output (type the number), toggle reasoning on/off,
101
+ and choose the default thinking level applied when that model is selected. Two
102
+ options at the end, Save & apply changes and Discard & exit. Saved
103
+ overrides are written to `~/.pi/agent/openai-responses-uva.models.json` and
104
+ applied live (and on every future launch).
105
+
106
+ By hand: point `UVA_MODEL_OVERRIDES_FILE` at a JSON file (this overrides the
107
+ default path above):
108
+
109
+ ```json
110
+ {
111
+ "gpt-5.6-sol": { "contextWindow": 1100000, "maxTokens": 128000, "defaultThinkingLevel": "high" },
112
+ "some-new-model": { "reasoning": false, "input": ["text", "image"], "contextWindow": 200000, "maxTokens": 32000 }
113
+ }
114
+ ```
115
+
116
+ The `defaultThinkingLevel` on `gpt-5.6-sol` above is just an example of pinning
117
+ one model to `high`; by default every reasoning model starts at `medium`.
118
+
119
+ Each key is a model id; each value may set any of `reasoning`,
120
+ `defaultThinkingLevel` (`off`/`low`/`medium`/`high`), `input`, `contextWindow`,
121
+ `maxTokens`, `vision`, `name`, `cost`, `thinkingLevelMap`.
122
+
123
+ ## How it works
124
+
125
+ For each turn the custom stream handler:
126
+
127
+ 1. Lets Pi's pristine built-in `openai-responses` handler build the exact
128
+ request params (full message + tool conversion, reasoning, caching) via an
129
+ `onPayload` hook that captures the params and throws before the network
130
+ call, so nothing extra is billed.
131
+ 2. Reissues the request itself and synthesizes Pi's content events
132
+ (`text` / `thinking` / `toolCall`), reconciling the incremental SSE events
133
+ with the terminal `response.output[]` by item id so a collapsed tool call is
134
+ never lost. Tool-call ids and signatures are preserved for multi-turn replay.
135
+
136
+ Two dispatch paths keep it reliable:
137
+
138
+ - Non-reasoning turns stream (`stream:true`): bytes flow, so the nginx
139
+ gateway read-timeout keeps resetting and output is token-by-token.
140
+ - Reasoning turns use background + poll (`background:true` +
141
+ `GET /responses/{id}`): the model can buffer its whole reasoning phase with
142
+ zero interim bytes without ever tripping a 504, because each request is short.
143
+ A streaming turn that still hits a gateway 5xx before any output falls back to
144
+ this path automatically.
145
+
146
+ Params incompatible with non-OpenAI backends (`prompt_cache_key` on
147
+ Bedrock/Vertex) are stripped per-model.
148
+
149
+ ### Robust to model changes
150
+
151
+ The UvA/HvA line-up changes often, so nothing about specific models is
152
+ hard-coded. On connect the extension reads the proxy's own
153
+ `/model_group/info` and derives each model's context window, max output,
154
+ reasoning/vision support, cost, and backend directly from it, then decides the
155
+ endpoint from the backend (`azure`/`bedrock` speak the Responses API;
156
+ open-weight `openai`/vLLM models use chat-completions). If that metadata
157
+ endpoint is ever unavailable it falls back to `/v1/models` plus a researched
158
+ name table, and if a model is still mis-routed, a Responses turn that 404s is
159
+ self-healed at runtime (retried on chat-completions and remembered). So even
160
+ if every current model is replaced with new ones, discovery, capabilities, and
161
+ routing keep working with no code change.
162
+
163
+ ### Trade-off
164
+
165
+ Reasoning replies are not token-by-token; they appear at once on completion
166
+ (the proxy only delivers background results as a single terminal payload).
167
+ Non-reasoning turns stream normally.
168
+
169
+ ## Reasoning models
170
+
171
+ Reasoning is enabled per model from the proxy metadata (`supports_reasoning` or a
172
+ `reasoning_effort` parameter), with the name table as a fallback, but only on the
173
+ Responses route (chat-completions rejects `reasoning_effort` alongside tools).
174
+ Reasoning models default to thinking ON at medium (disable with
175
+ `UVA_NO_AUTO_THINKING=1`). Override any model's capabilities, including its
176
+ default thinking level, per-id via `UVA_MODEL_OVERRIDES_FILE` or
177
+ `/configure-models`.
178
+
179
+ ## Compatibility
180
+
181
+ - Pi coding-agent with the `@earendil-works/pi-ai` runtime (verified on 0.80.x).
182
+ - Imports only the extension-facing `@earendil-works/pi-ai` surface, so it keeps
183
+ working across Pi updates (it does not patch `node_modules`).
184
+
185
+ ## Recommended extensions
186
+
187
+ Pi becomes far more capable with a few extensions. These are the ones I run
188
+ alongside this provider, grouped by what they do, with install commands below.
189
+
190
+ ### Context, memory & compaction
191
+
192
+ These three cover the three layers with one tool each, so nothing overlaps:
193
+
194
+ | Extension | Layer | What it does |
195
+ | --- | --- | --- |
196
+ | [context-mode](https://github.com/mksglu/context-mode) | Tool output | Offloads large tool/command output into a sandbox and a searchable store so it never floods your context window. |
197
+ | [pi-smart-compact](https://github.com/alpertarhan/pi-smart-compact) | History | Verification-oriented conversation compaction: deterministic extract, then synthesize, then verify what survived. |
198
+ | [gentle-engram](https://github.com/Gentleman-Programming/engram) | Memory | Persistent memory shared across sessions, compactions, and MCP agents. |
199
+
200
+ ### Planning, workflows & subagents
201
+
202
+ | Extension | What it does |
203
+ | --- | --- |
204
+ | [@juicesharp/rpiv-pi](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-pi) | Skill-based dev workflow: discover → research → design → plan → implement → validate → review. |
205
+ | [pi-code-planner](https://github.com/m62624/pi-code-planner) | Structured planning, TDD, and Git worktrees for local coding agents. |
206
+ | [@gotgenes/pi-subagents](https://github.com/gotgenes/pi-packages/tree/main/packages/pi-subagents) | In-process sub-agent core with a typed API and lifecycle events. |
207
+ | [@quintinshaw/pi-dynamic-workflows](https://github.com/QuintinShaw/pi-dynamic-workflows) | Fan a task across hundreds of subagents with real model routing and cost accounting. |
208
+ | [@juicesharp/rpiv-workflow](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-workflow) | Chain skills into typed multi-stage workflows with audited state. |
209
+ | [@juicesharp/rpiv-todo](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo) | A live todo overlay for the model that survives `/reload` and compaction. |
210
+
211
+ ### Providers & models
212
+
213
+ | Extension | What it does |
214
+ | --- | --- |
215
+ | [pi-multi-account](https://github.com/Sarrius/pi-multi-account) | Automatic multi-account failover & rotation across Anthropic, OpenAI, Qwen, Ollama. |
216
+ | [glm-vision](https://www.npmjs.com/package/glm-vision) | Gives non-vision GLM models (z.ai) image understanding via GLM-4.6V. |
217
+
218
+ ### Tools & UX
219
+
220
+ | Extension | What it does |
221
+ | --- | --- |
222
+ | [@juicesharp/rpiv-web-tools](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-web-tools) | Web search + fetch for the model with pluggable providers (Brave, Tavily, Exa, …). |
223
+ | [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter) | Connect any MCP (Model Context Protocol) server to Pi. |
224
+ | [@amaster.ai/pi-computer-use](https://github.com/TGYD-helige/pi) | Desktop automation via `computer_use_*` tools. |
225
+ | [pi-image-paste](https://github.com/tuanhung303/pi-image-paste) | Turns pasted image paths into first-class image attachments. |
226
+ | [@trevonistrevon/pi-loop](https://github.com/trvon/pi-loop) | Cron/event re-wake loops and background process monitoring. |
227
+ | [@juicesharp/rpiv-ask-user-question](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question) | Lets the model ask you a structured, typed questionnaire instead of guessing. |
228
+ | [@juicesharp/rpiv-advisor](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-advisor) | A second opinion the model can request from a stronger reviewer model. |
229
+ | [@juicesharp/rpiv-args](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-args) | `$1` / `$ARGUMENTS` placeholders and shell substitution in skills. |
230
+ | [@juicesharp/rpiv-i18n](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-i18n) | Localization foundation for the `rpiv-*` skills (`/languages`, `--locale`). |
231
+
232
+ ### Code quality
233
+
234
+ | Extension | What it does |
235
+ | --- | --- |
236
+ | [pi-simplify](https://github.com/MattDevy/pi-extensions/tree/main/packages/pi-simplify) | Reviews recently changed code for clarity, consistency, and maintainability. |
237
+ | [ponytail](https://github.com/DietrichGebert/ponytail) | Lazy senior dev mode: stops the agent over-engineering and writes the minimum code that works, with `/ponytail` review/audit/debt commands. |
238
+
239
+ ### Install them
240
+
241
+ Pi auto-installs anything listed in the `packages` array of
242
+ `~/.pi/agent/settings.json` on the next launch, with no manual `npm install`.
243
+
244
+ All at once: merge this into your `packages` array (keep any entries you
245
+ already have), then restart Pi:
246
+
247
+ ```jsonc
248
+ {
249
+ "packages": [
250
+ "npm:context-mode",
251
+ "npm:pi-smart-compact",
252
+ "npm:gentle-engram",
253
+ "npm:@juicesharp/rpiv-pi",
254
+ "npm:pi-code-planner",
255
+ "npm:@gotgenes/pi-subagents",
256
+ "npm:@quintinshaw/pi-dynamic-workflows",
257
+ "npm:@juicesharp/rpiv-workflow",
258
+ "npm:@juicesharp/rpiv-todo",
259
+ "npm:pi-multi-account",
260
+ "npm:glm-vision",
261
+ "npm:@juicesharp/rpiv-web-tools",
262
+ "npm:pi-mcp-adapter",
263
+ "npm:@amaster.ai/pi-computer-use",
264
+ "npm:pi-image-paste",
265
+ "npm:@trevonistrevon/pi-loop",
266
+ "npm:@juicesharp/rpiv-ask-user-question",
267
+ "npm:@juicesharp/rpiv-advisor",
268
+ "npm:@juicesharp/rpiv-args",
269
+ "npm:@juicesharp/rpiv-i18n",
270
+ "npm:pi-simplify",
271
+ "npm:opencode-ponytail"
272
+ ]
273
+ }
274
+ ```
275
+
276
+ One by one: add a single line to the same `packages` array and restart Pi.
277
+ Each entry is just `"npm:<name>"`, e.g.:
278
+
279
+ ```jsonc
280
+ "packages": [
281
+ "npm:context-mode"
282
+ ]
283
+ ```
284
+
285
+ ### Setup notes (extensions with a background DB or service)
286
+
287
+ Most of these are pure extensions that work the moment they're in `packages`. A
288
+ few run a background database or service and need one extra thing to work on a
289
+ single install:
290
+
291
+ - Node ≥ 22.5.0, required by `context-mode`. It stores its knowledge base in
292
+ SQLite and relies on Node's built-in `node:sqlite` (older Node falls back to a
293
+ native module that can crash). Check with `node -v`. Its `postinstall`
294
+ auto-wires the Pi hooks and heals the native binding, so no manual setup is
295
+ needed. Just verify afterward with `/context-mode:ctx-doctor` (or
296
+ `npx context-mode doctor`). If an install ever complains about
297
+ `better-sqlite3`, upgrading Node to 22.5+ is the fix. Known quirk: if you also
298
+ have a `~/.claude` folder, context-mode may store its knowledge base there
299
+ instead of under `~/.pi`; harmless, but that is where to look for it.
300
+
301
+ - `gentle-engram` needs the Engram backend. The npm package is only the Pi
302
+ bridge: persistence is handled by a separate `engram` binary that it launches
303
+ as an MCP server. Install Engram from
304
+ [Gentleman-Programming/engram](https://github.com/Gentleman-Programming/engram)
305
+ and make sure `engram` is on your `PATH` (or set `ENGRAM_BIN`); otherwise the
306
+ memory tools load but nothing is saved. Also keep only one engram entry in
307
+ `packages`: `npm:gentle-engram`, not a second pinned copy like
308
+ `npm:gentle-engram@0.1.8`.
309
+
310
+ > Some of these overlap in purpose. `rpiv-todo` gives the model its `todo`
311
+ > tracker; `pi-loop` also ships a native `TaskCreate` fallback that only
312
+ > activates when no dedicated task system is present, so it just sits unused
313
+ > beside `todo` (harmless, not a conflict). Several planning and workflow
314
+ > engines overlap too. Start with the context/memory group, then add planning
315
+ > and tools as you need them rather than enabling all of them at once.
316
+
317
+ ## License
318
+
319
+ MIT. See [LICENSE](./LICENSE).