pi-crew 0.2.15 → 0.2.17

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-crew",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Pi extension for coordinated AI teams, workflows, worktrees, and async task orchestration",
5
5
  "author": "baphuongna",
6
6
  "license": "MIT",
@@ -94,32 +94,37 @@ export function registerCompactionGuard(pi: ExtensionAPI, options: RegisterCompa
94
94
  });
95
95
  };
96
96
 
97
- // Phase 1.2: Defer compaction during foreground runs unless context is critically full.
97
+ // Phase 1.2: Always allow compaction to proceed.
98
+ // Previously this deferred compaction during foreground runs, but that prevented
99
+ // context-mode's PreCompact hook from running (which needs compaction to build resume snapshots).
100
+ // pi-crew state is preserved via customInstructions and artifactIndex appended above.
98
101
  pi.on("session_before_compact", async (_event, ctx) => {
99
- if (options.foregroundControllers.size === 0 && options.foregroundTeamRunControllers.size === 0) return;
100
- const ratio = usageRatio(ctx);
101
- if (ratio !== undefined && ratio >= HARD_RATIO) {
102
- ctx.ui.notify("Compaction allowed despite foreground run: context is critically full", "warning");
103
- return;
104
- }
105
- pendingCompactReason = "deferred-during-foreground-run";
106
- ctx.ui.notify("Compaction deferred: foreground team run in progress", "info");
107
- return { cancel: true };
102
+ // Always allow compaction - context-mode needs it for resume snapshots
103
+ return;
108
104
  });
109
105
 
110
- // Phase 2.1: Proactive compaction with dynamic threshold based on model context window.
106
+ // Phase 2.1: Proactive compaction with dynamic threshold.
107
+ // Only trigger compaction when context usage >=75%, or when deferred from a previous high-usage turn.
111
108
  pi.on("turn_end", (_event, ctx) => {
112
109
  if (compactionInProgress) return;
113
110
  const hasActiveForeground = options.foregroundControllers.size > 0 || options.foregroundTeamRunControllers.size > 0;
111
+ const ratio = usageRatio(ctx);
112
+ // If deferred compaction is pending and foreground just ended, check if still needed
114
113
  if (!hasActiveForeground && pendingCompactReason) {
115
114
  pendingCompactReason = null;
115
+ // Only compact if ratio still >= TRIGGER_RATIO, otherwise skip
116
+ if (ratio === undefined || ratio < TRIGGER_RATIO) return;
116
117
  startCompact(ctx, "deferred");
117
118
  return;
118
119
  }
119
- const ratio = usageRatio(ctx);
120
120
  if (ratio === undefined || ratio < TRIGGER_RATIO) return;
121
+ // During foreground run: defer unless context is critically full
121
122
  if (hasActiveForeground) {
122
- pendingCompactReason = "threshold-during-foreground-run";
123
+ if (ratio >= HARD_RATIO) {
124
+ startCompact(ctx, "critical");
125
+ } else {
126
+ pendingCompactReason = "threshold-during-foreground-run";
127
+ }
123
128
  return;
124
129
  }
125
130
  startCompact(ctx, "threshold");
@@ -121,7 +121,10 @@ function agentActivity(agent: CrewAgentRecord, liveHandle?: LiveAgentHandle): st
121
121
  }
122
122
  if (agent.progress?.currentTool) return `${TOOL_LABELS[agent.progress.currentTool] ?? agent.progress.currentTool}…`;
123
123
  const recent = agent.progress?.recentOutput?.at(-1);
124
- if (recent) return recent.replace(/\s+/g, " ").trim();
124
+ if (recent) {
125
+ const cleaned = recent.replace(/\s+/g, " ").trim();
126
+ return cleaned.length > 60 ? cleaned.slice(0, 60) + "…" : cleaned;
127
+ }
125
128
  if (agent.progress?.activityState === "needs_attention") return "needs attention";
126
129
  if (agent.status === "queued") return "queued";
127
130
  if (agent.status === "running") {
@@ -165,9 +168,20 @@ function agentStats(agent: CrewAgentRecord, liveHandle?: LiveAgentHandle): strin
165
168
  // If distance to seconds is much smaller AND value is in valid seconds range
166
169
  return distToSec < distToMs && distToSec < 31536000 * 2 && v > 1000000000;
167
170
  };
168
- const startedMs = isSeconds(rawStarted) ? rawStarted * 1000 : rawStarted;
169
- const completedMs = isSeconds(rawCompleted) ? rawCompleted * 1000 : rawCompleted;
170
- // Validate: startedAtMs should be within reasonable bounds
171
+ // Simple fix: detect if value is Unix seconds and convert properly
172
+ // Unix seconds are ~10 digits (e.g., 1779082445), Unix ms are ~13 digits (e.g., 1779082445000)
173
+ const toMs = (v: number): number => {
174
+ if (v <= 0) return 0;
175
+ // If 10 digits (or 9 with recent), treat as seconds
176
+ if (v > 1000000000 && v < 10000000000) return v * 1000;
177
+ // If 13 digits, treat as ms
178
+ if (v > 100000000000 && v < 10000000000000) return v;
179
+ // Fallback: use as-is
180
+ return v;
181
+ };
182
+ const startedMs = toMs(rawStarted);
183
+ const completedMs = rawCompleted > 0 ? toMs(rawCompleted) : 0;
184
+ // Validate bounds
171
185
  const isValidStarted = startedMs > 0 && startedMs < nowMs + 60000 && startedMs > nowMs - 3155692600000;
172
186
  const isValidCompleted = completedMs === 0 || (completedMs > 0 && completedMs < nowMs + 60000);
173
187
  const ms = (isValidCompleted ? completedMs : nowMs) - (isValidStarted ? startedMs : nowMs);
@@ -68,15 +68,19 @@ export class LiveConversationOverlay {
68
68
  const rawCompleted = act.completedAtMs || 0;
69
69
  const nowMs = Date.now();
70
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;
71
+ // Simple fix: detect if value is Unix seconds and convert properly
72
+ const toMs = (v: number): number => {
73
+ if (v <= 0) return 0;
74
+ // If 10 digits (or 9 with recent), treat as seconds
75
+ if (v > 1000000000 && v < 10000000000) return v * 1000;
76
+ // If 13 digits, treat as ms
77
+ if (v > 100000000000 && v < 10000000000000) return v;
78
+ // Fallback: use as-is
79
+ return v;
77
80
  };
78
- const startedMs = isSeconds(rawStarted) ? rawStarted * 1000 : rawStarted;
79
- const completedMs = isSeconds(rawCompleted) ? rawCompleted * 1000 : rawCompleted;
81
+ const startedMs = toMs(rawStarted);
82
+ const completedMs = rawCompleted > 0 ? toMs(rawCompleted) : 0;
83
+ // Validate bounds
80
84
  const isValidStarted = startedMs > 0 && startedMs < nowMs + 60000 && startedMs > nowMs - 3155692600000;
81
85
  const isValidCompleted = completedMs === 0 || (completedMs > 0 && completedMs < nowMs + 60000);
82
86
  return (isValidCompleted ? completedMs : nowMs) - (isValidStarted ? startedMs : nowMs);