@sooneocean/claude-hud 0.6.0 → 0.8.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/src/presets.ts ADDED
@@ -0,0 +1,56 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import type { HudConfig } from './config.js';
4
+
5
+ const DEBUG = process.env.DEBUG?.includes('claude-hud') || process.env.DEBUG === '*';
6
+
7
+ interface Preset {
8
+ name: string;
9
+ description: string;
10
+ config: Partial<HudConfig>;
11
+ createdAt: string;
12
+ }
13
+
14
+ function getPresetsPath(): string {
15
+ const configDir = process.env.CLAUDE_CONFIG_DIR || path.join(process.env.HOME || '', '.claude');
16
+ return path.join(configDir, 'plugins', 'claude-hud', 'presets.json');
17
+ }
18
+
19
+ export function loadPresets(): Preset[] {
20
+ try {
21
+ return JSON.parse(fs.readFileSync(getPresetsPath(), 'utf-8'));
22
+ } catch {
23
+ return [];
24
+ }
25
+ }
26
+
27
+ export function savePreset(name: string, description: string, config: Partial<HudConfig>): void {
28
+ const presets = loadPresets();
29
+ const existing = presets.findIndex(p => p.name === name);
30
+ const preset: Preset = { name, description, config, createdAt: new Date().toISOString() };
31
+ if (existing >= 0) presets[existing] = preset;
32
+ else presets.push(preset);
33
+
34
+ const dir = path.dirname(getPresetsPath());
35
+ fs.mkdirSync(dir, { recursive: true });
36
+ fs.writeFileSync(getPresetsPath(), JSON.stringify(presets, null, 2));
37
+ if (DEBUG) console.error(`[claude-hud:presets] saved preset "${name}"`);
38
+ }
39
+
40
+ export function getPreset(name: string): Preset | undefined {
41
+ return loadPresets().find(p => p.name === name);
42
+ }
43
+
44
+ export function deletePreset(name: string): boolean {
45
+ const presets = loadPresets();
46
+ const idx = presets.findIndex(p => p.name === name);
47
+ if (idx < 0) return false;
48
+ presets.splice(idx, 1);
49
+ fs.writeFileSync(getPresetsPath(), JSON.stringify(presets, null, 2));
50
+ if (DEBUG) console.error(`[claude-hud:presets] deleted preset "${name}"`);
51
+ return true;
52
+ }
53
+
54
+ export function exportPresetAsJson(preset: Preset): string {
55
+ return JSON.stringify(preset, null, 2);
56
+ }
@@ -12,6 +12,7 @@ export interface SessionRecord {
12
12
  autocompactCount: number;
13
13
  totalToolCalls: number;
14
14
  totalAgentRuns: number;
15
+ tags?: string[];
15
16
  }
16
17
 
17
18
  function getHistoryPath(): string {
@@ -57,6 +58,24 @@ export function getLastSession(): SessionRecord | null {
57
58
  return history.length >= 2 ? history[history.length - 2] : null;
58
59
  }
59
60
 
61
+ export function tagCurrentSession(tags: string[], _cacheDir: string): void {
62
+ const history = loadHistory();
63
+ if (history.length === 0) return;
64
+
65
+ // Tag the most recent session
66
+ const last = history[history.length - 1];
67
+ last.tags = [...new Set([...(last.tags || []), ...tags])];
68
+
69
+ const dir = path.dirname(getHistoryPath());
70
+ fs.mkdirSync(dir, { recursive: true });
71
+ fs.writeFileSync(getHistoryPath(), JSON.stringify(history, null, 2));
72
+ if (DEBUG) console.error(`[claude-hud:session-history] tagged session with: ${tags.join(', ')}`);
73
+ }
74
+
75
+ export function getSessionsByTag(tag: string): SessionRecord[] {
76
+ return loadHistory().filter(s => s.tags?.includes(tag));
77
+ }
78
+
60
79
  export function formatSessionSummary(record: SessionRecord): string {
61
80
  return `Last: ${record.model} ${record.duration} | ${record.peakContextPercent}% peak | ${record.totalToolCalls} tools | ${record.autocompactCount} compacts`;
62
81
  }