mu-agent 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +5 -4
  3. package/dist/bundle/chunks/anthropic-messages-MI4QHRXW.js +6 -0
  4. package/dist/bundle/chunks/anthropic.js +2 -2
  5. package/dist/bundle/chunks/azure-openai-responses-E3QGN4VN.js +2 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
  7. package/dist/bundle/chunks/chunk-33KL6IIQ.js +20 -0
  8. package/dist/bundle/chunks/chunk-4OBXYPH4.js +4 -0
  9. package/dist/bundle/chunks/chunk-C47CLQZK.js +2 -0
  10. package/dist/bundle/chunks/chunk-F5ZABL6Z.js +20 -0
  11. package/dist/bundle/chunks/chunk-H3QXYIF7.js +31 -0
  12. package/dist/bundle/chunks/chunk-HQHD6PZI.js +2 -0
  13. package/dist/bundle/chunks/chunk-KJUDFE6Y.js +11 -0
  14. package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
  15. package/dist/bundle/chunks/chunk-NG4PO5FP.js +1204 -0
  16. package/dist/bundle/chunks/chunk-NTSWBG4X.js +2 -0
  17. package/dist/bundle/chunks/chunk-RLZVFGW4.js +127 -0
  18. package/dist/bundle/chunks/{chunk-XDUWOHPL.js → chunk-S3GGRYIO.js} +2 -2
  19. package/dist/bundle/chunks/{chunk-4O2SCVYF.js → chunk-TAOL3JFA.js} +1 -1
  20. package/dist/bundle/chunks/chunk-TE3GUV6H.js +9 -0
  21. package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
  22. package/dist/bundle/chunks/{chunk-V7IXECST.js → chunk-WE4MXUQS.js} +3 -3
  23. package/dist/bundle/chunks/chunk-Y2PP32XV.js +2 -0
  24. package/dist/bundle/chunks/chunk-YLY6CKPK.js +132 -0
  25. package/dist/bundle/chunks/chunk-ZE5FMF3V.js +99 -0
  26. package/dist/bundle/chunks/cli-AOVD3SSZ.js +51 -0
  27. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NM3JRRWQ.js +2 -0
  28. package/dist/bundle/chunks/codemode-worker.js +374 -0
  29. package/dist/bundle/chunks/easter-egg-3d-G2LUBEMZ.js +2 -0
  30. package/dist/bundle/chunks/execute-MZVUC6BB.js +388 -0
  31. package/dist/bundle/chunks/github-copilot.js +1 -1
  32. package/dist/bundle/chunks/{google-generative-ai-C44KRRZ4.js → google-generative-ai-XMFHGQC5.js} +1 -1
  33. package/dist/bundle/chunks/{google-vertex-25DUXPTJ.js → google-vertex-4XRRNP74.js} +1 -1
  34. package/dist/bundle/chunks/{lib-HGQMNYVT.js → lib-TEDK3E5I.js} +2 -2
  35. package/dist/bundle/chunks/llama-cpp-classify-XT44PI3C.js +22 -0
  36. package/dist/bundle/chunks/mistral-conversations-Q22M3IBG.js +5 -0
  37. package/dist/bundle/chunks/node-N5BSDOA5.js +16 -0
  38. package/dist/bundle/chunks/openai-chatgpt.js +86 -0
  39. package/dist/bundle/chunks/{openai-codex-responses-3UAYOSSR.js → openai-codex-responses-4MYQSO5E.js} +1 -1
  40. package/dist/bundle/chunks/openai-codex.js +2 -2
  41. package/dist/bundle/chunks/openai-completions-OSRCWAAA.js +7 -0
  42. package/dist/bundle/chunks/openai-responses-UHF3DHNG.js +3 -0
  43. package/dist/bundle/chunks/{openrouter-images-JVEJN44Q.js → openrouter-images-ZVXWCSIM.js} +1 -1
  44. package/dist/bundle/chunks/openrouter.js +2 -2
  45. package/dist/bundle/chunks/radius.js +2 -2
  46. package/dist/bundle/chunks/runtime-VJMMDLVH.js +2 -0
  47. package/dist/bundle/chunks/typesafe-system-one-PRR5K6CI.js +2 -0
  48. package/dist/bundle/chunks/virtual-modules-RJXJGCPI.js +2 -0
  49. package/dist/bundle/cli-runtime.js +1 -1
  50. package/dist/bundle/index.js +1 -1
  51. package/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
  52. package/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
  53. package/dist/bundle/rpc-entry.js +1 -1
  54. package/dist/core/export-html/template.js +16 -0
  55. package/dist/modes/interactive/theme/dark.json +59 -72
  56. package/dist/modes/interactive/theme/light.json +57 -69
  57. package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
  58. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
  59. package/dist/modes/interactive/theme/system-theme.js +546 -0
  60. package/dist/modes/interactive/theme/system-theme.js.map +1 -0
  61. package/dist/modes/interactive/theme/theme-controller.d.ts +43 -9
  62. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  63. package/dist/modes/interactive/theme/theme-controller.js +121 -79
  64. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  65. package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -1
  66. package/dist/modes/interactive/theme/theme-json.js +1 -1
  67. package/dist/modes/interactive/theme/theme-json.js.map +1 -1
  68. package/dist/modes/interactive/theme/theme-schema.json +2 -2
  69. package/dist/modes/interactive/theme/theme.d.ts +34 -40
  70. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  71. package/dist/modes/interactive/theme/theme.js +139 -126
  72. package/dist/modes/interactive/theme/theme.js.map +1 -1
  73. package/dist/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
  74. package/dist/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
  75. package/docs/cli.md +60 -7
  76. package/docs/codemode.md +207 -0
  77. package/docs/configuration.md +2 -0
  78. package/docs/docs.json +13 -1
  79. package/docs/environment-variables.md +2 -2
  80. package/docs/extensions.md +53 -0
  81. package/docs/index.md +1 -1
  82. package/docs/keybindings.md +2 -2
  83. package/docs/llama-cpp.md +13 -0
  84. package/docs/mcp.md +270 -0
  85. package/docs/models.md +83 -1
  86. package/docs/packages.md +1 -1
  87. package/docs/providers.md +19 -6
  88. package/docs/quickstart.md +16 -2
  89. package/docs/rpc-commands.md +9 -3
  90. package/docs/rpc.md +3 -1
  91. package/docs/sdk.md +8 -3
  92. package/docs/security.md +2 -0
  93. package/docs/session-format.md +5 -1
  94. package/docs/settings.md +24 -5
  95. package/docs/themes.md +28 -6
  96. package/docs/usage.md +1 -1
  97. package/docs/virtual-models.md +114 -0
  98. package/docs/windows.md +2 -0
  99. package/examples/README.md +1 -1
  100. package/examples/extensions/README.md +1 -0
  101. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  102. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  103. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  104. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  105. package/examples/extensions/custom-provider-gitlab-duo/test.ts +5 -5
  106. package/examples/extensions/gondolin/package-lock.json +2 -2
  107. package/examples/extensions/gondolin/package.json +1 -1
  108. package/examples/extensions/jev-router.ts +113 -0
  109. package/examples/extensions/minimal-mode.ts +24 -96
  110. package/examples/extensions/sandbox/package-lock.json +2 -2
  111. package/examples/extensions/sandbox/package.json +1 -1
  112. package/examples/extensions/with-deps/package-lock.json +2 -2
  113. package/examples/extensions/with-deps/package.json +1 -1
  114. package/examples/rpc-client.ts +1 -1
  115. package/examples/rpc-extension-ui.ts +1 -1
  116. package/examples/sdk/14-codemode-mcp.ts +61 -0
  117. package/examples/sdk/README.md +2 -1
  118. package/judge/THIRD_PARTY_NOTICES.md +63 -0
  119. package/judge/dist/auth.js +128 -113
  120. package/judge/dist/import.js +10 -9
  121. package/judge/dist/kyrn-judge.js +5444 -5354
  122. package/judge/dist/setup.js +138 -12
  123. package/judge/manifest.json +414 -102
  124. package/kyrn/bin/kyrn-doctor +61 -11
  125. package/kyrn/bin/mu.mjs +84 -69
  126. package/package.json +4 -4
  127. package/dist/bundle/chunks/anthropic-messages-VMESUHQ7.js +0 -6
  128. package/dist/bundle/chunks/azure-openai-responses-K232MQFF.js +0 -2
  129. package/dist/bundle/chunks/chunk-AYFRR3OD.js +0 -2
  130. package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +0 -42
  131. package/dist/bundle/chunks/chunk-FU4XQUSL.js +0 -11
  132. package/dist/bundle/chunks/chunk-GNYZK6XN.js +0 -2
  133. package/dist/bundle/chunks/chunk-HEMXN7VJ.js +0 -1653
  134. package/dist/bundle/chunks/chunk-MVPXOVOJ.js +0 -2
  135. package/dist/bundle/chunks/chunk-NUHFSC37.js +0 -25
  136. package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
  137. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NR2TDCXU.js +0 -2
  138. package/dist/bundle/chunks/mistral-conversations-6IHQOR4R.js +0 -5
  139. package/dist/bundle/chunks/node-O3RIBJRH.js +0 -16
  140. package/dist/bundle/chunks/openai-completions-FIEQGWAH.js +0 -7
  141. package/dist/bundle/chunks/openai-responses-OZJXLHFC.js +0 -2
  142. package/dist/bundle/chunks/typesafe-system-one-VKYX4OGY.js +0 -2
  143. package/dist/bundle/chunks/virtual-modules-V7SXVVLP.js +0 -2
