@cortexkit/opencode-magic-context 0.49.85 → 0.49.87

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 (148) hide show
  1. package/dist/auto-search-worker.js +13 -7
  2. package/dist/chunk-embedding-write-worker.js +4 -4
  3. package/dist/{compartment-chunk-embedding-ymc9mtwv.js → compartment-chunk-embedding-fey2bsyf.js} +3 -1
  4. package/dist/{conflict-warning-hook-a0wrnzch.js → conflict-warning-hook-kbq6ppjf.js} +2 -2
  5. package/dist/{context-bjfwzbts.js → context-gnk68pyy.js} +126 -46
  6. package/dist/{embedding-backfill-v6sw58m8.js → embedding-backfill-9khxv6a9.js} +4 -4
  7. package/dist/{embedding-cache-mgyr73ef.js → embedding-cache-zn4r1c31.js} +5 -1
  8. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -0
  9. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  10. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  11. package/dist/features/magic-context/dreamer/token-budget.d.ts +8 -3
  12. package/dist/features/magic-context/dreamer/token-budget.d.ts.map +1 -1
  13. package/dist/features/magic-context/memory/embedding-cache.d.ts +7 -0
  14. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  15. package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -1
  16. package/dist/features/magic-context/search.d.ts +6 -0
  17. package/dist/features/magic-context/search.d.ts.map +1 -1
  18. package/dist/features/magic-context/tool-definition-tokens.d.ts +2 -0
  19. package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -1
  20. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  21. package/dist/hooks/magic-context/auto-search-worker-probe.fixture.d.ts +2 -0
  22. package/dist/hooks/magic-context/auto-search-worker-probe.fixture.d.ts.map +1 -0
  23. package/dist/hooks/magic-context/dropped-input-guard.d.ts.map +1 -1
  24. package/dist/hooks/magic-context/emergency-fail-closed.d.ts +2 -0
  25. package/dist/hooks/magic-context/emergency-fail-closed.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/send-session-notification.d.ts +11 -1
  27. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/transform.d.ts +1 -0
  29. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  30. package/dist/{index-7j2zv9nm.js → index-2qsca7h7.js} +47 -11
  31. package/dist/{index-9fsxmjs6.js → index-3jgzd7nz.js} +7 -7
  32. package/dist/{index-snbpdpa3.js → index-3pdknr07.js} +4 -4
  33. package/dist/{index-k0tb2z28.js → index-3x4qvp29.js} +2 -2
  34. package/dist/{index-0rge5rkh.js → index-5nmqgvz2.js} +21 -14
  35. package/dist/{index-xrnhxkz7.js → index-60wnwcwz.js} +1 -1
  36. package/dist/{index-g6hfh4h4.js → index-6zewd2n5.js} +14 -8
  37. package/dist/{index-nny4gm06.js → index-74sh122g.js} +2 -2
  38. package/dist/{index-70cv85b0.js → index-78t37mcq.js} +2 -2
  39. package/dist/{index-stx8zd81.js → index-83qd3n7s.js} +2 -2
  40. package/dist/{index-jjvbk92s.js → index-9emdjcb5.js} +1 -1
  41. package/dist/{index-sbr58jaf.js → index-awyqqnd8.js} +585 -82
  42. package/dist/{index-qvn3q9f1.js → index-b364vr04.js} +109 -505
  43. package/dist/{index-4w5rx7de.js → index-bxrfq3mv.js} +1 -1
  44. package/dist/{index-pw279hmt.js → index-c1s40xmj.js} +6 -5
  45. package/dist/{index-05bm2ndp.js → index-chpzb6xy.js} +1 -1
  46. package/dist/{index-tzbcb8yt.js → index-csztadkj.js} +46 -17
  47. package/dist/{index-798s7c8s.js → index-hdyfvdag.js} +1 -1
  48. package/dist/{index-4ntnt8ee.js → index-jka4y6mv.js} +1 -1
  49. package/dist/{index-w6v4dw5f.js → index-kmrv1fw3.js} +4 -4
  50. package/dist/{index-jrj95cce.js → index-m6dnydf8.js} +9 -2
  51. package/dist/{index-kqnef2tg.js → index-pmcvg3k1.js} +4 -4
  52. package/dist/{v2/server-4dhv7mqz.js → index-qjwpqvnf.js} +48 -1
  53. package/dist/{index-xccywqdj.js → index-rvf1726x.js} +3 -3
  54. package/dist/{index-1pf5qrx4.js → index-vyfrgwhk.js} +3 -3
  55. package/dist/{index-s8ks5nz4.js → index-watde7a1.js} +2 -2
  56. package/dist/{v2/server-fzgyvsb1.js → index-y14pawe1.js} +3 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +61 -52
  59. package/dist/{message-index-bounded-6fr624zf.js → message-index-bounded-r1qys471.js} +4 -4
  60. package/dist/migration-worker.js +3 -3
  61. package/dist/plugin/messages-transform.d.ts +3 -4
  62. package/dist/plugin/messages-transform.d.ts.map +1 -1
  63. package/dist/plugin/refusal-notice.d.ts +3 -0
  64. package/dist/plugin/refusal-notice.d.ts.map +1 -0
  65. package/dist/{project-embedding-registry-q80scexh.js → project-embedding-registry-8t0gwf59.js} +3 -3
  66. package/dist/raw-ordinal-warmup-worker.js +4 -4
  67. package/dist/{read-session-chunk-6wedfths.js → read-session-chunk-xv9f0wgb.js} +3 -3
  68. package/dist/{recomp-orchestrator-xzs0a455.js → recomp-orchestrator-2ztmtxt2.js} +18 -18
  69. package/dist/{render-yqp7q79f.js → render-d6q6h9hy.js} +10 -10
  70. package/dist/{rpc-notifications-t9q0ynq7.js → rpc-notifications-ta2zsxpq.js} +1 -1
  71. package/dist/{search-archive-r4h96j2z.js → search-archive-g96jn6p0.js} +5 -5
  72. package/dist/{search-ztgy3ya6.js → search-d5aajhs3.js} +14 -14
  73. package/dist/{send-session-notification-7x518gew.js → send-session-notification-gzxz88vq.js} +1 -1
  74. package/dist/shared/assistant-message-extractor.d.ts +2 -0
  75. package/dist/shared/assistant-message-extractor.d.ts.map +1 -1
  76. package/dist/shared/prompt-async-transport.d.ts.map +1 -1
  77. package/dist/shared/rpc-notifications.d.ts +1 -1
  78. package/dist/shared/rpc-notifications.d.ts.map +1 -1
  79. package/dist/{storage-memory-e6a7mb0k.js → storage-memory-hhrvfw0x.js} +2 -2
  80. package/dist/{storage-tags-y2mrb8e6.js → storage-tags-f1ftvjpw.js} +2 -2
  81. package/dist/{transform-postprocess-phase-39a5hm2a.js → transform-postprocess-phase-b2yjw8by.js} +19 -19
  82. package/dist/v2/auto-search-worker.js +13 -7
  83. package/dist/v2/chunk-embedding-write-worker.js +4 -4
  84. package/dist/v2/{compartment-chunk-embedding-x6qw6mjk.js → compartment-chunk-embedding-knt2468v.js} +3 -1
  85. package/dist/v2/{context-k2rrqzf4.js → context-s86114yy.js} +219 -62
  86. package/dist/v2/{embedding-backfill-k8kqnwfq.js → embedding-backfill-tazkbpyg.js} +4 -4
  87. package/dist/v2/{embedding-cache-mgyr73ef.js → embedding-cache-zn4r1c31.js} +5 -1
  88. package/dist/v2/fold/native-replay.d.ts +3 -1
  89. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  90. package/dist/v2/hidden-child-record.d.ts +1 -0
  91. package/dist/v2/hidden-child-record.d.ts.map +1 -1
  92. package/dist/v2/hidden-completion.d.ts.map +1 -1
  93. package/dist/v2/hooks/context.d.ts.map +1 -1
  94. package/dist/v2/{message-index-bounded-jqy7283g.js → message-index-bounded-b07r9cjv.js} +4 -4
  95. package/dist/v2/migration-worker.js +3 -3
  96. package/dist/v2/{project-embedding-registry-2jp1antr.js → project-embedding-registry-ah3gsg48.js} +3 -3
  97. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  98. package/dist/v2/{read-session-chunk-n3nhfvd7.js → read-session-chunk-38wdy8nd.js} +3 -3
  99. package/dist/v2/{recomp-orchestrator-jnbxbsc8.js → recomp-orchestrator-kc62xgb9.js} +17 -17
  100. package/dist/v2/{render-fezgh7pa.js → render-j05per51.js} +10 -10
  101. package/dist/v2/{rpc-notifications-t9q0ynq7.js → rpc-notifications-ta2zsxpq.js} +1 -1
  102. package/dist/v2/{search-archive-zz1kza50.js → search-archive-b4ptw02k.js} +5 -5
  103. package/dist/v2/{search-h5w7510x.js → search-kg31ad2s.js} +13 -13
  104. package/dist/v2/{send-session-notification-p52rhjzy.js → send-session-notification-zazaxxpf.js} +1 -1
  105. package/dist/v2/{server-ps6rz88g.js → server-2p0qayr1.js} +1 -1
  106. package/dist/v2/{server-s76ty4ws.js → server-2r9btf0g.js} +46 -17
  107. package/dist/v2/{server-wdq85mxj.js → server-6250cxzs.js} +14 -8
  108. package/dist/v2/{server-brgandk4.js → server-6vnbz81n.js} +2 -2
  109. package/dist/v2/{server-jjvbk92s.js → server-9emdjcb5.js} +1 -1
  110. package/dist/v2/{server-ap81bk3c.js → server-9n2qgk29.js} +1 -1
  111. package/dist/v2/{server-mbkwcwgw.js → server-axdmkvd5.js} +2 -2
  112. package/dist/v2/{server-2k8tkbhz.js → server-c7awk5s2.js} +10 -4
  113. package/dist/v2/{server-4wwwm2ya.js → server-ct0gs8fc.js} +4 -4
  114. package/dist/v2/{server-97w51d8n.js → server-ff5wcfy4.js} +3 -3
  115. package/dist/v2/{server-x77hd658.js → server-gqrw0br5.js} +20 -13
  116. package/dist/v2/{server-98hsp35q.js → server-gwhj0362.js} +6 -5
  117. package/dist/v2/{server-w7mpvkpj.js → server-pbp58w5x.js} +1 -1
  118. package/dist/v2/{server-s15knz0w.js → server-pmws7we9.js} +1 -1
  119. package/dist/{index-4dhv7mqz.js → v2/server-qjwpqvnf.js} +48 -1
  120. package/dist/v2/{server-a2f1bhyj.js → server-stjy5dxv.js} +9 -2
  121. package/dist/v2/{server-hn8b7sfe.js → server-xn7zqs4j.js} +2 -2
  122. package/dist/{index-fzgyvsb1.js → v2/server-y14pawe1.js} +3 -0
  123. package/dist/v2/{server-8pdfmc27.js → server-y17r5ryz.js} +4 -4
  124. package/dist/v2/{server-n5zr7190.js → server-yh2z4gg2.js} +3 -3
  125. package/dist/v2/{server-sxfbjdye.js → server-yx0nyj1q.js} +2 -2
  126. package/dist/v2/server.js +3 -3
  127. package/dist/v2/{storage-memory-e6a7mb0k.js → storage-memory-hhrvfw0x.js} +2 -2
  128. package/dist/v2/{storage-tags-xq81zgt2.js → storage-tags-pmw33chf.js} +2 -2
  129. package/dist/v2/{v2-archive-reader-e2w39c3p.js → v2-archive-reader-2ayz16s4.js} +1 -1
  130. package/dist/v2/{wrapup-orchestrator-mmje3etf.js → wrapup-orchestrator-e20sjbdz.js} +17 -17
  131. package/dist/{v2-archive-reader-8dsngf2j.js → v2-archive-reader-x39mzvwn.js} +1 -1
  132. package/dist/{wrapup-orchestrator-sm6pwf3p.js → wrapup-orchestrator-h3s905vs.js} +19 -19
  133. package/package.json +1 -1
  134. package/src/shared/assistant-message-extractor.test.ts +22 -0
  135. package/src/shared/assistant-message-extractor.ts +13 -0
  136. package/src/shared/model-suggestion-retry.test.ts +43 -12
  137. package/src/shared/prompt-async-transport.test.ts +275 -8
  138. package/src/shared/prompt-async-transport.ts +41 -2
  139. package/src/shared/reusable-worker.fixture.ts +15 -3
  140. package/src/shared/reusable-worker.test.ts +20 -10
  141. package/src/shared/rpc-notifications.ts +4 -1
  142. package/src/shared/sqlite-foreground-wait.test.ts +2 -2
  143. package/src/shared/startup-maintenance-policy.test.ts +4 -2
  144. package/src/tui/compaction-off.ts +2 -2
  145. package/src/tui/slots/sidebar-content-render.test.ts +309 -0
  146. package/src/tui/slots/sidebar-content.tsx +134 -99
  147. package/src/tui-compiled/compaction-off.ts +2 -2
  148. package/src/tui-compiled/slots/sidebar-content.tsx +321 -247
