@diegopetrucci/pi-annotate-last-message 0.1.10 → 0.1.12
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/README.md +1 -1
- package/glimpseui.d.ts +87 -78
- package/index.ts +210 -206
- package/package.json +1 -1
- package/prompt.ts +87 -66
- package/quiet-glimpse.ts +161 -155
- package/session.ts +94 -89
- package/theme.ts +199 -193
- package/types.ts +23 -23
- package/ui.ts +27 -25
- package/web/app.js +4 -7
- package/web/index.html +3 -3
- package/web/md-renderer.js +1 -1
package/types.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
export interface LastAssistantMessageLine {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
number: number;
|
|
3
|
+
text: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface LastAssistantMessageSection {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
text: string;
|
|
7
|
+
id: string;
|
|
8
|
+
index: number;
|
|
9
|
+
startLine: number;
|
|
10
|
+
endLine: number;
|
|
11
|
+
preview: string;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export interface LastAssistantMessageData {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
sections: LastAssistantMessageSection[];
|
|
15
|
+
lines: LastAssistantMessageLine[];
|
|
16
|
+
sections: LastAssistantMessageSection[];
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export type LastAssistantMessageLookupResult =
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
| { ok: true; data: LastAssistantMessageData }
|
|
21
|
+
| { ok: false; code: "missing" | "incomplete" | "empty"; message: string };
|
|
24
22
|
|
|
25
23
|
export interface AnnotateLastMessageInlineComment {
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
line: number;
|
|
25
|
+
body: string;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
export interface AnnotateLastMessageSectionComment {
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
sectionId: string;
|
|
30
|
+
body: string;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export interface AnnotateLastMessageSubmitPayload {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
type: "submit";
|
|
35
|
+
overallComment: string;
|
|
36
|
+
inlineComments: AnnotateLastMessageInlineComment[];
|
|
37
|
+
sectionComments: AnnotateLastMessageSectionComment[];
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
export interface AnnotateLastMessageCancelPayload {
|
|
43
|
-
|
|
41
|
+
type: "cancel";
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
export type AnnotateLastMessageWindowMessage =
|
|
44
|
+
export type AnnotateLastMessageWindowMessage =
|
|
45
|
+
| AnnotateLastMessageSubmitPayload
|
|
46
|
+
| AnnotateLastMessageCancelPayload;
|
package/ui.ts
CHANGED
|
@@ -10,40 +10,42 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
10
10
|
const webDir = join(__dirname, "web");
|
|
11
11
|
|
|
12
12
|
function escapeForInlineScript(value: string): string {
|
|
13
|
-
|
|
13
|
+
return value.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function escapeInlineScriptSource(value: string): string {
|
|
17
|
-
|
|
17
|
+
return value.replace(/<\/(script)/gi, "<\\/$1");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function buildThemeCssBlock(vars: Record<string, string>): string {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const declarations = Object.entries(vars)
|
|
22
|
+
.map(([key, value]) => ` ${key}: ${value};`)
|
|
23
|
+
.join("\n");
|
|
24
|
+
return `:root {\n${declarations}\n}`;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function buildAnnotateLastMessageHtml(
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
data: LastAssistantMessageData,
|
|
29
|
+
theme?: AnnotateTheme,
|
|
30
30
|
): string {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const templateHtml = readFileSync(join(webDir, "index.html"), "utf8");
|
|
32
|
+
const mdRendererJs = escapeInlineScriptSource(
|
|
33
|
+
readFileSync(join(webDir, "md-renderer.js"), "utf8"),
|
|
34
|
+
);
|
|
35
|
+
const appJs = escapeInlineScriptSource(readFileSync(join(webDir, "app.js"), "utf8"));
|
|
36
|
+
const payload = escapeForInlineScript(JSON.stringify(data));
|
|
37
|
+
const themeBlock = buildThemeCssBlock(getThemeCssVars(theme));
|
|
38
|
+
const replacements = new Map([
|
|
39
|
+
['"__INLINE_DATA__"', payload],
|
|
40
|
+
["__INLINE_MD_RENDERER_JS__", mdRendererJs],
|
|
41
|
+
["__INLINE_JS__", appJs],
|
|
42
|
+
["__INLINE_THEME__", themeBlock],
|
|
43
|
+
]);
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
// Replace the original template in one pass so marker-like message data,
|
|
46
|
+
// theme values, or runtime source is never scanned as another placeholder.
|
|
47
|
+
return templateHtml.replace(
|
|
48
|
+
/"__INLINE_DATA__"|__INLINE_MD_RENDERER_JS__|__INLINE_JS__|__INLINE_THEME__/g,
|
|
49
|
+
(marker) => replacements.get(marker) ?? marker,
|
|
50
|
+
);
|
|
49
51
|
}
|
package/web/app.js
CHANGED
|
@@ -305,9 +305,6 @@ function createSectionCard(section) {
|
|
|
305
305
|
meta.textContent = lineRange;
|
|
306
306
|
card.append(meta);
|
|
307
307
|
|
|
308
|
-
// Render the exact source lines in this section. Do not parse section.text
|
|
309
|
-
// independently: its opening fence may be in an earlier section separated
|
|
310
|
-
// by a blank line.
|
|
311
308
|
const preview = document.createElement("div");
|
|
312
309
|
preview.className = "section-preview markdown-content";
|
|
313
310
|
|
|
@@ -316,9 +313,7 @@ function createSectionCard(section) {
|
|
|
316
313
|
const sourceLines =
|
|
317
314
|
startIndex >= 0 && endIndex >= startIndex && endIndex <= messageData.lines.length
|
|
318
315
|
? messageData.lines.slice(startIndex, endIndex).map((line) => line.text)
|
|
319
|
-
:
|
|
320
|
-
? section.text.split("\n")
|
|
321
|
-
: [];
|
|
316
|
+
: [];
|
|
322
317
|
for (let idx = 0; idx < sourceLines.length; idx++) {
|
|
323
318
|
const lineDiv = document.createElement("div");
|
|
324
319
|
const sourceIndex = startIndex >= 0 ? startIndex + idx : -1;
|
|
@@ -342,7 +337,9 @@ function createSectionCard(section) {
|
|
|
342
337
|
function renderMessageLines() {
|
|
343
338
|
elements.messageLines.replaceChildren();
|
|
344
339
|
for (let i = 0; i < messageData.lines.length; i++) {
|
|
345
|
-
elements.messageLines.append(
|
|
340
|
+
elements.messageLines.append(
|
|
341
|
+
createLineRow(messageData.lines[i], fullMessageFenceState[i].lineType),
|
|
342
|
+
);
|
|
346
343
|
}
|
|
347
344
|
}
|
|
348
345
|
|
package/web/index.html
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* overrides semantic and Markdown colours from ctx.ui.theme. When Pi's theme
|
|
11
11
|
* cannot provide a token, the matching dark/light fallback remains readable.
|
|
12
12
|
*
|
|
13
|
-
* The --md* fallback values below are kept in sync with
|
|
14
|
-
*
|
|
13
|
+
* The --md* fallback values below are kept in sync with DARK_FALLBACK
|
|
14
|
+
* in theme.ts so this template renders correctly when the injected
|
|
15
15
|
* theme block is absent (e.g. opened standalone in a browser for debugging).
|
|
16
16
|
*/
|
|
17
17
|
:root {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
--error: #ffb3b3;
|
|
32
32
|
--warning: #f4c95d;
|
|
33
33
|
|
|
34
|
-
/* Markdown token colours — kept in sync with
|
|
34
|
+
/* Markdown token colours — kept in sync with DARK_FALLBACK in theme.ts */
|
|
35
35
|
--mdHeading: #f4c95d;
|
|
36
36
|
--mdLink: #7dd3fc;
|
|
37
37
|
--mdLinkUrl: #8a8a8a;
|
package/web/md-renderer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* global globalThis */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* annotate-last-message: pure markdown line parser.
|
|
5
5
|
*
|
|
6
6
|
* Single source of truth for the parsing logic. ui.ts reads this file and
|
|
7
7
|
* inlines it as a dedicated script before app.js, so globalThis.__tlhMdRenderer
|