package/docs/settings.md CHANGED
@@ -37,9 +37,25 @@ See [Choose a Model](models.md) for model selection and thinking controls.
37
37
 
38
38
  | Setting | Type | Default | Description |
39
39
  |---|---|---|---|
40
- | `defaultTools` | `string[]` | `read`, `bash`, `edit`, `write` | Built-in tools enabled at startup. An empty array disables all built-in tools but not extension or SDK tools. |
40
+ | `defaultTools` | `string[]` | `read`, `bash`, `edit`, `write` | Tools enabled at startup. Plain names replace the defaults; `+name` adds a tool and `-name` removes one. An empty array disables all built-in tools but not extension or SDK tools. |
41
+ | `codemode.mode` | `"on"` \| `"only"` | `"on"` | How the `codemode` tool presents tools while it is active. `on`: declared tools get a note on calling them from scripts appended to their description, and `codemode` lists only tools that are not declared. `only`: `codemode` lists every tool scripts can call, and active built-in and extension tools are hidden from the model, so it reaches them through `codemode`. |
42
+ | `codemode.inlineBudget` | number | `3000` | Estimated tokens (characters / 4) the `codemode` tool's description may spend on tool declarations. Tools that do not fit are left out and found with `searchTools()`. `0` lists only namespaces. |
41
43
 
