@bismawy/pi-arnative 0.15.0 → 0.16.1

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 (48) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +52 -67
  3. package/extensions/animations.ts +11 -26
  4. package/extensions/arnative.ts +253 -380
  5. package/extensions/autocompact.ts +17 -22
  6. package/extensions/budget.ts +87 -136
  7. package/extensions/footer.ts +79 -60
  8. package/extensions/model-heal.ts +0 -0
  9. package/extensions/render-cache.ts +29 -15
  10. package/extensions/section-headers.ts +4 -8
  11. package/extensions/timestamps.ts +118 -41
  12. package/extensions/todos.ts +83 -33
  13. package/extensions/tools.ts +13 -30
  14. package/extensions/ui-render-tweaks.ts +0 -0
  15. package/extensions/usage-export.ts +3 -12
  16. package/extensions/usage.ts +0 -0
  17. package/lib/ansi.ts +0 -0
  18. package/lib/box.ts +0 -0
  19. package/lib/check.ts +0 -0
  20. package/lib/color.ts +0 -0
  21. package/lib/compat.ts +117 -17
  22. package/lib/format.ts +0 -0
  23. package/lib/list-picker.ts +5 -5
  24. package/lib/model-heal.ts +4 -8
  25. package/lib/patch.ts +0 -0
  26. package/lib/preset-store.ts +63 -16
  27. package/lib/provider.ts +131 -17
  28. package/lib/shortcuts.ts +0 -0
  29. package/lib/spinner.ts +1 -1
  30. package/lib/status-widget.ts +0 -0
  31. package/lib/todos.ts +0 -0
  32. package/lib/usage-store.ts +11 -20
  33. package/package.json +1 -1
  34. package/themes/arnative-blossom.json +0 -0
  35. package/themes/arnative-crimson.json +0 -0
  36. package/themes/arnative-cyberpunk.json +0 -0
  37. package/themes/arnative-dracula.json +0 -0
  38. package/themes/arnative-earthy.json +0 -0
  39. package/themes/arnative-garden.json +0 -0
  40. package/themes/arnative-gruvbox.json +0 -0
  41. package/themes/arnative-lemonade.json +0 -0
  42. package/themes/arnative-magical.json +0 -0
  43. package/themes/arnative-matrix.json +0 -0
  44. package/themes/arnative-neutral.json +0 -0
  45. package/themes/arnative-nord.json +0 -0
  46. package/themes/arnative-zinc.json +0 -0
  47. package/themes/arnative.json +0 -0
  48. package/themes/gen-themes.mjs +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.16.1] - 2026-11-21
