@bismawy/pi-arnative 0.10.0 → 0.10.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.10.1] - 2026-11-11
4
+
5
+ ### Fixed
6
+ - Manual Model heal shows a start notice and live progress for flags, catalogs, and thinking probes. Final results now include partial failures.
7
+ - Manual Model heal now cancels on session reload or replacement. Model refresh captures the current model before awaiting and uses the bound extension API.
8
+ - Model heal now respects the one-hour cooldown after a failed effort probe. Reordering thinking map keys no longer triggers another probe.
9
+ - Failed model catalogs now wait one hour before an automatic retry. Successful catalogs keep their six-hour TTL; forced heals and endpoint changes bypass the cooldown.
10
+
3
11
  ## [Unreleased]
4
12
 
5
13
  ## [0.10.0] - 2026-11-08
package/README.md CHANGED
@@ -32,7 +32,7 @@ Saved to `~/.pi/agent/arnative/config.json` via `/arnative`:
32
32
  - **Headers & Footers:** `Arnative (Full)` (default), `Arnative (Minimal)` (footer only; click head text or press `ctrl+alt+m` to toggle), or `Pi (system)`.
33
33
  - **Animations:** 18 presets (`Arnative` default, `Pi (system)`, and alphabetical variants). Press `[g]` in the picker to toggle the Google gradient sweep.
34
34
  - **Auto-compact:** Off by default. **Smart** tiers trigger near ~200k tokens (`≥768k→20%`, `≥384k→40%`, `≥192k→80%`, `<192k→pi core`), or pick a fixed budget (`100k` to `400k`).
35
- - **Model heal:** **Full** (default: offline compat flags, `GET /models` limits with 6h TTL, reasoning effort probe with 24h TTL), **Flags** (offline only), or **Off**. Hand-edited fields are never overwritten.
35
+ - **Model heal:** **Full** (default: offline compat flags, `GET /models` limits with a 6h TTL, reasoning effort probe with a 24h TTL, and a failed fetch of either 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.
36
36
  - **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 `[click to expand]` / `[click to collapse]` 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).
37
37
 
38
38
  </details>
@@ -33,7 +33,7 @@ import {
33
33
  setAutoCompact,
34
34
  type AutoCompactChoice,
35
35
  } from "./autocompact.ts";
36
- import { healNow } from "./model-heal.ts";
36
+ import { cancelManualHeal, healNow } from "./model-heal.ts";
37
37
  import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type ModelHealChoice } from "../lib/model-heal.ts";
38
38
  import { LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../lib/list-picker.ts";
39
39
  import { openProviders } from "../lib/provider.ts";
@@ -563,6 +563,7 @@ export default function (pi: ExtensionAPI) {
563
563
  ctx.ui.setTheme(DEFAULT_THEME);
564
564
  });
565
565
  bindSetModel((model) => pi.setModel(model as never));
566
+ pi.on("session_shutdown", () => cancelManualHeal());
566
567
  registerCommands(pi);
