tiiny-router-pi 0.0.2 → 0.0.4

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,9 +1,9 @@
1
- # tiiny router
1
+ # tiiny router pi
2
2
 
3
- **`tiiny` + `pi`**
3
+ **`tiiny` + `pi` + model routing**
4
4
 
5
- Forked from
6
- [garciacionet-alt/AI_Articles](https://github.com/garciacionet-alt/AI_Articles/tree/main/tiiny-model-routing),
5
+ Forked from
6
+ [garciacionet-alt/AI_Articles][upstream],
7
7
  but with `pi` harness instead of `hermes`.
8
8
 
9
9
  This is a [pi](https://pi.dev) extension that sends each task to the best model
@@ -16,19 +16,22 @@ model, and a task whose shape is unclear goes to the generalist.
16
16
 
17
17
  <!-- toc -->
18
18
 
19
- - [Install](#install)
20
- * [Dry Run](#dry-run)
19
+ - [Quickstart](#quickstart)
20
+ * [Install](#install)
21
+ - [Configure](#configure)
22
+ - [Dry Run](#dry-run)
21
23
  - [Uninstall](#uninstall)
22
- - [Loops](#loops)
23
- - [Use](#use)
24
+ - [`redeye`/Loops](#redeyeloops)
25
+ * [Example](#example)
26
+ - [Examples](#examples)
24
27
  * [Interactive](#interactive)
25
28
  * [One-off](#one-off)
26
- * [With Redeye](#with-redeye)
29
+ * [With `redeye`](#with-redeye)
27
30
  * [Delegating with subagents](#delegating-with-subagents)
28
31
  * [Batches: plan, reserve, load, release](#batches-plan-reserve-load-release)
29
32
  - [Commands](#commands)
30
33
  * [`npx pirouter`](#npx-pirouter)
31
- * [`pirouter install`](#pirouter-install)
34
+ * [`pirouter init`](#pirouter-init)
32
35
  * [`pirouter uninstall`](#pirouter-uninstall)
33
36
  * [`pirouter check`](#pirouter-check)
34
37
  * [`pirouter status`](#pirouter-status)
@@ -56,55 +59,83 @@ model, and a task whose shape is unclear goes to the generalist.
56
59
 
57
60
  </details>
58
61
 
62
+ ## Quickstart
59
63
 
60
- ## Install
64
+ ### Install
61
65
 
62
- Install locally with npm, then run the setup script.
66
+ Use in an existing npm project with pi installed. Install locally with npm,
67
+ then run the setup script.
63
68
 
64
69
  ```bash
65
- npm i -D tiiny-router
70
+ npm i -D tiiny-router-pi
71
+ ```
72
+
73
+ Setup:
74
+
75
+ ```sh
76
+ npx pirouter init
66
77
  ```
67
78
 
68
79
  Installing is local to your current repo only, not global or user-scope.
80
+ `init` creates or updates `.pi/settings.json` to load the installed
81
+ package. Commit `.pi/`, `package.json` and the lockfile to use the same
82
+ setup in worktree [Loops](#redeyeloops).
83
+
84
+ ## Configure
85
+
86
+ `TIINY_API_KEY` must be available in the shell, and the `tiiny` provider must
87
+ be in the file `~/.pi/agent/models.json`.
88
+
89
+ Export and configure the
90
+ `tiiny` provider in pi's `~/.pi/agent/models.json`. Register every
91
+ model ID in `tiers.json` with its context window and output limit.
92
+ Use the device's inference URL, `api: "openai-completions"` and
93
+ `apiKey: "$TIINY_API_KEY"`. If `PI_CODING_AGENT_DIR` is set, put
94
+ `models.json` there instead. The installer does not create this config.
95
+ See [Configuration](#configuration) for the router's environment variables.
69
96
 
70
- After installing via `npm`, run the install script, `npx pirouter install`.
71
- The script adds symbolic links, and copies a folder
72
- to the project's `.pi/` directory, so pi can load the router's extension,
73
- the router's agents, and router skills in the project.
97
+ After installing via `npm`, initialize the project with `npx pirouter init`.
98
+ The script updates project settings, adds symbolic links, and copies
99
+ the subagent extension into `.pi/`, so pi can load the router's
100
+ extension, agents and skill in the project.
74
101
 
75
- To remove it, run `npx pirouter uninstall`, then `npm rm tiiny-router`.
102
+ To remove it, run `npx pirouter uninstall`, then `npm rm tiiny-router-pi`.
76
103
  See [Uninstall](#uninstall). Uninstall leaves `~/.pi/agent/tiiny` in
77
104
  place. Delete it yourself if you no longer use the controller.
78
105
 
79
- ### Dry Run
106
+ ## Dry Run
80
107
 
81
108
  Print what would change without changing anything:
82
109
 
83
110
  ```bash
84
- npx pirouter install --dry-run
111
+ npx pirouter init --dry-run
85
112
  ```
86
113
 
87
114
  Then install the extension, agents, and skill:
88
115
 
89
116
  ```bash
90
- npx pirouter install
117
+ npx pirouter init
91
118
  ```
92
119
 
93
- Run these from the project root. `npx pirouter install` stops with an error
94
- if the current directory has no `package.json`. It runs `scripts/install.sh`,
95
- which writes inside the project's `.pi/` directory. It makes these changes,
96
- in this order:
120
+ Run these from the project root. `npx pirouter init` stops with an error
121
+ if the current directory has no `package.json` or the package is not
122
+ installed in its `node_modules`. It runs `scripts/init.sh`, which writes
123
+ inside the project's `.pi/` directory. It makes these changes, in this
124
+ order:
97
125
 
98
- 1. Links the package as a pi extension:
99
- `.pi/extensions/tiiny-router -> node_modules/tiiny-router`. pi reads
100
- the `pi.extensions` field of the package's `package.json` to find
126
+ 1. Adds `../node_modules/tiiny-router-pi` to `packages` in
127
+ `.pi/settings.json`, creating the file if needed. Other settings and
128
+ package entries are preserved, and rerunning `init` adds no duplicate.
129
+ Invalid JSON or a non-array `packages` value causes an error before
130
+ changes are made. pi reads the package's `pi.extensions` field to find
101
131
  `index.ts`, which registers the `tiiny-router/*` virtual models.
132
+ An old `.pi/extensions/tiiny-router` symlink is removed.
102
133
  2. Links each agent definition into `.pi/agents/`: `tiiny-browser.md`,
103
134
  `tiiny-coder.md`, `tiiny-drafter.md`, `tiiny-indexer.md`,
104
135
  `tiiny-researcher.md` and `tiiny-worker.md`. These are for the
105
136
  subagent tool (see [Delegating with subagents](#delegating-with-subagents)).
106
137
  3. Links the skill folder:
107
- `.pi/skills/tiiny-routing -> node_modules/tiiny-router/skill`.
138
+ `.pi/skills/tiiny-routing -> node_modules/tiiny-router-pi/skill`.
108
139
  4. Copies `index.ts` and `agents.ts` from pi's example `subagent`
109
140
  extension into `.pi/extensions/subagent`, then edits the copy to set
110
141
  `MAX_CONCURRENCY = 1` (see [One task at a time](#one-task-at-a-time)).
@@ -112,23 +143,25 @@ in this order:
112
143
  this package's own `node_modules`, then in the global npm root. This is
113
144
  a copy, not a link, so later pi updates do not change it.
114
145
 
115
- Steps 1 to 3 create symbolic links. Because they point into
116
- `node_modules`, upgrading `tiiny-router` with npm updates them too.
146
+ The settings path and the links in steps 2 and 3 are relative to their
147
+ locations under `.pi/`. They resolve into the project's `node_modules`,
148
+ so upgrades and fresh worktrees use that project's installed package.
149
+ Commit `.pi/`, `package.json` and the lockfile; install dependencies in
150
+ each worktree before starting pi.
117
151
 
118
- It doesn't overwrite files or directories. If a destination exists
119
- and is not a symbolic link, it prints `skip:` and moves on. If it is a
120
- symbolic link, it is replaced, so running `install` again is safe and
121
- re-points old links at the current package. Step 4 is skipped if
152
+ At link destinations, it doesn't overwrite real files or directories.
153
+ If a destination exists and is not a symbolic link, it prints `skip:`
154
+ and moves on. Symbolic links are replaced, so running `init` again is
155
+ safe and re-points old links at the current package. Step 4 is skipped if
122
156
  `.pi/extensions/subagent` exists in any form. In that case, set
123
157
  `MAX_CONCURRENCY = 1` in your own subagent extension. Step 4 is also
124
158
  skipped, with a message, if pi's example cannot be found.
125
159
 
126
- Each change prints one line: `link:`, `copy:` or `skip:`. With
127
- `--dry-run`, it changes nothing, but prints each command it would run
128
- (`would: ...`) before the same `link:` and `copy:` lines.
160
+ Changes print `update:`, `remove:`, `link:`, `copy:` or `skip:` lines.
161
+ With `--dry-run`, it changes nothing and prints the planned settings
162
+ update and filesystem commands (`would: ...`).
129
163
 
130
- It does not edit `.pi/settings.json`, `~/.pi/agent/models.json` or any
131
- file outside `.pi/`.
164
+ It does not edit `~/.pi/agent/models.json` or any file outside `.pi/`.
132
165
 
133
166
  >
134
167
  > [!NOTE]
@@ -143,12 +176,15 @@ Everything else, the controller and the route checker, is a
143
176
  `pirouter` subcommand too. Run `npx pirouter` with no arguments for
144
177
  the list.
145
178
 
146
- To try the router for one run without installing anything:
179
+ To try the extension for one run without linking it into `.pi/`:
147
180
 
148
181
  ```bash
149
- pi -e npm:tiiny-router --model tiiny-router/auto
182
+ pi -e npm:tiiny-router-pi --model tiiny-router/auto
150
183
  ```
151
184
 
185
+ pi caches the npm package in its agent directory. This loads the
186
+ extension only; it does not install the agents or the routing skill.
187
+
152
188
  ## Uninstall
153
189
 
154
190
  From the project directory, preview the removal, then uninstall:
@@ -159,7 +195,9 @@ npx pirouter uninstall
159
195
  ```
160
196
 
161
197
  This removes router entries from global `~/.pi/agent/settings.json` and
162
- local `.pi/settings.json`, including npm sources and local package paths.
198
+ local `.pi/settings.json`, including local package paths and the legacy
199
+ npm source `npm:tiiny-router`. The current uninstaller does not recognize
200
+ `npm:tiiny-router-pi` sources; remove those `packages` entries manually.
163
201
  It also removes links to the router's extension, agents and skill from
164
202
  both scopes. If `PI_CODING_AGENT_DIR` is set, that directory is used for
165
203
  global config instead. Other projects' local config is unchanged.
@@ -173,37 +211,53 @@ them. Running uninstall again is safe, and no `package.json` is required.
173
211
  Restart pi or run `/reload`. To also remove the npm dependency, run:
174
212
 
175
213
  ```bash
176
- npm rm tiiny-router
214
+ npm rm tiiny-router-pi
177
215
  ```
178
216
 
179
217
 
180
- ## Loops
218
+ ## `redeye`/Loops
181
219
 
182
220
  For an orchestrator such as
183
221
  [redeye](https://github.com/nichoth/redeye) that runs `pi` in fresh `git`
184
- worktrees, add the package to the project's `pi` settings instead:
222
+ worktrees, use the same project setup:
185
223
 
186
224
  ```bash
187
- npm i -D tiiny-router
225
+ npm i -D tiiny-router-pi
226
+ npx pirouter init
188
227
  ```
189
228
 
190
- Commit `.pi/settings.json`:
229
+ `init` adds this package entry to `.pi/settings.json` automatically:
191
230
 
192
231
  ```json
193
- { "packages": ["../node_modules/tiiny-router"] }
232
+ { "packages": ["../node_modules/tiiny-router-pi"] }
194
233
  ```
195
234
 
196
235
  The path is relative to `.pi/`, so each worktree loads its own installed
197
- copy. Then use the `auto` model, which picks a tier for each message:
236
+ copy after installing dependencies. Commit the generated `.pi/` directory,
237
+ `package.json` and the lockfile. The relative agent and skill links that
238
+ `init` creates work in each worktree too.
239
+
240
+ Then use the `auto` model, which infers a tier for each message:
241
+
242
+ ### Example
243
+
244
+ #### Tiiny Model for Orchestrator and Subtasks:
198
245
 
199
246
  ```sh
200
247
  npx redeye pi -m tiiny-router/auto --concurrency 1
201
248
  ```
202
249
 
203
- To pin every task to one tier instead, name it, as in
250
+ #### Claude as Orchestrator with Tiiny for Subtasks:
251
+
252
+ ```sh
253
+
254
+ ```
255
+
256
+
257
+ To pin every task to one tier instead, name it, for example,
204
258
  `-m tiiny-router/code`.
205
259
 
206
- ## Use
260
+ ## Examples
207
261
 
208
262
  ### Interactive
209
263
 
@@ -213,9 +267,10 @@ pi --model tiiny-router/auto
213
267
 
214
268
  The footer shows the selection and the routed model (for example
215
269
  `auto -> Qwen3.6-35B-A3B-turbo`), and the status line shows the route
216
- label, such as `tiiny: draft->generalist [think:off]`. In `auto`, every
217
- new message is routed again. If the tier and model have not changed, the
218
- session stays on the same model.
270
+ label, such as `tiiny: draft->generalist [think:off]`. In `auto`, each
271
+ new message's tier is inferred again. If the tier is unchanged and the
272
+ previous model is still loaded, the session keeps that model, even if
273
+ a preferred candidate has since been loaded.
219
274
 
220
275
  ### One-off
221
276
 
@@ -223,12 +278,16 @@ session stays on the same model.
223
278
  pi --model tiiny-router/index:off -p "Classify every file under ./notes by topic"
224
279
  ```
225
280
 
226
- ### With Redeye
281
+ ### With `redeye`
227
282
 
228
283
  Use this with the [`redeye` CLI](https://github.com/nichoth/redeye) tool.
229
284
  See [the redeye docs](https://github.com/nichoth/redeye#local-model-with-pi)
230
285
  for more examples.
231
286
 
287
+ ```sh
288
+ npx redeye pi -m tiiny-router/auto --concurrency 1
289
+ ```
290
+
232
291
  ### Delegating with subagents
233
292
 
234
293
  The installed agents each pin a tier:
@@ -264,7 +323,7 @@ The subagent tool looks for agents in two places:
264
323
  - project agents, in the nearest `.pi/agents/` above the working
265
324
  directory
266
325
 
267
- `pirouter install` puts the `tiiny-*` agents in the project's
326
+ `pirouter init` puts the `tiiny-*` agents in the project's
268
327
  `.pi/agents/`, so they are project agents. The tool's `agentScope`
269
328
  parameter chooses where it looks:
270
329
 
@@ -272,7 +331,7 @@ parameter chooses where it looks:
272
331
  |---|---|
273
332
  | `"user"` (default) | user agents only |
274
333
  | `"project"` | project agents only |
275
- | `"both"` | both, and a project agent wins over a user agent with the same name |
334
+ | `"both"` | both; project agents take precedence when names match |
276
335
 
277
336
  With the default, the `tiiny-*` agents cannot be found. The model sets
278
337
  the tool's parameters, so say in your request that it should use project
@@ -319,12 +378,16 @@ planned, one at a time. Then restore the device and drop the lock:
319
378
  npx pirouter release
320
379
  ```
321
380
 
322
- `plan` packs the batch into waves that each fit in 100% NPU and writes
323
- `~/.pi/agent/tiiny/tiiny-plan.json`. The router reads it: a planned goal
324
- runs on its planned model, but only if that model is loaded. Until
325
- `load` runs, the planned model is not loaded, so the router falls back
326
- as usual. `release` reloads the `required` models from `tiers.json` and
327
- checks that it worked.
381
+ Repeat the load and delegation steps for every wave. Always release,
382
+ including after a failed batch.
383
+
384
+ `plan` packs the batch into waves that fit in 100% NPU and writes
385
+ `~/.pi/agent/tiiny/tiiny-plan.json`. The router prefers a planned model
386
+ when it is loaded, or when residency cannot be read. If it is known to
387
+ be unloaded, the router uses its normal fallback order. Planning does
388
+ not change which models are loaded. `release` restores the `required`
389
+ models from `tiers.json` and verifies them. It leaves other batch models
390
+ loaded if they still fit; it does not restore the exact previous set.
328
391
 
329
392
  See [Commands](#commands) for every option.
330
393
  The `tiiny-routing` skill walks a pi agent through this sequence.
@@ -339,30 +402,39 @@ pirouter [--device NAME] <command> [options]
339
402
 
340
403
  Run `npx pirouter` with no arguments for a list of commands.
341
404
 
342
- `install`, `uninstall` and `check` are handled by `pirouter` itself.
405
+ `init`, `uninstall` and `check` are handled by `pirouter` itself.
343
406
  Every other command runs
344
407
  the controller, `controller/tiiny_ctl.py`, with `python3`.
345
408
  `npx pirouter check -h` and `npx pirouter <controller command> -h`
346
409
  show a command's options.
347
410
 
348
- `--device NAME` goes before the command, and targets a device by name
349
- (for example `tiiny-ant`) or IP address. With a named device, the lock
350
- and plan files get the device name in them
351
- (`tiiny-lock-<name>.json`, `tiiny-plan-<name>.json`).
411
+ `--device NAME` is a controller option, so it goes before a controller
412
+ command. It requires an external `devices.py` registry module, which
413
+ this package does not ship. Without that module, the option has no
414
+ effect; use `TIINY_BASE_URL`, `TIINY_HOST` and the Tiiny CLI's device
415
+ configuration instead. These variables do not change the inference URL
416
+ in pi's `models.json`; configure that separately.
417
+
418
+ With a registry, lock and plan files include the device name
419
+ (`tiiny-lock-<name>.json`, `tiiny-plan-<name>.json`). Set
420
+ `TIINY_PLAN_FILE` to the same path for both the controller and pi,
421
+ because the extension does not select a named plan automatically.
352
422
 
353
- Several controller commands take `--owner`. If it is not given, the
354
- owner is `$TIINY_OWNER`, or else `$USER`. The lock is between owners:
355
- a command that changes the device refuses to run while a different
356
- owner holds the lock, unless you pass `--force`.
423
+ `reserve` requires `--owner`. `load`, `ensure` and `release` default to
424
+ `$TIINY_OWNER`, or else `$USER` outside a legacy Hermes profile. These
425
+ three commands refuse to change the device while another owner holds
426
+ the lock, unless you pass `--force`. `plan` defaults to `$TIINY_OWNER`
427
+ or `unassigned`. The lock is cooperative; it does not block direct
428
+ Tiiny CLI calls or `image --load`.
357
429
 
358
- ### `pirouter install`
430
+ ### `pirouter init`
359
431
 
360
432
  ```bash
361
- npx pirouter install [--dry-run]
433
+ npx pirouter init [--dry-run]
362
434
  ```
363
435
 
364
- Link the extension, agents and skill into `./.pi`, and copy the
365
- subagent extension. See [Install](#install).
436
+ Add the local package to `./.pi/settings.json`, link the agents and
437
+ skill, and copy the subagent extension. See [Install](#install).
366
438
  Flag `--dry-run` prints the changes without making them, and `-h`
367
439
  prints help.
368
440
 
@@ -412,13 +484,14 @@ npx pirouter plan --goal "GOAL" [--goal "GOAL" ...] [options]
412
484
 
413
485
  Picks a model for each goal, packs the models into waves that each fit
414
486
  in 100% NPU, and writes the plan file. It needs at least one `--goal`.
415
- Only models downloaded to the device are chosen.
487
+ Candidates must already be resident or marked downloaded/running in
488
+ the catalogue. If none qualifies, it falls back to the generalist.
416
489
 
417
490
  | Option | Meaning |
418
491
  |---|---|
419
492
  | `--goal GOAL` | a task goal; repeat it for a batch |
420
493
  | `--tier TIER` | use this tier for every goal |
421
- | `--model MODEL` | use this model for every goal |
494
+ | `--model MODEL` | restrict each goal to this model in its tier's candidates |
422
495
  | `--owner OWNER` | who is planning |
423
496
  | `--task TASK` | what the batch is for |
424
497
 
@@ -428,9 +501,9 @@ Only models downloaded to the device are chosen.
428
501
  npx pirouter reserve --owner OWNER [options]
429
502
  ```
430
503
 
431
- Takes the lock, so other agents do not load or unload models while
432
- your batch runs. The lock expires on its own, so a crashed agent does
433
- not hold the device forever.
504
+ Takes the lock, so other owners' `load`, `ensure` and `release`
505
+ commands refuse to change the device while your batch runs. The lock
506
+ expires on its own, so a crashed agent does not hold it forever.
434
507
 
435
508
  | Option | Meaning |
436
509
  |---|---|
@@ -482,7 +555,8 @@ npx pirouter release [--owner OWNER] [--force]
482
555
 
483
556
  Clears the hold, reloads the `required` models from `tiers.json`,
484
557
  checks that they loaded, and clears the lock. It checks who holds the
485
- lock before it changes anything.
558
+ lock before it changes anything. Batch models may remain loaded;
559
+ release does not restore the exact pre-batch residency.
486
560
 
487
561
  | Option | Meaning |
488
562
  |---|---|
@@ -505,6 +579,10 @@ now be wrong.
505
579
  | `--update` | save the current store as the new snapshot |
506
580
  | `--refresh` | the same as `--update` |
507
581
 
582
+ The current command only saves a snapshot if one already exists and
583
+ contains models. With no snapshot, it lists the store and returns,
584
+ even with `--update` or `--refresh`.
585
+
508
586
  ### `pirouter image`
509
587
 
510
588
  ```bash
@@ -517,7 +595,10 @@ shows its NPU share, whether it is loaded, and the other candidates.
517
595
  | Option | Meaning |
518
596
  |---|---|
519
597
  | `--kind KIND` | `image` (default), `music` or `ocr` |
520
- | `--load` | load the chosen model and record it as the hold; free it with `release` |
598
+ | `--load` | load the model and record it as the hold; skips the lock check |
599
+
600
+ `release` clears the hold and restores required models, but does not
601
+ necessarily unload the image model.
521
602
 
522
603
 
523
604
 
@@ -534,15 +615,17 @@ The thinking level on the virtual model sets the reasoning mode:
534
615
  For `off` and `on`, the router reads the routed model's `thinking` block
535
616
  from the device and rewrites the request:
536
617
 
537
- - `chat_template_kwargs.enable_thinking` is always sent, because the
618
+ - For a model reported as reasoning-capable,
619
+ `chat_template_kwargs.enable_thinking` is always sent, because the
538
620
  device's `toggleable` flag is not always right.
539
621
  - If the model has levels but no switch (for example `gpt-oss-20b`),
540
622
  `reasoning_effort` is set to its cheapest level for `off` and its
541
623
  highest for `on`. The label then says `off->low`, since the model still
542
624
  reasons, only less.
543
- - `max_tokens` is raised to at least 4096. A reasoning model with a
544
- small budget spends it all on the trace and returns an empty answer
545
- with HTTP 200.
625
+ - The output budget (`max_tokens`, or `max_completion_tokens` if
626
+ present) is raised to at least 4096 by default. Override the floor
627
+ with `TIINY_THINKING_MAX_TOKENS`. A reasoning model with a small
628
+ budget can spend it all on the trace and return an empty answer.
546
629
 
547
630
  The achieved state, not the requested one, is shown in the label:
548
631
  `off`, `on`, `off->low`, `on->high`, `unsupported` (the model does not
@@ -577,7 +660,14 @@ TIINY_ROUTER_TRACE=/tmp/tiiny-routes.jsonl pi --model tiiny-router/auto
577
660
  ```
578
661
 
579
662
  ```json
580
- {"reason":"user","virtual":"auto","tier":"index","model":"Qwen/Qwen3.6-35B-A3B-turbo","label":"index->generalist","thinking":"off->off"}
663
+ {
664
+ "reason": "user",
665
+ "virtual": "auto",
666
+ "tier": "index",
667
+ "model": "Qwen/Qwen3.6-35B-A3B-turbo",
668
+ "label": "index->generalist",
669
+ "thinking": "off->off"
670
+ }
581
671
  ```
582
672
 
583
673
  ## The tier table
@@ -619,12 +709,16 @@ same time.
619
709
  | `TIINY_HOST` | `http://tiinyhost.local` | model store catalogue |
620
710
  | `TIINY_PI_PROVIDER` | `tiiny` | provider id in `models.json` |
621
711
  | `TIINY_HOME` | `~/.pi/agent/tiiny` | plan, lock and hold files |
622
- | `TIINY_OWNER` | `$USER` | lock owner for controller commands |
712
+ | `TIINY_OWNER` | see [Commands](#commands) | controller owner |
623
713
  | `TIINY_PLAN_FILE` | `$TIINY_HOME/tiiny-plan.json` | plan the router reads |
624
- | `TIINY_TIERS_FILE` | `./tiers.json` | tier table |
714
+ | `TIINY_TIERS_FILE` | package's `tiers.json` | tier table |
625
715
  | `TIINY_THINKING_MAX_TOKENS` | `4096` | output floor when reasoning is set |
626
716
  | `TIINY_ROUTER_TRACE` | (off) | JSON-lines route log |
627
717
 
718
+ `TIINY_BIN` selects the controller's Tiiny CLI executable; its default
719
+ is `~/.local/tiiny/bin/tiiny`. `TIINY_LOCK_FILE`, `TIINY_HOLD_FILE` and
720
+ `TIINY_SNAPSHOT_FILE` override the controller's state file paths.
721
+
628
722
  ## Operating notes
629
723
 
630
724
  ### One task at a time
@@ -633,8 +727,9 @@ The device serves one generation-heavy stream at a time. Two heavy
633
727
  requests do not fail; they **hang**, and the device keeps reporting
634
728
  healthy. This applies to the device as a whole, not just to pi. Killing
635
729
  a client does not seem to stop its request on the device, so later
636
- requests can hang behind it until it finishes. To clear stuck work, run `tiiny interrupt --all`, but note
637
- that it stops every active request on the device, not just yours.
730
+ requests can hang behind it until it finishes. To clear stuck work,
731
+ run `tiiny interrupt --all`, but note that it stops every active
732
+ request on the device, not just yours.
638
733
 
639
734
  ### A 404 is residency, not a bad id
640
735
 
@@ -662,7 +757,7 @@ agents/ tiiny-* subagent definitions
662
757
  skill/SKILL.md the tiiny-routing skill
663
758
  controller/ tiiny_ctl.py and tiiny-swap.sh, adapted for pi
664
759
  bin/pirouter the `pirouter` command line
665
- scripts/install.sh `pirouter install`: links everything into ./.pi
760
+ scripts/init.sh `pirouter init`: settings and resources in ./.pi
666
761
  ```
667
762
 
668
763
  ## Development
@@ -722,6 +817,10 @@ they never touch `~/.pi` or a real device. They cover:
722
817
  - the whole cycle: plan, reserve, load, then a routed child on the loaded
723
818
  specialist, then release
724
819
 
820
+ The install-package tests also pack the repo, install the tarball in
821
+ fresh projects under `.test-tmp/`, and check the links and CLI from the
822
+ installed copy. Set `KEEP_TEST_TMP=1` to preserve these fixtures.
823
+
725
824
  ```bash
726
825
  npm run test:live
727
826
  ```
@@ -739,7 +838,10 @@ holds the lock. Run them only when nothing else is using the device.
739
838
 
740
839
  The routing design, the controller (`controller/tiiny_ctl.py`,
741
840
  `controller/tiiny-swap.sh`) and the special-model table come from
742
- [AI_Articles/tiiny-model-routing](https://github.com/garciacionet-alt/AI_Articles/tree/main/tiiny-model-routing)
841
+ [AI_Articles/tiiny-model-routing][upstream]
743
842
  by Gary Garcia, under the MIT License. The controller was changed to keep
744
843
  its state in `TIINY_HOME` and to read its tier table and restore set from
745
844
  `tiers.json`.
845
+
846
+ [upstream]:
847
+ https://github.com/garciacionet-alt/AI_Articles/tree/main/tiiny-model-routing
package/bin/pirouter CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bash
2
2
  # pirouter: the tiiny-router command line.
3
3
  #
4
- # pirouter install [--dry-run]
5
- # link the extension, agents and skill into ./.pi
4
+ # pirouter init [--dry-run]
5
+ # configure the extension, agents and skill in ./.pi
6
6
  # pirouter uninstall [--dry-run]
7
7
  # remove the router from global and local pi configuration
8
8
  # pirouter check [opts] goal
@@ -17,7 +17,7 @@ usage () {
17
17
  cat <<'EOF'
18
18
  usage: pirouter <command> [args]
19
19
 
20
- install [--dry-run] link tiiny-router into this project's .pi/
20
+ init [--dry-run] configure tiiny-router in this project's .pi/
21
21
  uninstall [--dry-run] remove global and local pi configuration
22
22
  check [opts] "goal" show the tier, model and thinking for a goal
23
23
  (--tier T, --thinking auto|off|on, --all)
@@ -42,9 +42,9 @@ case "${1:-}" in
42
42
  ''|-h|--help|help)
43
43
  usage
44
44
  ;;
45
- install)
45
+ init)
46
46
  shift
47
- exec bash "$pkg/scripts/install.sh" "$@"
47
+ exec bash "$pkg/scripts/init.sh" "$@"
48
48
  ;;
49
49
  check|uninstall)
50
50
  command="$1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiiny-router-pi",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "pi extension that routes each task to the Tiiny model matching its shape",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -32,7 +32,7 @@
32
32
  "typecheck": "tsc --noEmit",
33
33
  "build": "tsc -p tsconfig.build.json",
34
34
  "route-check": "node src/cli/route-check.ts",
35
- "install-pi": "bin/pirouter install",
35
+ "init-pi": "bin/pirouter init",
36
36
  "toc": "markdown-toc --maxdepth 3 -i README.md",
37
37
  "prepack": "npm run build",
38
38
  "version": "npm run toc && git add README.md",
@@ -0,0 +1,44 @@
1
+ // pattern: Imperative Shell
2
+ import { lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
3
+ import { dirname } from 'node:path'
4
+
5
+ function main () {
6
+ const [path, source, flag] = process.argv.slice(2)
7
+ if (!path || !source || (flag && flag !== '--dry-run')) {
8
+ throw new Error('expected <settings-file> <source> [--dry-run]')
9
+ }
10
+ if (lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) {
11
+ throw new Error('settings file must not be a symlink')
12
+ }
13
+ let settings = {}
14
+ try {
15
+ settings = JSON.parse(readFileSync(path, 'utf8'))
16
+ } catch (error) {
17
+ if (error.code !== 'ENOENT') throw error
18
+ }
19
+ if (!settings || typeof settings !== 'object' ||
20
+ Array.isArray(settings)) {
21
+ throw new Error('expected a settings object')
22
+ }
23
+ if ('packages' in settings && !Array.isArray(settings.packages)) {
24
+ throw new Error('expected packages to be an array')
25
+ }
26
+ const packages = settings.packages ?? []
27
+ if (packages.some(entry => entry === source ||
28
+ (entry && typeof entry === 'object' && entry.source === source))) {
29
+ console.log(`skip: ${path} already lists ${source}`)
30
+ return
31
+ }
32
+ console.log(`${flag ? 'would: update' : 'update:'} ${path}`)
33
+ if (flag) return
34
+ settings.packages = [...packages, source]
35
+ mkdirSync(dirname(path), { recursive: true })
36
+ writeFileSync(path, JSON.stringify(settings, null, 4) + '\n')
37
+ }
38
+
39
+ try {
40
+ main()
41
+ } catch (error) {
42
+ console.error(`pirouter init: failed to update settings: ${error.message}`)
43
+ process.exitCode = 1
44
+ }
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env bash
2
- # Install tiiny-router into this project's .pi/ directory, as links into
2
+ # Initialize this project's .pi/ directory with links into
3
3
  # the installed package. Run it from the project root, through `pirouter`:
4
4
  #
5
- # npx pirouter install install
6
- # npx pirouter install --dry-run print what would change
5
+ # npx pirouter init initialize the project
6
+ # npx pirouter init --dry-run print what would change
7
7
  #
8
- # It never overwrites a real file: an existing path that is not a symlink
9
- # is reported and skipped.
8
+ # Settings are merged. Existing real files at link destinations are skipped.
10
9
  set -euo pipefail
11
10
 
12
11
  pkg="$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)"
@@ -16,21 +15,22 @@ dry=0
16
15
 
17
16
  usage () {
18
17
  cat <<'EOF'
19
- usage: pirouter install [--dry-run]
18
+ usage: pirouter init [--dry-run]
20
19
 
21
- Install tiiny-router into this project's .pi/ directory. Run it from the
20
+ Initialize tiiny-router in this project's .pi/ directory. Run it from the
22
21
  project root, the directory with package.json.
23
22
 
24
23
  It makes these changes:
25
- .pi/extensions/tiiny-router link to the package (the pi extension)
24
+ .pi/settings.json add the local package to packages
26
25
  .pi/agents/tiiny-*.md links to the subagent definitions
27
26
  .pi/skills/tiiny-routing link to the tiiny-routing skill
28
27
  .pi/extensions/subagent copy of pi's example subagent extension,
29
28
  with MAX_CONCURRENCY = 1
30
29
 
31
- It never overwrites a real file or directory: an existing path that is
32
- not a symlink is skipped. Existing symlinks are re-pointed, so running
33
- it again is safe. Nothing outside .pi/ is changed.
30
+ Other settings are preserved; invalid settings cause an error. Existing
31
+ real files at link destinations are skipped. Links are relative and
32
+ re-pointed on each run. The old .pi/extensions/tiiny-router symlink is
33
+ removed. Nothing outside .pi/ is changed.
34
34
 
35
35
  options:
36
36
  --dry-run print what would change, and change nothing
@@ -43,7 +43,7 @@ for arg in "$@"; do
43
43
  --dry-run) dry=1 ;;
44
44
  -h|--help) usage; exit 0 ;;
45
45
  *)
46
- echo "pirouter install: unknown option $arg" >&2
46
+ echo "pirouter init: unknown option $arg" >&2
47
47
  echo >&2
48
48
  usage >&2
49
49
  exit 2
@@ -52,11 +52,16 @@ for arg in "$@"; do
52
52
  done
53
53
 
54
54
  if [ ! -f "$project/package.json" ]; then
55
- echo "pirouter install: no package.json in $project; run it from the" \
55
+ echo "pirouter init: no package.json in $project; run it from the" \
56
56
  "project root" >&2
57
57
  exit 1
58
58
  fi
59
59
 
60
+ if [ ! -f "$project/node_modules/tiiny-router-pi/package.json" ]; then
61
+ echo "pirouter init: install tiiny-router-pi in this project first" >&2
62
+ exit 1
63
+ fi
64
+
60
65
  run () {
61
66
  if [ "$dry" = 1 ]; then echo "would: $*"; else "$@"; fi
62
67
  }
@@ -72,16 +77,27 @@ link () {
72
77
  echo "link: $dest -> $src"
73
78
  }
74
79
 
75
- # 1. The extension. pi reads package.json "pi.extensions" in the directory.
76
- link "$pkg" "$pi_dir/extensions/tiiny-router"
80
+ # 1. Load the extension through project settings, not a duplicate link.
81
+ settings_args=("$pi_dir/settings.json" "../node_modules/tiiny-router-pi")
82
+ if [ "$dry" = 1 ]; then settings_args+=(--dry-run); fi
83
+ node "$pkg/scripts/add-pi-package.mjs" "${settings_args[@]}"
84
+ old_extension="$pi_dir/extensions/tiiny-router"
85
+ if [ -L "$old_extension" ]; then
86
+ run rm "$old_extension"
87
+ echo "remove: $old_extension"
88
+ elif [ -e "$old_extension" ]; then
89
+ echo "skip: $old_extension exists and is not a symlink" >&2
90
+ fi
77
91
 
78
92
  # 2. The tier agents, for the subagent tool.
79
- for f in "$pkg"/agents/*.md; do
80
- link "$f" "$pi_dir/agents/$(basename "$f")"
93
+ local_pkg="../../node_modules/tiiny-router-pi"
94
+ for f in "$project/node_modules/tiiny-router-pi"/agents/*.md; do
95
+ name="$(basename "$f")"
96
+ link "$local_pkg/agents/$name" "$pi_dir/agents/$name"
81
97
  done
82
98
 
83
99
  # 3. The skill the manager agent follows.
84
- link "$pkg/skill" "$pi_dir/skills/tiiny-routing"
100
+ link "$local_pkg/skill" "$pi_dir/skills/tiiny-routing"
85
101
 
86
102
  # 4. The subagent extension, copied from pi's examples, with one child at a
87
103
  # time: the device serves one generation-heavy stream, and two heavy
@@ -120,3 +136,4 @@ fi
120
136
  echo
121
137
  echo "Done. Start pi in $project and trust the project, or run /reload in"
122
138
  echo "a running session."
139
+ echo "Commit .pi/, package.json and your lockfile for use in worktrees."