42
- Available built-in tools are `read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, and `ls`. CLI tool options override this setting for one invocation. See [Command Line](cli.md#tools).
44
+ Available built-in tools are `read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, and `ls`. `defaultTools` can also name `codemode` and `tool_search`, which built-in extensions register inactive, and other extension tools registered inactive.
45
+
46
+ A list of only `+name` and `-name` entries changes the inherited selection instead of replacing it. For example, this enables `codemode` next to the default tools:
47
+
48
+ ```json
49
+ {
50
+ "defaultTools": ["+codemode"]
51
+ }
52
+ ```
53
+
54
+ This replaces `bash` with `powershell` and enables `grep`: `["-bash", "+powershell", "+grep"]`. Project settings apply on top of user settings: a project list with only `+name` and `-name` entries changes the user's selection, and a project list with a plain name replaces it. In one list, plain names form the selection, and `+name` and `-name` then apply in order.
55
+
56
+ `/reload` enables tools newly added to `defaultTools`. It does not disable tools removed from it or re-enable unchanged tools you turned off. `--tools`, `--no-tools`, and `--no-builtin-tools` override `defaultTools`, also on reload.
57
+
58
+ CLI tool options override this setting for one invocation; `--tools` does not accept `+name` or `-name`. See [Command Line](cli.md#tools).
43
59
 
44
60
  ## Sessions and context
45
61
 
@@ -73,12 +89,13 @@ See [Compaction Reference](compaction.md) for trigger, summarization, and valida
73
89
 
74
90
  | Setting | Type | Default | Description |
75
91
  |---|---|---|---|
76
- | `theme` | string | Detected | Built-in or custom theme name. |
77
- | `quietStartup` | boolean | `false` | Hide the startup header. |
78
- | `tuiMode` | `"regular" \| "fullscreen"` | `"regular"` | Interactive terminal UI mode. |
92
+ | `theme` | string | `"system"` | Built-in or custom theme name. `system` derives colors from the terminal theme. |
93
+ | `quietStartup` | boolean \| `"header"` | `false` | `true` hides the startup header and loaded-resource listing. `"header"` keeps the header (version and key hints) but hides the model scope line and loaded-resource listing. |
94
+ | `tuiMode` | `"regular" \| "fullscreen"` | `"fullscreen"` | Interactive terminal UI mode. |
79
95
  | `fullscreenExitOutput` | `"transcript" \| "resume-hint"` | `"transcript"` | Output printed when fullscreen mode exits. |
80
96
  | `fullscreenScrollbar` | `"auto" \| "always" \| "hidden"` | `"auto"` | Fullscreen transcript scrollbar behavior. |
81
97
  | `fullscreenCopyOnSelect` | boolean | `true` | Copy selected text automatically in fullscreen mode. |
98
+ | `fullscreenWheelScrollLines` | `"auto"` \| number | `"auto"` | Lines per mouse-wheel event in fullscreen mode, from 1 to 100. `"auto"` moves one line per event in local macOS terminals, which already accelerate wheel and trackpad input; elsewhere, and over SSH, it speeds up fast wheel spins to at most 6 lines per event. Alt+wheel moves five times as far. |
82
99
  | `editorPaddingX` | number | `0` | Horizontal editor padding from 0 to 3 cells. |
83
100
  | `outputPad` | `0 \| 1` | `1` | Horizontal transcript padding. |
84
101
  | `autocompleteMaxVisible` | number | `5` | Visible autocomplete entries, from 3 to 20. |
@@ -140,6 +157,8 @@ Resource paths in user settings resolve from the agent directory. Paths in proje
140
157
 
141
158
  Resource arrays support glob exclusions with `!pattern`, exact inclusion with `+path`, and exact exclusion with `-path`. Pi loads resources listed in both user-level and project settings.
142
159
 
160
+ The built-in extensions are named `builtin:mcp`, `builtin:llama.cpp`, `builtin:codemode`, and `builtin:tool-search` in `extensions`. They load by default; `-builtin:mcp` disables one. A `+builtin:<name>` or `-builtin:<name>` entry in project settings overrides the user setting. `pi config` lists them under Built-in. `--no-extensions` disables them too, and `-e builtin:<name>` loads one explicitly.
161
+
143
162
  ## Updates, telemetry, and warnings
144
163
 
145
164
  | Setting | Type | Default | Description |
package/docs/themes.md CHANGED
@@ -1,6 +1,25 @@
1
1
  # Customize Pi with themes
2
2
 
3
- Themes control the colors Pi uses in interactive mode and HTML exports. Pi includes `dark` and `light` themes. You can select one theme, follow your terminal's light or dark appearance, or create your own palette.
3
+ Themes control the colors Pi uses in interactive mode and HTML exports. Pi includes the `system`, `dark`, and `light` themes. You can select one theme, follow your terminal's light or dark appearance, or create your own palette.
4
+
5
+ ## Use your terminal's colors
6
+
7
+ The `system` theme is the default. It builds Pi's colors from your terminal's theme, so Pi matches the terminal instead of bringing its own palette:
8
+
9
+ - Pi queries the terminal's default foreground and background colors and its 16 ANSI colors.
10
+ - Each Pi color takes its hue from one ANSI color, for example errors from red and links from blue.
11
+ - Pi sets each color's lightness so that it stands out from the background by a minimum contrast. Body text keeps at least a 4.5:1 WCAG contrast ratio on the background and every panel.
12
+ - When the terminal switches between light and dark, Pi queries the colors again and rebuilds the theme.
13
+
14
+ The theme adapts to what the terminal reports:
15
+
16
+ | Terminal reports | Result |
17
+ |---|---|
18
+ | Background and ANSI colors | Colors from the terminal palette, placed for the actual background. |
19
+ | Background only | Pi's own hues, placed for the actual background. |
20
+ | Nothing | ANSI color indices and the terminal's default colors, which the terminal renders itself. Secondary text is faint, and panels have no background color. |
21
+
22
+ Pi asks the terminal for its colors when it starts. Terminals usually answer within a few milliseconds, and Pi waits at most 100 ms before showing the startup header. If the terminal does not answer in time, Pi uses the ANSI color fallback, and it still applies the colors if they arrive later, for example over a slow SSH connection. `system` is a reserved name: a custom theme with that name is ignored.
4
23
 
5
24
  <a id="selecting-a-theme"></a>
6
25
 
@@ -16,6 +35,8 @@ The selection is saved as the `theme` [setting](settings.md#terminal-and-display
16
35
  }
17
36
  ```
18
37
 
38
+ Without a `theme` setting, Pi uses `system`.
39
+
19
40
  Automatic mode stores the light theme first and the dark theme second:
20
41
 
21
42
  ```json
@@ -24,7 +45,7 @@ Automatic mode stores the light theme first and the dark theme second:
24
45
  }
