@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/types.ts CHANGED
@@ -1,46 +1,46 @@
1
1
  export interface LastAssistantMessageLine {
2
- number: number;
3
- text: string;
2
+ number: number;
3
+ text: string;
4
4
  }
5
5
 
6
6
  export interface LastAssistantMessageSection {
7
- id: string;
8
- index: number;
9
- startLine: number;
10
- endLine: number;
11
- preview: string;
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
- text: string;
17
- lines: LastAssistantMessageLine[];
18
- sections: LastAssistantMessageSection[];
15
+ lines: LastAssistantMessageLine[];
16
+ sections: LastAssistantMessageSection[];
19
17
  }
20
18
 
21
19
  export type LastAssistantMessageLookupResult =
22
- | { ok: true; data: LastAssistantMessageData }
23
- | { ok: false; code: "missing" | "incomplete" | "empty"; message: string };
20
+ | { ok: true; data: LastAssistantMessageData }
21
+ | { ok: false; code: "missing" | "incomplete" | "empty"; message: string };
24
22
 
25
23
  export interface AnnotateLastMessageInlineComment {
26
- line: number;
27
- body: string;
24
+ line: number;
25
+ body: string;
28
26
  }
29
27
 
30
28
  export interface AnnotateLastMessageSectionComment {
31
- sectionId: string;
32
- body: string;
29
+ sectionId: string;
30
+ body: string;
33
31
  }
34
32
 
35
33
  export interface AnnotateLastMessageSubmitPayload {
36
- type: "submit";
37
- overallComment: string;
38
- inlineComments: AnnotateLastMessageInlineComment[];
39
- sectionComments: AnnotateLastMessageSectionComment[];
34
+ type: "submit";
35
+ overallComment: string;
36
+ inlineComments: AnnotateLastMessageInlineComment[];
37
+ sectionComments: AnnotateLastMessageSectionComment[];
40
38
  }
41
39
 
42
40
  export interface AnnotateLastMessageCancelPayload {
43
- type: "cancel";
41
+ type: "cancel";
44
42
  }
45
43
 
46
- export type AnnotateLastMessageWindowMessage = AnnotateLastMessageSubmitPayload | AnnotateLastMessageCancelPayload;
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
- return value.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
13
+ return value.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
14
14
  }
15
15
 
16
16
  function escapeInlineScriptSource(value: string): string {
17
- return value.replace(/<\/(script)/gi, "<\\/$1");
17
+ return value.replace(/<\/(script)/gi, "<\\/$1");
18
18
  }
19
19
 
20
20
  function buildThemeCssBlock(vars: Record<string, string>): string {
21
- const declarations = Object.entries(vars)
22
- .map(([key, value]) => ` ${key}: ${value};`)
23
- .join("\n");
24
- return `:root {\n${declarations}\n}`;
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
- data: LastAssistantMessageData,
29
- theme?: AnnotateTheme,
28
+ data: LastAssistantMessageData,
29
+ theme?: AnnotateTheme,
30
30
  ): string {
31
- const templateHtml = readFileSync(join(webDir, "index.html"), "utf8");
32
- const mdRendererJs = escapeInlineScriptSource(readFileSync(join(webDir, "md-renderer.js"), "utf8"));
33
- const appJs = escapeInlineScriptSource(readFileSync(join(webDir, "app.js"), "utf8"));
34
- const payload = escapeForInlineScript(JSON.stringify(data));
35
- const themeBlock = buildThemeCssBlock(getThemeCssVars(theme));
36
- const replacements = new Map([
37
- ['"__INLINE_DATA__"', payload],
38
- ["__INLINE_MD_RENDERER_JS__", mdRendererJs],
39
- ["__INLINE_JS__", appJs],
40
- ["__INLINE_THEME__", themeBlock],
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
- // Replace the original template in one pass so marker-like message data,
44
- // theme values, or runtime source is never scanned as another placeholder.
45
- return templateHtml.replace(
46
- /"__INLINE_DATA__"|__INLINE_MD_RENDERER_JS__|__INLINE_JS__|__INLINE_THEME__/g,
47
- (marker) => replacements.get(marker) ?? marker,
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
- : typeof section.text === "string"
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(createLineRow(messageData.lines[i], fullMessageFenceState[i].lineType));
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 the FALLBACK
14
- * object in theme.ts so this template renders correctly when the injected
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 FALLBACK in theme.ts */
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;
@@ -1,7 +1,7 @@
1
1
  /* global globalThis */
2
2
 
3
3
  /**
4
- * TLH annotate-last-message: pure markdown line parser.
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