@xynogen/pix-data 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-data",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Pi extension — shared model data layer (models.dev + BenchLM), cached at ~/.cache/pi",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/data.test.ts CHANGED
@@ -100,33 +100,25 @@ describe("lookupInIndex", () => {
100
100
  ]);
101
101
 
102
102
  it("finds exact match", () => {
103
- expect(lookupInIndex("claude-sonnet-4-5", index)?.name).toBe(
104
- "Claude Sonnet 4.5",
105
- );
103
+ expect(lookupInIndex("claude-sonnet-4-5", index)?.name).toBe("Claude Sonnet 4.5");
106
104
  });
107
105
 
108
106
  it("strips provider prefix (provider/model)", () => {
109
- expect(lookupInIndex("anthropic/claude-opus-4", index)?.name).toBe(
110
- "Claude Opus 4",
111
- );
107
+ expect(lookupInIndex("anthropic/claude-opus-4", index)?.name).toBe("Claude Opus 4");
112
108
  });
113
109
 
114
110
  it("strips deep prefix (cc/model)", () => {
115
- expect(lookupInIndex("cc/claude-opus-4", index)?.name).toBe(
116
- "Claude Opus 4",
117
- );
111
+ expect(lookupInIndex("cc/claude-opus-4", index)?.name).toBe("Claude Opus 4");
118
112
  });
119
113
 
120
114
  it("strips date suffix", () => {
121
- expect(lookupInIndex("claude-sonnet-4-5-20250514", index)?.name).toBe(
122
- "Claude Sonnet 4.5",
123
- );
115
+ expect(lookupInIndex("claude-sonnet-4-5-20250514", index)?.name).toBe("Claude Sonnet 4.5");
124
116
  });
125
117
 
126
118
  it("strips provider prefix + date suffix", () => {
127
- expect(
128
- lookupInIndex("anthropic/claude-sonnet-4-5-20250514", index)?.name,
129
- ).toBe("Claude Sonnet 4.5");
119
+ expect(lookupInIndex("anthropic/claude-sonnet-4-5-20250514", index)?.name).toBe(
120
+ "Claude Sonnet 4.5",
121
+ );
130
122
  });
131
123
 
