@bismawy/pi-arnative 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/README.md +12 -4
- package/extensions/animations.ts +1 -1
- package/extensions/arnative.ts +21 -10
- package/extensions/model-heal.ts +32 -5
- package/extensions/todos.ts +43 -15
- package/extensions/tools.ts +128 -11
- package/extensions/ui-render-tweaks.ts +5 -5
- package/extensions/usage.ts +309 -19
- package/lib/ansi.ts +22 -12
- package/lib/box.ts +1 -1
- package/lib/compat.ts +13 -64
- package/lib/list-picker.ts +117 -22
- package/lib/model-heal.ts +63 -9
- package/lib/provider.ts +407 -109
- package/lib/shortcuts.ts +36 -20
- package/lib/status-widget.ts +14 -0
- package/lib/usage-store.ts +227 -24
- package/package.json +2 -1
- package/themes/arnative-blossom.json +89 -0
- package/themes/arnative-crimson.json +89 -0
- package/themes/arnative-cyberpunk.json +28 -28
- package/themes/arnative-dracula.json +40 -39
- package/themes/arnative-earthy.json +89 -0
- package/themes/arnative-garden.json +89 -0
- package/themes/arnative-gruvbox.json +40 -39
- package/themes/arnative-lemonade.json +89 -0
- package/themes/{arnative-synthwave.json → arnative-magical.json} +32 -31
- package/themes/arnative-matrix.json +37 -36
- package/themes/arnative-neutral.json +89 -0
- package/themes/arnative-nord.json +43 -42
- package/themes/arnative-zinc.json +43 -42
- package/themes/arnative.json +32 -31
- package/themes/gen-themes.mjs +376 -129
- package/themes/arnative-emerald.json +0 -88
- package/themes/arnative-sun.json +0 -88
- package/themes/arnative-violet.json +0 -88
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,90 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.10.0] - 2026-11-08
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Shortcut to open settings:** Press `Alt+a` (Windows/WSL) or `Ctrl+Alt+a` (macOS/Linux) to immediately open the `/arnative` settings menu (`lib/shortcuts.ts`, `extensions/arnative.ts`).
|
|
9
|
+
- **Five new themes:** Added `arnative-magical` (lavender & rose pink), `arnative-lemonade` (sage, peach & lime), `arnative-blossom` (rose & petal pink), `arnative-garden` (earth gold, olive moss & terracotta), and `arnative-earthy` (warm tan, sage moss & clay brown) (`themes/gen-themes.mjs`, `themes/*.json`).
|
|
10
|
+
- **Harmonized chat & system boxes:** User chat bubbles (`userMessageBg`) and system notification boxes like `[compaction]` (`customMessageBg` / `customMessageLabel`) now derive directly from each theme's `primary` hue for consistent theme accenting across Cyberpunk, Crimson, Matrix, Gruvbox, Neutral, Nord, Zinc, Dracula, and new themes. User chat backgrounds are deepened to a stealth dark tier (L: 19%) across all themes for softer reading contrast.
|
|
11
|
+
- **Custom theme auto-sync in dev loop:** `npm run overlay` now mirrors updated theme JSON files directly into `~/.pi/agent/themes/` (`scripts/overlay.mjs`).
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- **Four palettes: `arnative-zinc`, `arnative-nord`, `arnative-dracula`, `arnative-gruvbox`.** Zinc follows the sage-and-steel palette (`#e0e2db`, `#d2d4c8`, `#b8bdb5`, `#889696`, `#5f7470`): deep teal is the focus, soft linen the headings, cool steel the links and code, dust grey the footer labels. Nord, Dracula and Gruvbox follow their published palettes: polar-night canvas with frost-blue focus and aurora-purple labels, night canvas with purple focus, pink headings and model name, and orange labels, warm canvas with orange focus and aqua labels. Each palette declares a second hue at least 25° from its accent, so no screen reads as one colour, and the generator now rejects two themes that share an accent or footer colour (`themes/gen-themes.mjs`, `assertDistinctThemes`; `themes/*.json`). The README theme list names the real files again (`README.md`).
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- **Providers: a pinned thinking level no longer locks the model to that one level.** The wizard stored a level by mapping it to itself and every other level to `null`. pi reads `null` as unsupported, so `/thinking`, the thinking cycle key and turning thinking off all stayed on the pinned level (most visibly `xhigh`). A pinned level is now a ceiling: every effort up to it maps to itself, the levels above it are `null`, and `off` stays available. Model heal rewrites the old single-pin map in models.json to the ceiling shape, so an affected model recovers after `/reload` without deleting the provider (`lib/provider.ts` `levelToWire` and `wireToLevel`, `lib/model-heal.ts`, `test/thinking-levels.test.ts`).
|
|
18
|
+
- **Providers: a probed model offers only the thinking levels its channel really runs.** The `p` probe and model heal mapped a rejected effort to the nearest accepted one, so DeepSeek V4.1 Flash on River listed `medium` in `/thinking`, sent `high` for it, and a chosen `medium` never reached the wire as itself. The probe now writes an exact map: each accepted effort maps to itself and each rejected one is `null`, so pi lists only what the endpoint accepts (low, high and max on River) and never sends a level it drops; `off` stays pi's call. A probe replaces a pinned level instead of remapping around it. Model heal re-probes a map an older probe wrote rather than taking its remaps for the user's, while a map shaped by hand stays untouched. `wireToLevel` reads a map with gaps as a probed map, not a `max` ceiling, and `loadProviderEntry` keeps the stored map of an `auto` model, so a later save in the wizard no longer wipes what the probe learned. After a level is saved, the session's active model is reloaded through a registry refresh, so the new levels apply without a restart (`lib/compat.ts` `buildEffortMap`, `lib/model-heal.ts` `healEffort`, `lib/provider.ts`, `extensions/arnative.ts`, `extensions/model-heal.ts`).
|
|
19
|
+
- Model heal: a thinking level the relay rejects is removed from that model. When a turn fails with an error that names the reasoning effort, model heal sets that one level to null in the model's thinkingLevelMap, reloads the model and moves the session to the nearest level pi still offers, so the next request goes through and /thinking stops listing the level. The other levels stay, and off is never removed. A plain 400 that does not name the effort (context too long, a bad tool schema) leaves the map alone and only re-probes. The map stays probe-owned, so a later rejection can drop another level (lib/model-heal.ts markRejectedLevel, extensions/model-heal.ts isEffortRejection).
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- **Providers → Thinking states what each model accepts, not a level to use.** The screen cycled every model through off, auto and seven pinned levels, and a pin threw away the probed map, so a model pinned at high still listed `minimal` and `medium` that its relay rejects. Space now switches a model between off and auto, p probes the levels it accepts, and keys 1 to 6 toggle minimal, low, medium, high, xhigh and max by hand for a relay that answers a probe but ignores the effort. Each row shows the levels `/thinking` will list. The level to use is picked per session in `/thinking`. A pin from an older version, or an id suffix such as `-high`, opens as the level list it allowed, and the bulk keys no longer clear a probed map. Headless input takes `id:off`, `id:auto` or `id:low+high+max` (`lib/provider.ts` `thinkingFlow`, `offeredLevels`; `test/thinking-levels.test.ts`).
|
|
23
|
+
- Providers → Thinking: key 0 turns on all six levels for the model under the cursor, and a filter line under the description (dim "type to filter models…", as in pi-vision-watcher) narrows the models by name with a fuzzy match (the letters in order, spaces ignored, so river flash finds river/deepseek-ai/DeepSeek-V4.1-Flash-1017). / turns typing on and off: while it is on every key is text, and / or Enter turns it off and keeps the filter, so Space, 0 to 6, p (probe), a (all auto) and r (all off) act on the matching models. Esc clears the filter before it closes the screen. The footer reads [/] Filter [Space] Off/auto [0-6] Levels [p] Probe [a/r] All auto/off [Enter] Save [Esc] Back (lib/provider.ts thinkingFlow, lib/list-picker.ts search hook).
|
|
24
|
+
- The Models and Probe models screens in /providers take the same filter. A relay catalog runs to dozens of ids, so `/` now turns on a filter line that narrows the list by name (fuzzy, spaces ignored); while typing every key is text, and `/` or Enter keeps the narrowed list so Space still checks rows. The picked count stays whole (`3/75 picked`) because the filter hides rows, it does not unpick them (`lib/provider.ts` `pickModels`, `lib/list-picker.ts` search hook).
|
|
25
|
+
- Usage: the window bar is framed by two rules, and every rule on the dashboard takes the disabled tier (`borderMuted`) instead of `dim`, so the chrome recedes behind the numbers. The table rule above Total keeps its table width and only changes colour.
|
|
26
|
+
- **Reset the Usage history without losing it.** `R` in the dashboard asks first, on the footer row, and states what it is about to move: `Delete 326 sessions (283 MB)? moves to the trash [y] Yes [Esc] Cancel`. Confirming moves Pi's session files into `arnative/usage-trash/<stamp>/` with their folder structure, so the numbers start from the current session and `/resume` forgets the old ones until `U` puts them back. The session pi is writing to is never touched. A pending question owns every key, so a stray arrow answers no. (`lib/usage-store.ts` `resetUsageHistory`/`restoreUsageHistory`/`usageHistorySize`; `extensions/usage.ts` `runConfirm`; `lib/shortcuts.ts` `RESET_USAGE`/`UNDO_USAGE`.)
|
|
27
|
+
- **Usage counts cache reads in the Tokens column.** The headline only summed prompt input and completion output, so the same week that Magpie's own dashboard reports as 253M read as 7.6M here and the 233M cached tokens were visible only after selecting a row. Tokens now sums all three, which is what a vendor dashboard reports (242M for the same week, the rest being requests Magpie counts that pi never saw finish), and the detail line still splits `↑in · ↓out · cache` (`lib/usage-store.ts` `totalTokens`; pinned in `extensions/usage.ts`).
|
|
28
|
+
- A folded box is short again, whatever the payload. A single-line JSON reply (a fetch of one page) counted as one row, so it got no `[show]` and its summary wrapped into a full screen. Rows are now measured as they are painted, and the summary is clipped to one row (`extensions/tools.ts` `drawnRows`, `oneRow`).
|
|
29
|
+
- **Every theme is two-toned, and six now carry three hues.** The footer, the selected row in Models/Providers and every detail line draw on the label tier, which is `borderAccent`. Six themes pointed that token back at `accentBorder`, so its hue was the accent's own and the whole UI read as one colour no matter what `primary` and `secondary` declared. Arnative now pairs cyan with violet, emerald with gold, sun with indigo, violet with cyan, matrix with ice-cyan and zinc with faint sky, with headings and links taking a third tone where the palette has room. `themes/gen-themes.mjs` gained `assertDualTone`: a theme whose label tier sits closer than 25° to the accent, carries under 0.02 chroma, or falls below 3:1 contrast on the page background is refused at generation time.
|
|
30
|
+
- **Two themes join the family from Coolors palettes.** Ocean pairs a periwinkle-steel focus with foggy-teal labels (Coolors "Midnight Navy": 0d1b2a-778da9), and Fiesta is a warm coral focus with amber headings and navy labels (Coolors "Fiesta": f95738-f4d35e-0d3b66). Both pass the same dual-tone guard as the rest, and the picker lists them simply because they ship with the package; no extension code changed (`themes/gen-themes.mjs`).
|
|
31
|
+
- **Two pink-red themes from coolors trending palettes.** Blossom pairs a hot-fuchsia focus with royal-blue labels and purple headings (trending magenta ramp: f72585-7209b7-4361ee), and Crimson is a vivid-red focus with navy labels and cream headings (trending red: c1121f-fdf0d5-003049). Both pass the dual-tone guard; no extension code changed (`themes/gen-themes.mjs`).
|
|
32
|
+
- Blossom and Crimson now draw the footer model name in their accent tone (pink and red), so the right side of the status bar carries the theme's focus color; headings keep their own hue on a literal instead of aliasing the model tone.
|
|
33
|
+
- Correction: the footer paints the model name with the `mdHeading` token, not `vars.primary` directly (extensions/footer.ts `colorOr("mdHeading", acc)`), so the earlier Blossom/Crimson fix missed the carrier. `mdHeading` now references the pink/red `primary` var, so the model name (and headings) visibly carry the accent tone.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
- **Arnative is rebuilt on the teal-and-amber palette the user picked** (#16697a #489fb5 #82c0cc #ede7e3 #ffa62b): the focus moves from cyan/violet to the teal family, the label tier becomes amber, headings become warm white, links and inline code take the pale teal, and message panels gain a deep-teal tint. The generator stays the single source of truth and the dual-tone guard still passes (`themes/gen-themes.mjs`).
|
|
37
|
+
- **Arnative is rebuilt on a cyan-and-gold palette, all roles referencing vars.** Strong-cyan accent (#02cecb), bright-gold primary (#fed811), school-bus-yellow secondary (#fdc100), a new icy-aqua `tone` var (#b4ffff) for links/code, and a deep-teal message panel (#06837f, deepened to keep contrast floors; the decorative `mdHr` is now exempt from the text floor). `mdHeading`/`mdLink`/`mdCode` reference `primary`/`tone` instead of literals, matching the sun pattern. The generator gained an optional per-theme `tone` var (themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
38
|
+
- Arnative's footer label tier now follows the accent (`borderAccent: accentBorder`, so `secondarySoft` resolves to soft cyan), and markdown links join headings on `primary` (bright gold); inline code keeps the icy-aqua `tone`. The dual-tone guard allows a zero hue gap for arnative because the gold signature lives on headings/links (`themes/gen-themes.mjs`).
|
|
39
|
+
- The footer label tier (`secondarySoft`) is softened with a stronger chroma scale (0.35 vs 0.18), so arnative's cyan labels read as a tinted second tone instead of grey; the runtime self-check mirrors the same scale (themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
40
|
+
- Saturation of the label tier raised again: chroma scale 0.35 → 0.6 (aritynative secondarySoft ≈ 0.047 chroma), so footer labels read as a vivid cyan tint (themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
41
|
+
- Root cause fixed: the runtime label painter (`softSecondaryOf`) had its own fixed 0.18 chroma scale, so the earlier generator-only scale bumps never reached the screen. The scale is now a single shared constant — 0.5 — in lib/ansi.ts, gen-themes.mjs and the self-checks, so footer labels (and all soft tiers) render at the declared saturation (themes/gen-themes.mjs, lib/ansi.ts, extensions/ui-render-tweaks.ts, test/footer-minimal.test.ts).
|
|
42
|
+
- The theme family is trimmed to two: `arnative` and `arnative-cyberpunk`; the other thirteen variants are removed. Cyberpunk is rebuilt in arnative's var-based format — labels follow the accent (`borderAccent: accentBorder`), headings and links take `primary`, code takes a new electric-purple `tone` var, bullets take the accent — while keeping its own neon pink/lime/cyan palette (themes/gen-themes.mjs, extensions/arnative.ts, test/todo-box.test.ts).
|
|
43
|
+
- Cyberpunk swaps its purple tone for orange: code/links now take `vars.tone` (orange, `oklch(82% 0.18 45)`) and the footer model name/headings take a new `vars.headingTone` (purple, `oklch(78% 0.20 300)`) — both var-backed, no role literals (themes/gen-themes.mjs).
|
|
44
|
+
- Cyberpunk links now join headings on `vars.headingTone` (purple); code keeps the orange `vars.tone`, and labels stay pink-soft (themes/gen-themes.mjs).
|
|
45
|
+
- Cyberpunk chat background drops its literal override: `vars.surfaceMsg` now falls back to the generator-default neutral (deep purple tint `oklch(24% 0.01 275)`), so the panel stays in the theme without hand-picked colors (themes/gen-themes.mjs).
|
|
46
|
+
- Cyberpunk chat panel now reuses the `headingTone` var: the generator darkens a named var to the canvas level (L=base, chroma×0.35 capped at 0.06, same hue), so `surfaceMsg` = `oklch(24% 0.06 300)` — a visible deep purple instead of near-black (themes/gen-themes.mjs).
|
|
47
|
+
- The accent soft tier is tuned down: `accentSoft` chroma scale 0.5 → 0.35 (runtime `SOFT_CHROMA_SCALE_ACCENT`, generator and self-check mirror), so soft accents read quieter while footer labels (`secondarySoft`) keep 0.5 (lib/ansi.ts, themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
48
|
+
- `accentSoft` is now lighter and paler: lightness 0.82 → 0.86 and chroma scale 0.35 → 0.25 (`SOFT_L_ACCENT`/`SOFT_CHROMA_SCALE_ACCENT`), so it reads as a pale tint, clearly distinct from the accent; footer labels keep 0.5 at 0.82 (lib/ansi.ts, themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
49
|
+
- `accentSoft` now approaches white: lightness 0.86 → 0.94, chroma scale 0.25 → 0.15, so it reads as a near-white tint (lib/ansi.ts, themes/gen-themes.mjs, extensions/ui-render-tweaks.ts).
|
|
50
|
+
- All soft tiers (`secondarySoft` and `accentSoft`) now sit at lightness 0.94 and chroma scale 0.15, so footer labels and soft text render near-white with only a delicate hue whisper across both themes (themes/gen-themes.mjs, lib/ansi.ts, extensions/ui-render-tweaks.ts, test/footer-minimal.test.ts).
|
|
51
|
+
- `borderAccent` in both themes now points directly to `accentSoft` (L 0.90, chroma scale 0.25): footer labels and status lines take the soft accent tint directly, rendering as bright, readable pastel tints of the accent hue (pink in cyberpunk, cyan in arnative) without intermediate layers (themes/gen-themes.mjs, lib/ansi.ts, extensions/ui-render-tweaks.ts, test/footer-minimal.test.ts).
|
|
52
|
+
- Increased the saturation of footer labels slightly: `accentSoft` chroma scale 0.25 → 0.35 at L 0.90, so the pastel accent tint (pink, cyan, green, red, blush) reads more visibly while remaining light and high-contrast (themes/gen-themes.mjs, lib/ansi.ts, extensions/ui-render-tweaks.ts, test/footer-minimal.test.ts).
|
|
53
|
+
|
|
54
|
+
- Added `arnative-neutral` based on the user's palette: powder-blush warm accent (`#e0afa0`), parchment cream headings & model name (`#f4f3ee`), warm silver links/code (`#bcb8b1`, tone), grey-olive secondary (`#8a817c`), and deep taupe panels (`#463f3a`). Footer labels take soft blush-white pastel via `accentSoft` (themes/gen-themes.mjs, themes/arnative-neutral.json).
|
|
55
|
+
|
|
56
|
+
- Added `arnative-matrix` based on the user's palette: medium-jungle green accent (`#09a129`), phosphor spring-green headings & model name (`#27fb6b`), phosphor mint links/code (`#60ddc0`, tone), and jet-black teal panels (`#0a2e36`). Footer labels take soft matrix pastel green via `accentSoft` (themes/gen-themes.mjs, themes/arnative-matrix.json).
|
|
57
|
+
|
|
58
|
+
- Added `arnative-crimson` based on the user's palette: brick-red accent (`#c1121f`), molten-lava secondary (`#780000`), warm papaya-whip cream headings (`#fdf0d5`), steel-blue links/code (`#669bbc`), and deep-space-blue panels (`#003049`). Footer labels take soft brick-red pastel via `accentSoft` (themes/gen-themes.mjs, themes/arnative-crimson.json).
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
- **Every tool box can be folded again.** A box whose rows came from another extension (pi-web-access' `search`, `fetch`, `get_content`) was drawn from their template alone, so it had no title row: no `✓ name`, no runtime, and no `[show]`/`[hide]`, which left `ctrl+o` as the only way in. Those boxes now draw the title row like the rest, and the label appears only when their renderer really answers `expanded` (`extensions/tools.ts` `rightAlign`, `theirsAt`).
|
|
80
|
+
- **Usage gains a window bar and a five-row viewport.** The dashboard only ever showed one number: everything this machine has ever spent. It now opens on `All · Today · 7 day · 30 day · 3 month`, with the active window accented on its own line above the table, and the numbers below follow it. `[Tab]` walks the bar, `[Shift+Tab]` walks it back, and a click on a tab picks it. Day buckets are stored beside the all-time totals, so a window costs a sum instead of a rescan; a cache written before buckets existed is re-parsed once, and only when a window is actually asked for. The table shows five rows at a time with `↓ 2 more` / `↑ 6 more` above and below, and `5/14` on the bar states how many rows there are. Switching the window resets the cursor to the first row, because a provider that carried three months can be absent from today (`extensions/usage.ts`, `lib/usage-store.ts` `UsageRange`/`dayKey`/`rangeStart`; `lib/shortcuts.ts` `[Tab] Range`).
|
|
81
|
+
- **`[Esc]` steps out one level, on every screen.** Esc used to close `/arnative` from any depth, so leaving a Themes preview cost the whole menu, and only `←` went back. Esc now means Back wherever a parent screen exists: Themes, Headers, Footers, Animations, Model heal, Providers, the provider actions, the usage dashboard and the input fields all return to the screen that opened them, and a live preview is dropped on the way out. At the root menu Esc still closes. `←` keeps working as an alias but no footer advertises it, so each footer names one exit instead of two: `[↑↓] Preview [Enter] Select [Esc] Back`. A filter field spends its first Esc on ending typing, so the same key never leaves a screen the operator was still editing (`lib/list-picker.ts` `leave`, `lib/shortcuts.ts` legends, `extensions/usage.ts`).
|
|
82
|
+
- Model heal: its status row leads with its own mark, U+F06DE, in place of the shared one, and counts in plain words (1 change, 3 changes) instead of change(s). Any widget row that opens with a Nerd Font glyph keeps that glyph as its mark (lib/status-widget.ts, extensions/model-heal.ts).
|
|
83
|
+
|
|
84
|
+
## [0.9.1] - 2026-11-02
|
|
85
|
+
|
|
86
|
+
### Added
|
|
87
|
+
- **Providers → Edit changes the endpoint, the id or the key, one field per row.** Opening a provider now leads with `Edit`, and its menu shows what is stored beside each row: the base URL, the provider id, the key masked to its last four characters. A base URL is saved as typed (only a bare host gains its `http://`), so an edit lands what the user wrote instead of re-deriving `/v1` the way the add flow does, and the notify points at `Probe models` for the list that may have moved with it. A rename moves the models.json key and the auth.json credential together — the provider keeps its place in the list, a `name` that only repeated the old id follows it, the id is checked against the same `[A-Za-z0-9_-]` rule as create, and an id already taken is refused; if models.json cannot be written the credential is put back, so a failed rename never orphans the key. A new key lands in auth.json, the store pi reads before an inline `models.json` key, and the literal inline copy is dropped so the secret lives in one place, while an env-var or shell reference (`$VAR`, `!cmd`) is configuration and stays untouched; an emptied field keeps what is stored rather than blanking an endpoint or a credential. The three write paths share one row picker and one field patch with the action menu, which also gained the `Edit` row (`lib/provider.ts`, `withProviderFields`, `renameProvider`, `renameAuth`, `saveProviderKey`, `inlineKey`, `keyHint`; pinned in the module self-check).
|
|
88
|
+
|
|
5
89
|
## [0.9.0] - 2026-10-31
|
|
6
90
|
|
|
7
91
|
### Added
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Refined aesthetics. Cohesive tools. Built for Pi.
|
|
|
12
12
|
|
|
13
13
|
pi-arnative replaces pi’s default terminal chrome with a unified visual interface.
|
|
14
14
|
|
|
15
|
-
- Warm Themes: Contrast-checked OKLCH color palettes generated without drift (`arnative` plus
|
|
15
|
+
- Warm Themes: Contrast-checked OKLCH color palettes generated without drift (`arnative` plus eight variants).
|
|
16
16
|
- Tabbed Header: Compact box menu showing Directory, Model, Context, Skills, Extensions, and Shortcuts.
|
|
17
17
|
- Rounded Tool Boxes: Status, spinner, runtime duration, and clickable `[show]` / `[hide]` output toggles.
|
|
18
18
|
- Task List: `todo` tool, `/todos` view, and a boxed widget above the editor that auto-hides 30s after all tasks finish.
|
|
@@ -20,7 +20,7 @@ pi-arnative replaces pi’s default terminal chrome with a unified visual interf
|
|
|
20
20
|
- Working Spinners: 18 animated presets with live picker preview and optional `[g]` gradient sweep.
|
|
21
21
|
- Transcript Clock: Per-message timestamps with clean bubble backgrounds.
|
|
22
22
|
- Usage Dashboard: Real-time token counts and cost tracking across local sessions via `/usage`.
|
|
23
|
-
- Custom Providers: Interactive `/providers` wizard to probe endpoints, pick models, set thinking levels, and save OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`.
|
|
23
|
+
- Custom Providers: Interactive `/providers` wizard to probe endpoints, pick models, set thinking levels, edit the base URL, provider id or API key, and save OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`.
|
|
24
24
|
- Model Heal: Background sync (`/model-heal`) that fills missing compat flags, `/models` token limits, and accepted reasoning effort levels in `models.json`.
|
|
25
25
|
- Auto-compact: Automatic context compaction after a turn settles using smart window tiers or a fixed token budget.
|
|
26
26
|
|
|
@@ -47,9 +47,17 @@ Requires a [Nerd Font](https://www.nerdfonts.com/font-downloads). On a fresh ins
|
|
|
47
47
|
|
|
48
48
|
Local development:
|
|
49
49
|
```bash
|
|
50
|
-
npm run dev
|
|
50
|
+
npm run dev # run pi against this checkout, nothing installed
|
|
51
|
+
npm run overlay # copy extensions/ lib/ themes/ into the installed npm package
|
|
51
52
|
```
|
|
52
53
|
|
|
54
|
+
To see a change before publishing it: `npm run overlay`, then press `/reload` in pi — pi
|
|
55
|
+
re-evaluates extension TypeScript in the same process, so the reload loads the copied code with no
|
|
56
|
+
reinstall and no restart. The package stays an npm install; nothing points pi at this directory. A
|
|
57
|
+
module deleted here is pruned from the installed copy (a stale entry point would keep loading), and
|
|
58
|
+
`pi update --extensions` restores the published code once a higher version exists.
|
|
59
|
+
`npm run overlay -- --dry-run` lists what would move; `PI_CODING_AGENT_DIR` targets another agent dir.
|
|
60
|
+
|
|
53
61
|
## Shortcuts
|
|
54
62
|
|
|
55
63
|
| Key (Linux / Win) | Action |
|
|
@@ -114,7 +122,7 @@ Bind `app.session.new` in `~/.pi/agent/keybindings.json`:
|
|
|
114
122
|
<details>
|
|
115
123
|
<summary><b>Theme Variants & Development</b></summary>
|
|
116
124
|
|
|
117
|
-
**Themes (`themes/gen-themes.mjs` + `lib/color.ts`):** `arnative` · `
|
|
125
|
+
**Themes (`themes/gen-themes.mjs` + `lib/color.ts`):** `arnative` · `arnative-cyberpunk` · `arnative-crimson` · `arnative-matrix` · `arnative-neutral` · `arnative-zinc` · `arnative-nord` · `arnative-dracula` · `arnative-gruvbox`
|
|
118
126
|
|
|
119
127
|
```bash
|
|
120
128
|
npm test # Run self-checks and unit tests
|
package/extensions/animations.ts
CHANGED
|
@@ -127,7 +127,7 @@ export function animationsPickerText(): { title: string; description: string; le
|
|
|
127
127
|
return {
|
|
128
128
|
title: "Animations - Arnative\u2819",
|
|
129
129
|
description: "The working spinner — applies on the next tool call.",
|
|
130
|
-
legend: `[↑↓] Preview [g] Gradient ${activeSpinnerGradient() ? "on" : "off"} [Enter] Select [Esc]
|
|
130
|
+
legend: `[↑↓] Preview [g] Gradient ${activeSpinnerGradient() ? "on" : "off"} [Enter] Select [Esc] Back`,
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
|
package/extensions/arnative.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Screens share one chrome and one title shape ({@link renderScreen}); a box border takes
|
|
6
6
|
* the session's thinking slot (`lib/ansi.ts`), so it belongs to the active model.
|
|
7
7
|
*/
|
|
8
|
+
import { bindSetModel } from "../lib/provider.ts";
|
|
8
9
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
9
10
|
import { visibleWidth, type AutocompleteItem } from "@earendil-works/pi-tui";
|
|
10
11
|
import { stripAnsi } from "../lib/ansi.ts";
|
|
@@ -37,6 +38,7 @@ import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type
|
|
|
37
38
|
import { LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../lib/list-picker.ts";
|
|
38
39
|
import { openProviders } from "../lib/provider.ts";
|
|
39
40
|
import { openUsage } from "./usage.ts";
|
|
41
|
+
import { SHORTCUT_OPEN_ARNATIVE } from "../lib/shortcuts.ts";
|
|
40
42
|
|
|
41
43
|
export interface ArnativeMenu {
|
|
42
44
|
value: string;
|
|
@@ -560,7 +562,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
560
562
|
if (!shouldApplyDefaultTheme(pi.getSettings()?.theme, ctx.ui.getAllThemes())) return;
|
|
561
563
|
ctx.ui.setTheme(DEFAULT_THEME);
|
|
562
564
|
});
|
|
565
|
+
bindSetModel((model) => pi.setModel(model as never));
|
|
563
566
|
registerCommands(pi);
|
|
567
|
+
for (const key of SHORTCUT_OPEN_ARNATIVE.keys) {
|
|
568
|
+
pi.registerShortcut(key, {
|
|
569
|
+
description: "Open Arnative settings menu",
|
|
570
|
+
handler: (ctx) => arnativeHandler("", ctx as never),
|
|
571
|
+
});
|
|
572
|
+
}
|
|
564
573
|
}
|
|
565
574
|
|
|
566
575
|
// Self-check: `node extensions/arnative.ts`
|
|
@@ -624,7 +633,7 @@ if (isMain(import.meta.url)) {
|
|
|
624
633
|
// The /arnative picker lists the package's family only; everything else (system, dark,
|
|
625
634
|
// light, a theme of the user's own) stays in /settings → Theme.
|
|
626
635
|
assert(isArnativeThemeName("arnative"), "the default theme is family");
|
|
627
|
-
assert(isArnativeThemeName("arnative-
|
|
636
|
+
assert(isArnativeThemeName("arnative-cyberpunk"), "a variant is family");
|
|
628
637
|
for (const outsider of ["system", "dark", "light", "omarchy-system", "arnativeX", ""])
|
|
629
638
|
assert(!isArnativeThemeName(outsider), `${JSON.stringify(outsider)} is not family`);
|
|
630
639
|
|
|
@@ -637,11 +646,11 @@ if (isMain(import.meta.url)) {
|
|
|
637
646
|
|
|
638
647
|
// Live-preview picker (shared by Themes and Headers): move = preview, Enter = keep, Esc = revert.
|
|
639
648
|
const fakeTheme = { fg: (_c: string, t: string) => t, bold: (t: string) => t };
|
|
640
|
-
const pickerText: ListPickerText = { title: screenTitle("Themes"), description: "sub", legend: "[Esc]
|
|
649
|
+
const pickerText: ListPickerText = { title: screenTitle("Themes"), description: "sub", legend: "[Esc] Back" };
|
|
641
650
|
const previews: string[] = [];
|
|
642
651
|
let reverted = 0;
|
|
643
652
|
let done = 0;
|
|
644
|
-
const picker = new ListPicker(fakeTheme, nameRows(["arnative", "arnative-
|
|
653
|
+
const picker = new ListPicker(fakeTheme, nameRows(["arnative", "arnative-cyberpunk"]), "arnative", {
|
|
645
654
|
preview: (n) => previews.push(n),
|
|
646
655
|
revert: () => reverted++,
|
|
647
656
|
done: () => done++,
|
|
@@ -654,8 +663,8 @@ if (isMain(import.meta.url)) {
|
|
|
654
663
|
assert(lines.some((l) => l.includes("→ arnative")), "the cursor marks the live value");
|
|
655
664
|
assert(!lines.some((l) => l.includes("●")), "no redundant ● column next to the → cursor");
|
|
656
665
|
picker.handleInput("\x1b[B"); // down
|
|
657
|
-
assert(previews.length === 1 && previews[0] === "arnative-
|
|
658
|
-
assert(picker.render(50).some((l) => l.includes("→ arnative-
|
|
666
|
+
assert(previews.length === 1 && previews[0] === "arnative-cyberpunk", "move previews immediately");
|
|
667
|
+
assert(picker.render(50).some((l) => l.includes("→ arnative-cyberpunk")), "the cursor follows the preview");
|
|
659
668
|
picker.handleInput("\r"); // enter
|
|
660
669
|
assert(done === 1 && reverted === 0, "Enter keeps (no revert)");
|
|
661
670
|
picker.handleInput("\x1b[B");
|
|
@@ -665,8 +674,8 @@ if (isMain(import.meta.url)) {
|
|
|
665
674
|
// `←` reports upward instead of closing on a screen with a parent, reverting the live
|
|
666
675
|
// preview first; the root menu has nothing behind it and omits the key.
|
|
667
676
|
assert(LIST_LEGEND_ROOT === "[↑↓] Move [Enter] Open [Esc] Close", "the root menu legend omits ←");
|
|
668
|
-
assert(LIST_LEGEND_MOVE === "[↑↓] Move [Enter] Open [
|
|
669
|
-
assert(LIST_LEGEND_LIVE === "[↑↓] Preview [Enter] Select [
|
|
677
|
+
assert(LIST_LEGEND_MOVE === "[↑↓] Move [Enter] Open [Esc] Back", "submenu legend advertises Esc Back");
|
|
678
|
+
assert(LIST_LEGEND_LIVE === "[↑↓] Preview [Enter] Select [Esc] Back", "live legend advertises Esc Back");
|
|
670
679
|
let backs = 0;
|
|
671
680
|
let backReverts = 0;
|
|
672
681
|
const childPicker = new ListPicker(fakeTheme, nameRows(["a", "b"]), "a", {
|
|
@@ -677,8 +686,9 @@ if (isMain(import.meta.url)) {
|
|
|
677
686
|
requestRender: () => {},
|
|
678
687
|
}, pickerText);
|
|
679
688
|
childPicker.handleInput("\x1b[D"); // ←
|
|
680
|
-
|
|
681
|
-
|
|
689
|
+
childPicker.handleInput("\x1b"); // Esc
|
|
690
|
+
assert(backs === 2 && backReverts === 0, "Esc and ← both report back; the parent owns the revert");
|
|
691
|
+
// The root menu has no parent, so the same keys must still leave the screen.
|
|
682
692
|
let rootCancels = 0;
|
|
683
693
|
const rootPicker = new ListPicker(fakeTheme, nameRows(["a"]), undefined, {
|
|
684
694
|
preview: () => {},
|
|
@@ -688,7 +698,8 @@ if (isMain(import.meta.url)) {
|
|
|
688
698
|
requestRender: () => {},
|
|
689
699
|
}, pickerText, false);
|
|
690
700
|
rootPicker.handleInput("\x1b[D");
|
|
691
|
-
|
|
701
|
+
rootPicker.handleInput("\x1b"); // Esc
|
|
702
|
+
assert(rootCancels === 2, "Esc and ← close the root menu, which has no parent");
|
|
692
703
|
|
|
693
704
|
// The main menu reuses the picker with preview/revert as no-ops: moving changes no
|
|
694
705
|
// setting, only Enter opens a row. `reverted` proves it.
|
package/extensions/model-heal.ts
CHANGED
|
@@ -9,13 +9,17 @@
|
|
|
9
9
|
* only, Off = nothing. While pi-auto-compat is installed this module defers to it and says so
|
|
10
10
|
* once, so two healers never write models.json at the same time.
|
|
11
11
|
*/
|
|
12
|
+
import { reloadCurrentModel } from "../lib/provider.ts";
|
|
12
13
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
13
14
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
14
15
|
import { type FSWatcher, watch } from "node:fs";
|
|
15
16
|
import { join } from "node:path";
|
|
16
17
|
import { assert, isMain } from "../lib/check.ts";
|
|
17
18
|
import { REJECTION_RE } from "../lib/compat.ts";
|
|
18
|
-
import { activeModelHeal, autoCompatInstalled, healEffort, healFlags, healMeta, type HealDeps, type HealResult, type ModelHealChoice, type RtModel } from "../lib/model-heal.ts";
|
|
19
|
+
import { activeModelHeal, autoCompatInstalled, healEffort, healFlags, healMeta, markRejectedLevel, type HealDeps, type HealResult, type ModelHealChoice, type RtModel } from "../lib/model-heal.ts";
|
|
20
|
+
|
|
21
|
+
// Nerd Font md-shield-sync (U+F06DE), written as a code point so the source stays ASCII.
|
|
22
|
+
const HEAL_ICON = String.fromCodePoint(0xf06de);
|
|
19
23
|
|
|
20
24
|
interface RegistryLike {
|
|
21
25
|
getAll?: () => unknown[];
|
|
@@ -59,6 +63,12 @@ export function isRejectedParam(message: AssistantMessage | undefined): boolean
|
|
|
59
63
|
return REJECTION_RE.test(message.errorMessage ?? "");
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
/** A rejection that names the effort itself, so dropping the level is the fix. A plain
|
|
67
|
+
* 400 (context too long, bad tool schema) leaves the map alone and only re-probes. */
|
|
68
|
+
export function isEffortRejection(message: AssistantMessage | undefined): boolean {
|
|
69
|
+
return isRejectedParam(message) && /reasoning.?effort|thinking|effort/i.test(message!.errorMessage ?? "");
|
|
70
|
+
}
|
|
71
|
+
|
|
62
72
|
/** Whether a pass may run: Off runs nothing, Flags runs only the offline flags pass, Full runs
|
|
63
73
|
* everything, and an installed pi-auto-compat owns models.json in every mode. */
|
|
64
74
|
export function healAllowed(need: "Flags" | "Full", mode: ModelHealChoice, autoCompat: boolean): boolean {
|
|
@@ -81,7 +91,7 @@ export default function registerModelHeal(pi: ExtensionAPI): void {
|
|
|
81
91
|
let ui: ExtensionContext["ui"] | undefined;
|
|
82
92
|
try {
|
|
83
93
|
ui = ctx.ui;
|
|
84
|
-
ui?.setWidget?.("model-heal", lines.map((line) => "model-heal: " + line));
|
|
94
|
+
ui?.setWidget?.("model-heal", lines.map((line) => HEAL_ICON + " model-heal: " + line));
|
|
85
95
|
} catch {
|
|
86
96
|
return;
|
|
87
97
|
}
|
|
@@ -100,11 +110,12 @@ export default function registerModelHeal(pi: ExtensionAPI): void {
|
|
|
100
110
|
if (!result.changed) return;
|
|
101
111
|
let refreshed = true;
|
|
102
112
|
try {
|
|
103
|
-
await
|
|
113
|
+
refreshed = await reloadCurrentModel(ctx as never, (m) => pi.setModel(m as never));
|
|
104
114
|
} catch {
|
|
105
115
|
refreshed = false;
|
|
106
116
|
}
|
|
107
|
-
|
|
117
|
+
const count = result.detail.length;
|
|
118
|
+
notify(ctx, [label + " (" + count + (count === 1 ? " change)" : " changes)") + (refreshed ? "" : " - run /reload to load it")]);
|
|
108
119
|
}
|
|
109
120
|
|
|
110
121
|
const enabled = (need: "Flags" | "Full"): boolean => healAllowed(need, activeModelHeal(), autoCompatInstalled());
|
|
@@ -183,6 +194,20 @@ export default function registerModelHeal(pi: ExtensionAPI): void {
|
|
|
183
194
|
const deps = depsFor(ctx);
|
|
184
195
|
const target = deps.models().find((m) => m.provider.toLowerCase() === message!.provider!.toLowerCase() && m.id === message!.model);
|
|
185
196
|
if (!target) return;
|
|
197
|
+
const level = pi.getThinkingLevel();
|
|
198
|
+
if (isEffortRejection(message) && level !== "off") {
|
|
199
|
+
const marked = markRejectedLevel(deps, target, level);
|
|
200
|
+
if (marked.changed) {
|
|
201
|
+
void reloadCurrentModel(ctx as never, (m) => pi.setModel(m as never))
|
|
202
|
+
.then((loaded) => {
|
|
203
|
+
// pi clamps to the nearest level the map still offers.
|
|
204
|
+
if (loaded) pi.setThinkingLevel(level);
|
|
205
|
+
notify(ctx, [target.id + " rejected thinking " + level + "; removed it" + (loaded ? ", now " + pi.getThinkingLevel() : " - run /reload to load it")]);
|
|
206
|
+
})
|
|
207
|
+
.catch(() => undefined);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
186
211
|
void healEffort(deps, true, [target]).then((r) => apply(ctx, "thinking levels re-probed", r)).catch(() => undefined);
|
|
187
212
|
} catch {
|
|
188
213
|
// stale ctx
|
|
@@ -211,7 +236,7 @@ export async function healNow(ctx: ExtensionContext): Promise<void> {
|
|
|
211
236
|
const detail = [...flags.detail, ...meta.detail, ...effort.detail];
|
|
212
237
|
const errors = [...flags.errors, ...meta.errors, ...effort.errors];
|
|
213
238
|
if (detail.length > 0) {
|
|
214
|
-
await
|
|
239
|
+
await reloadCurrentModel(ctx as never, (m) => pi.setModel(m as never)).catch(() => undefined);
|
|
215
240
|
ctx.ui.notify("[arnative] Model heal fixed:\n - " + detail.join("\n - "), "info");
|
|
216
241
|
return;
|
|
217
242
|
}
|
|
@@ -233,6 +258,8 @@ if (isMain(import.meta.url)) {
|
|
|
233
258
|
assert(!isRejectedParam({ role: "assistant", provider: "r", model: "m", errorMessage: "401 unauthorized" }), "an auth failure costs no probe");
|
|
234
259
|
assert(!isRejectedParam({ role: "user", provider: "r", model: "m", errorMessage: "bad request" }), "only assistant messages count");
|
|
235
260
|
assert(!isRejectedParam(undefined), "no message, no probe");
|
|
261
|
+
assert(isEffortRejection({ role: "assistant", provider: "r", model: "m", errorMessage: "400 invalid reasoning_effort: medium" }), "an effort rejection drops the level");
|
|
262
|
+
assert(!isEffortRejection({ role: "assistant", provider: "r", model: "m", errorMessage: "400 bad request: context too long" }), "a plain 400 keeps the map");
|
|
236
263
|
assert(healAllowed("Flags", "Full", false) && healAllowed("Full", "Full", false), "Full runs every pass");
|
|
237
264
|
assert(healAllowed("Flags", "Flags", false) && !healAllowed("Full", "Flags", false), "Flags runs only the offline pass");
|
|
238
265
|
assert(!healAllowed("Flags", "Off", false) && !healAllowed("Full", "Off", false), "Off runs nothing");
|
package/extensions/todos.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node
|
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
13
|
-
import { StringEnum, Type } from "@earendil-works/pi-ai";
|
|
14
13
|
import type { TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
15
14
|
import { assert, isMain } from "../lib/check.ts";
|
|
16
15
|
import { inSpans, screenTitle, type TextSpan, textSpans } from "../lib/box.ts";
|
|
@@ -115,21 +114,50 @@ function saveState(ctx: ExtensionContext): void {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
const PARAMS =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
const PARAMS = {
|
|
118
|
+
type: "object",
|
|
119
|
+
required: ["action"],
|
|
120
|
+
properties: {
|
|
121
|
+
action: {
|
|
122
|
+
type: "string",
|
|
123
|
+
enum: ["create", "update", "delete", "clear", "list"],
|
|
124
|
+
description: "create adds tasks, update changes one, delete removes one, clear empties the list, list reads it back",
|
|
125
|
+
},
|
|
126
|
+
id: {
|
|
127
|
+
type: "number",
|
|
128
|
+
description: "Task id: required by update and delete, ignored by the other actions",
|
|
129
|
+
},
|
|
130
|
+
subject: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Task title: the new task on create, the new title on update",
|
|
133
|
+
},
|
|
134
|
+
status: {
|
|
135
|
+
type: "string",
|
|
136
|
+
enum: [...LIST_STATUSES],
|
|
137
|
+
description: "New status of the task named by id",
|
|
138
|
+
},
|
|
139
|
+
note: {
|
|
140
|
+
type: "string",
|
|
141
|
+
description: "One short line about what is happening now; shown while the task is in progress",
|
|
142
|
+
},
|
|
143
|
+
activeForm: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description: "Alias for note, kept for existing sessions",
|
|
146
|
+
},
|
|
147
|
+
tasks: {
|
|
148
|
+
type: "array",
|
|
129
149
|
description: "Several tasks to add at once",
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
items: {
|
|
151
|
+
type: "object",
|
|
152
|
+
required: ["subject"],
|
|
153
|
+
properties: {
|
|
154
|
+
subject: { type: "string" },
|
|
155
|
+
note: { type: "string" },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
} as never;
|
|
133
161
|
|
|
134
162
|
const SUMMARY = (state: TaskState): string => {
|
|
135
163
|
const { done, total, doing, queued } = countTodos(state);
|
package/extensions/tools.ts
CHANGED
|
@@ -141,6 +141,18 @@ export function resHead(theme: Theme): string {
|
|
|
141
141
|
return theme.fg("dim", "");
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/** Rows a block of text takes once painted at `width`, blank lines dropped: one long JSON
|
|
145
|
+
* string is a single newline but twenty-five rows on screen. */
|
|
146
|
+
const drawnRows = (text: string, width: number): number =>
|
|
147
|
+
text
|
|
148
|
+
.split("\n")
|
|
149
|
+
.filter((l) => l.trim())
|
|
150
|
+
.reduce((n, l) => n + Math.max(1, Math.ceil(visibleWidth(l) / Math.max(1, width))), 0);
|
|
151
|
+
|
|
152
|
+
/** A summary is one row by definition: a single-line JSON payload of 40k chars would
|
|
153
|
+
* otherwise wrap into a full screen and the box would look expanded while folded. */
|
|
154
|
+
const oneRow = (text: string, inner: number): string => truncateToWidth(text, inner, "…");
|
|
155
|
+
|
|
144
156
|
// Title line: duration right-aligned and space-aware (title truncated when it
|
|
145
157
|
// doesn't fit); expanded = full title wrapped. All lines stay <= inner (overflow bug).
|
|
146
158
|
export function titleRow(
|
|
@@ -412,6 +424,17 @@ const componentLines = (component: any, width: number): string[] => {
|
|
|
412
424
|
}
|
|
413
425
|
};
|
|
414
426
|
|
|
427
|
+
/** Right-align a label on the first row of `rows`, for a row pi did not build: the fold
|
|
428
|
+
* hint and the runtime still land where every other box puts them. */
|
|
429
|
+
const rightAlign = (th: Theme, rows: string[], inner: number, right: string): string[] => {
|
|
430
|
+
if (!right || rows.length === 0) return rows;
|
|
431
|
+
const label = th.fg("dim", right);
|
|
432
|
+
const avail = Math.max(4, inner - visibleWidth(label) - 1);
|
|
433
|
+
const head = truncateToWidth(rows[0]!, avail, "…");
|
|
434
|
+
const pad = Math.max(1, avail - visibleWidth(head));
|
|
435
|
+
return [`${head}${" ".repeat(pad)}${label}`, ...rows.slice(1)];
|
|
436
|
+
};
|
|
437
|
+
|
|
415
438
|
// Status icon + third-party lines -> our box content lines.
|
|
416
439
|
const boxedRows = (icon: string, lines: string[]): string[] => {
|
|
417
440
|
const body = lines.filter((l) => !isBlankLine(l));
|
|
@@ -505,21 +528,50 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
505
528
|
// MCP dumps the whole output on error (1-line summary instead), Chrome
|
|
506
529
|
// DevTools is a bare line, and errors take our own path (pi-web-access'
|
|
507
530
|
// own error box would nest a box inside a box).
|
|
508
|
-
const theirs =
|
|
509
|
-
own && !isErr && !cdp && !MCP_TOOL(name)
|
|
510
|
-
? safeCall(() => own.call(this, { content: result.content, details: result.details }, opts, th, ctx))
|
|
511
|
-
: null;
|
|
512
531
|
return new Lines((width) => {
|
|
513
532
|
const soft = softSecondaryOf(th);
|
|
514
533
|
const inner = Math.max(8, width - 4);
|
|
515
534
|
const icon = isErr ? th.fg("error", "x") : th.fg("success", "✓");
|
|
516
|
-
|
|
535
|
+
// Their renderer already answers `expanded`, so both states are measured: the fold
|
|
536
|
+
// label appears only when the other state really shows a different number of rows.
|
|
537
|
+
const theirsAt = (exp: boolean) =>
|
|
538
|
+
own && !isErr && !cdp && !MCP_TOOL(name)
|
|
539
|
+
? componentLines(
|
|
540
|
+
safeCall(() =>
|
|
541
|
+
own.call(this, { content: result.content, details: result.details }, { ...opts, expanded: exp }, th, ctx),
|
|
542
|
+
),
|
|
543
|
+
width - 6,
|
|
544
|
+
)
|
|
545
|
+
: [];
|
|
546
|
+
const boxed2 = theirsAt(opts.expanded);
|
|
547
|
+
// Only rows on screen decide: a renderer that answers `expanded` with the same visible
|
|
548
|
+
// height (a trailing newline, a blank row) has nothing to fold.
|
|
549
|
+
const rowsShown = (rows: string[]) => rows.filter((l) => !isBlankLine(l)).length;
|
|
550
|
+
const foldHint = rowsShown(theirsAt(!opts.expanded)) === rowsShown(boxed2) ? "" : opts.expanded ? HINT_COLLAPSE : HINT_EXPAND;
|
|
517
551
|
if (fff && boxed2.length) {
|
|
518
552
|
const callLines = componentLines(safeCall(() => origCall.call(this)?.call(this, ctx.args, th, ctx)), width - 6);
|
|
519
|
-
|
|
553
|
+
const head = `${icon} ${callLines[0]?.trim() || th.fg("accent", displayName(name))}`;
|
|
554
|
+
const right = [durationOf(ctx), foldHint].filter(Boolean).join(" · ");
|
|
555
|
+
return box(th, width, rightAlign(th, [head, ...boxed2], inner, right));
|
|
520
556
|
}
|
|
521
|
-
|
|
522
|
-
|
|
557
|
+
// Third-party content keeps its own template but not its own chrome: without this the
|
|
558
|
+
// box had no title row, so the tool name, the runtime and the fold label were all lost.
|
|
559
|
+
if (boxed2.length && !cdp) {
|
|
560
|
+
const rows = titleRow(
|
|
561
|
+
th,
|
|
562
|
+
icon,
|
|
563
|
+
th.fg("accent", displayName(name)),
|
|
564
|
+
mcpInfo(name, ctx.args, th),
|
|
565
|
+
inner,
|
|
566
|
+
durationOf(ctx),
|
|
567
|
+
opts.expanded,
|
|
568
|
+
foldHint,
|
|
569
|
+
);
|
|
570
|
+
return box(th, width, [...rows, ...boxed2]);
|
|
571
|
+
}
|
|
572
|
+
// A payload with no newline can still be a full screen of wrapped text, so the row
|
|
573
|
+
// count is measured at this width: a 40k-char JSON line folds like any other box.
|
|
574
|
+
const more = drawnRows(text, inner) > 1;
|
|
523
575
|
const rows = titleRow(
|
|
524
576
|
th,
|
|
525
577
|
icon,
|
|
@@ -533,7 +585,11 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
533
585
|
more ? (opts.expanded ? HINT_COLLAPSE : HINT_EXPAND) : "",
|
|
534
586
|
);
|
|
535
587
|
const summary = toolSummary(name, text, ctx.args);
|
|
536
|
-
|
|
588
|
+
const summaryRow = oneRow(
|
|
589
|
+
`${resHead(th)}${summary ? ` ${paintLinks(summary, soft)}` : ""}`,
|
|
590
|
+
inner,
|
|
591
|
+
);
|
|
592
|
+
rows.push(summaryRow);
|
|
537
593
|
if (opts.expanded && more) {
|
|
538
594
|
// MCP args are gone once the call box is replaced by the result.
|
|
539
595
|
if (MCP_TOOL(name)) rows.push(th.fg("dim", `args ${JSON.stringify(ctx.args ?? {})}`));
|
|
@@ -697,7 +753,8 @@ function minimal(
|
|
|
697
753
|
const inner = Math.max(8, width - 4);
|
|
698
754
|
// Anything the collapsed summary hides gets the standard hint; without it a
|
|
699
755
|
// two-line box (edit: `+1 / -1`) looks complete while the diff sits behind it.
|
|
700
|
-
const hasDetail =
|
|
756
|
+
const hasDetail =
|
|
757
|
+
drawnRows(text, inner) > 1 || Boolean((result.details as { diff?: string } | undefined)?.diff);
|
|
701
758
|
const label = hasDetail ? (expanded ? HINT_COLLAPSE : HINT_EXPAND) : "";
|
|
702
759
|
const rows = titleRow(
|
|
703
760
|
theme,
|
|
@@ -711,7 +768,7 @@ function minimal(
|
|
|
711
768
|
);
|
|
712
769
|
const resLine = res(result, theme, soft, isErr, expanded);
|
|
713
770
|
if (expanded) rows.push(...full(result, theme));
|
|
714
|
-
else if (resLine) rows.push(resLine);
|
|
771
|
+
else if (resLine) rows.push(oneRow(resLine, inner));
|
|
715
772
|
return box(theme, width, rows);
|
|
716
773
|
});
|
|
717
774
|
},
|
|
@@ -1680,5 +1737,65 @@ if (isMain(import.meta.url)) {
|
|
|
1680
1737
|
);
|
|
1681
1738
|
}
|
|
1682
1739
|
|
|
1740
|
+
|
|
1741
|
+
// --- Third-party boxes carry a title row, so they can be folded like any other ----
|
|
1742
|
+
// pi-web-access paints its own template; without our title row the box lost the tool
|
|
1743
|
+
// name, the runtime and the [show] label, so the only way to expand it was ctrl+o.
|
|
1744
|
+
const paFolding = {
|
|
1745
|
+
toolName: "web_search",
|
|
1746
|
+
toolDefinition: {
|
|
1747
|
+
renderResult: (_r: unknown, o: { expanded?: boolean }) => ({
|
|
1748
|
+
render: () => (o.expanded ? ["a", "b", "c", "d"] : ["a"]),
|
|
1749
|
+
}),
|
|
1750
|
+
},
|
|
1751
|
+
};
|
|
1752
|
+
const paFold = (expanded: boolean) =>
|
|
1753
|
+
(ToolExecutionComponent.prototype.getResultRenderer.call(paFolding) as any)(
|
|
1754
|
+
{ content: [{ type: "text", text: "raw" }], details: {} },
|
|
1755
|
+
{ expanded, isPartial: false },
|
|
1756
|
+
th,
|
|
1757
|
+
{ args: {}, state: {} },
|
|
1758
|
+
).render(80) as string[];
|
|
1759
|
+
const paFolded = paFold(false).map(stripAnsi);
|
|
1760
|
+
const paOpen = paFold(true).map(stripAnsi);
|
|
1761
|
+
assert(paFolded[1]!.includes("search"), "third-party box: the title row names the tool");
|
|
1762
|
+
assert(paFolded[1]!.includes("[show]"), "third-party box: collapsed offers [show]");
|
|
1763
|
+
assert(paOpen[1]!.includes("[hide]"), "third-party box: expanded offers [hide]");
|
|
1764
|
+
assert(paOpen.length > paFolded.length, "third-party box: expanding really shows more rows");
|
|
1765
|
+
// A renderer that ignores `expanded` has nothing to fold, so it gets no label.
|
|
1766
|
+
const flat = { toolName: "web_search", toolDefinition: { renderResult: () => ({ render: () => ["only line"] }) } };
|
|
1767
|
+
for (const expanded of [false, true]) {
|
|
1768
|
+
const rows = (ToolExecutionComponent.prototype.getResultRenderer.call(flat) as any)(
|
|
1769
|
+
{ content: [{ type: "text", text: "raw" }], details: {} },
|
|
1770
|
+
{ expanded, isPartial: false },
|
|
1771
|
+
th,
|
|
1772
|
+
{ args: {}, state: {} },
|
|
1773
|
+
).render(80) as string[];
|
|
1774
|
+
assert(rows.every((l: string) => !l.includes("[show]") && !l.includes("[hide]")), `third-party box: nothing to fold, no label (expanded=${expanded})`);
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// --- A one-line payload that fills the screen still folds ---------------------
|
|
1778
|
+
// A JSON reply has no newline, so it used to count as one row: no [show], and the
|
|
1779
|
+
// summary row wrapped into 30 rows because nothing clipped it.
|
|
1780
|
+
const longJson = JSON.stringify({ results: [{ url: "https://example.com", text: "x".repeat(4000) }] });
|
|
1781
|
+
const longBox = resRenderer(
|
|
1782
|
+
{ content: [{ type: "text", text: longJson }] },
|
|
1783
|
+
{ expanded: false, isPartial: false },
|
|
1784
|
+
th,
|
|
1785
|
+
{ args: {}, state: {} },
|
|
1786
|
+
).render(80) as string[];
|
|
1787
|
+
assert(longBox.some((l: string) => l.includes("[show]")), "a wrapped one-line payload offers [show]");
|
|
1788
|
+
assert(longBox.length <= 6, `a folded box stays short whatever the payload (${longBox.length} rows)`);
|
|
1789
|
+
assert(
|
|
1790
|
+
longBox.every((l: string) => !l.includes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")),
|
|
1791
|
+
"the summary row is one row: the payload is clipped, not wrapped",
|
|
1792
|
+
);
|
|
1793
|
+
const shortBox = resRenderer(
|
|
1794
|
+
{ content: [{ type: "text", text: "done" }] },
|
|
1795
|
+
{ expanded: false, isPartial: false },
|
|
1796
|
+
th,
|
|
1797
|
+
{ args: {}, state: {} },
|
|
1798
|
+
).render(80) as string[];
|
|
1799
|
+
assert(shortBox.every((l: string) => !l.includes("[show]")), "a one-row answer has nothing to fold, so no label");
|
|
1683
1800
|
console.log("OK");
|
|
1684
1801
|
}
|