pi-context 1.1.2 → 1.1.4

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/dist/index.js CHANGED
@@ -281,7 +281,7 @@ export default function (pi) {
281
281
  // --- Context Dashboard (HUD) ---
282
282
  const usage = await ctx.getContextUsage();
283
283
  let usageStr = "Unknown";
284
- if (usage) {
284
+ if (usage && usage.percent != null && usage.tokens != null && usage.contextWindow != null) {
285
285
  usageStr = `${usage.percent.toFixed(1)}% (${formatTokens(usage.tokens)}/${formatTokens(usage.contextWindow)})`;
286
286
  }
287
287
  // Find the distance to the nearest tag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-context",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Agentic Context Management for the Pi",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@sinclair/typebox": "^0.34.13",
27
27
  "typescript": "^5.7.2",
28
- "@mariozechner/pi-coding-agent": "latest"
28
+ "@earendil-works/pi-coding-agent": "latest"
29
29
  },
30
30
  "pi": {
31
31
  "extensions": [
package/src/context.ts CHANGED
@@ -62,6 +62,11 @@ export default function (pi: ExtensionAPI) {
62
62
  const totalActual = usage.tokens;
63
63
  const limit = usage.contextWindow;
64
64
 
65
+ if (totalActual == null || limit == null || usage.percent == null) {
66
+ ctx.ui.notify("Context usage info not available.", "warning");
67
+ return;
68
+ }
69
+
65
70
  const totalRaw = systemTokensRaw + toolDefTokensRaw + msgTokensRaw + toolUseTokensRaw + toolResultTokensRaw;
66
71
  const ratio = totalRaw > 0 ? (totalActual / totalRaw) : 1;
67
72
 
package/src/index.ts CHANGED
@@ -82,11 +82,18 @@ export default function (pi: ExtensionAPI) {
82
82
  });
83
83
 
84
84
  // Helper: Check if a tag name already exists in the tree
85
+ // Iterative DFS to avoid call stack overflows on deep histories.
86
+ // Push children in reverse order to preserve left-to-right pre-order semantics.
85
87
  const findTagInTree = (sm: SessionManager, nodes: SessionTreeNode[], tagName: string): string | null => {
86
- for (const n of nodes) {
88
+ const stack: SessionTreeNode[] = [...nodes].reverse();
89
+ while (stack.length > 0) {
90
+ const n = stack.pop()!;
87
91
  if (sm.getLabel(n.entry.id) === tagName) return n.entry.id;
88
- const r = findTagInTree(sm, n.children, tagName);
89
- if (r) return r;
92
+ if (n.children?.length) {
93
+ for (let i = n.children.length - 1; i >= 0; i--) {
94
+ stack.push(n.children[i]);
95
+ }
96
+ }
90
97
  }
91
98
  return null;
92
99
  };
package/src/utils.ts CHANGED
@@ -1,4 +1,5 @@
1
- export const formatTokens = (n: number) => {
1
+ export const formatTokens = (n: number | null | undefined) => {
2
+ if (n == null) return "N/A";
2
3
  if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M";
3
4
  if (n >= 1_000) return Math.round(n / 1_000) + "k";
4
5
  return n.toString();