pi-crew 0.2.16 → 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
|
@@ -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:
|
|
97
|
-
// Previously this deferred compaction, but that
|
|
98
|
-
// which needs compaction to
|
|
99
|
-
//
|
|
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
|
|
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
|
-
//
|
|
112
|
-
|
|
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
|
}
|
package/src/ui/crew-widget.ts
CHANGED
|
@@ -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)
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
//
|
|
72
|
-
const
|
|
73
|
-
if (v <= 0) return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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 =
|
|
79
|
-
const completedMs =
|
|
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);
|