567
568
  for (const key of SHORTCUT_OPEN_ARNATIVE.keys) {
568
569
  pi.registerShortcut(key, {
@@ -9,7 +9,7 @@
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
+ import { bindSetModel, reloadCurrentModel } from "../lib/provider.ts";
13
13
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
14
14
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
15
15
  import { type FSWatcher, watch } from "node:fs";
@@ -80,6 +80,7 @@ export function healAllowed(need: "Flags" | "Full", mode: ModelHealChoice, autoC
80
80
  export const deferNotice = (mode: ModelHealChoice, autoCompat: boolean): boolean => mode !== "Off" && autoCompat;
81
81
 
82
82
  export default function registerModelHeal(pi: ExtensionAPI): void {
83
+ bindSetModel((model) => pi.setModel(model as never));
83
84
  let watcher: FSWatcher | undefined;
84
85
  let timer: ReturnType<typeof setTimeout> | undefined;
85
86
  let widgetTimer: ReturnType<typeof setTimeout> | undefined;
@@ -215,6 +216,7 @@ export default function registerModelHeal(pi: ExtensionAPI): void {
215
216
  });
216
217
 
217
218
  pi.on("session_shutdown", () => {
219
+ cancelManualHeal();
218
220
  stopWatcher();
219
221
  if (widgetTimer) clearTimeout(widgetTimer);
220
222
  widgetTimer = undefined;
@@ -223,27 +225,73 @@ export default function registerModelHeal(pi: ExtensionAPI): void {
223
225
  registerCommands(pi, (_args, ctx) => healNow(ctx));
224
226
  }
225
227
 
228
+ let manualHeal: { controller: AbortController; ui: ExtensionContext["ui"] } | undefined;
229
+
230
+ /** Both the command extension and the settings extension cancel their own imported runner. */
231
+ export function cancelManualHeal(): void {
232
+ const run = manualHeal;
233
+ manualHeal = undefined;
234
+ if (!run) return;
235
+ run.controller.abort();
236
+ run.ui.setWidget("model-heal-progress", undefined);
237
+ }
238
+
226
239
  /** Every pass now, ignoring TTLs: the /model-heal command and the /arnative Run now row. */
227
240
  export async function healNow(ctx: ExtensionContext): Promise<void> {
241
+ const ui = ctx.ui;
228
242
  if (autoCompatInstalled()) {
229
- ctx.ui.notify("[arnative] pi-auto-compat is installed and heals models.json. Run /auto-compat, or uninstall it to use model heal.", "warning");
243
+ ui.notify("[arnative] pi-auto-compat is installed and heals models.json. Run /auto-compat, or uninstall it to use model heal.", "warning");
230
244
  return;
231
245
  }
232
- const deps = depsFor(ctx);
233
- const flags = healFlags(deps, undefined, ctx.model as RtModel | undefined);
234
- const meta = await healMeta(deps, true);
235
- const effort = await healEffort(deps, true);
236
- const detail = [...flags.detail, ...meta.detail, ...effort.detail];
237
- const errors = [...flags.errors, ...meta.errors, ...effort.errors];
238
- if (detail.length > 0) {
239
- await reloadCurrentModel(ctx as never, (m) => pi.setModel(m as never)).catch(() => undefined);
240
- ctx.ui.notify("[arnative] Model heal fixed:\n - " + detail.join("\n - "), "info");
246
+ if (manualHeal) {
247
+ ui.notify("[arnative] Model heal is already running.", "warning");
241
248
  return;
242
249
  }
243
- ctx.ui.notify(
244
- errors.length ? "[arnative] Model heal: nothing to fix; " + errors.length + " endpoint(s) unreachable: " + errors.join("; ") : "[arnative] Model heal: nothing to fix.",
245
- errors.length ? "warning" : "info",
246
- );
250
+ const registry = ctx.modelRegistry;
251
+ const current = ctx.model as RtModel | undefined;
252
+ const controller = new AbortController();
253
+ manualHeal = { controller, ui };
254
+ try {
255
+ ui.notify("[arnative] Model heal started (forced). Thinking probes can use paid tokens.", "info");
256
+ ui.setWidget("model-heal-progress", [HEAL_ICON + " model-heal: [1/3] Offline compat flags"]);
257
+ const deps: HealDeps = {
258
+ ...depsFor({ modelRegistry: registry }),
259
+ signal: controller.signal,
260
+ fetchImpl: (input, init) => {
261
+ controller.signal.throwIfAborted();
262
+ return fetch(input, { ...init, signal: AbortSignal.any([controller.signal, ...(init?.signal ? [init.signal] : [])]) });
263
+ },
264
+ };
265
+ const flags = healFlags(deps, undefined, current);
266
+ ui.setWidget("model-heal-progress", [HEAL_ICON + " model-heal: [2/3] Fetching /models catalogs"]);
267
+ const meta = await healMeta(deps, true);
268
+ controller.signal.throwIfAborted();
269
+ ui.setWidget("model-heal-progress", [HEAL_ICON + " model-heal: [3/3] Probing thinking levels (may use paid tokens)"]);
270
+ const effort = await healEffort(deps, true);
271
+ controller.signal.throwIfAborted();
272
+ const detail = [...flags.detail, ...meta.detail, ...effort.detail];
273
+ const errors = [...flags.errors, ...meta.errors, ...effort.errors];
274
+ if (detail.length > 0) {
275
+ ui.setWidget("model-heal-progress", [HEAL_ICON + " model-heal: Refreshing current model"]);
276
+ const loaded = await reloadCurrentModel({ modelRegistry: registry, model: current }, undefined, controller.signal);
277
+ controller.signal.throwIfAborted();
278
+ ui.notify("[arnative] Model heal fixed:\n - " + detail.join("\n - ")
279
+ + (errors.length ? "\nWarnings:\n - " + errors.join("\n - ") : "")
280
+ + (loaded ? "" : "\nRun /reload to load these changes."), errors.length || !loaded ? "warning" : "info");
281
+ return;
282
+ }
283
+ ui.notify(
284
+ errors.length ? "[arnative] Model heal: nothing to fix; " + errors.length + " issue(s): " + errors.join("; ") : "[arnative] Model heal: nothing to fix.",
285
+ errors.length ? "warning" : "info",
286
+ );
287
+ } catch (error) {
288
+ if (!controller.signal.aborted || error !== controller.signal.reason) throw error;
289
+ } finally {
290
+ if (manualHeal?.controller === controller) {
291
+ manualHeal = undefined;
292
+ ui.setWidget("model-heal-progress", undefined);
293
+ }
294
+ }
247
295
  }
248
296
 
249
297
  function registerCommands(pi: ExtensionAPI, runNow: (args: string, ctx: ExtensionContext) => Promise<void>): void {
package/lib/model-heal.ts CHANGED
@@ -69,6 +69,7 @@ export interface HealDeps {
69
69
  * models.json, so only `modelOverrides` reaches the merged model. */
70
70
  ownsModels: (provider: string) => boolean;
71
71
  fetchImpl?: typeof fetch;
72
+ signal?: AbortSignal;
72
73
  }
73
74
 
74
75
  export interface HealResult {
@@ -88,6 +89,7 @@ export const DEFAULT_THINKING_MAP = { low: "low", medium: "medium", high: "high"
88
89
 
89
90
  const HOUR_MS = 60 * 60 * 1000;
90
91
  const META_TTL_MS = 6 * HOUR_MS;
92
+ const META_FAILURE_TTL_MS = HOUR_MS;
91
93
  const META_TIMEOUT_MS = 8000;
92
94
  const META_MAX_BYTES = 2 * 1024 * 1024;
93
95
  const EFFORT_TTL_MS = 24 * HOUR_MS;
@@ -254,7 +256,7 @@ export function healFlags(deps: HealDeps, only?: RtModel[], active?: RtModel): H
254
256
 
255
257
  interface HealState {
256
258
  schema: 1;
257
- providers: Record<string, { signature: string; fetchedAt: number }>;
259
+ providers: Record<string, { signature: string; fetchedAt: number; failed?: boolean }>;
258
260
  sources: Record<string, { contextWindow?: number; maxTokens?: number; at: number }>;
259
261
  efforts: Record<string, { at: number; map: Record<string, string | null>; failed?: boolean; exact?: boolean }>;
260
262
  }
@@ -385,15 +387,22 @@ export async function healMeta(deps: HealDeps, force: boolean): Promise<HealResu
385
387
  const errors: string[] = [];
386
388
  const fetched = new Map<string, { meta: Map<string, ModelMeta>; signature: string }>();
387
389
  for (const channel of channelsOf(cfg, deps)) {
390
+ deps.signal?.throwIfAborted();
388
391
  const signature = JSON.stringify({ baseUrl: channel.baseUrl, ids: channel.ids });
389
392
  const prev = state.providers[channel.provider];
390
- if (!force && prev?.signature === signature && now - prev.fetchedAt < META_TTL_MS) continue;
393
+ if (!force && prev?.signature === signature && now - prev.fetchedAt < (prev.failed ? META_FAILURE_TTL_MS : META_TTL_MS)) continue;
391
394
  try {
392
- fetched.set(channel.provider, { meta: await fetchMeta(channel, deps.fetchImpl ?? fetch), signature });
395
+ const meta = await fetchMeta(channel, deps.fetchImpl ?? fetch);
396
+ deps.signal?.throwIfAborted();
397
+ fetched.set(channel.provider, { meta, signature });
393
398
  } catch (error) {
399
+ deps.signal?.throwIfAborted();
394
400
  errors.push(`${channel.provider}: ${errText(error)}`);
401
+ state.providers[channel.provider] = { signature, fetchedAt: Date.now(), failed: true };
395
402
  }
396
403
  }
404
+ // A failed endpoint needs a cooldown even when no catalog answered.
405
+ if (errors.length > 0) saveState({ providers: state.providers });
397
406
  if (fetched.size === 0) return { changed: false, detail: [], errors };
398
407
 
399
408
  const byProvider = groupByProvider(deps.models());
@@ -484,9 +493,9 @@ export async function healEffort(deps: HealDeps, force: boolean, only?: RtModel[
484
493
  // older probe wrote (nearest-effort remaps) is redone now, not after the TTL.
485
494
  const probeWrote = prev !== undefined && sameMap(mapOf(m), prev.map);
486
495
  if (carriesRemap(mapOf(m)) && !probeWrote) return false;
487
- if (force || !prev || (probeWrote && prev.exact !== true)) return true;
496
+ if (force || !prev || (probeWrote && !prev.failed && prev.exact !== true)) return true;
488
497
  if (now - prev.at >= (prev.failed ? EFFORT_FAILURE_TTL_MS : EFFORT_TTL_MS)) return true;
489
- return JSON.stringify(mapOf(m) ?? {}) !== JSON.stringify(prev.map); // edited since: respect it
498
+ return !sameMap(mapOf(m), prev.map);
490
499
  });
491
500
  if (pending.length === 0) return none();
492
501
 
@@ -494,6 +503,7 @@ export async function healEffort(deps: HealDeps, force: boolean, only?: RtModel[
494
503
  const answered: { model: RtModel; supported: string[] }[] = [];
495
504
  const deadline = now + EFFORT_BUDGET_MS;
496
505
  for (const model of pending) {
506
+ deps.signal?.throwIfAborted();
497
507
  if (Date.now() >= deadline) {
498
508
  errors.push(`${model.provider}: probe budget exhausted`);
499
509
  break;
@@ -503,6 +513,7 @@ export async function healEffort(deps: HealDeps, force: boolean, only?: RtModel[
503
513
  { ...model, compat: { ...channel.compat, ...(model.compat ?? {}) } },
504
514
  { baseUrl: channel.baseUrl, key: channel.key(), headers: channel.headers, fetchImpl: deps.fetchImpl },
505
515
  );
516
+ deps.signal?.throwIfAborted();
506
517
  if (supported.length === 0) {
507
518
  // Stamped as failed so the next run waits the short TTL instead of re-sending.
508
519
  errors.push(`${model.provider}/${model.id}: no level answered (not patched)`);
package/lib/provider.ts CHANGED
@@ -753,11 +753,13 @@ export const bindSetModel = (fn: SetModel): void => {
753
753
  /** Load models.json into the running session. A registry refresh alone is not enough: pi keeps
754
754
  * the session model object (and its thinkingLevelMap) until the model is picked again, so
755
755
  * /thinking kept offering the old levels even after /reload. */
756
- export async function reloadCurrentModel(ctx: { modelRegistry?: RegistryRef; model?: ModelRef }, setModel: SetModel | undefined = setSessionModel): Promise<boolean> {
756
+ export async function reloadCurrentModel(ctx: { modelRegistry?: RegistryRef; model?: ModelRef }, setModel: SetModel | undefined = setSessionModel, signal?: AbortSignal): Promise<boolean> {
757
+ signal?.throwIfAborted();
757
758
  const registry = ctx.modelRegistry;
758
759
  if (!registry) return false;
759
- await registry.refresh({ allowNetwork: false });
760
760
  const current = ctx.model;
761
+ await registry.refresh({ allowNetwork: false });
762
+ signal?.throwIfAborted();
761
763
  if (!current) return true;
762
764
  const fresh = registry.find(current.provider, current.id);
763
765
  if (!fresh || fresh === current) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bismawy/pi-arnative",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
5
5
  "keywords": [
6
6
  "pi-package",