@pi-unipi/core 0.1.10 → 0.1.11

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/constants.ts CHANGED
@@ -158,9 +158,10 @@ export const UTILITY_COMMANDS = {
158
158
  CLEANUP: "cleanup",
159
159
  ENV: "env",
160
160
  DOCTOR: "doctor",
161
- NAME_BADGE: "name-badge",
161
+ BADGE_NAME: "badge-name",
162
162
  BADGE_GEN: "badge-gen",
163
163
  BADGE_TOGGLE: "badge-toggle",
164
+ BADGE_SETTINGS: "badge-settings",
164
165
  } as const;
165
166
 
166
167
  /** Utility tool names */
@@ -247,7 +248,6 @@ export const COMPACTOR_DIRS = {
247
248
  export const KANBOARD_COMMANDS = {
248
249
  KANBOARD: "kanboard",
249
250
  KANBOARD_DOCTOR: "kanboard-doctor",
250
- NAME_GEN: "name-gen",
251
251
  } as const;
252
252
 
253
253
  /** Kanboard directory paths */
package/index.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./constants.js";
8
8
  export * from "./events.js";
9
9
  export * from "./sandbox.js";
10
10
  export * from "./utils.js";
11
+ export * from "./model-cache.js";
package/model-cache.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @pi-unipi/core — Model Cache
3
+ *
4
+ * File-based model list cache at ~/.unipi/config/models-cache.json.
5
+ * Allows TUI components and other packages to list available models
6
+ * without needing ctx.modelRegistry at runtime.
7
+ */
8
+
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+
12
+ /** Path to the model cache directory */
13
+ const CACHE_DIR = path.join(
14
+ process.env.HOME ?? process.env.USERPROFILE ?? "~",
15
+ ".unipi/config",
16
+ );
17
+
18
+ /** Path to the model cache file */
19
+ const CACHE_FILE = path.join(CACHE_DIR, "models-cache.json");
20
+
21
+ /** A single cached model entry */
22
+ export interface CachedModel {
23
+ /** Model provider (e.g. "openai", "anthropic") */
24
+ provider: string;
25
+ /** Model ID (e.g. "gpt-4o", "claude-sonnet-4-6") */
26
+ id: string;
27
+ /** Optional display name */
28
+ name?: string;
29
+ }
30
+
31
+ /** The full model cache structure */
32
+ export interface ModelCache {
33
+ /** ISO timestamp of last cache write */
34
+ updatedAt: string;
35
+ /** List of cached models */
36
+ models: CachedModel[];
37
+ }
38
+
39
+ /**
40
+ * Read cached model list from disk.
41
+ * Returns empty array if no cache file exists or it's malformed.
42
+ */
43
+ export function readModelCache(): CachedModel[] {
44
+ try {
45
+ if (!fs.existsSync(CACHE_FILE)) return [];
46
+ const parsed = JSON.parse(fs.readFileSync(CACHE_FILE, "utf-8"));
47
+ return Array.isArray(parsed.models) ? parsed.models : [];
48
+ } catch {
49
+ return [];
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Write model list to cache file.
55
+ * Creates directory if needed. Best effort — silently ignores errors.
56
+ */
57
+ export function writeModelCache(models: CachedModel[]): void {
58
+ try {
59
+ if (!fs.existsSync(CACHE_DIR)) {
60
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
61
+ }
62
+ const cache: ModelCache = {
63
+ updatedAt: new Date().toISOString(),
64
+ models,
65
+ };
66
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2) + "\n", "utf-8");
67
+ } catch {
68
+ // Best effort — cache is optional
69
+ }
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/core",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Shared utilities, event types, and constants for Unipi extension suite",
5
5
  "type": "module",
6
6
  "license": "MIT",