@mrclrchtr/supi-review 2.6.0 → 2.7.0
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/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/package.json +2 -2
- package/src/history/synthesize.ts +1 -5
- package/src/review.ts +43 -31
- package/src/tool/agent-review-tools.ts +8 -10
- package/src/tool/agent-review-workflow.ts +41 -28
- package/src/tool/brief-runner.ts +25 -25
- package/src/tool/child-failure-diagnostics.ts +145 -0
- package/src/tool/child-lifecycle-trace.ts +329 -0
- package/src/tool/review-handlers.ts +9 -30
- package/src/tool/review-runner.ts +25 -44
- package/src/tool/runner-helpers.ts +0 -14
- package/src/tool/session-lifecycle.ts +105 -10
- package/src/types.ts +51 -40
- package/src/ui/format-content.ts +47 -38
- package/src/ui/renderer.ts +67 -45
- package/src/ui/review-tool-renderer.ts +32 -1
- package/src/tool/review-debug.ts +0 -124
package/src/tool/review-debug.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { AgentSession, AgentSessionEvent } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { ReviewFailureDebugInfo, ReviewProgress } from "../types.ts";
|
|
3
|
-
import { buildProgressTokens, extractAssistantText } from "./runner-helpers.ts";
|
|
4
|
-
|
|
5
|
-
export const RECENT_EVENTS_MAX = 10;
|
|
6
|
-
export const LAST_ASSISTANT_TEXT_DEBUG_MAX = 2_000;
|
|
7
|
-
|
|
8
|
-
export interface LastAssistantDebugInfo {
|
|
9
|
-
text?: string;
|
|
10
|
-
stopReason?: string;
|
|
11
|
-
errorMessage?: string;
|
|
12
|
-
toolCalls?: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function extractLastAssistantDebugFromMessages(
|
|
16
|
-
messages: ArrayLike<Record<string, unknown>> | undefined,
|
|
17
|
-
): LastAssistantDebugInfo | undefined {
|
|
18
|
-
if (!messages) return undefined;
|
|
19
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
20
|
-
const message = messages[i];
|
|
21
|
-
if (message?.role !== "assistant") continue;
|
|
22
|
-
|
|
23
|
-
const text = extractAssistantText(message.content);
|
|
24
|
-
const stopReason =
|
|
25
|
-
typeof message.stopReason === "string" ? (message.stopReason as string) : undefined;
|
|
26
|
-
const errorMessage =
|
|
27
|
-
typeof message.errorMessage === "string" ? (message.errorMessage as string) : undefined;
|
|
28
|
-
const toolCalls = extractAssistantToolCalls(message.content);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
text: text ? truncateText(text, LAST_ASSISTANT_TEXT_DEBUG_MAX) : undefined,
|
|
32
|
-
stopReason,
|
|
33
|
-
errorMessage,
|
|
34
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function extractLastAssistantDebug(
|
|
41
|
-
session: AgentSession,
|
|
42
|
-
): LastAssistantDebugInfo | undefined {
|
|
43
|
-
return extractLastAssistantDebugFromMessages(
|
|
44
|
-
session.messages as unknown as Array<Record<string, unknown>>,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function extractAssistantToolCalls(content: unknown): string[] {
|
|
49
|
-
if (!Array.isArray(content)) return [];
|
|
50
|
-
|
|
51
|
-
return content
|
|
52
|
-
.map((part) => {
|
|
53
|
-
if (typeof part !== "object" || !part) return undefined;
|
|
54
|
-
const toolPart = part as { type?: unknown; name?: unknown };
|
|
55
|
-
return toolPart.type === "toolCall" && typeof toolPart.name === "string"
|
|
56
|
-
? toolPart.name
|
|
57
|
-
: undefined;
|
|
58
|
-
})
|
|
59
|
-
.filter((name): name is string => !!name);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function summarizeSessionEvent(event: AgentSessionEvent): string | undefined {
|
|
63
|
-
switch (event.type) {
|
|
64
|
-
case "message_end": {
|
|
65
|
-
const message = event.message as unknown as Record<string, unknown>;
|
|
66
|
-
if (message.role !== "assistant") return undefined;
|
|
67
|
-
const stopReason =
|
|
68
|
-
typeof message.stopReason === "string" ? String(message.stopReason) : undefined;
|
|
69
|
-
const suffix = stopReason ? `:${stopReason}` : "";
|
|
70
|
-
return `assistant:end${suffix}`;
|
|
71
|
-
}
|
|
72
|
-
case "tool_execution_start":
|
|
73
|
-
return `tool:start:${event.toolName}`;
|
|
74
|
-
case "tool_execution_end":
|
|
75
|
-
return `tool:end:${event.toolName}${event.isError ? ":error" : ""}`;
|
|
76
|
-
case "turn_end":
|
|
77
|
-
return "turn:end";
|
|
78
|
-
case "agent_end":
|
|
79
|
-
return `agent:end${event.willRetry ? ":retry" : ""}`;
|
|
80
|
-
case "agent_settled":
|
|
81
|
-
return "agent:settled";
|
|
82
|
-
case "auto_retry_start":
|
|
83
|
-
return `retry:start:${event.attempt}/${event.maxAttempts}`;
|
|
84
|
-
case "auto_retry_end":
|
|
85
|
-
return `retry:end:${event.success ? "success" : "failed"}`;
|
|
86
|
-
default:
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function pushRecentEvent(recentEvents: string[], summary: string | undefined): void {
|
|
92
|
-
if (!summary) return;
|
|
93
|
-
recentEvents.push(summary);
|
|
94
|
-
if (recentEvents.length > RECENT_EVENTS_MAX) {
|
|
95
|
-
recentEvents.splice(0, recentEvents.length - RECENT_EVENTS_MAX);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface BuildFailureDebugInput {
|
|
100
|
-
progress: ReviewProgress;
|
|
101
|
-
session: AgentSession;
|
|
102
|
-
recentEvents: string[];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function buildFailureDebug(input: BuildFailureDebugInput): ReviewFailureDebugInfo {
|
|
106
|
-
input.progress.tokens = buildProgressTokens(() => input.session.getSessionStats());
|
|
107
|
-
const lastAssistant = extractLastAssistantDebug(input.session);
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
turns: input.progress.turns,
|
|
111
|
-
toolUses: input.progress.toolUses,
|
|
112
|
-
tokens: input.progress.tokens,
|
|
113
|
-
recentEvents: input.recentEvents.length > 0 ? [...input.recentEvents] : undefined,
|
|
114
|
-
lastAssistantText: lastAssistant?.text,
|
|
115
|
-
lastAssistantStopReason: lastAssistant?.stopReason,
|
|
116
|
-
lastAssistantErrorMessage: lastAssistant?.errorMessage,
|
|
117
|
-
lastAssistantToolCalls: lastAssistant?.toolCalls,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function truncateText(text: string, maxLen: number): string {
|
|
122
|
-
if (text.length <= maxLen) return text;
|
|
123
|
-
return `${text.slice(0, maxLen)}... (${text.length - maxLen} more chars)`;
|
|
124
|
-
}
|