6
+
7
+ ### Fixed
8
+ - **Pi 1.6.0 render immutability, `childLines` sync, and `wire-bytes` test isolation.** `timestamps.ts` now uses copy-on-write with per-instance render caching and idempotent `repairBubbleBg` so frozen `readonly string[]` outputs from Pi 1.6.0+ never throw `TypeError` or double-append ANSI resets; `render-cache.ts` synchronizes `Container.childLines` alongside `mouseLayout` and hooks Pi 1.6.0+ `InteractiveMode` session-render methods; `autocompact.ts` and `test/wire-bytes.test.ts` reset the preset cache after `PI_CODING_AGENT_DIR` overrides and read live `activeByteCeilings()`. Added `test/pi-compat-contract.test.ts` (`extensions/timestamps.ts`, `extensions/render-cache.ts`, `extensions/autocompact.ts`, `test/wire-bytes.test.ts`, `test/pi-compat-contract.test.ts`).
9
+
10
+ ## [0.16.0] - 2026-11-20
11
+
12
+ ### Added
13
+ - **Automatic `contextWindow` and `maxTokens` fallback in `/providers`.** When a provider's `/models` response omits context limits, `/providers` now resolves missing limits from pi's local `modelRegistry` first (matching exact, bare, and variant-stripped model IDs) and then from OpenRouter's public model catalog (`https://openrouter.ai/api/v1/models`). `parseMeta` also reads camelCase limit keys, Gemini `inputTokenLimit`/`outputTokenLimit`, and nested `top_provider`, `limit`/`limits`, and `capabilities.limits` objects (`lib/compat.ts`, `lib/provider.ts`).
14
+
15
+ ### Changed
16
+ - **Automatic cleanup of old completed task lists in `todos/`.** On `session_start`, session todo files older than 30 days whose tasks are all completed or empty are pruned automatically (`extensions/todos.ts`).
17
+
18
+ ### Fixed
19
+ - **Budget total estimate no longer double-counts today's spend.** The Budget modal summed `estimatedToday + estimatedMonth`, even though the rolling 30-day window already includes today (`extensions/budget.ts`).
20
+ - **`/usage` Project view omits empty sessions after a reset or range filter.** Files with zero effective messages are no longer counted into `summary.projects` (`lib/usage-store.ts`).
21
+ - **`mergeMeta` keeps `maxTokens` intact when an anomalous `contextWindow` is rejected.** Output caps now clamp against the accepted `out.contextWindow` instead of the rejected candidate (`lib/compat.ts`).
22
+ - **Closing `/providers` → Thinking aborts any in-flight effort probe, and atomic file writes share Windows lock fallback.** Leaving the Thinking picker cancels pending probe requests via `AbortController`, and all seven atomic-write paths now share `writeAtomicSync` with Windows `EPERM`/`EBUSY`/`EXDEV` fallback and temp-file cleanup (`lib/provider.ts`, `lib/preset-store.ts`, `lib/usage-store.ts`, `lib/model-heal.ts`, `extensions/todos.ts`, `extensions/usage-export.ts`).
23
+
5
24
  ## [0.15.0] - 2026-11-19
6
25
 
7
26
  ### Changed
package/README.md CHANGED
@@ -10,42 +10,17 @@ Refined aesthetics. Cohesive tools. Built for Pi.
10
10
 
11
11
  ## Overview
12
12
 
