opencode-plugin-context 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/dist/tui.js +35 -19
  2. package/package.json +1 -1
package/dist/tui.js CHANGED
@@ -211,30 +211,46 @@ function renderPanel(api, sessionId, config) {
211
211
  ] })
212
212
  );
213
213
  if (config.estimate) {
214
- const legend = (ids) => {
215
- const entries = usage.segments.filter((segment) => ids.includes(segment.id));
216
- if (entries.length === 0) return null;
217
- return /* @__PURE__ */ jsx("box", { flexDirection: "row", children: entries.map((segment) => /* @__PURE__ */ jsxs("box", { flexDirection: "row", children: [
218
- /* @__PURE__ */ jsx("text", { fg: segmentColor(segment.id, theme, true), children: "\u258D" }),
219
- /* @__PURE__ */ jsxs("text", { fg: theme.textMuted, children: [
220
- SEGMENT_LABEL[segment.id],
221
- compactFmt.format(segment.tokens)
222
- ] })
223
- ] })) });
214
+ const cellsById = new Map(bar.map((cell) => [cell.id, cell.cells]));
215
+ const tokenById = new Map(usage.segments.map((segment) => [segment.id, segment.tokens]));
216
+ const row = (ids, startAt) => {
217
+ const items = ids.map((id) => ({ id, cells: cellsById.get(id) ?? 0, tokens: tokenById.get(id) ?? 0 })).filter((item) => item.cells > 0 || item.tokens > 0);
218
+ if (items.length === 0) return null;
219
+ let cumulative = startAt;
220
+ return /* @__PURE__ */ jsx("box", { flexDirection: "row", children: items.map((item) => {
221
+ const marginLeft = cumulative;
222
+ cumulative += item.cells;
223
+ return /* @__PURE__ */ jsxs("box", { flexDirection: "row", marginLeft, children: [
224
+ /* @__PURE__ */ jsx("text", { fg: segmentColor(item.id, theme, true), children: "\u258D" }),
225
+ /* @__PURE__ */ jsxs("text", { fg: theme.textMuted, children: [
226
+ SEGMENT_LABEL[item.id],
227
+ compactFmt.format(item.tokens)
228
+ ] })
229
+ ] });
230
+ }) });
224
231
  };
225
- const usedLegend = legend(["cached", "user", "tools", "system", "think", "out"]);
226
- const budgetLegend = legend(["reserved", "free"]);
232
+ const usedStart = 0;
233
+ const usedIds = ["cached", "user", "tools", "system", "think", "out"];
234
+ const budgetStart = usedIds.reduce((sum, id) => sum + (cellsById.get(id) ?? 0), 0);
235
+ const usedLegend = row(usedIds, usedStart);
236
+ const budgetLegend = row(["reserved", "free"], budgetStart);
227
237
  if (usedLegend) lines.push(usedLegend);
228
238
  if (budgetLegend) lines.push(budgetLegend);
229
239
  } else {
240
+ const tokenById = new Map(usage.segments.map((segment) => [segment.id, segment.tokens]));
241
+ let cumulative = 0;
230
242
  lines.push(
231
- /* @__PURE__ */ jsx("box", { flexDirection: "row", gap: 1, children: usage.segments.map((segment) => /* @__PURE__ */ jsxs("box", { flexDirection: "row", children: [
232
- /* @__PURE__ */ jsx("text", { fg: segmentColor(segment.id, theme, false), children: "\u258D" }),
233
- /* @__PURE__ */ jsxs("text", { fg: theme.textMuted, children: [
234
- SEGMENT_LABEL[segment.id],
235
- compactFmt.format(segment.tokens)
236
- ] })
237
- ] })) })
243
+ /* @__PURE__ */ jsx("box", { flexDirection: "row", children: bar.map((cell) => {
244
+ const marginLeft = cumulative;
245
+ cumulative += cell.cells;
246
+ return /* @__PURE__ */ jsxs("box", { flexDirection: "row", marginLeft, children: [
247
+ /* @__PURE__ */ jsx("text", { fg: segmentColor(cell.id, theme, false), children: "\u258D" }),
248
+ /* @__PURE__ */ jsxs("text", { fg: theme.textMuted, children: [
249
+ SEGMENT_LABEL[cell.id],
250
+ compactFmt.format(tokenById.get(cell.id) ?? 0)
251
+ ] })
252
+ ] });
253
+ }) })
238
254
  );
239
255
  }
240
256
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "opencode-plugin-context",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "OpenCode TUI plugin that renders the session's context-window usage as a colored, segmented bar (cached / prompt / thinking / output / reserved output) in the sidebar",
6
6
  "type": "module",
7
7
  "exports": {