pi-goal 0.1.4 → 0.1.5

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.
@@ -1,5 +1,6 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
2
2
  import { Box, Spacer, Text } from "@mariozechner/pi-tui";
3
+ import { tokenDeltaFromUsage } from "./usage";
3
4
 
4
5
  const CUSTOM_TYPE = "pi-goal";
5
6
  const EVENT_TYPE = "pi-goal-event";
@@ -71,14 +72,6 @@ function goalUsage(state: GoalState): string {
71
72
  return formatElapsed(state.timeUsedSeconds);
72
73
  }
73
74
 
74
- type UsageSnapshot = { totalTokens?: number; input?: number; output?: number } | null | undefined;
75
-
76
- function tokenDeltaFromUsage(usage: UsageSnapshot): number {
77
- if (!usage) return 0;
78
- if (typeof usage.totalTokens === "number") return Math.max(0, usage.totalTokens);
79
- return Math.max(0, (Number(usage.input) || 0) + (Number(usage.output) || 0));
80
- }
81
-
82
75
  function truncateObjective(objective: string, max = 96): string {
83
76
  const singleLine = objective.replace(/\s+/g, " ").trim();
84
77
  return singleLine.length > max ? `${singleLine.slice(0, max - 1)}…` : singleLine;
@@ -0,0 +1,17 @@
1
+ export type UsageSnapshot = {
2
+ totalTokens?: number;
3
+ input?: number;
4
+ output?: number;
5
+ cacheRead?: number;
6
+ cacheWrite?: number;
7
+ } | null | undefined;
8
+
9
+ export function tokenDeltaFromUsage(usage: UsageSnapshot): number {
10
+ if (!usage) return 0;
11
+ if (typeof usage.totalTokens === "number") return Math.max(0, usage.totalTokens);
12
+ const input = Number(usage.input) || 0;
13
+ const output = Number(usage.output) || 0;
14
+ const cacheRead = Number(usage.cacheRead) || 0;
15
+ const cacheWrite = Number(usage.cacheWrite) || 0;
16
+ return Math.max(0, input + output + cacheRead + cacheWrite);
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-goal",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Persistent autonomous goals for pi — /goal loops until complete, paused, or budget-limited",
5
5
  "type": "commonjs",
6
6
  "keywords": [
@@ -24,8 +24,12 @@
24
24
  "@mariozechner/pi-coding-agent": "*",
25
25
  "@mariozechner/pi-tui": "*"
26
26
  },
27
+ "devDependencies": {
28
+ "jiti": "^2.7.0"
29
+ },
27
30
  "scripts": {
28
31
  "check": "pi --no-extensions -e ./.pi/extensions/pi-goal/index.ts --list-models __pi_goal_load_check__",
32
+ "test": "node --test test/**/*.test.cjs",
29
33
  "pack:dry": "npm pack --dry-run"
30
34
  },
31
35
  "author": "michaelliv",