pi-thread-engine 0.4.5 → 0.4.6

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/PLAN.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-thread-engine
2
2
 
3
- ## Current State (v0.4.4)
3
+ ## Current State (v0.4.5)
4
4
 
5
5
  ### Working
6
6
  - All 7 thread types: Base (via /pthread), P (parallel), C (chained), B (branch/meta), F (fusion), Z (zero-touch), L (long)
@@ -15,7 +15,7 @@
15
15
 
16
16
  ## Next Steps (ranked by impact/effort)
17
17
 
18
- ### P0 — Required for completeness
18
+ ### P0 — Required for completeness
19
19
  1. **Live progress with % + ETA** — Wire event emitter from executor to dashboard for real-time progress
20
20
  2. **Token/cost counters** — Hook into pi's usage tracking per thread (use `pi.exec` output parsing)
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-thread-engine",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Thread-Based Engineering for pi — all 7 thread types + stories + fusion + zero-touch + TUI dashboard. Based on @IndyDevDan framework from agenticengineer.com.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,7 +31,25 @@ export class ThreadExecutor {
31
31
  });
32
32
 
33
33
  if (result.code === 0) {
34
- this.registry.completeTask(thread.id, task.id, result.stdout);
34
+ this.registry.completeTask(thread.id, task.id, result.stdout);
35
+ // Parse --mode json output for token/cost data
36
+ try {
37
+ const jsonLines = result.stdout.split("\n").filter(l => l.startsWith("{\"type\":\"message_end\"}"));
38
+ const last = jsonLines[jsonLines.length - 1];
39
+ if (last) {
40
+ const msg = JSON.parse(last);
41
+ if (msg.message?.usage) {
42
+ const u = msg.message.usage;
43
+ task.usage = {
44
+ inputTokens: u.input ?? 0,
45
+ outputTokens: u.output ?? 0,
46
+ totalTokens: u.totalTokens ?? 0,
47
+ cacheRead: u.cacheRead ?? 0,
48
+ cost: (u.cost?.input ?? 0) + (u.cost?.output ?? 0),
49
+ };
50
+ }
51
+ }
52
+ } catch {}
35
53
  } else {
36
54
  this.registry.failTask(thread.id, task.id, result.stderr || `Exit code: ${result.code}`);
37
55
  }
@@ -199,6 +199,8 @@ export class ThreadRegistry {
199
199
  state: thread.state,
200
200
  progress,
201
201
  elapsed,
202
+ totalTokens: thread.tasks.reduce((a, tk) => a + (tk.usage?.totalTokens ?? 0), 0),
203
+ totalCost: thread.tasks.reduce((a, tk) => a + (tk.usage?.cost ?? 0), 0),
202
204
  backend: thread.config.backend,
203
205
  };
204
206
  }
package/src/core/types.ts CHANGED
@@ -9,6 +9,7 @@ export type ExecutionBackend = "subagent" | "native";
9
9
 
10
10
  /** A single unit of work within a thread */
11
11
  export interface ThreadTask {
12
+ usage?: { inputTokens: number; outputTokens: number; cacheRead: number; totalTokens: number; cost: number };
12
13
  id: string;
13
14
  label: string;
14
15
  prompt: string;
@@ -85,6 +86,8 @@ export interface ThreadSummary {
85
86
  state: ThreadState;
86
87
  progress: string;
87
88
  elapsed: string;
89
+ totalTokens: number;
90
+ totalCost: number;
88
91
  backend: ExecutionBackend;
89
92
  }
90
93
 
package/src/dashboard.ts CHANGED
@@ -194,7 +194,11 @@ export function createDashboard(
194
194
  const icon = stateIcon(task.state);
195
195
  const color = stateColor(task.state);
196
196
  lines.push(theme.fg(color, `${indent}${icon} ${task.id}: ${truncateToWidth(task.label, maxW)}`));
197
- if (task.model) lines.push(theme.fg("dim", `${indent} model: ${task.model}`));
197
+ if (task.model) lines.push(theme.fg("dim", `${indent} model: ${task.model}`));
198
+ if (task.usage) {
199
+ const costStr = task.usage.cost > 0 ? ` ${task.usage.cost.toFixed(4)}` : "";
200
+ lines.push(theme.fg("dim", `${indent} tokens: ${task.usage.totalTokens}${costStr}`));
201
+ }
198
202
  if (task.result) {
199
203
  const preview = task.result.replace(/\n/g, " ").slice(0, 200);
200
204
  lines.push(theme.fg("muted", `${indent} → ${truncateToWidth(preview, maxW)}`));