@oh-my-pi/pi-utils 14.9.8 → 15.0.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 +2 -2
- package/src/dirs.ts +11 -0
- package/src/env.ts +14 -0
- package/src/prompt.ts +25 -19
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-utils",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "15.0.0",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/bun": "^1.3.13",
|
|
41
|
-
"@oh-my-pi/pi-natives": "
|
|
41
|
+
"@oh-my-pi/pi-natives": "15.0.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"bun": ">=1.3.7"
|
package/src/dirs.ts
CHANGED
|
@@ -324,6 +324,17 @@ export function getGpuCachePath(): string {
|
|
|
324
324
|
return dirs.rootSubdir("gpu_cache.json", "cache");
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Get the GitHub view cache database path (~/.omp/cache/github-cache.db).
|
|
329
|
+
* Honors the `OMP_GITHUB_CACHE_DB` env var when set so tests can isolate the
|
|
330
|
+
* cache file without touching the rest of the config root.
|
|
331
|
+
*/
|
|
332
|
+
export function getGithubCacheDbPath(): string {
|
|
333
|
+
const override = process.env.OMP_GITHUB_CACHE_DB;
|
|
334
|
+
if (override) return override;
|
|
335
|
+
return dirs.rootSubdir(path.join("cache", "github-cache.db"), "cache");
|
|
336
|
+
}
|
|
337
|
+
|
|
327
338
|
/** Get the natives directory (~/.omp/natives). */
|
|
328
339
|
export function getNativesDir(): string {
|
|
329
340
|
return dirs.rootSubdir("natives", "cache");
|
package/src/env.ts
CHANGED
|
@@ -100,6 +100,20 @@ export function isBunTestRuntime(): boolean {
|
|
|
100
100
|
return Bun.env.BUN_ENV === "test" || Bun.env.NODE_ENV === "test";
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* True when this code is running inside a `bun build --compile` standalone
|
|
105
|
+
* binary. Detects via the embedded virtual-filesystem path markers
|
|
106
|
+
* (`$bunfs`, `~BUN`, or its URL-encoded form `%7EBUN`) in `import.meta.url`,
|
|
107
|
+
* which Bun rewrites for every module bundled into the executable. The
|
|
108
|
+
* `PI_COMPILED` env var (set by the build script's `--define`) is checked
|
|
109
|
+
* first for cheap fast-path detection.
|
|
110
|
+
*/
|
|
111
|
+
export function isCompiledBinary(): boolean {
|
|
112
|
+
if (Bun.env.PI_COMPILED) return true;
|
|
113
|
+
const url = import.meta.url;
|
|
114
|
+
return url.includes("$bunfs") || url.includes("~BUN") || url.includes("%7EBUN");
|
|
115
|
+
}
|
|
116
|
+
|
|
103
117
|
const TRUTHY: Dict<boolean> = { "1": true, Y: true, TRUE: true, YES: true, ON: true };
|
|
104
118
|
export function $flag(name: string, def: boolean = false): boolean {
|
|
105
119
|
const value = $env[name];
|
package/src/prompt.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type PromptRenderPhase = "pre-render" | "post-render";
|
|
|
8
8
|
export interface PromptFormatOptions {
|
|
9
9
|
renderPhase?: PromptRenderPhase;
|
|
10
10
|
replaceAsciiSymbols?: boolean;
|
|
11
|
-
|
|
11
|
+
normalizeRfc2119?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
// Opening XML tag (not self-closing, not closing)
|
|
@@ -22,21 +22,27 @@ const TABLE_ROW = /^\|.*\|$/;
|
|
|
22
22
|
// Table separator (|---|---|)
|
|
23
23
|
const TABLE_SEP = /^\|[-:\s|]+\|$/;
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
/**
|
|
26
|
+
* RFC 2119 keywords (plus project aliases NEVER/AVOID) wrapped in markdown bold
|
|
27
|
+
* — `**MUST**`, `**MUST NOT**`, `**NEVER**`, etc.
|
|
28
|
+
*/
|
|
29
|
+
const RFC2119_BOLD = /\*\*(MUST NOT|SHOULD NOT|RECOMMENDED|REQUIRED|OPTIONAL|SHOULD|MUST|MAY|NEVER|AVOID)\*\*/g;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Normalize RFC 2119 markers per project convention:
|
|
33
|
+
* - Strip `**KEYWORD**` bold (visual noise, no semantics).
|
|
34
|
+
* - Alias `MUST NOT` → `NEVER` and `SHOULD NOT` → `AVOID` (single-token equivalents).
|
|
35
|
+
* Skips spans inside inline code (`` `…` ``) so alias definitions can be quoted literally.
|
|
36
|
+
*/
|
|
37
|
+
function normalizeRfc2119(line: string): string {
|
|
38
|
+
const segments = line.split("`");
|
|
39
|
+
for (let i = 0; i < segments.length; i += 2) {
|
|
40
|
+
segments[i] = segments[i]
|
|
41
|
+
.replace(RFC2119_BOLD, "$1")
|
|
42
|
+
.replace(/\bMUST NOT\b/g, "NEVER")
|
|
43
|
+
.replace(/\bSHOULD NOT\b/g, "AVOID");
|
|
44
|
+
}
|
|
45
|
+
return segments.join("`");
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
/** Compact a table row by trimming cell padding */
|
|
@@ -75,7 +81,7 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
75
81
|
const {
|
|
76
82
|
renderPhase = "post-render",
|
|
77
83
|
replaceAsciiSymbols = false,
|
|
78
|
-
|
|
84
|
+
normalizeRfc2119: shouldNormalizeRfc2119 = false,
|
|
79
85
|
} = options;
|
|
80
86
|
const isPreRender = renderPhase === "pre-render";
|
|
81
87
|
const lines = content.split("\n");
|
|
@@ -125,8 +131,8 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
125
131
|
line = `${leadingWhitespace}${compactTableRow(trimmedStart)}`;
|
|
126
132
|
}
|
|
127
133
|
|
|
128
|
-
if (
|
|
129
|
-
line =
|
|
134
|
+
if (shouldNormalizeRfc2119) {
|
|
135
|
+
line = normalizeRfc2119(line);
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
if (trimmed === "") {
|