132
124
  it("returns undefined for unknown model", () => {
@@ -183,10 +175,7 @@ describe("modelgrep adapters", () => {
183
175
  });
184
176
 
185
177
  it("lookupModelsDev finds hy3 via prefix + suffix strip", () => {
186
- expect(
187
- lookupModelsDev("openrouter", "tencent/hy3-preview:nitro")?.limit
188
- ?.context,
189
- ).toBe(256000);
178
+ expect(lookupModelsDev("openrouter", "tencent/hy3-preview:nitro")?.limit?.context).toBe(256000);
190
179
  });
191
180
 
192
181
  it("lookupModelsDev returns undefined for unknown model", () => {
@@ -251,8 +240,7 @@ describe("benchlm fallback", () => {
251
240
 
252
241
  beforeEach(() => {
253
242
  (modelgrep as unknown as { _mem: ModelGrepModel[] })._mem = catalog;
254
- (benchlm as unknown as { _mem: typeof benchlmEntries })._mem =
255
- benchlmEntries;
243
+ (benchlm as unknown as { _mem: typeof benchlmEntries })._mem = benchlmEntries;
256
244
  });
257
245
  afterEach(() => {
258
246
  (modelgrep as unknown as { _mem: ModelGrepModel[] | null })._mem = null;
@@ -293,14 +281,11 @@ describe("modelgrep AA primary wins over benchlm", () => {
293
281
  bench: { intelligence: 60 }, // AA index: 60/65 → 92
294
282
  }),
295
283
  ];
296
- const benchlmEntries = [
297
- { rank: 1, model: "Claude Opus 4.8", overallScore: 50 },
298
- ];
284
+ const benchlmEntries = [{ rank: 1, model: "Claude Opus 4.8", overallScore: 50 }];
299
285
 
300
286
  beforeEach(() => {
301
287
  (modelgrep as unknown as { _mem: ModelGrepModel[] })._mem = catalog;
302
- (benchlm as unknown as { _mem: typeof benchlmEntries })._mem =
303
- benchlmEntries;
288
+ (benchlm as unknown as { _mem: typeof benchlmEntries })._mem = benchlmEntries;
304
289
  });
305
290
  afterEach(() => {
306
291
  (modelgrep as unknown as { _mem: ModelGrepModel[] | null })._mem = null;
package/src/data.ts CHANGED
@@ -40,10 +40,7 @@ export interface ModelsDevModel {
40
40
  };
41
41
  }
42
42
 
43
- export type ModelsDevApi = Record<
44
- string,
45
- { models?: Record<string, ModelsDevModel> }
46
- >;
43
+ export type ModelsDevApi = Record<string, { models?: Record<string, ModelsDevModel> }>;
47
44
 
48
45
  export interface BenchmarkEntry {
49
46
  rank: number;
@@ -158,13 +155,8 @@ export class DataSource<T> {
158
155
  return val;
159
156
  }
160
157
  try {
161
- const url =
162
- typeof this.opts.url === "function" ? this.opts.url() : this.opts.url;
163
- const raw = await this.opts.fetchRaw(
164
- url,
165
- this.opts.headers(),
166
- this.opts.timeoutMs,
167
- );
158
+ const url = typeof this.opts.url === "function" ? this.opts.url() : this.opts.url;
159
+ const raw = await this.opts.fetchRaw(url, this.opts.headers(), this.opts.timeoutMs);
168
160
  const val = this.opts.parse(raw);
169
161
  this._mem = val;
170
162
  void this._writeCache(raw);
@@ -172,9 +164,7 @@ export class DataSource<T> {
172
164
  } catch (error) {
173
165
  const msg = error instanceof Error ? error.message : String(error);
174
166
  if (cached !== undefined) {
175
- console.warn(
176
- `${this.opts.label} fetch failed, using stale cache: ${msg}`,
177
- );
167
+ console.warn(`${this.opts.label} fetch failed, using stale cache: ${msg}`);
178
168
  const val = this.opts.parseCache(cached.data);
179
169
  this._mem = val;
180
170
  return val;
@@ -184,9 +174,7 @@ export class DataSource<T> {
184
174
  }
185
175
  }
186
176
 
187
- private async _readCache(): Promise<
188
- { ts: number; data: unknown } | undefined
189
- > {
177
+ private async _readCache(): Promise<{ ts: number; data: unknown } | undefined> {
190
178
  try {
191
179
  const raw = await readFile(this.opts.cachePath, "utf8");
192
180
  const parsed = JSON.parse(raw) as { ts: number; data: unknown };
@@ -200,10 +188,7 @@ export class DataSource<T> {
200
188
  private async _writeCache(data: unknown): Promise<void> {
201
189
  try {
202
190
  await mkdir(dirname(this.opts.cachePath), { recursive: true });
203
- await writeFile(
204
- this.opts.cachePath,
205
- JSON.stringify({ ts: Date.now(), data }),
206
- );
191
+ await writeFile(this.opts.cachePath, JSON.stringify({ ts: Date.now(), data }));
207
192
  } catch {
208
193
  // Write failure is non-fatal — stale cache used on next run
209
194
  }
@@ -217,9 +202,7 @@ function fetchWithTimeout(
217
202
  ): Promise<Response> {
218
203
  const controller = new AbortController();
219
204
  const timer = setTimeout(() => controller.abort(), timeoutMs);
220
- return fetch(url, { signal: controller.signal, headers }).finally(() =>
221
- clearTimeout(timer),
222
- );
205
+ return fetch(url, { signal: controller.signal, headers }).finally(() => clearTimeout(timer));
223
206
  }
224
207
 
225
208
  /** Single-request raw fetch — the default DataSource fetch strategy. */
@@ -270,10 +253,7 @@ async function fetchModelGrepAll(
270
253
 
271
254
  // ── Cache dir ─────────────────────────────────────────────────────────────────
272
255
 
273
- export const CACHE_DIR = join(
274
- process.env.XDG_CACHE_HOME || join(homedir(), ".cache"),
275
- "pi",
276
- );
256
+ export const CACHE_DIR = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "pi");
277
257
 
278
258
  // ── Data sources ──────────────────────────────────────────────────────────────
279
259
 
@@ -375,9 +355,7 @@ function toModelsDevModel(g: ModelGrepModel): ModelsDevModel {
375
355
  };
376
356
  }
377
357
 
378
- export function buildModelsDevIndex(
379
- source: ModelGrepModel[],
380
- ): Map<string, ModelsDevModel> {
358
+ export function buildModelsDevIndex(source: ModelGrepModel[]): Map<string, ModelsDevModel> {
381
359
  const index = new Map<string, ModelsDevModel>();
382
360
  for (const g of source) {
383
361
  const m = toModelsDevModel(g);
@@ -388,18 +366,13 @@ export function buildModelsDevIndex(
388
366
  return index;
389
367
  }
390
368
 
391
- export function lookupModelsDev(
392
- _provider: string,
393
- id: string,
394
- ): ModelsDevModel | undefined {
369
+ export function lookupModelsDev(_provider: string, id: string): ModelsDevModel | undefined {
395
370
  // Provider prefix differs between Pi routing (cc/ds/openrouter) and modelgrep
396
371
  // (anthropic/tencent), so join on the model slug only via the normalized index.
397
372
  return findInIndex(id, buildModelsDevIndex(modelgrep.getCached()));
398
373
  }
399
374
 
400
- export async function fetchModelsDevIndex(): Promise<
401
- Map<string, ModelsDevModel>
402
- > {
375
+ export async function fetchModelsDevIndex(): Promise<Map<string, ModelsDevModel>> {
403
376
  return buildModelsDevIndex(await modelgrep.get());
404
377
  }
405
378
 
@@ -438,9 +411,7 @@ const clamp01to100 = (x: number) => Math.max(0, Math.min(100, x));
438
411
  // agentic-heavy (.60) since tool-call matters most, coding (.30), reasoning a
439
412
  // .10 tiebreaker. Sub-weights likewise fit — tau2 dominates the agentic group.
440
413
  function heuristicScore(
441
- aa: NonNullable<
442
- NonNullable<ModelGrepModel["benchmarks"]>["artificial_analysis"]
443
- >,
414
+ aa: NonNullable<NonNullable<ModelGrepModel["benchmarks"]>["artificial_analysis"]>,
444
415
  ): number | null {
445
416
  const coding = blend([
446
417
  [0.6, frac(aa.coding)],
@@ -464,17 +435,13 @@ function heuristicScore(
464
435
  // Model score 0–100. Prefer AA's Intelligence Index (authoritative 9-eval
465
436
  // composite); when absent, map our heuristic onto the index scale via the
466
437
  // fitted line. Null only when nothing is benchmarked.
467
- function codingScore(
468
- bench: NonNullable<ModelGrepModel["benchmarks"]>,
469
- ): number | null {
438
+ function codingScore(bench: NonNullable<ModelGrepModel["benchmarks"]>): number | null {
470
439
  const aa = bench.artificial_analysis ?? {};
471
440
  if (aa.intelligence != null) {
472
441
  return Math.round((aa.intelligence / INTELLIGENCE_MAX) * 100);
473
442
  }
474
443
  const h = heuristicScore(aa);
475
- return h == null
476
- ? null
477
- : Math.round(clamp01to100(FALLBACK_SLOPE * h + FALLBACK_INTERCEPT));
444
+ return h == null ? null : Math.round(clamp01to100(FALLBACK_SLOPE * h + FALLBACK_INTERCEPT));
478
445
  }
479
446
 
480
447
  function buildBenchIndex(): Map<string, BenchmarkEntry> {
@@ -508,8 +475,7 @@ function buildBenchIndex(): Map<string, BenchmarkEntry> {
508
475
  inputPrice: g.pricing?.input ?? null,
509
476
  outputPrice: g.pricing?.output ?? null,
510
477
  };
511
- for (const k of [slug, normalize(slug)])
512
- if (!index.has(k)) index.set(k, entry);
478
+ for (const k of [slug, normalize(slug)]) if (!index.has(k)) index.set(k, entry);
513
479
  });
514
480
  return index;
515
481
  }
@@ -544,8 +510,7 @@ function lookupBenchlmScore(
544
510
  if (direct) candidates.push(...direct);
545
511
  for (const [key, entries] of benchlmByNorm) {
546
512
  if (key === norm) continue;
547
- if (key.startsWith(norm) || norm.startsWith(key))
548
- candidates.push(...entries);
513
+ if (key.startsWith(norm) || norm.startsWith(key)) candidates.push(...entries);
549
514
  }
550
515
  if (candidates.length === 0) return null;
551
516
 
@@ -555,10 +520,7 @@ function lookupBenchlmScore(
555
520
  const sa = a.overallScore ?? -Infinity;
556
521
  const sb = b.overallScore ?? -Infinity;
557
522
  if (sa !== sb) return sb - sa;
558
- return (
559
- normalizeBenchlmName(a.model).length -
560
- normalizeBenchlmName(b.model).length
561
- );
523
+ return normalizeBenchlmName(a.model).length - normalizeBenchlmName(b.model).length;
562
524
  });
563
525
  const best = sorted[0];
564
526
  if (!best) return null;
package/src/pix-config.ts CHANGED
@@ -208,10 +208,7 @@ function mergeDiff(raw: unknown): DiffColors {
208
208
  if (!isObj(raw)) return { ...DEFAULT_DIFF };
209
209
  return {
210
210
  splitMinWidth: num(raw.splitMinWidth, DEFAULT_DIFF.splitMinWidth),
211
- splitMinCodeWidth: num(
212
- raw.splitMinCodeWidth,
213
- DEFAULT_DIFF.splitMinCodeWidth,
214
- ),
211
+ splitMinCodeWidth: num(raw.splitMinCodeWidth, DEFAULT_DIFF.splitMinCodeWidth),
215
212
  bgAdd: str(raw.bgAdd, DEFAULT_DIFF.bgAdd),
216
213
  bgDel: str(raw.bgDel, DEFAULT_DIFF.bgDel),
217
214
  bgAddHighlight: str(raw.bgAddHighlight, DEFAULT_DIFF.bgAddHighlight),
@@ -230,10 +227,7 @@ function mergePretty(raw: unknown): PrettyConfig {
230
227
  icons: str(raw.icons, DEFAULT_PRETTY.icons),
231
228
  maxPreviewLines: num(raw.maxPreviewLines, DEFAULT_PRETTY.maxPreviewLines),
232
229
  maxRenderLines: num(raw.maxRenderLines, DEFAULT_PRETTY.maxRenderLines),
233
- maxHighlightChars: num(
234
- raw.maxHighlightChars,
235
- DEFAULT_PRETTY.maxHighlightChars,
236
- ),
230
+ maxHighlightChars: num(raw.maxHighlightChars, DEFAULT_PRETTY.maxHighlightChars),
237
231
  cacheLimit: num(raw.cacheLimit, DEFAULT_PRETTY.cacheLimit),
238
232
  diff: mergeDiff(raw.diff),
239
233
  };