25
46
  ```
26
47
 
27
- When automatic mode is active, Pi changes themes when the terminal reports an appearance change. Theme names cannot contain `/` because Pi reserves it for this setting format.
48
+ Pi decides whether the terminal is light or dark from its reported background and foreground colors. If the terminal does not report its background, Pi uses the terminal's light/dark notification, then the `COLORFGBG` environment variable, then dark. The same decision picks the theme of a light/dark pair and the appearance of `system`. When automatic mode is active, Pi changes themes when the terminal reports an appearance change. Theme names cannot contain `/` because Pi reserves it for this setting format.
28
49
 
29
50
  Use `--use-theme` to choose the initial theme for one invocation without changing the saved setting:
30
51
 
@@ -37,7 +58,7 @@ See [CLI resources](cli.md#resources) for the command-line option.
37
58
 
38
59
  ## Create a custom theme
39
60
 
40
- Copy one of the [built-in themes](https://github.com/earendil-works/pi/tree/main/packages/coding-agent/src/modes/interactive/theme) or create a new JSON file conforming to the [schema](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json).
61
+ Copy one of the [built-in themes](https://github.com/earendil-works/pi/tree/main/packages/coding-agent/src/modes/interactive/theme) or create a new JSON file conforming to the [schema](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json). The built-in themes use OKHSL colors, with variables for colors that several roles share, so you can adjust a hue, saturation, or lightness directly.
41
62
 
42
63
  1. Save the file as `<agent-dir>/themes/my-theme.json`. The agent directory defaults to `~/.pi/agent`.
43
64
  2. Set its `name` to `my-theme`.
@@ -51,25 +72,26 @@ Use the theme name as the filename. Pi hot-reloads the active user theme only fr
51
72
  | Property | Required | Responsibility |
52
73
  |---|---|---|
53
74
  | `$schema` | No | Enables editor validation and completion against Pi's published schema. |
54
- | `name` | Yes | Identifies the theme in selectors and settings. It must be unique and cannot contain `/`. |
75
+ | `name` | Yes | Identifies the theme in selectors and settings. It must be unique, cannot contain `/`, and cannot be `system`. |
55
76
  | `appearance` | No | `"dark"` or `"light"`: the background the theme is designed for. Pi detects it from the theme colors when omitted. |
56
77
  | `vars` | No | Defines reusable color values. Variables can reference other variables. |
57
78
  | `colors` | Yes | Assigns colors to terminal UI roles. The schema identifies required and optional roles. |
58
79
  | `export` | No | Overrides page and panel backgrounds in HTML exports. |
59
80
 
60
- A color can be written in five forms:
81
+ A color can be written in six forms:
61
82
 
62
83
  | Form | Example | Meaning |
63
84
  |---|---|---|
64
85
  | RGB hexadecimal | `"#0af"` or `"#00aaff"` | A three- or six-digit sRGB color. |
65
86
  | OKLCH | `"oklch(62% 0.1 200)"` | Perceptual lightness, chroma, and hue. |
87
+ | OKHSL | `"okhsl(250 60% 55%)"` | Hue, saturation, and lightness. Saturation is relative to the most the sRGB gamut allows at that hue and lightness, so every value is in gamut and equal saturation looks equally colorful. |
66
88
  | 256-color index | `39` | An ANSI palette index from `0` through `255`. |
67
89
  | Variable reference | `"primary"` | The value of an entry in `vars`. |
68
90
  | Terminal default | `""` | The terminal's default foreground or background color. |
69
91
 
70
92
  Terminal default colors render as the terminal's own colors. Where Pi needs a concrete value, such as HTML export or extension color math, it uses the default colors the terminal reports, or a black or white guess based on the theme's appearance.
71
93
 
72
- Pi resolves chained variable references. A missing variable or circular reference makes the theme invalid. Pi uses truecolor when available, gamut-maps OKLCH to sRGB, and approximates colors for 256-color terminals. If colors differ from their source values, check your terminal's truecolor detection and contrast settings. See [Configure Your Terminal](terminal-setup.md#override-detected-capabilities).
94
+ Pi resolves chained variable references. A missing variable or circular reference makes the theme invalid. Pi uses truecolor when available, gamut-maps OKLCH to sRGB, and approximates colors for 256-color terminals. HTML exports convert OKHSL values to hexadecimal because CSS does not support them. If colors differ from their source values, check your terminal's truecolor detection and contrast settings. See [Configure Your Terminal](terminal-setup.md#override-detected-capabilities).
73
95
 
74
96
  Use the [theme JSON schema](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json) for the exact properties, required colors, and accepted value types.
75
97
 
package/docs/usage.md CHANGED
@@ -83,7 +83,7 @@ Use `/share` to upload the session and get a viewer link. With Radius authentica
83
83
 
84
84
  ## Adjust the terminal
85
85
 
86
- Regular mode uses the terminal's normal scrollback. Fullscreen mode keeps the editor and status area fixed while the transcript scrolls within the terminal window. Choose a mode through `/settings` or `--tui-mode`.
86
+ Fullscreen mode, the default, keeps the editor and status area fixed while the transcript scrolls within the terminal window. Regular mode uses the terminal's normal scrollback. Choose a mode through `/settings` or `--tui-mode`.
87
87
 
88
88
  Terminal support for mouse input, keyboard shortcuts, and inline images varies. See [Terminal Setup](terminal-setup.md) for platform-specific configuration and [Keybindings](keybindings.md) for every configurable shortcut. Run `/hotkeys` to inspect the shortcuts active in your current session.
89
89
 
@@ -0,0 +1,114 @@
1
+ # Virtual Models
2
+
3
+ A virtual model is a selectable model that picks a physical model for each request. Use one to route by task, cost, or conversation state. For example, a router can send quick questions to a small model and hard problems to a large one, while the user selects a single model.
4
+
5
+ Register virtual models from an [extension](extensions.md). They appear in `/model`, `--model`, scoped models, and settings like any other model. A virtual model can be listed under any provider, including one with physical models, such as `openai-codex/auto`.
6
+
7
+ ## Selection and dispatch
8
+
9
+ A virtual model selects a model and a thinking level. A router maps that pair to a physical pair for each request:
10
+
11
+ ```
12
+ selected (virtual model, virtual level) -> dispatched (physical model, physical level)
13
+ jev/auto:low -> anthropic/claude-sonnet-4-5:high
14
+ ```
15
+
16
+ The virtual thinking level is an input to the router. Its meaning is up to the router; it need not correspond to a reasoning budget.
17
+
18
+ Pi keeps the two pairs apart:
19
+
20
+ | | Selection | Dispatch |
21
+ |---|---|---|
22
+ | Recorded in | `model_change` and `thinking_level_change` entries | Each assistant message: `provider`, `api`, `model`, `thinkingLevel` |
23
+ | Visible as | `ctx.model`, `ctx.thinkingLevel`, `PI_MODEL`, `PI_REASONING_LEVEL`, `/model` | The assistant message of each response |
24
+
25
+ Providers only receive physical models. Assistant messages name the physical model, so replaying a conversation across different physical models works the same as after a manual model switch. Resuming a session restores the virtual selection from its latest `model_change` entry. If the virtual model is no longer registered, Pi falls back to the physical model that answered last.
26
+
27
+ In interactive mode, the footer shows the routed model next to the selection, for example `auto • high → gpt-5.6-luna • medium`. `/session` lists the cost for each physical model.
28
+
29
+ Context usage uses the limits of the physical model that produced the latest response, even if that response came before switching to the virtual model. Without such a response, it uses the limits declared on the virtual model, if any. Compaction checks the same limits, and again the limits of the model each request is routed to. If that model's context window is too small for the conversation, Pi compacts before sending the request; the route stays as the router chose it.
30
+
31
+ ## Register a virtual model
32
+
33
+ ```typescript
34
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
35
+
36
+ export default function (pi: ExtensionAPI) {
37
+ pi.registerVirtualModel({
38
+ provider: "router",
39
+ id: "auto",
40
+ name: "Auto",
41
+ thinkingLevels: ["low", "high"],
42
+ route(request, ctx) {
43
+ // Tool follow-ups and retries stay on the model that handled the turn.
44
+ const sticky = request.failed ?? request.previous;
45
+ if (request.reason !== "user" && sticky) {
46
+ return { model: sticky.model, thinkingLevel: sticky.thinkingLevel ?? "medium" };
47
+ }
48
+ const id = request.thinkingLevel === "high" ? "claude-sonnet-4-5" : "claude-haiku-4-5";
49
+ return { model: ctx.modelRegistry.find("anthropic", id)!, thinkingLevel: "medium" };
50
+ },
51
+ });
52
+ }
53
+ ```
54
+
55
+ - `provider` is the provider the model is listed under. It can be any provider ID. A provider can list several virtual models next to its physical ones. On a physical provider, the virtual model is available when that provider has credentials. Under an ID that no provider uses, it is always available.
56
+ - `id` must not be the ID of a physical model of that provider. If a catalog refresh later adds a physical model with the same ID, the virtual model hides it.
57
+ - `thinkingLevels` lists the levels offered for selection. It defaults to `["off"]`.
58
+ - `contextWindow` and `maxTokens` are shown before the first response. Unset limits are unknown.
59
+ - `input` lists the input types offered for selection. It defaults to text and images; physical models without image support receive placeholders.
60
+
61
+ Registration follows the same queuing and reload rules as `pi.registerProvider()`. Registering the same provider and ID again replaces the virtual model. `pi.unregisterVirtualModel(provider, id)` removes it; `pi.unregisterProvider()` does not. SDK code can register one without an extension: `modelRuntime.registerVirtualModel(definition)`.
62
+
63
+ ## Route requests
64
+
65
+ `route(request, ctx)` runs before every request made with the virtual model and returns `{ model, thinkingLevel }`. The model can be any physical model in the catalog whose provider has credentials; look it up with `ctx.modelRegistry`. A virtual model cannot route to another virtual model. Pi clamps the thinking level to the returned model.
66
+
67
+ | Field | Meaning |
68
+ |---|---|
69
+ | `model`, `thinkingLevel` | The selected virtual model and level |
70
+ | `reason` | Why the request is made, see below |
71
+ | `previous` | Physical model and thinking level of the latest successful response in `messages` |
72
+ | `failed` | For `retry`: physical model, thinking level, and assistant `message` of the failed request, which `messages` no longer contains. The message carries `stopReason` and `errorMessage`. Absent when routing itself failed |
73
+ | `state` | Router state last returned on this session branch, see below |
74
+ | `messages` | The conversation for this request, including system messages |
75
+ | `signal` | Abort signal of the request |
76
+
77
+ | `reason` | Request |
78
+ |---|---|
79
+ | `user` | First request after a message the user wrote, including steering and follow-up messages |
80
+ | `continuation` | Any other request in the agent loop, such as after tool results or extension messages |
81
+ | `retry` | Automatic retry after a failed request, including after compaction for a context overflow |
82
+ | `direct` | Request made outside the agent loop, such as a compaction summary or an extension calling `ctx.modelRegistry.streamSimple()` |
83
+
84
+ Returning `previous` for `continuation` and `failed` for `retry` keeps prompt caches and thinking signatures valid. Switching models between turns is allowed but loses the prompt cache. A retry can also switch to another model, for example when `failed.message.errorMessage` reports that a provider is overloaded or the context overflowed.
85
+
86
+ If `route()` throws, or returns a virtual model or a model without credentials, the request ends with an error response.
87
+
88
+ ## Keep routing state
89
+
90
+ `route()` can return `state` next to the model. Pi stores it on the session branch and passes it back as `request.state` on later requests. Use it for decisions the transcript does not record, such as classifier results or a routing phase:
91
+
92
+ ```typescript
93
+ pi.registerVirtualModel<{ phase: "plan" | "build" }>({
94
+ provider: "router",
95
+ id: "phased",
96
+ name: "Phased",
97
+ route(request, ctx) {
98
+ const state = request.state ?? { phase: "plan" };
99
+ const id = state.phase === "plan" ? "claude-opus-4-5" : "claude-haiku-4-5";
100
+ return { model: ctx.modelRegistry.find("anthropic", id)!, thinkingLevel: "medium", state };
101
+ },
102
+ });
103
+ ```
104
+
105
+ - State must be JSON-serializable. Returning `undefined` or `request.state` itself keeps the current state.
106
+ - Pi stores any other returned object as new state, before the request is sent, even when it equals the current state. Return a new object only when the state changes. The state stays stored if the request later fails.
107
+ - State follows the session tree, so forks and `/tree` navigation see the state of their branch. It survives compaction.
108
+ - `direct` requests have no state, and Pi ignores state they return.
109
+
110
+ The transcript already records the selection and every dispatched model, and `ctx.sessionManager.getBranch()` exposes both.
111
+
112
+ Routers can call other models through `ctx.modelRegistry`, for example `ctx.modelRegistry.classify()` with a classifier model from `ctx.modelRegistry.findOfType("classifier", provider, id)`. The call adds latency before the first token of the turn.
113
+
114
+ See [`jev-router.ts`](../examples/extensions/jev-router.ts) for a complete router. It plans on a strong OpenAI Codex model chosen by the Jev classifier, lets that model make the first edit, and then switches once to a cheaper model, accepting a single prompt-cache miss. It keeps the phase as router state.
package/docs/windows.md CHANGED
@@ -42,6 +42,8 @@ To replace the model-facing `bash` tool with `powershell`, add this to `~/.pi/ag
42
42
  }
