aiblueprint-cli 1.4.13 → 1.4.14

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 (25) hide show
  1. package/claude-code-config/scripts/CLAUDE.md +50 -0
  2. package/claude-code-config/scripts/biome.json +37 -0
  3. package/claude-code-config/scripts/bun.lockb +0 -0
  4. package/claude-code-config/scripts/package.json +39 -0
  5. package/claude-code-config/scripts/statusline/__tests__/context.test.ts +229 -0
  6. package/claude-code-config/scripts/statusline/__tests__/formatters.test.ts +108 -0
  7. package/claude-code-config/scripts/statusline/__tests__/statusline.test.ts +309 -0
  8. package/claude-code-config/scripts/statusline/data/.gitignore +8 -0
  9. package/claude-code-config/scripts/statusline/data/.gitkeep +0 -0
  10. package/claude-code-config/scripts/statusline/defaults.json +4 -0
  11. package/claude-code-config/scripts/statusline/docs/ARCHITECTURE.md +166 -0
  12. package/claude-code-config/scripts/statusline/fixtures/mock-transcript.jsonl +4 -0
  13. package/claude-code-config/scripts/statusline/fixtures/test-input.json +35 -0
  14. package/claude-code-config/scripts/statusline/src/index.ts +74 -0
  15. package/claude-code-config/scripts/statusline/src/lib/config-types.ts +4 -0
  16. package/claude-code-config/scripts/statusline/src/lib/menu-factories.ts +224 -0
  17. package/claude-code-config/scripts/statusline/src/lib/presets.ts +177 -0
  18. package/claude-code-config/scripts/statusline/src/lib/render-pure.ts +341 -21
  19. package/claude-code-config/scripts/statusline/src/lib/utils.ts +15 -0
  20. package/claude-code-config/scripts/statusline/src/tests/spend-v2.test.ts +306 -0
  21. package/claude-code-config/scripts/statusline/statusline.config.json +25 -39
  22. package/claude-code-config/scripts/statusline/test-with-fixtures.ts +37 -0
  23. package/claude-code-config/scripts/statusline/test.ts +20 -0
  24. package/claude-code-config/scripts/tsconfig.json +27 -0
  25. package/package.json +1 -1