13
- pi-arnative replaces pi’s default terminal chrome with a unified visual interface.
14
-
15
- - Warm Themes: Contrast-checked OKLCH color palettes generated without drift (`arnative` plus eight variants).
16
- - Tabbed Header: Compact box menu showing Directory, Model, Context, Skills, Extensions, and Shortcuts.
17
- - Rounded Tool Boxes: Status, spinner, runtime duration, and clickable `[show]` / `[hide]` output toggles.
18
- - Task List: `todo` tool, `/todos` view, and a boxed widget above the editor that auto-hides 30s after all tasks finish.
19
- - Enhanced Footer: 3-row status grid (`Arnative (Full)`) or single collapsible row (`Arnative (Minimal)`) tracking branch, diff, active duration, and token speed.
20
- - Working Spinners: 18 animated presets with live picker preview and optional `[g]` gradient sweep.
21
- - Transcript Clock: Per-message timestamps with clean bubble backgrounds.
22
- - Usage Dashboard: Real-time token counts and cost tracking across local sessions via `/usage`.
23
- - Budget Guardrails: `/arnative` → Budget sets UTC day and rolling 30-day caps on billed spend, draws each window as a spend-vs-cap bar, turns the footer cost cell amber at 80% and red at 100%, and can stop the next turn when enforce is on.
24
- - Prometheus Textfile Export: On every `turn_end` (at most one write per minute, and only when the numbers changed) the usage summary is written as an exposition file to `~/.pi/agent/arnative/usage.prom` — point a textfile collector at that folder (`node_exporter --collector.textfile.directory=~/.pi/agent/arnative`) and the spend lands in Grafana next to the infra metrics; set `PI_ARNATIVE_EXPORT=0` to turn it off.
25
- - 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`.
26
- - Model Heal: Background sync (`/model-heal`) that fills missing compat flags, `/models` token limits, and accepted reasoning effort levels in `models.json`.
27
- - Auto-compact: Triggers context compaction after a turn settles using Render-cache-aware Smart tiers or a fixed token budget, plus silent in-memory byte trimming for byte-capped proxies.
28
- - Render Cache: Caches settled transcript components inside `chatContainer` so TUI redraws stay fast on large sessions (`On` by default).
29
-
30
- <details>
31
- <summary><b>Configuration & Presets</b></summary>
32
-
33
- Saved to `~/.pi/agent/arnative/config.json` via `/arnative`:
34
-
35
- - **Headers & Footers:** `Arnative (Full)` (default), `Arnative (Minimal)` (footer only; click head text or press `ctrl+alt+m` to toggle), or `Pi (system)`.
36
- - **Footer cost:** off by default. Press `[c]` in the Footers picker to add the session's cost (`$0.42`, `~$0.42` when no provider reported a billed total) to the metrics row; the choice is stored as `footerCost` in `config.json`.
37
- - **Chatbox:** `Arnative` (default: rounded box with configurable prompt icon `❯`, `>`, `›`, `▸`, `→`, `\uf44f`, `\udb82\udf79`, `\uf51b`, `\udb80\udf7d`, `\uf120`, `\uf489`, or `\udb80\udd7a` cycled with `[i]`, painted `primary` while typing and `dim` after 3s idle) or `Pi (system)` (built-in top and bottom lines), plus `[D]` to position the working status dialog (`Left`, `Center`, `Right`, `Inside`, `Outside`).
38
- - **Animations:** 18 presets (`Arnative` default, `Pi (system)`, and alphabetical variants). Press `[g]` in the picker to toggle the Google gradient sweep.
39
- - **Render cache:** `On` by default. Reuses rendered lines for settled Pi transcript components in `chatContainer`; streaming items, active animations, and custom or unknown renderers bypass the cache.
40
- - **Auto-compact:** `Off` by default (extension trigger disabled; Pi core compaction stays in charge).
41
- - **Smart:** Adapts to `Render cache` and `contextWindow`. With `Render cache: On`, windows `>= 192k` trigger at `90%` (`~180k` on `200k`, `~900k` on `1M`, `943,718` on `1,048,576`), while `< 192k` defers to Pi core. With `Render cache: Off`, `Smart` uses conservative tiers (`1M -> 20%`, `512k -> 40%`, `256k -> 80%`, `< 192k -> pi core`).
42
- - **Fixed budgets (`100k` to `400k`):** Fire at one absolute token count on any window. A budget above a model's capacity does not expand it; Pi core (`reserveTokens`) and provider limits still apply first.
43
- - **Trade-offs:** `Smart` retains raw history longer on large windows and avoids unnecessary summarization on short sessions. An earlier fixed budget such as `300k` shrinks prompts after compaction on 1M-window models, but pays an upfront summary cost and resets the prefix cache once; in a 6-turn GLM/Magpie coding A/B sample, `300k` broke even at request 5 and cost 16.1% less at configured rates, while a 2-turn ~250k test cost more than keeping the prefix cached. Thresholds are triggers, not hard caps.
44
- - **Payload limit (`/arnative` → Payload limit, or `PI_ARNATIVE_BYTE_WALL_MB`):** For `remote/*`, `remote-magpie/*`, and models that saw HTTP 413, payloads approaching `900 KB` (at the default `1 MB` limit) are trimmed in-memory before sending without triggering compaction or altering session history. Choose `Off`, `1 MB`, `4 MB`, `8 MB`, `16 MB`, `32 MB`, or `Custom` (1 to 1024 MB) in `/arnative` (saved to `config.json` and applied immediately; `PI_ARNATIVE_BYTE_WALL_MB` overrides it per shell). The footer shows wire bytes on the left row while active.
45
- - **Model heal:** **Full** (default: offline compat flags, `GET /models` limits and reasoning effort probes cached locally until new models appear, with failed fetches retried after 1h), **Flags** (offline only), or **Off**. Hand-edited fields are never overwritten. `/model-heal` forces every pass, warns that thinking probes can use paid tokens, and shows the stage it is in.
46
- - **Task list (`todo`):** Stored per session in `~/.pi/agent/arnative/todos/<session-id>.json` (uninstall `@juicesharp/rpiv-todo` first to avoid tool name conflict). Click `[show]` / `[hide]` (or single-click anywhere on the box) or press `ctrl+alt+o` (`alt+o`) to toggle; click `↑`/`↓` counters or press `ctrl+alt+j`/`k` (`alt+j`/`k`) to scroll. Auto-hides 30s after completion (set `PI_ARNATIVE_TODO_HIDE_MS` to override, `0` for immediate hide; expanding pauses the timer).
47
-
48
- </details>
13
+ `pi-arnative` replaces Pi's default terminal UI with warm themes, rounded tool boxes, a tabbed header, a status footer, and session tools.
14
+
15
+ - **Themes:** 14 contrast-checked OKLCH themes (`arnative` and 13 variants).
16
+ - **Header:** Tabbed box showing Directory, Model, Context, Skills, Extensions, and Shortcuts.
17
+ - **Tool boxes:** Rounded borders with status, spinner, duration, and clickable `[show]` or `[hide]` toggles.
18
+ - **Task list:** `todo` tool, `/todos` recap screen, and a boxed widget above the editor that hides 30s after all tasks finish.
19
+ - **Footer:** 3-row status grid (`Arnative (Full)`) or a single collapsible row (`Arnative (Minimal)`) with git branch, diff stats, active duration, token speed, and optional session cost.
20
+ - **Spinners and timestamps:** 18 animated spinner presets with an optional `[g]` gradient sweep, plus per-message timestamps and bubble backgrounds.
21
+ - **Usage and budget:** `/usage` tracks local token counts and spend across sessions, with optional Prometheus export to `~/.pi/agent/arnative/usage.prom` (set `PI_ARNATIVE_EXPORT=0` to disable). Budget settings in `/arnative` add UTC day and rolling 30-day spend caps with footer warnings at 80% and 100%, and can block the next turn when enforced.
22
+ - **Providers and model heal:** `/providers` probes endpoints and saves OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`. `/model-heal` fills missing compat flags, `/models` token limits, and accepted reasoning effort levels.
23
+ - **Context and rendering:** `Render cache` (`On` by default) caches settled transcript components in `chatContainer`. `Auto-compact` (`Off` by default) triggers compaction via Smart tiers or a fixed token budget, with silent in-memory byte trimming for byte-capped proxies.
49
24
 
50
25
  ## Install
51
26
 
@@ -53,25 +28,32 @@ Saved to `~/.pi/agent/arnative/config.json` via `/arnative`:
53
28
  pi install npm:@bismawy/pi-arnative
54
29
  ```
55
30
 
56
- Requires a [Nerd Font](https://www.nerdfonts.com/font-downloads). On a fresh install, `arnative` is applied automatically if no theme is set; switch anytime via `/arnative themes` or `/settings` → **Theme**.
31
+ Requires a [Nerd Font](https://www.nerdfonts.com/font-downloads). On a fresh install, `arnative` is applied automatically if no theme is set. You can switch themes anytime from `/arnative` or `/settings`.
32
+
33
+ For local development:
57
34
 
58
- Local development:
59
35
  ```bash
60
- npm run dev # run pi against this checkout, nothing installed
61
- npm run overlay # copy extensions/ lib/ themes/ into the installed npm package
36
+ npm run dev # run pi against this checkout without installing
37
+ npm run overlay # copy extensions/, lib/, and themes/ into the installed npm package
62
38
  ```
63
39
 
64
- To see a change before publishing it: `npm run overlay`, then press `/reload` in pi — pi
65
- re-evaluates extension TypeScript in the same process, so the reload loads the copied code with no
66
- reinstall and no restart. The package stays an npm install; nothing points pi at this directory. A
67
- module deleted here is pruned from the installed copy (a stale entry point would keep loading), and
68
- `pi update --extensions` restores the published code once a higher version exists.
69
- `npm run overlay -- --dry-run` lists what would move; `PI_CODING_AGENT_DIR` targets another agent dir.
40
+ Run `npm run overlay` and then `/reload` in Pi to test local changes without reinstalling or restarting. Removed modules are pruned from the installed copy, and `pi update --extensions` restores the published package when a newer version is out. Use `npm run overlay -- --dry-run` to preview changes, or set `PI_CODING_AGENT_DIR` to target another agent directory.
70
41
 
71
- ## Shortcuts
42
+ ## Commands and shortcuts
43
+
44
+ | Command | Purpose |
45
+ | --- | --- |
46
+ | `/arnative` | Open settings (Themes, Headers, Footers, Animations, Render cache, Auto-compact, Model heal, Payload limit, Providers, Usage, Budget) |
47
+ | `/usage` | Open the token and cost dashboard |
48
+ | `/todos` | Open the full task list recap |
49
+ | `/providers` | Manage custom providers |
50
+ | `/model-heal` | Run `models.json` heal passes now |
51
+
52
+ In `/usage`, press `R` to reset model and provider statistics after confirmation. Session files are left untouched and stay available in `/resume`. New messages are counted from the reset baseline in `~/.pi/agent/arnative/usage-baseline.json`, and `U` undoes the latest reset while the dashboard is open.
72
53
 
73
54
  | Key (Linux / Win) | Action |
74
55
  | --- | --- |
56
+ | `ctrl+alt+a` · `alt+a` | Open settings menu (`/arnative`) |
75
57
  | `ctrl+alt+t` · `alt+t` | Cycle header tabs |
76
58
  | `ctrl+alt+r` · `alt+r` | Quick reload (`/reload`) |
77
59
  | `ctrl+alt+n` · `alt+n` | New session (`/new`) |
@@ -80,17 +62,10 @@ module deleted here is pruned from the installed copy (a stale entry point would
80
62
  | `ctrl+alt+j` · `alt+j` | Scroll task list down |
81
63
  | `ctrl+alt+k` · `alt+k` | Scroll task list up |
82
64
  | Click `[show]` / `[hide]` · `ctrl+o` | Toggle tool output box |
83
- | `←` / `Esc` | Step back to parent menu / close active screen |
84
- | `/arnative` | Settings menu (Themes, Headers, Footers, Animations, Render cache, Auto-compact, Model heal, Payload limit, Providers, Usage, Budget) |
85
- | `/usage` | Token & cost dashboard |
86
- | `/todos` | Full task list recap |
87
- | `/providers` | Custom provider manager |
88
- | `/model-heal` | Run `models.json` heal passes now |
89
-
90
- In Usage, `R` resets all model/provider statistics after confirmation. Session files stay unchanged and remain available through `/resume`. New messages count from the reset, including messages in existing sessions. The baseline persists in `~/.pi/agent/arnative/usage-baseline.json`; `U` undoes the latest reset while that dashboard remains open. Files from earlier resets in `usage-trash` stay untouched.
65
+ | `←` / `Esc` | Go back or close active screen |
91
66
 
92
67
  <details>
93
- <summary><b>Keybindings & Platform Notes</b></summary>
68
+ <summary>Keybindings and platform notes</summary>
94
69
 
95
70
  Bind `app.session.new` in `~/.pi/agent/keybindings.json`:
96
71
  ```json
@@ -99,16 +74,31 @@ Bind `app.session.new` in `~/.pi/agent/keybindings.json`:
99
74
  }
100
75
  ```
101
76
 
102
- - **Windows / WSL:** Windows Terminal maps `Ctrl+Alt` to AltGr; use `alt+…` or disable `altGrAliasing`.
103
- - **macOS:** Use `ctrl+option+…`.
104
- - **tmux / Herdr:** Set `PI_TUI_ESC_TIMEOUT=100` if `Esc` has a delay.
77
+ - **Windows / WSL:** Windows Terminal maps `Ctrl+Alt` to AltGr. Use `alt+...` or disable `altGrAliasing`.
78
+ - **macOS:** Use `ctrl+option+...`.
79
+ - **tmux / Herdr:** Set `PI_TUI_ESC_TIMEOUT=100` if `Esc` feels delayed.
105
80
 
106
81
  </details>
107
82
 
108
- ## Architecture
83
+ <details>
84
+ <summary>Configuration and presets</summary>
85
+
86
+ Settings from `/arnative` are saved in `~/.pi/agent/arnative/config.json`:
87
+
88
+ - **Headers and footers:** `Arnative (Full)` (default), `Arnative (Minimal)` (footer only; click the head text or press `ctrl+alt+m` to toggle), or `Pi (system)`.
89
+ - **Footer cost:** Off by default. Press `[c]` in the Footers picker to show session cost (`$0.42`, or `~$0.42` when estimated) in the metrics row.
90
+ - **Chatbox:** `Arnative` (default rounded box with 12 prompt icons cycled via `[i]`, colored `primary` while typing and `dim` after 3s idle) or `Pi (system)`. Press `[D]` to position the working status dialog (`Left`, `Center`, `Right`, `Inside`, `Outside`).
91
+ - **Animations:** 18 presets (`Arnative` default, `Pi (system)`, and variants). Press `[g]` in the picker to toggle the gradient sweep.
92
+ - **Render cache:** `On` by default. Reuses rendered lines for settled transcript items in `chatContainer`. Streaming items, active animations, and custom renderers bypass the cache.
93
+ - **Auto-compact:** `Off` by default (Pi core compaction handles context). `Smart` adapts to `Render cache` and `contextWindow` (triggers at 90% on `>= 192k` windows when `Render cache` is `On`, or conservative tiers when `Off`). Fixed budgets (`100k` to `400k`) trigger at an absolute token count, subject to Pi core `reserveTokens` and provider limits.
94
+ - **Payload limit:** Configured in `/arnative` or `PI_ARNATIVE_BYTE_WALL_MB` (`Off`, `1 MB`, `4 MB`, `8 MB`, `16 MB`, `32 MB`, or `Custom` from 1 to 1024 MB). For `remote/*`, `remote-magpie/*`, and models that return HTTP 413, payloads near the ceiling are trimmed in memory before sending without changing session history.
95
+ - **Model heal:** `Full` (default: offline compat flags, `GET /models` limits, and reasoning effort probes cached locally), `Flags` (offline only), or `Off`. Hand-edited fields are never overwritten.
96
+ - **Task list:** Stored per session in `~/.pi/agent/arnative/todos/<session-id>.json` (uninstall `@juicesharp/rpiv-todo` first to avoid a tool name conflict). Auto-hides 30s after completion (`PI_ARNATIVE_TODO_HIDE_MS` overrides the delay; `0` hides immediately).
97
+
98
+ </details>
109
99
 
110
100
  <details>
111
- <summary><b>Extensions & Components</b></summary>
101
+ <summary>Architecture and development</summary>
112
102
 
113
103
  | File | Role |
114
104
  | --- | --- |
@@ -132,12 +122,7 @@ Bind `app.session.new` in `~/.pi/agent/keybindings.json`:
132
122
  | `lib/model-heal.ts` | Compat flags, `/models` limit sync, and reasoning effort probe |
133
123
  | `lib/list-picker.ts` | Shared live-preview and multi-select picker component |
134
124
 
135
- </details>
136
-
137
- <details>
138
- <summary><b>Theme Variants & Development</b></summary>
139
-
140
- **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`
125
+ **Themes (`themes/gen-themes.mjs` + `lib/color.ts`):** `arnative` · `arnative-blossom` · `arnative-crimson` · `arnative-cyberpunk` · `arnative-dracula` · `arnative-earthy` · `arnative-garden` · `arnative-gruvbox` · `arnative-lemonade` · `arnative-magical` · `arnative-matrix` · `arnative-neutral` · `arnative-nord` · `arnative-zinc`
141
126
 
142
127
  ```bash
143
128
  npm test # Run self-checks and unit tests
@@ -12,7 +12,7 @@
12
12
  * coupling between the two, and it is a published symbol, not an import.
13
13
  */