@@ -0,0 +1,309 @@
1
+ import { beforeAll, describe, expect, test } from "bun:test";
2
+ import { join } from "node:path";
3
+ import type { RenderCase, RenderResult } from "../../../scripts/render-compiled-sidebar";
4
+ import type { SidebarSnapshot } from "../data/context-db";
5
+
6
+ const BASE: SidebarSnapshot = {
7
+ sessionId: "ses_sidebar",
8
+ usagePercentage: 10,
9
+ inputTokens: 1000,
10
+ contextLimit: 10_000,
11
+ systemPromptTokens: 500,
12
+ compartmentCount: 0,
13
+ memoryCount: 7,
14
+ memoryBlockCount: 0,
15
+ pendingOpsCount: 0,
16
+ historianRunning: false,
17
+ compartmentInProgress: false,
18
+ sessionNoteCount: 0,
19
+ readySmartNoteCount: 0,
20
+ cacheTtl: "5m",
21
+ lastTransformError: null,
22
+ lastDreamerRunAt: null,
23
+ projectIdentity: null,
24
+ compartmentTokens: 0,
25
+ factTokens: 0,
26
+ memoryTokens: 0,
27
+ docsTokens: 0,
28
+ profileTokens: 0,
29
+ conversationTokens: 500,
30
+ toolCallTokens: 0,
31
+ toolDefinitionTokens: 0,
32
+ executeThreshold: 65,
33
+ };
34
+ const REFRESHED = {
35
+ ...BASE,
36
+ usagePercentage: 20,
37
+ inputTokens: 2000,
38
+ conversationTokens: 1500,
39
+ memoryCount: 8,
40
+ };
41
+ const tailHygiene = {
42
+ u: 250,
43
+ t: 500,
44
+ severity: 0.5,
45
+ evaluable: true,
46
+ generationInvalidated: false,
47
+ baselineGeneration: 1,
48
+ computedAt: 1,
49
+ };
50
+ const dreamerProgress = { task: "verify", processed: 2, total: 5, startedAt: 1 } as const;
51
+
52
+ function without(
53
+ ...fields: Exclude<keyof SidebarSnapshot, "sessionId">[]
54
+ ): RenderCase["snapshots"][0] {
55
+ const reply: RenderCase["snapshots"][0] = { ...REFRESHED };
56
+ for (const field of fields) delete reply[field];
57
+ return reply;
58
+ }
59
+
60
+ type Removal = {
61
+ name: string;
62
+ render: RenderCase;
63
+ present: RegExp;
64
+ absent: RegExp;
65
+ fresh?: RegExp;
66
+ };
67
+ const removals: Removal[] = [
68
+ {
69
+ name: "removes Hygiene without throwing when the third snapshot omits tailHygiene",
70
+ // A second snapshot with Hygiene keeps the row active before the field goes away.
71
+ render: {
72
+ snapshots: [
73
+ { ...BASE, tailHygiene },
74
+ { ...BASE, usagePercentage: 15, tailHygiene },
75
+ REFRESHED,
76
+ ],
77
+ },
78
+ present: /Hygiene +50\.0% · 250\/500/,
79
+ absent: /Hygiene/,
80
+ },
81
+ {
82
+ name: "guards Dreamer progress removal when dreamerProgress is omitted",
83
+ render: {
84
+ snapshots: [
85
+ { ...BASE, dreamerProgress },
86
+ { ...BASE, usagePercentage: 15, dreamerProgress },
87
+ REFRESHED,
88
+ ],
89
+ },
90
+ present: /Dreamer verify: 2\/5 processed/,
91
+ absent: /Dreamer/,
92
+ },
93
+ {
94
+ name: "guards warning removal when lastTransformError is omitted",
95
+ render: {
96
+ snapshots: [
97
+ { ...BASE, lastTransformError: "Transform failed" },
98
+ without("lastTransformError"),
99
+ ],
100
+ },
101
+ present: /Transform failed/,
102
+ absent: /Transform failed/,
103
+ },
104
+ {
105
+ name: "guards marker removal when executeThresholdClamped is omitted",
106
+ render: { snapshots: [{ ...BASE, executeThresholdClamped: true }, REFRESHED] },
107
+ present: /10\.0% \/ 65%\*/,
108
+ absent: /65%\*/,
109
+ },
110
+ {
111
+ name: "guards Stats removal when totalInputTokens is omitted",
112
+ render: { snapshots: [{ ...BASE, totalInputTokens: 0 }, REFRESHED] },
113
+ present: /Total tokens +0\b/,
114
+ absent: /Total tokens/,
115
+ },
116
+ {
117
+ name: "guards renderer mode when compaction_enabled is omitted",
118
+ render: { snapshots: [{ ...BASE, compaction_enabled: false }, REFRESHED] },
119
+ present: /native compaction/,
120
+ absent: /native compaction/,
121
+ },
122
+ {
123
+ name: "guards archived compartments removal when archivedCompartmentCount is omitted",
124
+ render: {
125
+ snapshots: [
126
+ { ...BASE, compaction_enabled: false, archivedCompartmentCount: 3 },
127
+ { ...REFRESHED, compaction_enabled: false },
128
+ ],
129
+ },
130
+ present: /Archived compartments +3\b/,
131
+ absent: /Archived compartments/,
132
+ },
133
+ {
134
+ name: "guards the token breakdown when inputTokens is omitted",
135
+ render: { snapshots: [BASE, without("inputTokens")] },
136
+ present: /Conversation/,
137
+ absent: /Conversation/,
138
+ },
139
+ {
140
+ name: "guards the context summary when contextLimit is omitted",
141
+ render: { snapshots: [BASE, without("contextLimit")] },
142
+ present: /10\.0% \/ 65%/,
143
+ absent: /65%/,
144
+ },
145
+ {
146
+ name: "omits the usage percentage without throwing when usagePercentage is omitted",
147
+ render: { snapshots: [BASE, without("usagePercentage")] },
148
+ present: /10\.0% \/ 65%/,
149
+ absent: /10\.0%|undefined|NaN/,
150
+ },
151
+ {
152
+ name: "guards the threshold when executeThreshold is omitted",
153
+ render: { snapshots: [BASE, without("executeThreshold")] },
154
+ present: /65%/,
155
+ absent: /65%|undefined|NaN/,
156
+ },
157
+ {
158
+ name: "omits the Conversation row when conversationTokens is omitted",
159
+ render: { snapshots: [BASE, without("conversationTokens")] },
160
+ present: /Conversation +500 \(50%\)/,
161
+ absent: /Conversation|NaN/,
162
+ },
163
+ {
164
+ name: "leaves native-compaction counts empty when the counts are omitted",
165
+ render: {
166
+ snapshots: [
167
+ { ...BASE, compaction_enabled: false, sessionNoteCount: 6 },
168
+ { ...without("memoryCount", "sessionNoteCount"), compaction_enabled: false },
169
+ ],
170
+ },
171
+ present: /Notes +6\b/,
172
+ absent: /Notes +6\b|Memories +7\b|undefined|NaN/,
173
+ fresh: /Context: 20\.0% · native compaction/,
174
+ },
175
+ {
176
+ name: "guards Injected removal when memoryBlockCount is omitted",
177
+ render: { snapshots: [{ ...BASE, memoryBlockCount: 3 }, without("memoryBlockCount")] },
178
+ present: /Injected +3\b/,
179
+ absent: /Injected/,
180
+ },
181
+ {
182
+ name: "guards the collapsed Memories count when memoryBlockCount is omitted",
183
+ render: {
184
+ collapsed: true,
185
+ snapshots: [{ ...BASE, memoryBlockCount: 3 }, without("memoryBlockCount")],
186
+ },
187
+ present: /Memories +3\/7\b/,
188
+ absent: /3\/7|undefined|NaN/,
189
+ },
190
+ {
191
+ name: "guards Queue removal when pendingOpsCount is omitted",
192
+ render: {
193
+ snapshots: [
194
+ { ...BASE, pendingOpsCount: 3, sessionNoteCount: 1 },
195
+ { ...without("pendingOpsCount"), sessionNoteCount: 1 },
196
+ ],
197
+ },
198
+ present: /Queue +3 pending/,
199
+ absent: /Queue/,
200
+ },
201
+ {
202
+ name: "guards Notes removal when sessionNoteCount is omitted",
203
+ render: {
204
+ snapshots: [
205
+ { ...BASE, sessionNoteCount: 4, pendingOpsCount: 1 },
206
+ { ...without("sessionNoteCount"), pendingOpsCount: 1 },
207
+ ],
208
+ },
209
+ present: /Notes +4\b/,
210
+ absent: /Notes/,
211
+ },
212
+ {
213
+ name: "guards Smart Notes removal when readySmartNoteCount is omitted",
214
+ render: {
215
+ snapshots: [
216
+ { ...BASE, readySmartNoteCount: 4, pendingOpsCount: 1 },
217
+ { ...without("readySmartNoteCount"), pendingOpsCount: 1 },
218
+ ],
219
+ },
220
+ present: /Smart Notes +4 ready/,
221
+ absent: /Smart Notes/,
222
+ },
223
+ ];
224
+
225
+ const updated: RenderCase = {
226
+ snapshots: [
227
+ { ...BASE, tailHygiene, dreamerProgress },
228
+ {
229
+ ...REFRESHED,
230
+ tailHygiene: { ...tailHygiene, u: 125, severity: 0.25, evaluable: false },
231
+ dreamerProgress: { ...dreamerProgress, processed: 4 },
232
+ },
233
+ ],
234
+ };
235
+ const forcedError: RenderCase = {
236
+ snapshots: [
237
+ { ...BASE, tailHygiene },
238
+ { ...REFRESHED, tailHygiene },
239
+ ],
240
+ throwOnEvaluable: true,
241
+ };
242
+ const equalReply = { ...BASE, tailHygiene, dreamerProgress };
243
+ const unchanged = {
244
+ snapshots: [equalReply, equalReply, equalReply],
245
+ trackText: ["10.0% / 65%", "1K / 10K", "Dreamer verify: 2/5 processed", "Hygiene"],
246
+ } satisfies RenderCase;
247
+ let results: RenderResult[];
248
+
249
+ beforeAll(() => {
250
+ const cases = [...removals.map(({ render }) => render), updated, forcedError, unchanged];
251
+ const script = join(import.meta.dir, "../../../scripts/render-compiled-sidebar.ts");
252
+ const child = Bun.spawnSync(["bun", "--conditions=browser", script], {
253
+ stdin: new TextEncoder().encode(JSON.stringify(cases)),
254
+ stdout: "pipe",
255
+ stderr: "pipe",
256
+ windowsHide: true,
257
+ });
258
+ if (child.exitCode !== 0)
259
+ throw new Error(`sidebar render script failed: ${child.stderr.toString()}`);
260
+ results = JSON.parse(child.stdout.toString());
261
+ }, 120_000);
262
+
263
+ describe("compiled sidebar refresh", () => {
264
+ for (const [index, { name, render, present, absent, fresh }] of removals.entries()) {
265
+ test(name, () => {
266
+ const { frames, error } = results[index];
267
+ expect(frames[0]).toMatch(present);
268
+ if (render.snapshots.length === 3) {
269
+ expect(frames[1]).toContain("15.0% / 65%");
270
+ expect(frames[1]).toMatch(present);
271
+ }
272
+ expect(error).toBeUndefined();
273
+ expect(frames).toHaveLength(render.snapshots.length);
274
+ const after = frames[frames.length - 1];
275
+ expect(after).not.toMatch(absent);
276
+ expect(after).toMatch(fresh ?? /Memories +8\b/);
277
+ });
278
+ }
279
+
280
+ test("guards the new Hygiene and Dreamer readings when both fields stay present", () => {
281
+ const {
282
+ frames: [before, after],
283
+ error,
284
+ } = results[removals.length];
285
+ expect(error).toBeUndefined();
286
+ expect(before).toMatch(/Hygiene +50\.0% · 250\/500/);
287
+ expect(before).toContain("Dreamer verify: 2/5 processed");
288
+ expect(after).toMatch(/Hygiene +25\.0% · 125\/500/);
289
+ expect(after).toContain("Dreamer verify: 4/5 processed");
290
+ });
291
+
292
+ test("reports a forced slot error on refresh after a valid Hygiene frame", () => {
293
+ const { frames, error } = results[removals.length + 1];
294
+ expect(frames).toHaveLength(1);
295
+ expect(frames[0]).toMatch(/Hygiene +50\.0% · 250\/500/);
296
+ expect(error).toBe("forced error reading tailHygiene.evaluable during refresh");
297
+ });
298
+
299
+ test("retains the Context, Dreamer and Hygiene elements across equal refreshes", () => {
300
+ const { frames, error, textIds } = results[removals.length + 2];
301
+ expect(error).toBeUndefined();
302
+ expect(frames).toHaveLength(3);
303
+ expect(textIds).toHaveLength(3);
304
+ expect(textIds?.map((frame) => frame.map((ids) => ids.length))).toEqual(
305
+ frames.map(() => unchanged.trackText.map(() => 1)),
306
+ );
307
+ expect(textIds?.slice(1)).toEqual([textIds?.[0], textIds?.[0]]);
308
+ });
309
+ });
@@ -161,7 +161,7 @@ interface TokenSegment {
161
161
  // Segmented token breakdown bar with legend
162
162
  const TokenBreakdown = (props: {
163
163
  theme: TuiThemeCurrent
164
- snapshot: SidebarSnapshot
164
+ snapshot: SidebarSnapshot | null
165
165
  // Collapsed mode renders only the proportional bar (no per-category legend
166
166
  // rows) so the sidebar shrinks to the progress bar + a few summary lines.
167
167
  collapsed?: boolean
@@ -175,8 +175,8 @@ const TokenBreakdown = (props: {
175
175
  // space on the right on wide sidebars.
176
176
  const segments = createMemo<TokenSegment[]>(() => {
177
177
  const s = props.snapshot
178
- const total = s.inputTokens || 1
179
178
  const result: TokenSegment[] = []
179
+ if (!s) return result
180
180
 
181
181
  // System Prompt (purple)
182
182
  if (s.systemPromptTokens > 0) {
@@ -250,12 +250,14 @@ const TokenBreakdown = (props: {
250
250
  // segment is also skipped in the bar at 0 width because the segment
251
251
  // builder uses `Math.max(1, ...)` only when tokens > 0 (see
252
252
  // segmentWidths), so the visual bar stays correct either way.
253
- result.push({
254
- key: "conv",
255
- tokens: s.conversationTokens,
256
- color: COLORS.conversation,
253
+ if (s.conversationTokens != null) {
254
+ result.push({
255
+ key: "conv",
256
+ tokens: s.conversationTokens,
257
+ color: COLORS.conversation,
257
258
  label: "Conversation",
258
- })
259
+ })
260
+ }
259
261
 
260
262
  // Tool Calls = tool_use/tool_result/tool/tool-invocation parts in messages
261
263
  // (actionable — users can reduce via ctx_reduce)
@@ -284,7 +286,7 @@ const TokenBreakdown = (props: {
284
286
  return result
285
287
  })
286
288
 
287
- const totalTokens = createMemo(() => props.snapshot.inputTokens || 1)
289
+ const totalTokens = createMemo(() => props.snapshot?.inputTokens || 1)
288
290
 
289
291
  // Render-time segments for the bar. Zero-token segments are filtered out
290
292
  // entirely (no flex weight, no rendered box) so they don't claim any
@@ -739,6 +741,51 @@ const SidebarContent = (props: {
739
741
 
740
742
  const s = createMemo(() => snapshot())
741
743
  const compactionOff = () => s()?.compaction_enabled === false
744
+ const nativeRows = createMemo(() => {
745
+ const current = s()
746
+ return current?.compaction_enabled === false ? compactionOffSidebarRows(current) : []
747
+ })
748
+ const dreamerLabel = createMemo(() => {
749
+ const progress = s()?.dreamerProgress
750
+ if (!progress) return
751
+ return `Dreamer ${progress.task}: ${progress.processed}/${progress.total} processed`
752
+ })
753
+ const contextSummary = createMemo(() => {
754
+ const current = s()
755
+ if (!current || !(current.inputTokens > 0 && current.contextLimit > 0)) return
756
+ const tokens = `${compactTokens(current.inputTokens)} / ${compactTokens(current.contextLimit)}`
757
+ if (current.compaction_enabled === false) {
758
+ return { tokens, native: nativeCompactionContextLabel(current) }
759
+ }
760
+ const usage = current.usagePercentage?.toFixed(1)
761
+ const threshold = current.executeThreshold == null
762
+ ? undefined
763
+ : `${formatThresholdPercent(current.executeThreshold)}%${current.executeThresholdClamped ? "*" : ""}`
764
+ return { tokens, usage, threshold }
765
+ }, undefined, {
766
+ equals: (a, b) =>
767
+ a?.tokens === b?.tokens && a?.native === b?.native &&
768
+ a?.usage === b?.usage && a?.threshold === b?.threshold,
769
+ })
770
+ const hygieneSummary = createMemo(() => {
771
+ const current = s()
772
+ if (!current || !(current.inputTokens > 0)) return
773
+ const hygiene = current.tailHygiene
774
+ if (!hygiene) return
775
+ return { value: hygieneValue(hygiene), warning: !hygiene.evaluable }
776
+ }, undefined, {
777
+ equals: (a, b) => a?.value === b?.value && a?.warning === b?.warning,
778
+ })
779
+ const totalInputTokensLabel = () => {
780
+ const tokens = s()?.totalInputTokens
781
+ return tokens == null ? undefined : compactTokens(tokens)
782
+ }
783
+ const collapsedMemoryValue = () => {
784
+ const current = s()
785
+ const count = current?.memoryCount ?? 0
786
+ const injected = current?.memoryBlockCount ?? 0
787
+ return injected > 0 ? `${injected}/${count}` : String(count)
788
+ }
742
789
  const contextSummaryColor = createMemo(() => {
743
790
  if (compactionOff()) return props.theme.accent
744
791
  const usage = s()?.usagePercentage ?? 0
@@ -778,11 +825,13 @@ const SidebarContent = (props: {
778
825
  {/* The fence probe writes the failure into the server-owned snapshot,
779
826
  so this survives sidebar refreshes and is visible independently of
780
827
  the one-shot toast. */}
781
- {s()?.lastTransformError && (
782
- <box marginTop={1} width="100%">
783
- <text fg={props.theme.error}>⚠ {s()!.lastTransformError}</text>
784
- </box>
785
- )}
828
+ <Show keyed when={s()?.lastTransformError}>
829
+ {(error) => (
830
+ <box marginTop={1} width="100%">
831
+ <text fg={props.theme.error}>⚠ {error}</text>
832
+ </box>
833
+ )}
834
+ </Show>
786
835
 
787
836
  {s()?.projectBindingWarning && (
788
837
  <box marginTop={1} width="100%">
@@ -802,47 +851,51 @@ const SidebarContent = (props: {
802
851
  )}
803
852
  </For>
804
853
 
805
- {s()?.dreamerProgress && (
806
- <box marginTop={1} width="100%">
807
- <text fg={props.theme.warning}>
808
- Dreamer {s()!.dreamerProgress!.task}: {s()!.dreamerProgress!.processed}/{s()!.dreamerProgress!.total} processed
809
- </text>
810
- </box>
811
- )}
854
+ <Show keyed when={dreamerLabel()}>
855
+ {(label) => (
856
+ <box marginTop={1} width="100%">
857
+ <text fg={props.theme.warning}>{label}</text>
858
+ </box>
859
+ )}
860
+ </Show>
812
861
 
813
862
  {/* Token breakdown bar. In collapsed mode the header, bar and the
814
863
  3 summary rows stack with no vertical padding for a compact look;
815
864
  expanded mode keeps the 1-row gap above the bar. */}
816
- {s() && s()!.inputTokens > 0 && (
865
+ {(s()?.inputTokens ?? 0) > 0 && (
817
866
  <box marginTop={collapsed() ? 0 : 1} flexDirection="column">
818
- {(s()?.contextLimit ?? 0) > 0 && (
819
- <box width="100%" flexDirection="row" justifyContent="space-between">
820
- {compactionOff() ? (
821
- <text fg={contextSummaryColor()}>
822
- <b>{nativeCompactionContextLabel(s()!)}</b>
823
- </text>
824
- ) : (
825
- <text fg={contextSummaryColor()}>
826
- <b>{s()!.usagePercentage.toFixed(1)}%</b> / {formatThresholdPercent(s()!.executeThreshold)}%{s()!.executeThresholdClamped ? "*" : ""}
827
- </text>
828
- )}
829
- {/* Right: absolute token usage against the usable
830
- scheduler window — the same denominator as the
831
- percentage and nudge/trigger scheduling. */}
832
- <text fg={contextSummaryColor()}>
833
- {compactTokens(s()!.inputTokens)} / {compactTokens(s()!.contextLimit)}
834
- </text>
835
- </box>
836
- )}
837
- <TokenBreakdown theme={props.theme} snapshot={s()!} collapsed={collapsed()} />
838
- {s()!.tailHygiene !== undefined && (
839
- <StatRow
840
- theme={props.theme}
841
- label="Hygiene"
842
- value={hygieneValue(s()!.tailHygiene!)}
843
- warning={!s()!.tailHygiene!.evaluable}
844
- />
845
- )}
867
+ <Show keyed when={contextSummary()}>
868
+ {(summary) => (
869
+ <box width="100%" flexDirection="row" justifyContent="space-between">
870
+ {summary.native != null ? (
871
+ <text fg={contextSummaryColor()}>
872
+ <b>{summary.native}</b>
873
+ </text>
874
+ ) : (
875
+ <text fg={contextSummaryColor()}>
876
+ {summary.usage != null && <b>{summary.usage}%</b>}
877
+ {summary.usage != null && summary.threshold != null ? " / " : ""}
878
+ {summary.threshold ?? ""}
879
+ </text>
880
+ )}
881
+ {/* Right: absolute token usage against the usable
882
+ scheduler window — the same denominator as the
883
+ percentage and nudge/trigger scheduling. */}
884
+ <text fg={contextSummaryColor()}>{summary.tokens}</text>
885
+ </box>
886
+ )}
887
+ </Show>
888
+ <TokenBreakdown theme={props.theme} snapshot={s()} collapsed={collapsed()} />
889
+ <Show keyed when={hygieneSummary()}>
890
+ {(hygiene) => (
891
+ <StatRow
892
+ theme={props.theme}
893
+ label="Hygiene"
894
+ value={hygiene.value}
895
+ warning={hygiene.warning}
896
+ />
897
+ )}
898
+ </Show>
846
899
  </box>
847
900
  )}
848
901
 
@@ -852,7 +905,7 @@ const SidebarContent = (props: {
852
905
  {collapsed() && (
853
906
  <box width="100%" flexDirection="column">
854
907
  {compactionOff() ? (
855
- compactionOffSidebarRows(s()!).map((row) => (
908
+ nativeRows().map((row) => (
856
909
  <StatRow
857
910
  theme={props.theme}
858
911
  label={row.label}
@@ -883,11 +936,7 @@ const SidebarContent = (props: {
883
936
  </Show>
884
937
  <box width="100%" flexDirection="row" justifyContent="space-between">
885
938
  <text fg={props.theme.textMuted}>Memories</text>
886
- <text fg={props.theme.textMuted}>
887
- {(s()?.memoryBlockCount ?? 0) > 0
888
- ? `${s()!.memoryBlockCount}/${s()?.memoryCount ?? 0}`
889
- : String(s()?.memoryCount ?? 0)}
890
- </text>
939
+ <text fg={props.theme.textMuted}>{collapsedMemoryValue()}</text>
891
940
  </box>
892
941
  <box width="100%" flexDirection="row" justifyContent="space-between">
893
942
  <text fg={props.theme.textMuted}>Status</text>
@@ -941,7 +990,7 @@ const SidebarContent = (props: {
941
990
  <>
942
991
  <SectionHeader theme={props.theme} title="Memory" />
943
992
  {compactionOff() ? (
944
- compactionOffSidebarRows(s()!)
993
+ nativeRows()
945
994
  .filter((row) => row.label === "Memories")
946
995
  .map((row) => (
947
996
  <StatRow theme={props.theme} label={row.label} value={row.value} accent />
@@ -954,14 +1003,11 @@ const SidebarContent = (props: {
954
1003
  value={String(s()?.memoryCount ?? 0)}
955
1004
  accent
956
1005
  />
957
- {(s()?.memoryBlockCount ?? 0) > 0 && (
958
- <StatRow
959
- theme={props.theme}
960
- label="Injected"
961
- value={String(s()!.memoryBlockCount)}
962
- dim
963
- />
964
- )}
1006
+ <Show keyed when={(s()?.memoryBlockCount ?? 0) > 0 && s()?.memoryBlockCount}>
1007
+ {(count) => (
1008
+ <StatRow theme={props.theme} label="Injected" value={String(count)} dim />
1009
+ )}
1010
+ </Show>
965
1011
  </>
966
1012
  )}
967
1013
  </>
@@ -976,7 +1022,7 @@ const SidebarContent = (props: {
976
1022
  <>
977
1023
  <SectionHeader theme={props.theme} title="Status" />
978
1024
  {compactionOff() ? (
979
- compactionOffSidebarRows(s()!)
1025
+ nativeRows()
980
1026
  .filter((row) => row.label !== "Memories")
981
1027
  .map((row) => (
982
1028
  <StatRow
@@ -988,29 +1034,21 @@ const SidebarContent = (props: {
988
1034
  ))
989
1035
  ) : (
990
1036
  <>
991
- {(s()?.pendingOpsCount ?? 0) > 0 && (
992
- <StatRow
993
- theme={props.theme}
994
- label="Queue"
995
- value={`${s()!.pendingOpsCount} pending`}
996
- warning
997
- />
998
- )}
999
- {(s()?.sessionNoteCount ?? 0) > 0 && (
1000
- <StatRow
1001
- theme={props.theme}
1002
- label="Notes"
1003
- value={String(s()!.sessionNoteCount)}
1004
- />
1005
- )}
1006
- {(s()?.readySmartNoteCount ?? 0) > 0 && (
1007
- <StatRow
1008
- theme={props.theme}
1009
- label="Smart Notes"
1010
- value={`${s()!.readySmartNoteCount} ready`}
1011
- accent
1012
- />
1013
- )}
1037
+ <Show keyed when={(s()?.pendingOpsCount ?? 0) > 0 && s()?.pendingOpsCount}>
1038
+ {(count) => (
1039
+ <StatRow theme={props.theme} label="Queue" value={`${count} pending`} warning />
1040
+ )}
1041
+ </Show>
1042
+ <Show keyed when={(s()?.sessionNoteCount ?? 0) > 0 && s()?.sessionNoteCount}>
1043
+ {(count) => (
1044
+ <StatRow theme={props.theme} label="Notes" value={String(count)} />
1045
+ )}
1046
+ </Show>
1047
+ <Show keyed when={(s()?.readySmartNoteCount ?? 0) > 0 && s()?.readySmartNoteCount}>
1048
+ {(count) => (
1049
+ <StatRow theme={props.theme} label="Smart Notes" value={`${count} ready`} accent />
1050
+ )}
1051
+ </Show>
1014
1052
  </>
1015
1053
  )}
1016
1054
  </>
@@ -1059,17 +1097,14 @@ const SidebarContent = (props: {
1059
1097
  snapshot fields (newWorkTokens, totalInputTokens) and the
1060
1098
  session_meta columns are still populated; only the UI is
1061
1099
  simplified for now. */}
1062
- {sections().stats && s()?.totalInputTokens != null && (
1063
- <>
1064
- <SectionHeader theme={props.theme} title="Stats" />
1065
- <StatRow
1066
- theme={props.theme}
1067
- label="Total tokens"
1068
- value={compactTokens(s()!.totalInputTokens ?? 0)}
1069
- dim
1070
- />
1071
- </>
1072
- )}
1100
+ <Show keyed when={sections().stats && totalInputTokensLabel()}>
1101
+ {(total) => (
1102
+ <>
1103
+ <SectionHeader theme={props.theme} title="Stats" />
1104
+ <StatRow theme={props.theme} label="Total tokens" value={total} dim />
1105
+ </>
1106
+ )}
1107
+ </Show>
1073
1108
  </>
1074
1109
  )}
1075
1110
  </box>
@@ -18,8 +18,8 @@ export function nativeCompactionContextLabel(snapshot: SidebarSnapshot): string
18
18
 
19
19
  export function compactionOffSidebarRows(snapshot: SidebarSnapshot): CompactionOffSidebarRow[] {
20
20
  const rows: CompactionOffSidebarRow[] = [
21
- { label: "Memories", value: String(snapshot.memoryCount) },
22
- { label: "Notes", value: String(snapshot.sessionNoteCount) },
21
+ { label: "Memories", value: String(snapshot.memoryCount ?? "") },
22
+ { label: "Notes", value: String(snapshot.sessionNoteCount ?? "") },
23
23
  ];
24
24
  const archivedCount = snapshot.archivedCompartmentCount ?? 0;
25
25
  if (archivedCount > 0) {