@diegopetrucci/pi-extensions 0.1.74 → 0.1.78
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/LICENSE +2 -0
- package/README.md +17 -12
- package/extensions/agent-workflow-audit/README.md +1 -1
- package/extensions/agent-workflow-audit/index.ts +1631 -1009
- package/extensions/agent-workflow-audit/package.json +1 -1
- package/extensions/annotate-git-diff/README.md +3 -1
- package/extensions/annotate-git-diff/clipboard.ts +109 -100
- package/extensions/annotate-git-diff/git.ts +846 -768
- package/extensions/annotate-git-diff/glimpseui.d.ts +87 -78
- package/extensions/annotate-git-diff/index.ts +712 -671
- package/extensions/annotate-git-diff/package.json +1 -1
- package/extensions/annotate-git-diff/prompt.ts +45 -45
- package/extensions/annotate-git-diff/quiet-glimpse.ts +161 -155
- package/extensions/annotate-git-diff/review-server.ts +337 -311
- package/extensions/annotate-git-diff/types.ts +132 -132
- package/extensions/annotate-git-diff/ui.ts +27 -27
- package/extensions/annotate-git-diff/watch.ts +74 -74
- package/extensions/annotate-git-diff/web/app.js +1947 -1884
- package/extensions/annotate-git-diff/web/index.html +5 -6
- package/extensions/annotate-last-message/README.md +1 -1
- package/extensions/annotate-last-message/glimpseui.d.ts +87 -78
- package/extensions/annotate-last-message/index.ts +210 -206
- package/extensions/annotate-last-message/package.json +1 -1
- package/extensions/annotate-last-message/prompt.ts +87 -66
- package/extensions/annotate-last-message/quiet-glimpse.ts +161 -155
- package/extensions/annotate-last-message/session.ts +94 -89
- package/extensions/annotate-last-message/theme.ts +199 -193
- package/extensions/annotate-last-message/types.ts +23 -23
- package/extensions/annotate-last-message/ui.ts +27 -25
- package/extensions/annotate-last-message/web/app.js +4 -7
- package/extensions/annotate-last-message/web/index.html +3 -3
- package/extensions/annotate-last-message/web/md-renderer.js +1 -1
- package/extensions/brrr/README.md +1 -1
- package/extensions/brrr/index.ts +213 -191
- package/extensions/brrr/package.json +1 -1
- package/extensions/claude-fast/README.md +5 -79
- package/extensions/claude-fast/index.ts +31 -289
- package/extensions/claude-fast/package.json +2 -3
- package/extensions/code-reviewer/README.md +6 -6
- package/extensions/code-reviewer/index.ts +1825 -1373
- package/extensions/code-reviewer/package.json +1 -1
- package/extensions/confirm-destructive/README.md +1 -1
- package/extensions/confirm-destructive/index.ts +50 -52
- package/extensions/confirm-destructive/package.json +1 -1
- package/extensions/context-cap/README.md +9 -9
- package/extensions/context-cap/index.ts +313 -305
- package/extensions/context-cap/package.json +2 -2
- package/extensions/context-inspector/index.ts +1211 -1064
- package/extensions/context-inspector/package.json +1 -1
- package/extensions/contrarian/README.md +4 -3
- package/extensions/contrarian/index.ts +1863 -1737
- package/extensions/contrarian/package.json +1 -1
- package/extensions/dirty-repo-guard/index.ts +37 -41
- package/extensions/dirty-repo-guard/package.json +1 -1
- package/extensions/dynamic-context-pruning/README.md +11 -43
- package/extensions/dynamic-context-pruning/index.ts +2131 -2105
- package/extensions/dynamic-context-pruning/package.json +1 -1
- package/extensions/fast/README.md +52 -14
- package/extensions/fast/index.ts +513 -317
- package/extensions/fast/package.json +1 -1
- package/extensions/git-footer/README.md +1 -1
- package/extensions/git-footer/index.ts +458 -411
- package/extensions/git-footer/package.json +2 -3
- package/extensions/gnosis/index.ts +180 -130
- package/extensions/gnosis/package.json +1 -1
- package/extensions/inline-bash/index.ts +87 -103
- package/extensions/inline-bash/package.json +1 -1
- package/extensions/librarian/README.md +1 -1
- package/extensions/librarian/index.ts +1877 -1419
- package/extensions/librarian/package.json +1 -1
- package/extensions/minimal-footer/README.md +5 -5
- package/extensions/minimal-footer/index.ts +987 -1012
- package/extensions/minimal-footer/minimal-footer.example.json +1 -1
- package/extensions/minimal-footer/openai-usage.ts +195 -190
- package/extensions/minimal-footer/package.json +1 -1
- package/extensions/notify/index.ts +222 -230
- package/extensions/notify/package.json +1 -1
- package/extensions/openai-fast/README.md +5 -73
- package/extensions/openai-fast/index.ts +32 -272
- package/extensions/openai-fast/package.json +2 -3
- package/extensions/oracle/README.md +4 -3
- package/extensions/oracle/index.ts +1740 -1627
- package/extensions/oracle/package.json +1 -1
- package/extensions/permission-gate/README.md +3 -0
- package/extensions/permission-gate/index.ts +785 -612
- package/extensions/permission-gate/package.json +1 -1
- package/extensions/permission-gate/powershell-safety.ts +840 -793
- package/extensions/project-mcp-json/.pi-fleet-tested-version +1 -0
- package/extensions/project-mcp-json/README.md +199 -0
- package/extensions/project-mcp-json/config.ts +564 -0
- package/extensions/project-mcp-json/index.ts +119 -0
- package/extensions/project-mcp-json/package.json +38 -0
- package/extensions/quiet-tools/.pi-fleet-tested-version +1 -1
- package/extensions/quiet-tools/README.md +30 -19
- package/extensions/quiet-tools/index.ts +376 -291
- package/extensions/quiet-tools/package.json +2 -2
- package/extensions/review/README.md +2 -2
- package/extensions/review/index.ts +1745 -1872
- package/extensions/review/package.json +1 -1
- package/extensions/todo/index.ts +280 -280
- package/extensions/todo/package.json +1 -1
- package/extensions/triage-comments/README.md +6 -4
- package/extensions/triage-comments/index.ts +2620 -1888
- package/extensions/triage-comments/package.json +1 -1
- package/package.json +9 -6
- package/assets/social-preview.png +0 -0
- package/extensions/claude-fast/claude-fast.example.json +0 -4
- package/extensions/openai-fast/openai-fast.example.json +0 -4
|
@@ -4,228 +4,232 @@ import { openQuietGlimpse, type QuietGlimpseWindow } from "./quiet-glimpse.js";
|
|
|
4
4
|
import { composeAnnotateLastMessagePrompt, hasAnnotateLastMessageFeedback } from "./prompt.js";
|
|
5
5
|
import { findLastAssistantMessage } from "./session.js";
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
AnnotateLastMessageCancelPayload,
|
|
8
|
+
AnnotateLastMessageInlineComment,
|
|
9
|
+
AnnotateLastMessageSectionComment,
|
|
10
|
+
AnnotateLastMessageSubmitPayload,
|
|
11
|
+
AnnotateLastMessageWindowMessage,
|
|
12
|
+
LastAssistantMessageData,
|
|
13
13
|
} from "./types.js";
|
|
14
14
|
import { buildAnnotateLastMessageHtml } from "./ui.js";
|
|
15
15
|
|
|
16
16
|
function isInlineComment(value: unknown): value is AnnotateLastMessageInlineComment {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
return (
|
|
18
|
+
typeof value === "object" &&
|
|
19
|
+
value != null &&
|
|
20
|
+
"line" in value &&
|
|
21
|
+
typeof value.line === "number" &&
|
|
22
|
+
Number.isInteger(value.line) &&
|
|
23
|
+
value.line > 0 &&
|
|
24
|
+
"body" in value &&
|
|
25
|
+
typeof value.body === "string"
|
|
26
|
+
);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function isSectionComment(value: unknown): value is AnnotateLastMessageSectionComment {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
return (
|
|
31
|
+
typeof value === "object" &&
|
|
32
|
+
value != null &&
|
|
33
|
+
"sectionId" in value &&
|
|
34
|
+
typeof value.sectionId === "string" &&
|
|
35
|
+
"body" in value &&
|
|
36
|
+
typeof value.body === "string"
|
|
37
|
+
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function isSubmitPayload(value: unknown): value is AnnotateLastMessageSubmitPayload {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
return (
|
|
42
|
+
typeof value === "object" &&
|
|
43
|
+
value != null &&
|
|
44
|
+
"type" in value &&
|
|
45
|
+
value.type === "submit" &&
|
|
46
|
+
"overallComment" in value &&
|
|
47
|
+
typeof value.overallComment === "string" &&
|
|
48
|
+
"inlineComments" in value &&
|
|
49
|
+
Array.isArray(value.inlineComments) &&
|
|
50
|
+
value.inlineComments.every(isInlineComment) &&
|
|
51
|
+
"sectionComments" in value &&
|
|
52
|
+
Array.isArray(value.sectionComments) &&
|
|
53
|
+
value.sectionComments.every(isSectionComment)
|
|
54
|
+
);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function isCancelPayload(value: unknown): value is AnnotateLastMessageCancelPayload {
|
|
58
|
-
|
|
58
|
+
return typeof value === "object" && value != null && "type" in value && value.type === "cancel";
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
61
|
+
function registerAnnotateLastMessageCommand(pi: ExtensionAPI): void {
|
|
62
|
+
let activeWindow: QuietGlimpseWindow | null = null;
|
|
63
|
+
let annotationOpening = false;
|
|
64
|
+
let annotationAttempt = 0;
|
|
65
|
+
const suppressedWindows = new WeakSet<QuietGlimpseWindow>();
|
|
66
|
+
|
|
67
|
+
function closeActiveWindow(options: { suppressResults?: boolean } = {}): void {
|
|
68
|
+
annotationAttempt += 1;
|
|
69
|
+
const windowToClose = activeWindow;
|
|
70
|
+
activeWindow = null;
|
|
71
|
+
if (windowToClose == null) return;
|
|
72
|
+
if (options.suppressResults) {
|
|
73
|
+
suppressedWindows.add(windowToClose);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
windowToClose.close();
|
|
77
|
+
} catch {
|
|
78
|
+
// Ignore races when the native window is already closing.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function openAnnotationWindow(ctx: ExtensionCommandContext): Promise<void> {
|
|
83
|
+
if (ctx.mode !== "tui") {
|
|
84
|
+
ctx.ui.notify("annotate-last-message requires interactive mode.", "error");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (annotationOpening || activeWindow != null) {
|
|
88
|
+
ctx.ui.notify("A last-message annotation window is already open.", "warning");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const messageResult = findLastAssistantMessage(ctx.sessionManager.getBranch());
|
|
93
|
+
if (!messageResult.ok) {
|
|
94
|
+
ctx.ui.notify(messageResult.message, "error");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const messageData = messageResult.data;
|
|
99
|
+
annotationOpening = true;
|
|
100
|
+
const attempt = ++annotationAttempt;
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const html = buildAnnotateLastMessageHtml(messageData, ctx.ui.theme);
|
|
104
|
+
const window = await openQuietGlimpse(html, {
|
|
105
|
+
width: 1440,
|
|
106
|
+
height: 980,
|
|
107
|
+
title: "annotate last message",
|
|
108
|
+
});
|
|
109
|
+
if (attempt !== annotationAttempt) {
|
|
110
|
+
suppressedWindows.add(window);
|
|
111
|
+
window.close();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
activeWindow = window;
|
|
115
|
+
if (window.failure != null) throw window.failure;
|
|
116
|
+
if (window.closed)
|
|
117
|
+
throw new Error("Glimpse closed while the annotation window was starting.");
|
|
118
|
+
|
|
119
|
+
const terminalMessagePromise = new Promise<
|
|
120
|
+
AnnotateLastMessageSubmitPayload | AnnotateLastMessageCancelPayload | null
|
|
121
|
+
>((resolve, reject) => {
|
|
122
|
+
let settled = false;
|
|
123
|
+
let closeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
124
|
+
|
|
125
|
+
const requestWindowClose = (): void => {
|
|
126
|
+
try {
|
|
127
|
+
window.close();
|
|
128
|
+
} catch {
|
|
129
|
+
// Ignore races when the native process has already exited.
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const cleanup = (): void => {
|
|
134
|
+
if (closeTimer != null) {
|
|
135
|
+
clearTimeout(closeTimer);
|
|
136
|
+
closeTimer = null;
|
|
137
|
+
}
|
|
138
|
+
window.removeListener("message", onMessage);
|
|
139
|
+
window.removeListener("closed", onClosed);
|
|
140
|
+
window.removeListener("error", onError);
|
|
141
|
+
if (activeWindow === window) {
|
|
142
|
+
activeWindow = null;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const settle = (value: AnnotateLastMessageWindowMessage | null): void => {
|
|
147
|
+
if (settled) return;
|
|
148
|
+
settled = true;
|
|
149
|
+
cleanup();
|
|
150
|
+
resolve(value);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const onMessage = (data: unknown): void => {
|
|
154
|
+
if (isSubmitPayload(data) || isCancelPayload(data)) {
|
|
155
|
+
settle(data);
|
|
156
|
+
requestWindowClose();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const onClosed = (): void => {
|
|
161
|
+
if (settled || closeTimer != null) return;
|
|
162
|
+
closeTimer = setTimeout(() => {
|
|
163
|
+
closeTimer = null;
|
|
164
|
+
settle(null);
|
|
165
|
+
}, 250);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const onError = (error: Error): void => {
|
|
169
|
+
if (settled) return;
|
|
170
|
+
settled = true;
|
|
171
|
+
requestWindowClose();
|
|
172
|
+
cleanup();
|
|
173
|
+
reject(error);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
window.on("message", onMessage);
|
|
177
|
+
window.on("closed", onClosed);
|
|
178
|
+
window.on("error", onError);
|
|
179
|
+
if (window.failure != null) onError(window.failure);
|
|
180
|
+
else if (window.closed) onClosed();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
void (async (
|
|
184
|
+
windowMessageSource: QuietGlimpseWindow,
|
|
185
|
+
sourceData: LastAssistantMessageData,
|
|
186
|
+
) => {
|
|
187
|
+
try {
|
|
188
|
+
const result = await terminalMessagePromise;
|
|
189
|
+
if (suppressedWindows.has(windowMessageSource) || attempt !== annotationAttempt) return;
|
|
190
|
+
if (result == null) return;
|
|
191
|
+
if (result.type === "cancel") {
|
|
192
|
+
ctx.ui.notify("Annotation cancelled.", "info");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!hasAnnotateLastMessageFeedback(result)) {
|
|
196
|
+
ctx.ui.notify("No annotation feedback submitted.", "info");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const prompt = composeAnnotateLastMessagePrompt(sourceData, result);
|
|
201
|
+
pi.sendUserMessage(prompt, { deliverAs: "followUp" });
|
|
202
|
+
ctx.ui.notify("Annotation feedback sent to the agent.", "info");
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (suppressedWindows.has(windowMessageSource) || attempt !== annotationAttempt) return;
|
|
205
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
206
|
+
ctx.ui.notify(`Annotation failed: ${message}`, "error");
|
|
207
|
+
}
|
|
208
|
+
})(window, messageData);
|
|
209
|
+
|
|
210
|
+
ctx.ui.notify("Opened native annotation window.", "info");
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (attempt !== annotationAttempt) return;
|
|
213
|
+
closeActiveWindow({ suppressResults: true });
|
|
214
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
215
|
+
ctx.ui.notify(`Annotation failed: ${message}`, "error");
|
|
216
|
+
} finally {
|
|
217
|
+
annotationOpening = false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
pi.registerCommand("annotate-last-message", {
|
|
222
|
+
description: "Open a native annotation window for the latest assistant message",
|
|
223
|
+
handler: async (_args, ctx) => {
|
|
224
|
+
await openAnnotationWindow(ctx);
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
pi.on("session_shutdown", async () => {
|
|
229
|
+
closeActiveWindow({ suppressResults: true });
|
|
230
|
+
});
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
export default function (pi: ExtensionAPI): void {
|
|
230
|
-
|
|
234
|
+
registerAnnotateLastMessageCommand(pi);
|
|
231
235
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegopetrucci/pi-annotate-last-message",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "A standalone pi extension that adds /annotate-last-message, a native Glimpse UI for annotating the latest assistant reply.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -1,93 +1,114 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AnnotateLastMessageInlineComment,
|
|
3
|
+
AnnotateLastMessageSectionComment,
|
|
4
|
+
AnnotateLastMessageSubmitPayload,
|
|
5
|
+
LastAssistantMessageData,
|
|
6
|
+
LastAssistantMessageLine,
|
|
7
|
+
LastAssistantMessageSection,
|
|
8
|
+
} from "./types.js";
|
|
2
9
|
|
|
3
10
|
const EXCERPT_LIMIT = 120;
|
|
4
11
|
|
|
5
12
|
function truncateExcerpt(value: string, limit = EXCERPT_LIMIT): string {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
14
|
+
if (normalized.length === 0) return "(blank line)";
|
|
15
|
+
if (normalized.length <= limit) return normalized;
|
|
16
|
+
return `${normalized.slice(0, Math.max(0, limit - 1)).trimEnd()}…`;
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
function formatLineLabel(line: number): string {
|
|
13
|
-
|
|
20
|
+
return `line ${line}`;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
function formatLineComment(
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
function formatLineComment(
|
|
24
|
+
comment: AnnotateLastMessageInlineComment,
|
|
25
|
+
line: LastAssistantMessageLine | undefined,
|
|
26
|
+
): string {
|
|
27
|
+
const excerpt = truncateExcerpt(line?.text ?? "");
|
|
28
|
+
return `${formatLineLabel(comment.line)} — “${excerpt}”`;
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
function formatSectionLineRange(section: LastAssistantMessageSection): string {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
return section.startLine === section.endLine
|
|
33
|
+
? `line ${section.startLine}`
|
|
34
|
+
: `lines ${section.startLine}-${section.endLine}`;
|
|
25
35
|
}
|
|
26
36
|
|
|
27
|
-
function formatSectionComment(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
function formatSectionComment(
|
|
38
|
+
comment: AnnotateLastMessageSectionComment,
|
|
39
|
+
section: LastAssistantMessageSection | undefined,
|
|
40
|
+
): string {
|
|
41
|
+
if (section == null) {
|
|
42
|
+
return "Unknown section";
|
|
43
|
+
}
|
|
44
|
+
return `Section ${section.index} (${formatSectionLineRange(section)}) — “${truncateExcerpt(section.preview)}”`;
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
export function hasAnnotateLastMessageFeedback(payload: AnnotateLastMessageSubmitPayload): boolean {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
if (payload.overallComment.trim().length > 0) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (payload.inlineComments.some((comment) => comment.body.trim().length > 0)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return payload.sectionComments.some((comment) => comment.body.trim().length > 0);
|
|
42
55
|
}
|
|
43
56
|
|
|
44
57
|
export function composeAnnotateLastMessagePrompt(
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
message: LastAssistantMessageData,
|
|
59
|
+
payload: AnnotateLastMessageSubmitPayload,
|
|
47
60
|
): string {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
const lineMap = new Map(message.lines.map((line) => [line.number, line]));
|
|
62
|
+
const sectionMap = new Map(message.sections.map((section) => [section.id, section]));
|
|
63
|
+
const inlineComments = payload.inlineComments
|
|
64
|
+
.filter((comment) => comment.body.trim().length > 0)
|
|
65
|
+
.sort((left, right) => left.line - right.line);
|
|
66
|
+
const sectionComments = payload.sectionComments
|
|
67
|
+
.filter((comment) => comment.body.trim().length > 0)
|
|
68
|
+
.sort(
|
|
69
|
+
(left, right) =>
|
|
70
|
+
(sectionMap.get(left.sectionId)?.index ?? Number.MAX_SAFE_INTEGER) -
|
|
71
|
+
(sectionMap.get(right.sectionId)?.index ?? Number.MAX_SAFE_INTEGER),
|
|
72
|
+
);
|
|
73
|
+
const lines: string[] = [];
|
|
57
74
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
lines.push("Please revisit your last assistant message using the annotation feedback below.");
|
|
76
|
+
lines.push("");
|
|
77
|
+
lines.push("Treat this as planning-oriented feedback:");
|
|
78
|
+
lines.push("- update your explanation, plan, or proposed approach in chat;");
|
|
79
|
+
lines.push("- do not assume any code or file changes have already been applied;");
|
|
80
|
+
lines.push("- do not auto-apply anything outside the normal response flow.");
|
|
81
|
+
lines.push("");
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
const overallComment = payload.overallComment.trim();
|
|
84
|
+
if (overallComment.length > 0) {
|
|
85
|
+
lines.push("## Overall guidance");
|
|
86
|
+
lines.push(overallComment);
|
|
87
|
+
lines.push("");
|
|
88
|
+
}
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
if (sectionComments.length > 0) {
|
|
91
|
+
lines.push("## Section comments");
|
|
92
|
+
sectionComments.forEach((comment, index) => {
|
|
93
|
+
lines.push(
|
|
94
|
+
`${index + 1}. ${formatSectionComment(comment, sectionMap.get(comment.sectionId))}`,
|
|
95
|
+
);
|
|
96
|
+
lines.push(` ${comment.body.trim()}`);
|
|
97
|
+
lines.push("");
|
|
98
|
+
});
|
|
99
|
+
}
|
|
81
100
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
if (inlineComments.length > 0) {
|
|
102
|
+
lines.push("## Inline comments");
|
|
103
|
+
inlineComments.forEach((comment, index) => {
|
|
104
|
+
lines.push(`${index + 1}. ${formatLineComment(comment, lineMap.get(comment.line))}`);
|
|
105
|
+
lines.push(` ${comment.body.trim()}`);
|
|
106
|
+
lines.push("");
|
|
107
|
+
});
|
|
108
|
+
}
|
|
90
109
|
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
lines.push(
|
|
111
|
+
"Please respond by revising your last message or its plan in chat, incorporating the feedback above.",
|
|
112
|
+
);
|
|
113
|
+
return lines.join("\n").trim();
|
|
93
114
|
}
|