14
14
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
15
- import { loadChoice, saveChoice } from "../lib/preset-store.ts";
15
+ import { choiceSetting, flagSetting } from "../lib/preset-store.ts";
16
16
  import {
17
17
  DEFAULT_SPINNER_PRESET,
18
18
  SPINNER_GRADIENT_KEY,
@@ -29,8 +29,10 @@ import { ROW_DIVIDER } from "../lib/format.ts";
29
29
 
30
30
  /** The arnative editor instance, published by `footer.ts` so the live spinner is reachable. */
31
31
  export const EDITOR_KEY = Symbol.for("pi-arnative.editor");
32
- const SPINNER_PRESET_CONFIG_KEY = Symbol.for("pi-arnative.spinnerPreset");
33
- const SPINNER_GRADIENT_CONFIG_KEY = Symbol.for("pi-arnative.spinnerGradient");
32
+ const spinnerPresetSetting = choiceSetting(SPINNER_PRESET_KEY, SPINNER_PRESETS, DEFAULT_SPINNER_PRESET);
33
+ const spinnerGradientSetting = flagSetting(SPINNER_GRADIENT_KEY);
34
+ const SPINNER_PRESET_CONFIG_KEY = spinnerPresetSetting.slot;
35
+ const SPINNER_GRADIENT_CONFIG_KEY = spinnerGradientSetting.slot;
34
36
 
35
37
  /** The `setWorkingMessage`/`setWorkingIndicator` surface of `ctx.ui`. */
36
38
  type WorkingUi = { setWorkingIndicator?: (options?: unknown) => void } | null | undefined;
@@ -62,37 +64,20 @@ function activeWorkingTheme(): ThemeLike {
62
64
  return ((globalThis as Record<symbol, unknown>)[THEME_KEY] as ThemeLike) ?? null;
63
65
  }
64
66
 
65
- export function activeSpinnerPreset(): SpinnerPreset {
66
- const stored =
67
- (globalThis as Record<symbol, unknown>)[SPINNER_PRESET_CONFIG_KEY] ??
68
- loadChoice(SPINNER_PRESET_KEY, SPINNER_PRESETS);
69
- return SPINNER_PRESETS.includes(stored as SpinnerPreset) ? (stored as SpinnerPreset) : DEFAULT_SPINNER_PRESET;
70
- }
67
+ export const activeSpinnerPreset = (): SpinnerPreset => spinnerPresetSetting.get();
71
68
 
72
- /** Is the `accent` → gradient override on? Stored as `"on"`/`"off"` so an absent key reads as
73
- * off through the same allow-list path every other choice uses. */
74
- export function activeSpinnerGradient(): boolean {
75
- const stored =
76
- (globalThis as Record<symbol, unknown>)[SPINNER_GRADIENT_CONFIG_KEY] ??
77
- loadChoice(SPINNER_GRADIENT_KEY, ["on", "off"] as const);
78
- return stored === "on";
79
- }
69
+ /** Is the `accent` → gradient override on? */
70
+ export const activeSpinnerGradient = (): boolean => spinnerGradientSetting.get();
80
71
 
81
72
  /** Flip the gradient override, persist it, and repaint the live spinner at once. */
82
73
  export function setSpinnerGradient(on: boolean): void {
83
- (globalThis as Record<symbol, unknown>)[SPINNER_GRADIENT_CONFIG_KEY] = on ? "on" : "off";
84
- saveChoice(SPINNER_GRADIENT_KEY, on ? "on" : "off");
74
+ spinnerGradientSetting.set(on);
85
75
  applySpinnerPreset(activeWorkingUi(), activeWorkingTheme());
86
76
  }
87
77
 
88
- /**
89
- * Publish the choice for this process, write it to `arnative-config.json`, and install it on
90
- * the running session right away — the picker previews by moving the cursor, so a choice that
91
- * only took effect on the next `session_start` would look like the selection did nothing.
92
- */
78
+ /** Publish the choice for this process, write it to config, and install it on the running session. */
93
79
  export function setSpinnerPreset(preset: SpinnerPreset): void {
94
- (globalThis as Record<symbol, unknown>)[SPINNER_PRESET_CONFIG_KEY] = preset;
95
- saveChoice(SPINNER_PRESET_KEY, preset);
80
+ spinnerPresetSetting.set(preset);
96
81
  applySpinnerPreset(activeWorkingUi(), activeWorkingTheme());
97
82
  }
98
83