@f5xc-salesdemos/pi-utils 18.38.0 → 18.38.2

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/prompt.ts +14 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5xc-salesdemos/pi-utils",
4
- "version": "18.38.0",
4
+ "version": "18.38.2",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/f5xc-salesdemos/xcsh",
7
7
  "author": "Can Boluk",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3",
41
- "@f5xc-salesdemos/pi-natives": "18.38.0"
41
+ "@f5xc-salesdemos/pi-natives": "18.38.2"
42
42
  },
43
43
  "engines": {
44
44
  "bun": ">=1.3.7"
package/src/prompt.ts CHANGED
@@ -29,7 +29,7 @@ const TABLE_SEP = /^\|[-:\s|]+\|$/;
29
29
  /** RFC 2119 keywords used in prompts. */
30
30
  const RFC2119_KEYWORDS = /\b(?:MUST NOT|SHOULD NOT|SHALL NOT|RECOMMENDED|REQUIRED|OPTIONAL|SHOULD|SHALL|MUST|MAY)\b/g;
31
31
 
32
- function boldRfc2119Keywords(line: string): string {
32
+ function boldRfc2119Keywords(line: string, inBoldSpan: boolean): string {
33
33
  return line.replace(RFC2119_KEYWORDS, (match, offset, source) => {
34
34
  const isAlreadyBold =
35
35
  source[offset - 2] === "*" &&
@@ -39,6 +39,13 @@ function boldRfc2119Keywords(line: string): string {
39
39
  if (isAlreadyBold) {
40
40
  return match;
41
41
  }
42
+ // Count ** markers before keyword to detect mid-line bold spans;
43
+ // XOR with cross-line state to handle spans opened on a prior line.
44
+ const before = source.slice(0, offset);
45
+ const beforeBoldCount = (before.match(/\*\*/g) || []).length;
46
+ if (inBoldSpan !== (beforeBoldCount % 2 === 1)) {
47
+ return match;
48
+ }
42
49
  return `**${match}**`;
43
50
  });
44
51
  }
@@ -68,7 +75,7 @@ function replaceCommonAsciiSymbols(line: string): string {
68
75
  return line
69
76
  .replace(/\.{3}/g, "…")
70
77
  .replace(/<->/g, "↔")
71
- .replace(/->/g, "→")
78
+ .replace(/(?<!-)->/g, "→")
72
79
  .replace(/<-/g, "←")
73
80
  .replace(/!=/g, "≠")
74
81
  .replace(/<=/g, "≤")
@@ -85,6 +92,7 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
85
92
  const lines = content.split("\n");
86
93
  const result: string[] = [];
87
94
  let inCodeBlock = false;
95
+ let inBoldSpan = false;
88
96
  const topLevelTags: string[] = [];
89
97
 
90
98
  for (let i = 0; i < lines.length; i++) {
@@ -130,8 +138,11 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
130
138
  }
131
139
 
132
140
  if (shouldBoldRfc2119) {
133
- line = boldRfc2119Keywords(line);
141
+ line = boldRfc2119Keywords(line, inBoldSpan);
134
142
  }
143
+ // Track cross-line bold state: odd number of ** markers toggles the span.
144
+ const boldMarkerCount = (line.match(/\*\*/g) || []).length;
145
+ if (boldMarkerCount % 2 === 1) inBoldSpan = !inBoldSpan;
135
146
 
136
147
  const isBlank = trimmed === "";
137
148
  if (isBlank) {