tiiny-router-pi 0.0.3 → 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 +52 -33
- package/bin/pirouter +2 -2
- package/package.json +1 -1
- package/scripts/add-pi-package.mjs +44 -0
- package/scripts/init.sh +28 -11
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ model, and a task whose shape is unclear goes to the generalist.
|
|
|
22
22
|
- [Dry Run](#dry-run)
|
|
23
23
|
- [Uninstall](#uninstall)
|
|
24
24
|
- [`redeye`/Loops](#redeyeloops)
|
|
25
|
+
* [Example](#example)
|
|
25
26
|
- [Examples](#examples)
|
|
26
27
|
* [Interactive](#interactive)
|
|
27
28
|
* [One-off](#one-off)
|
|
@@ -76,6 +77,9 @@ npx pirouter init
|
|
|
76
77
|
```
|
|
77
78
|
|
|
78
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).
|
|
79
83
|
|
|
80
84
|
## Configure
|
|
81
85
|
|
|
@@ -91,9 +95,9 @@ Use the device's inference URL, `api: "openai-completions"` and
|
|
|
91
95
|
See [Configuration](#configuration) for the router's environment variables.
|
|
92
96
|
|
|
93
97
|
After installing via `npm`, initialize the project with `npx pirouter init`.
|
|
94
|
-
The script adds symbolic links, and copies
|
|
95
|
-
|
|
96
|
-
|
|
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.
|
|
97
101
|
|
|
98
102
|
To remove it, run `npx pirouter uninstall`, then `npm rm tiiny-router-pi`.
|
|
99
103
|
See [Uninstall](#uninstall). Uninstall leaves `~/.pi/agent/tiiny` in
|
|
@@ -114,14 +118,18 @@ npx pirouter init
|
|
|
114
118
|
```
|
|
115
119
|
|
|
116
120
|
Run these from the project root. `npx pirouter init` stops with an error
|
|
117
|
-
if the current directory has no `package.json
|
|
118
|
-
|
|
119
|
-
in this
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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:
|
|
125
|
+
|
|
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
|
|
124
131
|
`index.ts`, which registers the `tiiny-router/*` virtual models.
|
|
132
|
+
An old `.pi/extensions/tiiny-router` symlink is removed.
|
|
125
133
|
2. Links each agent definition into `.pi/agents/`: `tiiny-browser.md`,
|
|
126
134
|
`tiiny-coder.md`, `tiiny-drafter.md`, `tiiny-indexer.md`,
|
|
127
135
|
`tiiny-researcher.md` and `tiiny-worker.md`. These are for the
|
|
@@ -135,25 +143,25 @@ in this order:
|
|
|
135
143
|
this package's own `node_modules`, then in the global npm root. This is
|
|
136
144
|
a copy, not a link, so later pi updates do not change it.
|
|
137
145
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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.
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
and is not a symbolic link, it prints `skip:`
|
|
145
|
-
|
|
146
|
-
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
|
|
147
156
|
`.pi/extensions/subagent` exists in any form. In that case, set
|
|
148
157
|
`MAX_CONCURRENCY = 1` in your own subagent extension. Step 4 is also
|
|
149
158
|
skipped, with a message, if pi's example cannot be found.
|
|
150
159
|
|
|
151
|
-
|
|
152
|
-
`--dry-run`, it changes nothing
|
|
153
|
-
(`would: ...`)
|
|
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: ...`).
|
|
154
163
|
|
|
155
|
-
It does not edit
|
|
156
|
-
file outside `.pi/`.
|
|
164
|
+
It does not edit `~/.pi/agent/models.json` or any file outside `.pi/`.
|
|
157
165
|
|
|
158
166
|
>
|
|
159
167
|
> [!NOTE]
|
|
@@ -211,31 +219,42 @@ npm rm tiiny-router-pi
|
|
|
211
219
|
|
|
212
220
|
For an orchestrator such as
|
|
213
221
|
[redeye](https://github.com/nichoth/redeye) that runs `pi` in fresh `git`
|
|
214
|
-
worktrees,
|
|
222
|
+
worktrees, use the same project setup:
|
|
215
223
|
|
|
216
224
|
```bash
|
|
217
225
|
npm i -D tiiny-router-pi
|
|
226
|
+
npx pirouter init
|
|
218
227
|
```
|
|
219
228
|
|
|
220
|
-
|
|
229
|
+
`init` adds this package entry to `.pi/settings.json` automatically:
|
|
221
230
|
|
|
222
231
|
```json
|
|
223
232
|
{ "packages": ["../node_modules/tiiny-router-pi"] }
|
|
224
233
|
```
|
|
225
234
|
|
|
226
235
|
The path is relative to `.pi/`, so each worktree loads its own installed
|
|
227
|
-
copy after installing dependencies. Commit
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
The interactive install above provides those resources in one checkout.
|
|
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.
|
|
231
239
|
|
|
232
240
|
Then use the `auto` model, which infers a tier for each message:
|
|
233
241
|
|
|
242
|
+
### Example
|
|
243
|
+
|
|
244
|
+
#### Tiiny Model for Orchestrator and Subtasks:
|
|
245
|
+
|
|
234
246
|
```sh
|
|
235
247
|
npx redeye pi -m tiiny-router/auto --concurrency 1
|
|
236
248
|
```
|
|
237
249
|
|
|
238
|
-
|
|
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,
|
|
239
258
|
`-m tiiny-router/code`.
|
|
240
259
|
|
|
241
260
|
## Examples
|
|
@@ -414,8 +433,8 @@ Tiiny CLI calls or `image --load`.
|
|
|
414
433
|
npx pirouter init [--dry-run]
|
|
415
434
|
```
|
|
416
435
|
|
|
417
|
-
|
|
418
|
-
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).
|
|
419
438
|
Flag `--dry-run` prints the changes without making them, and `-h`
|
|
420
439
|
prints help.
|
|
421
440
|
|
|
@@ -738,7 +757,7 @@ agents/ tiiny-* subagent definitions
|
|
|
738
757
|
skill/SKILL.md the tiiny-routing skill
|
|
739
758
|
controller/ tiiny_ctl.py and tiiny-swap.sh, adapted for pi
|
|
740
759
|
bin/pirouter the `pirouter` command line
|
|
741
|
-
scripts/init.sh `pirouter init`:
|
|
760
|
+
scripts/init.sh `pirouter init`: settings and resources in ./.pi
|
|
742
761
|
```
|
|
743
762
|
|
|
744
763
|
## Development
|
package/bin/pirouter
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# pirouter: the tiiny-router command line.
|
|
3
3
|
#
|
|
4
4
|
# pirouter init [--dry-run]
|
|
5
|
-
#
|
|
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
|
-
init [--dry-run]
|
|
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)
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/scripts/init.sh
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
# npx pirouter init initialize the project
|
|
6
6
|
# npx pirouter init --dry-run print what would change
|
|
7
7
|
#
|
|
8
|
-
#
|
|
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)"
|
|
@@ -22,15 +21,16 @@ 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/
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
@@ -57,6 +57,11 @@ if [ ! -f "$project/package.json" ]; then
|
|
|
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.
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
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 "$
|
|
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."
|