pi-crew 0.2.16 → 0.2.18

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.16",
3
+ "version": "0.2.18",
4
4
  "description": "Pi extension for coordinated AI teams, workflows, worktrees, and async task orchestration",
5
5
  "author": "baphuongna",
6
6
  "license": "MIT",
@@ -77,10 +77,10 @@
77
77
  "@mariozechner/pi-tui": "*"
78
78
  },
79
79
  "dependencies": {
80
+ "@sinclair/typebox": "^0.34.49",
80
81
  "cli-highlight": "^2.1.11",
81
82
  "diff": "^5.2.0",
82
- "jiti": "^2.6.1",
83
- "@sinclair/typebox": "^0.34.49"
83
+ "jiti": "^2.6.1"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@mariozechner/pi-agent-core": "^0.65.0",
@@ -76,6 +76,7 @@ export interface CrewUiConfig {
76
76
  dashboardLiveRefreshMs?: number;
77
77
  autoOpenDashboard?: boolean;
78
78
  autoOpenDashboardForForegroundRuns?: boolean;
79
+ autoCloseDashboardMs?: number;
79
80
  showModel?: boolean;
80
81
  showTokens?: boolean;
81
82
  showTools?: boolean;
@@ -67,6 +67,7 @@ function formatCrewArtifactIndex(entries: CrewArtifactIndexEntry[]): string {
67
67
  }
68
68
 
69
69
  export function registerCompactionGuard(pi: ExtensionAPI, options: RegisterCompactionGuardOptions): void {
70
+ let pendingCompactReason: string | null = null;
70
71
  let compactionInProgress = false;
71
72
 
72
73
  const startCompact = (ctx: ExtensionContext, reason: string): void => {
@@ -93,22 +94,39 @@ export function registerCompactionGuard(pi: ExtensionAPI, options: RegisterCompa
93
94
  });
94
95
  };
95
96
 
96
- // Phase 1.2: Allow compaction during foreground runs.
97
- // Previously this deferred compaction, but that conflicts with context-mode's PreCompact hook
98
- // which needs compaction to run to build resume snapshots.
99
- // Instead, we now prioritize crew state in the compaction summary (see startCompact).
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.
100
101
  pi.on("session_before_compact", async (_event, ctx) => {
101
102
  // Always allow compaction - context-mode needs it for resume snapshots
102
- // pi-crew state is preserved via customInstructions and artifactIndex
103
103
  return;
104
104
  });
105
105
 
106
- // 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.
107
108
  pi.on("turn_end", (_event, ctx) => {
108
109
  if (compactionInProgress) return;
110
+ const hasActiveForeground = options.foregroundControllers.size > 0 || options.foregroundTeamRunControllers.size > 0;
109
111
  const ratio = usageRatio(ctx);
112
+ // If deferred compaction is pending and foreground just ended, check if still needed
113
+ if (!hasActiveForeground && pendingCompactReason) {
114
+ pendingCompactReason = null;
115
+ // Only compact if ratio still >= TRIGGER_RATIO, otherwise skip
116
+ if (ratio === undefined || ratio < TRIGGER_RATIO) return;
117
+ startCompact(ctx, "deferred");
118
+ return;
119
+ }
110
120
  if (ratio === undefined || ratio < TRIGGER_RATIO) return;
111
- // Always allow compaction during foreground runs - context-mode needs it
112
- startCompact(ctx, ratio >= HARD_RATIO ? "critical" : "threshold");
121
+ // During foreground run: defer unless context is critically full
122
+ if (hasActiveForeground) {
123
+ if (ratio >= HARD_RATIO) {
124
+ startCompact(ctx, "critical");
125
+ } else {
126
+ pendingCompactReason = "threshold-during-foreground-run";
127
+ }
128
+ return;
129
+ }
130
+ startCompact(ctx, "threshold");
113
131
  });
114
132
  }
@@ -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);