@pi-archimedes/core 2.4.0 → 2.5.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/package.json +3 -3
- package/src/thinking/theme.ts +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-archimedes/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@earendil-works/pi-tui": ">=0.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@earendil-works/pi-coding-agent": "^0.84.
|
|
31
|
-
"@earendil-works/pi-tui": "^0.84.
|
|
30
|
+
"@earendil-works/pi-coding-agent": "^0.84.4",
|
|
31
|
+
"@earendil-works/pi-tui": "^0.84.4",
|
|
32
32
|
"typescript": "^6.0.0"
|
|
33
33
|
},
|
|
34
34
|
"pi": {
|
package/src/thinking/theme.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
highlightCode as piHighlightCode,
|
|
4
|
+
initTheme as piInitTheme,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
3
6
|
import type { MarkdownTheme } from "@earendil-works/pi-tui";
|
|
4
7
|
import {
|
|
5
8
|
deriveDimColor,
|
|
@@ -23,6 +26,26 @@ const DEFAULT_CODE_DEFAULT_L = 0.85;
|
|
|
23
26
|
// (bold/italic/reset/etc.) are left untouched.
|
|
24
27
|
const FG_COLOR_ESCAPE_RE = /\x1b\[38;(?:2;\d{1,3};\d{1,3};\d{1,3}|5;\d{1,3})m/g;
|
|
25
28
|
|
|
29
|
+
// pi 0.84.4's module-level `highlightCode` reads a *global* Theme
|
|
30
|
+
// singleton that throws until `initTheme()` runs. pi's interactive
|
|
31
|
+
// mode initializes it at startup, but contexts that build the muted
|
|
32
|
+
// theme without going through that initialization (e.g. unit tests)
|
|
33
|
+
// would otherwise get "Theme not initialized. Call initTheme() first."
|
|
34
|
+
// We probe on first use and, only when the global is not set, call
|
|
35
|
+
// `initTheme("dark")` — built-in theme, no file watcher attached.
|
|
36
|
+
let piThemeReady = false;
|
|
37
|
+
function ensurePiHighlightable(): void {
|
|
38
|
+
if (piThemeReady) return;
|
|
39
|
+
piThemeReady = true;
|
|
40
|
+
try {
|
|
41
|
+
piHighlightCode(""); // probe: throws when the global is unset
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// Only fall back when the probe failed for the known reason, so an
|
|
44
|
+
// already-established pi theme is never clobbered by a surprise.
|
|
45
|
+
if (String(err).includes("Theme not initialized")) piInitTheme("dark");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
26
49
|
/**
|
|
27
50
|
* Rewrite every foreground-color SGR escape in `line` to its dimmed truecolor
|
|
28
51
|
* variant, preserving all other content (text, non-color escapes, resets).
|
|
@@ -114,6 +137,7 @@ export function buildMutedMarkdownTheme(
|
|
|
114
137
|
strikethrough: (text) => `\x1b[9m${fg("dim", text)}\x1b[29m`,
|
|
115
138
|
underline: (text) => `\x1b[4m${fg("thinkingText", text)}\x1b[24m`,
|
|
116
139
|
highlightCode: (code, lang) => {
|
|
140
|
+
ensurePiHighlightable();
|
|
117
141
|
const lines = piHighlightCode(code, lang);
|
|
118
142
|
return lines.map((l) => {
|
|
119
143
|
const dimmed = dimAnsiLine(l, anchorL, saturationFactor, dimCache);
|