pi-context-map 0.4.3 → 0.4.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.4] - 2026-06-15
4
+ ### Bug Fixes
5
+ - **Fixed SSE rendering**: Changed `document.replaceChild(document.documentElement)` to `document.body.innerHTML` replacement. CSS and JavaScript no longer render as visible text on the page.
6
+ - **Singleton server**: `start()` now kills any pre-existing server instance before starting a new one. Only one localhost server runs at a time — no duplicate ports.
7
+
3
8
  ## [0.4.3] - 2026-06-15
4
9
  ### Apple-Inspired HTML Redesign
5
10
  - **Complete visual overhaul**: Report now uses Apple design language — white canvas, Inter font (SF Pro substitute), Action Blue (#0066cc) accent, 18px card radius, pill-shaped inputs.
@@ -16,8 +16,7 @@ export class ReportGenerator {
16
16
  insights: Insight[],
17
17
  ): string {
18
18
  const total = composition.total.tokens;
19
- const usagePercent =
20
- total > 0 ? Math.round((total / 128_000) * 100) : 0;
19
+ const usagePercent = total > 0 ? Math.round((total / 128_000) * 100) : 0;
21
20
 
22
21
  const fileCards = composition.files_detail
23
22
  .map(
@@ -497,7 +496,7 @@ h2:first-of-type { margin-top: 48px; }
497
496
  <span class="stat-label">Files</span>
498
497
  </div>
499
498
  <div class="stat">
500
- <span class="stat-value">${insights.filter(i => i.severity === "warning" || i.severity === "critical").length}</span>
499
+ <span class="stat-value">${insights.filter((i) => i.severity === "warning" || i.severity === "critical").length}</span>
501
500
  <span class="stat-label">Alerts</span>
502
501
  </div>
503
502
  <div class="stat">
@@ -613,8 +612,16 @@ h2:first-of-type { margin-top: 48px; }
613
612
  try {
614
613
  var p = JSON.parse(e.data);
615
614
  if (p.html) {
615
+ // Only replace the body content to preserve <style> and <script>
616
616
  var d = new DOMParser().parseFromString(p.html, 'text/html');
617
- document.replaceChild(document.importNode(d.documentElement, true), document.documentElement);
617
+ var newBody = d.querySelector('body');
618
+ var newTitle = d.querySelector('title');
619
+ if (newBody) {
620
+ document.body.innerHTML = newBody.innerHTML;
621
+ }
622
+ if (newTitle) {
623
+ document.title = newTitle.textContent || document.title;
624
+ }
618
625
  }
619
626
  } catch(_) {}
620
627
  };
@@ -657,7 +664,11 @@ h2:first-of-type { margin-top: 48px; }
657
664
  }
658
665
 
659
666
  private static escapeHtml(text: string): string {
660
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
661
- .replace(/"/g, "&quot;").replace(/'/g, "&#039;");
667
+ return text
668
+ .replace(/&/g, "&amp;")
669
+ .replace(/</g, "&lt;")
670
+ .replace(/>/g, "&gt;")
671
+ .replace(/"/g, "&quot;")
672
+ .replace(/'/g, "&#039;");
662
673
  }
663
674
  }
@@ -51,8 +51,9 @@ export class LiveReportServer {
51
51
  * Start the server. Returns a Promise that resolves to the URL, or null on failure.
52
52
  */
53
53
  public start(): Promise<string | null> {
54
+ // Kill any pre-existing server to ensure only one instance runs
54
55
  if (this.server) {
55
- return Promise.resolve(this.url);
56
+ this.stop();
56
57
  }
57
58
 
58
59
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-context-map",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Professional context profiler for Pi that visualizes the session context window, token distribution, and integrates with Nexus packages for actionable insights.",
5
5
  "keywords": [
6
6
  "pi-package",