43
43
  ```
44
44
 
45
+ `["-bash", "+powershell"]` does the same while keeping any other default tools you configured.
46
+
45
47
  Restart Pi, then ask it to run a harmless PowerShell command. The `!` and `!!` editor commands continue to use Bash. The `powershell` tool is available only when Pi runs as a native Windows process.
46
48
 
47
49
  See [Settings](settings.md#tools) for other tool combinations.
@@ -9,7 +9,7 @@ Example code for the pi-coding-agent SDK, process integration, and extensions.
9
9
  Build the coding-agent package before running it from a repository checkout:
10
10
 
11
11
  ```bash
12
- npx tsx examples/rpc-client.ts "Explain this repository"
12
+ node examples/rpc-client.ts "Explain this repository"
13
13
  ```
14
14
 
15
15
  ## Directories
@@ -129,6 +129,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
129
129
  |-----------|-------------|
130
130
  | `custom-provider-anthropic/` | Custom Anthropic provider with OAuth support and custom streaming implementation |
131
131
  | `custom-provider-gitlab-duo/` | GitLab Duo provider using pi-ai's built-in Anthropic/OpenAI streaming via proxy |
132
+ | `jev-router.ts` | Virtual model via `registerVirtualModel` that plans on Codex Sol or Terra (picked by the Jev classifier) and switches to Luna after the first edit |
132
133
 
133
134
  ### External Dependencies
134
135
 
@@ -12,8 +12,8 @@
12
12
  *
13
13
  * How it works:
14
14
  * - registerTool() with the same name as a built-in replaces it entirely
15
- * - We create instances of the original tools via createReadTool(), etc.
16
- * and delegate execute() to them
15
+ * - We create the original definitions via createReadToolDefinition(), etc.
16
+ * and override only their renderers
17
17
  * - renderCall() controls what's shown when the tool is invoked
18
18
  * - renderResult() controls what's shown after execution completes
19
19
  * - renderShell: "self" lets a tool render its own outer shell instead of
@@ -26,23 +26,21 @@
26
26
  */
27
27
 
28
28
  import type { BashToolDetails, EditToolDetails, ExtensionAPI, ReadToolDetails } from "@earendil-works/pi-coding-agent";
29
- import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@earendil-works/pi-coding-agent";
29
+ import {
30
+ createBashToolDefinition,
31
+ createEditToolDefinition,
32
+ createReadToolDefinition,
33
+ createWriteToolDefinition,
34
+ } from "@earendil-works/pi-coding-agent";
30
35
  import { Text } from "@earendil-works/pi-tui";
31
36
 
32
37
  export default function (pi: ExtensionAPI) {
33
38
  const cwd = process.cwd();
34
39
 
35
40
  // --- Read tool: show path and line count ---
36
- const originalRead = createReadTool(cwd);
41
+ const originalRead = createReadToolDefinition(cwd);
37
42
  pi.registerTool({
38
- name: "read",
39
- label: "read",
40
- description: originalRead.description,
41
- parameters: originalRead.parameters,
42
-
43
- async execute(toolCallId, params, signal, onUpdate) {
44
- return originalRead.execute(toolCallId, params, signal, onUpdate);
45
- },
43
+ ...originalRead,
46
44
 
47
45
  renderCall(args, theme, _context) {
48
46
  let text = theme.fg("toolTitle", theme.bold("read "));
@@ -92,16 +90,9 @@ export default function (pi: ExtensionAPI) {
92
90
  });
93
91
 
94
92
  // --- Bash tool: show command and exit code ---
95
- const originalBash = createBashTool(cwd);
93
+ const originalBash = createBashToolDefinition(cwd);
96
94
  pi.registerTool({
97
- name: "bash",
98
- label: "bash",
99
- description: originalBash.description,
100
- parameters: originalBash.parameters,
101
-
102
- async execute(toolCallId, params, signal, onUpdate) {
103
- return originalBash.execute(toolCallId, params, signal, onUpdate);
104
- },
95
+ ...originalBash,
105
96
 
106
97
  renderCall(args, theme, _context) {
107
98
  let text = theme.fg("toolTitle", theme.bold("$ "));
@@ -151,17 +142,9 @@ export default function (pi: ExtensionAPI) {
151
142
  });
152
143
 
153
144
  // --- Edit tool: show path and diff stats ---
154
- const originalEdit = createEditTool(cwd);
145
+ const originalEdit = createEditToolDefinition(cwd);
155
146
  pi.registerTool({
156
- name: "edit",
157
- label: "edit",
158
- description: originalEdit.description,
159
- parameters: originalEdit.parameters,
160
- renderShell: "self",
161
-
162
- async execute(toolCallId, params, signal, onUpdate) {
163
- return originalEdit.execute(toolCallId, params, signal, onUpdate);
164
- },
147
+ ...originalEdit,
165
148
 
166
149
  renderCall(args, theme, _context) {
167
150
  let text = theme.fg("toolTitle", theme.bold("edit "));
@@ -216,16 +199,9 @@ export default function (pi: ExtensionAPI) {
216
199
  });
217
200
 
218
201
  // --- Write tool: show path and size ---
219
- const originalWrite = createWriteTool(cwd);
202
+ const originalWrite = createWriteToolDefinition(cwd);
220
203
  pi.registerTool({
221
- name: "write",
222
- label: "write",
223
- description: originalWrite.description,
224
- parameters: originalWrite.parameters,
225
-
226
- async execute(toolCallId, params, signal, onUpdate) {
227
- return originalWrite.execute(toolCallId, params, signal, onUpdate);
228
- },
204
+ ...originalWrite,
229
205
 
230
206
  renderCall(args, theme, _context) {
231
207
  let text = theme.fg("toolTitle", theme.bold("write "));
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.87.1",
3
+ "version": "1.0.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.87.1",
9
+ "version": "1.0.2",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.87.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "0.87.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Test script for GitLab Duo extension
3
- * Run: npx tsx test.ts [model-id] [--thinking]
3
+ * Run: node test.ts [model-id] [--thinking]
4
4
  *
5
5
  * Examples:
6
- * npx tsx test.ts # Test default (claude-sonnet-4-5-20250929)
7
- * npx tsx test.ts gpt-5-codex # Test GPT-5 Codex
8
- * npx tsx test.ts claude-sonnet-4-5-20250929 --thinking
6
+ * node test.ts # Test default (claude-sonnet-4-5-20250929)
7
+ * node test.ts gpt-5-codex # Test GPT-5 Codex
8
+ * node test.ts claude-sonnet-4-5-20250929 --thinking
9
9
  */
10
10
 
11
11
  import { type Api, type Context, type Model, registerApiProvider, streamSimple } from "@earendil-works/pi-ai/compat";
12
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
12
13
  import { readFileSync } from "fs";
13
- import { getAgentDir } from "packages/coding-agent/src/config.js";
14
14
  import { join } from "path";
15
15
  import { MODELS, streamGitLabDuo } from "./index.ts";
16
16
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
- "version": "0.87.1",
3
+ "version": "1.0.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-gondolin",
9
- "version": "0.87.1",
9
+ "version": "1.0.2",
10
10
  "dependencies": {
11
11
  "@earendil-works/gondolin": "0.12.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
3
  "private": true,
4
- "version": "0.87.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Jev router - a virtual model that plans on a strong model and implements on a cheap one.
3
+ *
4
+ * Registers `jev/auto`, which routes between three OpenAI Codex models:
5
+ *
6
+ * - Planning: GPT-5.6 Sol for complex work, GPT-5.6 Terra otherwise. The Jev classifier rates the
7
+ * first user message; planning stays on the chosen model.
8
+ * - Implementation: GPT-5.6 Luna.
9
+ *
10
+ * The planning model explores, plans, and makes the first edit. After the first successful `edit`
11
+ * or `write` tool call, the next request of the same turn goes to Luna, and the session stays
12
+ * there. A session therefore switches models once and accepts a single prompt-cache miss.
13
+ *
14
+ * The phase is router state: Pi stores it on the session branch, so it follows the session tree
15
+ * and survives compaction. The selected thinking level passes through as the reasoning effort of
16
+ * the chosen model. Requests outside the agent loop, such as compaction summaries, go to Luna.
17
+ *
18
+ * Requires TypeSafe credentials (TYPESAFE_API_KEY) and an OpenAI Codex login.
19
+ * Usage: pi -e ./jev-router.ts --model jev/auto
20
+ */
21
+
22
+ import type { Message } from "@earendil-works/pi-ai";
23
+ import type { ExtensionAPI, ExtensionContext, ModelRoute, ModelRouteRequest } from "@earendil-works/pi-coding-agent";
24
+
25
+ const PROVIDER = "openai-codex";
26
+ const SOL = "gpt-5.6-sol";
27
+ const TERRA = "gpt-5.6-terra";
28
+ const LUNA = "gpt-5.6-luna";
29
+
30
+ /** Tools whose successful result means implementation has started. */
31
+ const EDIT_TOOLS = new Set(["edit", "write"]);
32
+
33
+ interface JevState {
34
+ phase: "planning" | "implementation";
35
+ /** OpenAI Codex model for this phase. */
36
+ model: string;
37
+ }
38
+
39
+ type JevRequest = ModelRouteRequest<JevState>;
40
+
41
+ function routeTo(request: JevRequest, ctx: ExtensionContext, id: string, state?: JevState): ModelRoute<JevState> {
42
+ const model = ctx.modelRegistry.find(PROVIDER, id);
43
+ if (!model) throw new Error(`Model ${PROVIDER}/${id} is not in the catalog`);
44
+ return { model, thinkingLevel: request.thinkingLevel, state };
45
+ }
46
+
47
+ function lastUserText(messages: readonly Message[]): string {
48
+ const content = messages.filter((message) => message.role === "user").at(-1)?.content ?? "";
49
+ if (typeof content === "string") return content;
50
+ return content.flatMap((block) => (block.type === "text" ? [block.text] : [])).join("\n");
51
+ }
52
+
53
+ /** Whether a tool call since the last user message edited a file successfully. */
54
+ function editedThisTurn(messages: readonly Message[]): boolean {
55
+ const lastUser = messages.findLastIndex((message) => message.role === "user");
56
+ return messages
57
+ .slice(lastUser + 1)
58
+ .some((message) => message.role === "toolResult" && EDIT_TOOLS.has(message.toolName) && !message.isError);
59
+ }
60
+
61
+ /** Planning model for a new session: Sol for complex work, Terra otherwise or when Jev is unavailable. */
62
+ async function choosePlanningModel(request: JevRequest, ctx: ExtensionContext): Promise<string> {
63
+ // Keep a planning model the session already uses, so switching to jev/auto costs no cache miss.
64
+ const previous = request.previous?.model;
65
+ if (previous?.provider === PROVIDER && (previous.id === SOL || previous.id === TERRA)) return previous.id;
66
+
67
+ const jev = ctx.modelRegistry.findOfType("classifier", "typesafe", "jev-latest");
68
+ if (!jev) return TERRA;
69
+ const result = await ctx.modelRegistry.classify(
70
+ jev,
71
+ {
72
+ state: { prompt: lastUserText(request.messages).slice(0, 16_000) },
73
+ questions: {
74
+ complexity: {
75
+ type: "choice",
76
+ instructions: "How demanding is the software engineering work requested in `prompt`?",
77
+ criteria: {
78
+ standard: "Ordinary features, fixes, reviews, or questions",
79
+ complex: "Subtle design, cross-cutting changes, or hard debugging",
80
+ },
81
+ },
82
+ },
83
+ },
84
+ { signal: request.signal },
85
+ );
86
+ const answer = result.stopReason === "stop" ? result.answers.complexity : undefined;
87
+ return answer?.type === "choice" && (answer.probabilities.complex ?? 0) >= 0.5 ? SOL : TERRA;
88
+ }
89
+
90
+ export default function (pi: ExtensionAPI) {
91
+ pi.registerVirtualModel<JevState>({
92
+ provider: "jev",
93
+ id: "auto",
94
+ name: "Auto (Jev)",
95
+ thinkingLevels: ["low", "medium", "high", "xhigh"],
96
+ // Shared by all three models; shown before the first response.
97
+ contextWindow: 272_000,
98
+ maxTokens: 128_000,
99
+ async route(request, ctx) {
100
+ if (request.reason === "direct") return routeTo(request, ctx, LUNA);
101
+ const state = request.state;
102
+ if (!state) {
103
+ const model = await choosePlanningModel(request, ctx);
104
+ return routeTo(request, ctx, model, { phase: "planning", model });
105
+ }
106
+ // The planning model made the first edit: hand the rest of the work to Luna.
107
+ if (state.phase === "planning" && editedThisTurn(request.messages)) {
108
+ return routeTo(request, ctx, LUNA, { phase: "implementation", model: LUNA });
109
+ }
110
+ return routeTo(request, ctx, state.model);
111
+ },
112
+ });
113
+ }