pi-crew 0.2.13 → 0.2.15
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/package.json
CHANGED
package/src/ui/crew-widget.ts
CHANGED
|
@@ -152,10 +152,22 @@ function agentStats(agent: CrewAgentRecord, liveHandle?: LiveAgentHandle): strin
|
|
|
152
152
|
const ctxPct = stats?.contextUsage?.percent;
|
|
153
153
|
if (ctxPct != null) parts.push(`${Math.round(ctxPct)}% ctx`);
|
|
154
154
|
} catch { /* ignore */ }
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
// Validate: startedAtMs should be within reasonable bounds (not seconds, not far future)
|
|
155
|
+
const rawStarted = act.startedAtMs || 0;
|
|
156
|
+
const rawCompleted = act.completedAtMs || 0;
|
|
158
157
|
const nowMs = Date.now();
|
|
158
|
+
const nowSec = Math.floor(nowMs / 1000);
|
|
159
|
+
// Detect if value is in seconds vs milliseconds by comparing distance to current time
|
|
160
|
+
// If value is closer to nowSec (within ±2 years) AND not close to nowMs, treat as seconds
|
|
161
|
+
const isSeconds = (v: number) => {
|
|
162
|
+
if (v <= 0) return false;
|
|
163
|
+
const distToSec = Math.abs(v - nowSec);
|
|
164
|
+
const distToMs = Math.abs(v - nowMs);
|
|
165
|
+
// If distance to seconds is much smaller AND value is in valid seconds range
|
|
166
|
+
return distToSec < distToMs && distToSec < 31536000 * 2 && v > 1000000000;
|
|
167
|
+
};
|
|
168
|
+
const startedMs = isSeconds(rawStarted) ? rawStarted * 1000 : rawStarted;
|
|
169
|
+
const completedMs = isSeconds(rawCompleted) ? rawCompleted * 1000 : rawCompleted;
|
|
170
|
+
// Validate: startedAtMs should be within reasonable bounds
|
|
159
171
|
const isValidStarted = startedMs > 0 && startedMs < nowMs + 60000 && startedMs > nowMs - 3155692600000;
|
|
160
172
|
const isValidCompleted = completedMs === 0 || (completedMs > 0 && completedMs < nowMs + 60000);
|
|
161
173
|
const ms = (isValidCompleted ? completedMs : nowMs) - (isValidStarted ? startedMs : nowMs);
|
|
@@ -64,9 +64,19 @@ export class LiveConversationOverlay {
|
|
|
64
64
|
private static readonly SUMMARY_PREFIX = "\u200B"; // zero-width space as summary sentinel
|
|
65
65
|
|
|
66
66
|
private safeElapsedMs(act: typeof this.handle.activity): number {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
67
|
+
const rawStarted = act.startedAtMs || 0;
|
|
68
|
+
const rawCompleted = act.completedAtMs || 0;
|
|
69
69
|
const nowMs = Date.now();
|
|
70
|
+
const nowSec = Math.floor(nowMs / 1000);
|
|
71
|
+
// Detect if value is in seconds vs milliseconds by comparing distance to current time
|
|
72
|
+
const isSeconds = (v: number) => {
|
|
73
|
+
if (v <= 0) return false;
|
|
74
|
+
const distToSec = Math.abs(v - nowSec);
|
|
75
|
+
const distToMs = Math.abs(v - nowMs);
|
|
76
|
+
return distToSec < distToMs && distToSec < 31536000 * 2 && v > 1000000000;
|
|
77
|
+
};
|
|
78
|
+
const startedMs = isSeconds(rawStarted) ? rawStarted * 1000 : rawStarted;
|
|
79
|
+
const completedMs = isSeconds(rawCompleted) ? rawCompleted * 1000 : rawCompleted;
|
|
70
80
|
const isValidStarted = startedMs > 0 && startedMs < nowMs + 60000 && startedMs > nowMs - 3155692600000;
|
|
71
81
|
const isValidCompleted = completedMs === 0 || (completedMs > 0 && completedMs < nowMs + 60000);
|
|
72
82
|
return (isValidCompleted ? completedMs : nowMs) - (isValidStarted ? startedMs : nowMs);
|