@@ -0,0 +1,309 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import { renderStatusline, type StatuslineData } from "../src/index";
3
+ import { defaultConfig, type StatuslineConfig } from "../src/lib/config";
4
+
5
+ function createMockData(
6
+ overrides: Partial<StatuslineData> = {},
7
+ ): StatuslineData {
8
+ return {
9
+ branch: "main",
10
+ dirPath: "~/project",
11
+ modelName: "Sonnet 4.5",
12
+ sessionCost: "0.5",
13
+ sessionDuration: "10m",
14
+ contextTokens: 50000,
15
+ contextPercentage: 25,
16
+ usageLimits: {
17
+ five_hour: { utilization: 30, resets_at: "2025-01-01T15:00:00Z" },
18
+ seven_day: { utilization: 10, resets_at: "2025-01-07T00:00:00Z" },
19
+ },
20
+ periodCost: 1.5,
21
+ todayCost: 2.0,
22
+ ...overrides,
23
+ };
24
+ }
25
+
26
+ function createConfig(
27
+ overrides: Partial<StatuslineConfig> = {},
28
+ ): StatuslineConfig {
29
+ return { ...defaultConfig, ...overrides };
30
+ }
31
+
32
+ describe("renderStatusline", () => {
33
+ describe("basic rendering", () => {
34
+ it("should render branch and directory", () => {
35
+ const data = createMockData();
36
+ const config = createConfig();
37
+ const output = renderStatusline(data, config);
38
+
39
+ expect(output).toContain("main");
40
+ expect(output).toContain("~/project");
41
+ });
42
+
43
+ it("should hide Sonnet model name when showSonnetModel is false", () => {
44
+ const data = createMockData({ modelName: "Sonnet 4.5" });
45
+ const config = createConfig({ showSonnetModel: false });
46
+ const output = renderStatusline(data, config);
47
+
48
+ expect(output).not.toContain("Sonnet");
49
+ });
50
+
51
+ it("should show Sonnet model name when showSonnetModel is true", () => {
52
+ const data = createMockData({ modelName: "Sonnet 4.5" });
53
+ const config = createConfig({ showSonnetModel: true });
54
+ const output = renderStatusline(data, config);
55
+
56
+ expect(output).toContain("Sonnet");
57
+ });
58
+
59
+ it("should always show non-Sonnet models", () => {
60
+ const data = createMockData({ modelName: "Opus 4.5" });
61
+ const config = createConfig({ showSonnetModel: false });
62
+ const output = renderStatusline(data, config);
63
+
64
+ expect(output).toContain("Opus");
65
+ });
66
+ });
67
+
68
+ describe("session info", () => {
69
+ it("should show cost when enabled", () => {
70
+ const data = createMockData({ sessionCost: "1.5" });
71
+ const config = createConfig({
72
+ session: {
73
+ ...defaultConfig.session,
74
+ cost: { enabled: true, format: "decimal1" },
75
+ },
76
+ });
77
+ const output = renderStatusline(data, config);
78
+
79
+ expect(output).toContain("$");
80
+ expect(output).toContain("1.5");
81
+ });
82
+
83
+ it("should hide cost when disabled", () => {
84
+ const data = createMockData({ sessionCost: "1.5" });
85
+ const config = createConfig({
86
+ session: {
87
+ ...defaultConfig.session,
88
+ cost: { enabled: false, format: "decimal1" },
89
+ },
90
+ });
91
+ const output = renderStatusline(data, config);
92
+
93
+ expect(output).toContain("S:");
94
+ });
95
+
96
+ it("should show duration when enabled", () => {
97
+ const data = createMockData({ sessionDuration: "15m" });
98
+ const config = createConfig({
99
+ session: {
100
+ ...defaultConfig.session,
101
+ duration: { enabled: true },
102
+ },
103
+ });
104
+ const output = renderStatusline(data, config);
105
+
106
+ expect(output).toContain("15m");
107
+ });
108
+
109
+ it("should show percentage when enabled", () => {
110
+ const data = createMockData({ contextPercentage: 45 });
111
+ const config = createConfig({
112
+ session: {
113
+ ...defaultConfig.session,
114
+ percentage: {
115
+ enabled: true,
116
+ showValue: true,
117
+ progressBar: {
118
+ ...defaultConfig.session.percentage.progressBar,
119
+ enabled: false,
120
+ },
121
+ },
122
+ },
123
+ });
124
+ const output = renderStatusline(data, config);
125
+
126
+ expect(output).toContain("45");
127
+ expect(output).toContain("%");
128
+ });
129
+ });
130
+
131
+ describe("limits section", () => {
132
+ it("should show limits when enabled", () => {
133
+ const data = createMockData({
134
+ usageLimits: {
135
+ five_hour: { utilization: 50, resets_at: "2025-01-01T15:00:00Z" },
136
+ seven_day: null,
137
+ },
138
+ });
139
+ const config = createConfig({
140
+ limits: {
141
+ ...defaultConfig.limits,
142
+ enabled: true,
143
+ percentage: {
144
+ enabled: true,
145
+ showValue: true,
146
+ progressBar: {
147
+ ...defaultConfig.limits.percentage.progressBar,
148
+ enabled: false,
149
+ },
150
+ },
151
+ },
152
+ });
153
+ const output = renderStatusline(data, config);
154
+
155
+ expect(output).toContain("L:");
156
+ expect(output).toContain("50");
157
+ });
158
+
159
+ it("should hide limits when disabled", () => {
160
+ const data = createMockData();
161
+ const config = createConfig({
162
+ limits: { ...defaultConfig.limits, enabled: false },
163
+ });
164
+ const output = renderStatusline(data, config);
165
+
166
+ expect(output).not.toContain("L:");
167
+ });
168
+
169
+ it("should show reset time when enabled", () => {
170
+ const futureTime = new Date(Date.now() + 3600000).toISOString();
171
+ const data = createMockData({
172
+ usageLimits: {
173
+ five_hour: { utilization: 50, resets_at: futureTime },
174
+ seven_day: null,
175
+ },
176
+ });
177
+ const config = createConfig({
178
+ limits: {
179
+ ...defaultConfig.limits,
180
+ enabled: true,
181
+ showTimeLeft: true,
182
+ },
183
+ });
184
+ const output = renderStatusline(data, config);
185
+
186
+ expect(output).toMatch(/\(\d+[hm]/);
187
+ });
188
+ });
189
+
190
+ describe("weekly usage", () => {
191
+ it("should show weekly when enabled=true", () => {
192
+ const data = createMockData({
193
+ usageLimits: {
194
+ five_hour: { utilization: 30, resets_at: null },
195
+ seven_day: { utilization: 20, resets_at: null },
196
+ },
197
+ });
198
+ const config = createConfig({
199
+ weeklyUsage: {
200
+ ...defaultConfig.weeklyUsage,
201
+ enabled: true,
202
+ percentage: {
203
+ enabled: true,
204
+ showValue: true,
205
+ progressBar: {
206
+ ...defaultConfig.weeklyUsage.percentage.progressBar,
207
+ enabled: false,
208
+ },
209
+ },
210
+ },
211
+ });
212
+ const output = renderStatusline(data, config);
213
+
214
+ expect(output).toContain("W:");
215
+ });
216
+
217
+ it("should show weekly when enabled=90% and five_hour >= 90", () => {
218
+ const data = createMockData({
219
+ usageLimits: {
220
+ five_hour: { utilization: 95, resets_at: null },
221
+ seven_day: { utilization: 20, resets_at: null },
222
+ },
223
+ });
224
+ const config = createConfig({
225
+ weeklyUsage: {
226
+ ...defaultConfig.weeklyUsage,
227
+ enabled: "90%",
228
+ percentage: {
229
+ enabled: true,
230
+ showValue: true,
231
+ progressBar: {
232
+ ...defaultConfig.weeklyUsage.percentage.progressBar,
233
+ enabled: false,
234
+ },
235
+ },
236
+ },
237
+ });
238
+ const output = renderStatusline(data, config);
239
+
240
+ expect(output).toContain("W:");
241
+ });
242
+
243
+ it("should hide weekly when enabled=90% and five_hour < 90", () => {
244
+ const data = createMockData({
245
+ usageLimits: {
246
+ five_hour: { utilization: 50, resets_at: null },
247
+ seven_day: { utilization: 20, resets_at: null },
248
+ },
249
+ });
250
+ const config = createConfig({
251
+ weeklyUsage: { ...defaultConfig.weeklyUsage, enabled: "90%" },
252
+ });
253
+ const output = renderStatusline(data, config);
254
+
255
+ expect(output).not.toContain("W:");
256
+ });
257
+ });
258
+
259
+ describe("daily spend", () => {
260
+ it("should show daily cost when enabled and > 0", () => {
261
+ const data = createMockData({ todayCost: 5.5 });
262
+ const config = createConfig({
263
+ dailySpend: { cost: { enabled: true, format: "decimal1" } },
264
+ });
265
+ const output = renderStatusline(data, config);
266
+
267
+ expect(output).toContain("D:");
268
+ expect(output).toContain("5.5");
269
+ });
270
+
271
+ it("should hide daily cost when todayCost is 0", () => {
272
+ const data = createMockData({ todayCost: 0 });
273
+ const config = createConfig({
274
+ dailySpend: { cost: { enabled: true, format: "decimal1" } },
275
+ });
276
+ const output = renderStatusline(data, config);
277
+
278
+ expect(output).not.toContain("D:");
279
+ });
280
+ });
281
+
282
+ describe("separators", () => {
283
+ it("should use configured separator", () => {
284
+ const data = createMockData();
285
+ const config = createConfig({ separator: "|" });
286
+ const output = renderStatusline(data, config);
287
+
288
+ expect(output).toContain("|");
289
+ });
290
+ });
291
+
292
+ describe("one line vs two lines", () => {
293
+ it("should render on one line when oneLine is true", () => {
294
+ const data = createMockData();
295
+ const config = createConfig({ oneLine: true });
296
+ const output = renderStatusline(data, config);
297
+
298
+ expect(output.split("\n").length).toBe(1);
299
+ });
300
+
301
+ it("should render on two lines when oneLine is false", () => {
302
+ const data = createMockData();
303
+ const config = createConfig({ oneLine: false });
304
+ const output = renderStatusline(data, config);
305
+
306
+ expect(output).toContain("\n");
307
+ });
308
+ });
309
+ });
@@ -0,0 +1,8 @@
1
+ # Ignore all data files
2
+ *.db
3
+ *.json
4
+
5
+ # But keep this .gitignore
6
+ !.gitignore
7
+
8
+ last_payload.txt
@@ -1,4 +1,8 @@
1
1
  {
2
+ "features": {
3
+ "usageLimits": true,
4
+ "spendTracking": true
5
+ },
2
6
  "oneLine": true,
3
7
  "showSonnetModel": false,
4
8
  "pathDisplayMode": "truncated",
@@ -0,0 +1,166 @@
1
+ # Statusline Architecture - Session & Period Tracking
2
+
3
+ ## Concepts Fondamentaux
4
+
5
+ ### Session Claude Code
6
+
7
+ Une **session** est créée chaque fois qu'on ouvre un chat avec Claude Code.
8
+
9
+ Caractéristiques:
10
+ - **ID unique**: `session_id` (UUID)
11
+ - **Coût cumulatif**: Le coût total de la session qui AUGMENTE au fil du temps
12
+ - **Persistance**: Une session peut durer des heures/jours
13
+ - **Commande /clear**: Efface la conversation mais GARDE la même session
14
+ - **Le coût ne reset jamais**: Si une session a coûté $10, puis on fait /clear, le coût reste $10 et continue d'augmenter
15
+
16
+ ```
17
+ Session "abc-123"
18
+ ├── Début: $0
19
+ ├── Après 1h: $5
20
+ ├── /clear (conversation effacée)
21
+ ├── Après 2h: $12 (coût continue d'augmenter)
22
+ ├── Fermeture terminal
23
+ ├── Réouverture (même session)
24
+ └── Après 3h: $18 (toujours cumulatif)
25
+ ```
26
+
27
+ ### Période (5 heures)
28
+
29
+ Une **période** est une fenêtre de 5 heures pour le rate limiting d'Anthropic.
30
+
31
+ Caractéristiques:
32
+ - **resets_at**: Timestamp de fin de période (ex: "2025-12-09T10:00:00.000Z")
33
+ - **Durée fixe**: 5 heures
34
+ - **Indépendant des sessions**: Les sessions peuvent traverser plusieurs périodes
35
+
36
+ ```
37
+ Période A (05:00-10:00) Période B (10:00-15:00)
38
+ ├────────────────────┤ ├────────────────────┤
39
+ Session 1: +$5 Session 1: +$3 (continue)
40
+ Session 2: +$8 Session 3: +$10 (nouvelle)
41
+ ───────────── ─────────────
42
+ Total: $13 Total: $13
43
+ ```
44
+
45
+ ## Le Problème Actuel
46
+
47
+ ### Bug: Double Comptage
48
+
49
+ Quand on calcule le coût d'une période en sommant les coûts totaux des sessions:
50
+
51
+ ```
52
+ Session X: coût total = $24
53
+ Session X: last_resets_at = période actuelle
54
+
55
+ getCurrentPeriodCost() retourne $24 ❌ FAUX!
56
+ ```
57
+
58
+ Mais si la session X avait déjà $10 AVANT cette période:
59
+ - Coût réel de cette période = $24 - $10 = $14
60
+ - On affiche $24 au lieu de $14 = **double comptage**
61
+
62
+ ### Scénario Réel
63
+
64
+ ```
65
+ 1. Période A: Session X coûte $10, on compte $10 ✓
66
+ 2. Période B commence
67
+ 3. Session X continue, coût monte à $24
68
+ 4. On calcule période B: on voit session X = $24
69
+ 5. On affiche $24 pour période B ❌
70
+ 6. Mais on avait déjà compté $10 en période A!
71
+ 7. Total affiché: $10 + $24 = $34
72
+ 8. Total réel: $24
73
+ ```
74
+
75
+ ## Solution: Tracking des Deltas par Session
76
+
77
+ ### Nouvelle Structure de Données
78
+
79
+ On doit tracker pour chaque session:
80
+ - Combien on a DÉJÀ compté
81
+ - Dans quelle période on l'a compté
82
+
83
+ ```sql
84
+ -- Table: sessions
85
+ session_id TEXT PRIMARY KEY
86
+ total_cost REAL -- Coût total actuel de la session
87
+ cwd TEXT
88
+ date TEXT
89
+ duration_ms INTEGER
90
+ lines_added INTEGER
91
+ lines_removed INTEGER
92
+
93
+ -- Table: session_period_tracking
94
+ session_id TEXT
95
+ period_id TEXT -- resets_at normalisé
96
+ counted_cost REAL -- Combien on a compté pour cette période
97
+ last_update INTEGER -- Timestamp
98
+ PRIMARY KEY (session_id, period_id)
99
+
100
+ -- Table: periods
101
+ period_id TEXT PRIMARY KEY -- resets_at normalisé
102
+ total_cost REAL -- Somme des deltas de toutes les sessions
103
+ utilization INTEGER
104
+ date TEXT
105
+ ```
106
+
107
+ ### Algorithme Correct
108
+
109
+ ```
110
+ Quand saveSession(session_id, new_cost, current_period):
111
+ 1. Chercher session dans DB
112
+ 2. Si existe:
113
+ old_cost = session.total_cost
114
+ delta = new_cost - old_cost
115
+ Sinon:
116
+ delta = new_cost
117
+
118
+ 3. Chercher tracking pour (session_id, current_period)
119
+ 4. Si existe:
120
+ // Déjà compté dans cette période, calculer le vrai delta
121
+ already_counted = tracking.counted_cost
122
+ period_delta = delta // Le delta depuis la dernière update
123
+ Sinon:
124
+ // Nouvelle session dans cette période
125
+ period_delta = delta
126
+
127
+ 5. Mettre à jour:
128
+ - session.total_cost = new_cost
129
+ - tracking.counted_cost += period_delta
130
+ - period.total_cost += period_delta
131
+ ```
132
+
133
+ ### Exemple Concret
134
+
135
+ ```
136
+ Session X traverse 2 périodes:
137
+
138
+ Période A:
139
+ - Session X: $0 → $10
140
+ - tracking(X, A).counted_cost = $10
141
+ - period(A).total_cost = $10
142
+
143
+ Période B:
144
+ - Session X: $10 → $24
145
+ - delta = $24 - $10 = $14
146
+ - tracking(X, B).counted_cost = $14
147
+ - period(B).total_cost = $14
148
+
149
+ Calcul période B:
150
+ - On lit period(B).total_cost = $14 ✓ CORRECT!
151
+ ```
152
+
153
+ ## Avantages SQLite
154
+
155
+ 1. **Transactions ACID**: Pas de corruption de données
156
+ 2. **Requêtes complexes**: Agrégations, joins faciles
157
+ 3. **Index**: Performance pour les lookups par session_id
158
+ 4. **Single file**: Toujours portable
159
+ 5. **Intégrité référentielle**: FK entre tables
160
+
161
+ ## Migration
162
+
163
+ 1. Créer nouveau fichier `statusline.db`
164
+ 2. Migrer données existantes de spend.json et daily-usage.json
165
+ 3. Recalculer les period_costs correctement
166
+ 4. Supprimer les anciens fichiers JSON
@@ -0,0 +1,4 @@
1
+ {"parentUuid":null,"isSidechain":false,"userType":"external","cwd":"/Users/melvynx/.claude/scripts/statusline","sessionId":"demo-session","version":"2.0.31","gitBranch":"main","timestamp":"2025-11-11T10:00:00.000Z","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_01","type":"message","role":"user","content":[{"type":"text","text":"Hello"}],"usage":{"input_tokens":1000,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":100}},"uuid":"uuid-1"}
2
+ {"parentUuid":"uuid-1","isSidechain":false,"userType":"external","cwd":"/Users/melvynx/.claude/scripts/statusline","sessionId":"demo-session","version":"2.0.31","gitBranch":"main","timestamp":"2025-11-11T10:05:00.000Z","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_02","type":"message","role":"assistant","content":[{"type":"text","text":"Hi there!"}],"usage":{"input_tokens":50000,"cache_creation_input_tokens":30000,"cache_read_input_tokens":0,"output_tokens":200}},"uuid":"uuid-2"}
3
+ {"parentUuid":"uuid-2","isSidechain":false,"userType":"external","cwd":"/Users/melvynx/.claude/scripts/statusline","sessionId":"demo-session","version":"2.0.31","gitBranch":"main","timestamp":"2025-11-11T10:10:00.000Z","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_03","type":"message","role":"user","content":[{"type":"text","text":"Can you help me?"}],"usage":{"input_tokens":20000,"cache_creation_input_tokens":0,"cache_read_input_tokens":40000,"output_tokens":150}},"uuid":"uuid-3"}
4
+ {"parentUuid":"uuid-3","isSidechain":false,"userType":"external","cwd":"/Users/melvynx/.claude/scripts/statusline","sessionId":"demo-session","version":"2.0.31","gitBranch":"main","timestamp":"2025-11-11T10:15:00.000Z","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_04","type":"message","role":"assistant","content":[{"type":"text","text":"Of course! What do you need?"}],"usage":{"input_tokens":30000,"cache_creation_input_tokens":0,"cache_read_input_tokens":45000,"output_tokens":300}},"uuid":"uuid-4"}
@@ -0,0 +1,35 @@
1
+ {
2
+ "session_id": "06a7b019-03f8-4083-a9db-410d95cb01e6",
3
+ "transcript_path": "/Users/melvynx/.claude/scripts/statusline/fixtures/mock-transcript.jsonl",
4
+ "cwd": "/Users/melvynx/.claude",
5
+ "model": {
6
+ "id": "claude-sonnet-4-5-20250929",
7
+ "display_name": "Sonnet 4.5"
8
+ },
9
+ "workspace": {
10
+ "current_dir": "/Users/melvynx/.claude",
11
+ "project_dir": "/Users/melvynx/.claude"
12
+ },
13
+ "version": "2.0.68",
14
+ "output_style": {
15
+ "name": "default"
16
+ },
17
+ "cost": {
18
+ "total_cost_usd": 0.17468000000000003,
19
+ "total_duration_ms": 385160,
20
+ "total_api_duration_ms": 252694,
21
+ "total_lines_added": 185,
22
+ "total_lines_removed": 75
23
+ },
24
+ "context_window": {
25
+ "total_input_tokens": 136349,
26
+ "total_output_tokens": 21612,
27
+ "context_window_size": 200000,
28
+ "current_usage": {
29
+ "input_tokens": 62500,
30
+ "cache_creation_input_tokens": 0,
31
+ "cache_read_input_tokens": 0
32
+ }
33
+ },
34
+ "exceeds_200k_tokens": false
35
+ }
@@ -15,13 +15,46 @@ import { getGitStatus } from "./lib/git";
15
15
  import {
16
16
  renderStatusline,
17
17
  type StatuslineData,
18
+ type UsageLimit,
18
19
  } from "./lib/render-pure";
19
20
  import type { HookInput } from "./lib/types";
20
21
 
22
+ // Optional feature imports - just delete the folder to disable!
23
+ let getUsageLimits: any = null;
24
+ let normalizeResetsAt: any = null;
25
+ let getPeriodCost: any = null;
26
+ let getTodayCostV2: any = null;
27
+ let saveSessionV2: any = null;
28
+
29
+ try {
30
+ const limitsModule = await import("./lib/features/limits");
31
+ getUsageLimits = limitsModule.getUsageLimits;
32
+ } catch {
33
+ // Limits feature not available - that's OK!
34
+ }
35
+
36
+ try {
37
+ const utilsModule = await import("./lib/utils");
38
+ normalizeResetsAt = utilsModule.normalizeResetsAt;
39
+ } catch {
40
+ // Fallback normalizeResetsAt
41
+ normalizeResetsAt = (resetsAt: string) => resetsAt;
42
+ }
43
+
44
+ try {
45
+ const spendModule = await import("./lib/features/spend");
46
+ getPeriodCost = spendModule.getPeriodCost;
47
+ getTodayCostV2 = spendModule.getTodayCostV2;
48
+ saveSessionV2 = spendModule.saveSessionV2;
49
+ } catch {
50
+ // Spend tracking feature not available - that's OK!
51
+ }
52
+
21
53
  // Re-export from render-pure for backwards compatibility
22
54
  export {
23
55
  renderStatusline,
24
56
  type StatuslineData,
57
+ type UsageLimit,
25
58
  } from "./lib/render-pure";
26
59
 
27
60
  const CONFIG_FILE_PATH = join(import.meta.dir, "..", "statusline.config.json");
@@ -49,6 +82,18 @@ async function main() {
49
82
  await writeFile(LAST_PAYLOAD_PATH, JSON.stringify(input, null, 2));
50
83
 
51
84
  const config = await loadConfig();
85
+
86
+ // Get usage limits (if feature exists)
87
+ const usageLimits = getUsageLimits
88
+ ? await getUsageLimits()
89
+ : { five_hour: null, seven_day: null };
90
+ const currentResetsAt = usageLimits.five_hour?.resets_at ?? undefined;
91
+
92
+ // Save session with current period context (if feature exists)
93
+ if (saveSessionV2) {
94
+ await saveSessionV2(input, currentResetsAt);
95
+ }
96
+
52
97
  const git = await getGitStatus();
53
98
 
54
99
  let contextTokens: number | null;
@@ -88,6 +133,18 @@ async function main() {
88
133
  contextPercentage = contextData.percentage;
89
134
  }
90
135
 
136
+ // Get period cost from SQLite (if feature exists)
137
+ let periodCost: number | undefined;
138
+ let todayCost: number | undefined;
139
+
140
+ if (getPeriodCost && getTodayCostV2 && normalizeResetsAt) {
141
+ const normalizedPeriodId = currentResetsAt
142
+ ? normalizeResetsAt(currentResetsAt)
143
+ : null;
144
+ periodCost = normalizedPeriodId ? getPeriodCost(normalizedPeriodId) : 0;
145
+ todayCost = getTodayCostV2();
146
+ }
147
+
91
148
  const data: StatuslineData = {
92
149
  branch: formatBranch(git, config.git),
93
150
  dirPath: formatPath(input.workspace.current_dir, config.pathDisplayMode),
@@ -99,6 +156,23 @@ async function main() {
99
156
  sessionDuration: formatDuration(input.cost.total_duration_ms),
100
157
  contextTokens,
101
158
  contextPercentage,
159
+ ...(getUsageLimits && {
160
+ usageLimits: {
161
+ five_hour: usageLimits.five_hour
162
+ ? {
163
+ utilization: usageLimits.five_hour.utilization,
164
+ resets_at: usageLimits.five_hour.resets_at,
165
+ }
166
+ : null,
167
+ seven_day: usageLimits.seven_day
168
+ ? {
169
+ utilization: usageLimits.seven_day.utilization,
170
+ resets_at: usageLimits.seven_day.resets_at,
171
+ }
172
+ : null,
173
+ },
174
+ }),
175
+ ...((getPeriodCost || getTodayCostV2) && { periodCost, todayCost }),
102
176
  };
103
177
 
104
178
  const output = renderStatusline(data, config);
@@ -50,6 +50,10 @@ export interface PercentageConfig {
50
50
  }
51
51
 
52
52
  export interface StatuslineConfig {
53
+ features?: {
54
+ usageLimits?: boolean;
55
+ spendTracking?: boolean;
56
+ };
53
57
  oneLine: boolean;
54
58
  showSonnetModel: boolean;
55
59
  pathDisplayMode: "full" | "truncated" | "basename";