@oh-my-pi/pi-utils 17.2.8 → 17.2.10

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 (89) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/types/acp/connection.d.ts +118 -0
  3. package/dist/types/acp/protocol.d.ts +526 -0
  4. package/dist/types/acp/schema.d.ts +41 -0
  5. package/dist/types/acp/stream.d.ts +8 -0
  6. package/dist/types/acp/transport.d.ts +81 -0
  7. package/dist/types/acp.d.ts +6 -0
  8. package/dist/types/browsers.d.ts +68 -0
  9. package/dist/types/chalk.d.ts +125 -0
  10. package/dist/types/dates.d.ts +7 -0
  11. package/dist/types/docx/converter.d.ts +46 -0
  12. package/dist/types/docx/xml.d.ts +26 -0
  13. package/dist/types/docx/zip.d.ts +6 -0
  14. package/dist/types/docx.d.ts +11 -0
  15. package/dist/types/dom/core.d.ts +431 -0
  16. package/dist/types/dom/parser.d.ts +7 -0
  17. package/dist/types/dom/selector.d.ts +5 -0
  18. package/dist/types/dom.d.ts +5 -0
  19. package/dist/types/headers.d.ts +34 -0
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/logger/rotating-file.d.ts +18 -0
  22. package/dist/types/lru.d.ts +46 -0
  23. package/dist/types/marked/core.d.ts +445 -0
  24. package/dist/types/marked.d.ts +2 -0
  25. package/dist/types/postmortem.d.ts +14 -0
  26. package/dist/types/procmgr.d.ts +16 -0
  27. package/dist/types/prompt.d.ts +2 -2
  28. package/dist/types/readability/readability.d.ts +9 -0
  29. package/dist/types/readability/readerable.d.ts +10 -0
  30. package/dist/types/readability/types.d.ts +70 -0
  31. package/dist/types/readability.d.ts +4 -0
  32. package/dist/types/template.d.ts +62 -0
  33. package/dist/types/turndown/gfm.d.ts +11 -0
  34. package/dist/types/turndown/html.d.ts +5 -0
  35. package/dist/types/turndown/service.d.ts +21 -0
  36. package/dist/types/turndown/types.d.ts +70 -0
  37. package/dist/types/turndown.d.ts +4 -0
  38. package/dist/types/version.d.ts +18 -0
  39. package/dist/types/vterm/buffer.d.ts +99 -0
  40. package/dist/types/vterm/terminal.d.ts +44 -0
  41. package/dist/types/vterm.d.ts +8 -0
  42. package/dist/types/xml.d.ts +31 -0
  43. package/package.json +2 -5
  44. package/src/acp/connection.ts +344 -0
  45. package/src/acp/protocol.ts +466 -0
  46. package/src/acp/schema.ts +160 -0
  47. package/src/acp/stream.ts +82 -0
  48. package/src/acp/transport.ts +213 -0
  49. package/src/acp.ts +6 -0
  50. package/src/browsers.ts +501 -0
  51. package/src/chalk.ts +312 -0
  52. package/src/dates.ts +194 -0
  53. package/src/docx/converter.ts +681 -0
  54. package/src/docx/xml.ts +166 -0
  55. package/src/docx/zip.ts +87 -0
  56. package/src/docx.ts +20 -0
  57. package/src/dom/core.ts +1254 -0
  58. package/src/dom/parser.ts +370 -0
  59. package/src/dom/selector.ts +290 -0
  60. package/src/dom.ts +33 -0
  61. package/src/fetch-retry.ts +7 -1
  62. package/src/frontmatter.ts +1 -1
  63. package/src/headers.ts +167 -0
  64. package/src/index.ts +1 -0
  65. package/src/logger/rotating-file.ts +149 -0
  66. package/src/logger.ts +12 -28
  67. package/src/lru.ts +185 -0
  68. package/src/marked/core.ts +1576 -0
  69. package/src/marked.ts +2 -0
  70. package/src/postmortem.ts +44 -1
  71. package/src/procmgr.ts +21 -4
  72. package/src/prompt.ts +5 -22
  73. package/src/readability/readability.ts +533 -0
  74. package/src/readability/readerable.ts +51 -0
  75. package/src/readability/types.ts +72 -0
  76. package/src/readability.ts +11 -0
  77. package/src/template.ts +586 -0
  78. package/src/turndown/gfm.ts +106 -0
  79. package/src/turndown/html.ts +257 -0
  80. package/src/turndown/service.ts +334 -0
  81. package/src/turndown/types.ts +81 -0
  82. package/src/turndown.ts +5 -0
  83. package/src/version.ts +99 -0
  84. package/src/vterm/buffer.ts +218 -0
  85. package/src/vterm/terminal.ts +773 -0
  86. package/src/vterm.ts +8 -0
  87. package/src/which.ts +6 -4
  88. package/src/xml.ts +313 -0
  89. package/src/winston-daily-rotate-file.d.ts +0 -6
package/src/version.ts ADDED
@@ -0,0 +1,99 @@
1
+ const DIGITS = /^\d+$/;
2
+
3
+ /**
4
+ * Compare two version strings.
5
+ *
6
+ * Canonical comparator that supersedes the historical in-repo copies
7
+ * (update-cli, hackage scraper, release scripts):
8
+ * - inputs are trimmed and at most one leading `v`/`V` is stripped
9
+ * - dot-separated segments are compared numerically, missing trailing
10
+ * segments count as 0, so `1.2` === `1.2.0` and any segment count works
11
+ * - a SemVer-2.0 prerelease suffix sorts before the plain release
12
+ * (`1.0.0-beta` < `1.0.0`); prerelease identifiers follow SemVer order
13
+ * (numeric < alphanumeric, numeric compared by value, alphanumeric
14
+ * compared lexically, longer sets of equal fields win)
15
+ * - SemVer build metadata begins at the first `+` and does not participate
16
+ * in precedence; it is stripped before core/prerelease parsing
17
+ * - malformed numeric segments compare as 0 (`1.2.x` === `1.2.0`)
18
+ * - never throws; returns only -1 | 0 | 1
19
+ */
20
+ export function compareVersions(a: string, b: string): number {
21
+ const pa = parseVersion(a);
22
+ const pb = parseVersion(b);
23
+
24
+ const core = compareNumericParts(pa.core, pb.core);
25
+ if (core !== 0) return core;
26
+
27
+ return comparePrerelease(pa.prerelease, pb.prerelease);
28
+ }
29
+
30
+ interface ParsedVersion {
31
+ core: string[];
32
+ prerelease: string[] | null;
33
+ }
34
+
35
+ function parseVersion(version: string): ParsedVersion {
36
+ const trimmed = version.trim();
37
+ const stripped = trimmed.startsWith("v") || trimmed.startsWith("V") ? trimmed.slice(1) : trimmed;
38
+ const plusIndex = stripped.indexOf("+");
39
+ const withoutBuild = plusIndex === -1 ? stripped : stripped.slice(0, plusIndex);
40
+ const dashIndex = withoutBuild.indexOf("-");
41
+ if (dashIndex === -1) {
42
+ return { core: withoutBuild.split("."), prerelease: null };
43
+ }
44
+ return {
45
+ core: withoutBuild.slice(0, dashIndex).split("."),
46
+ prerelease: withoutBuild.slice(dashIndex + 1).split("."),
47
+ };
48
+ }
49
+
50
+ /** Compare dot-separated numeric segments; missing/malformed segments count as 0. */
51
+ function compareNumericParts(a: string[], b: string[]): number {
52
+ const length = Math.max(a.length, b.length);
53
+ for (let i = 0; i < length; i++) {
54
+ // Missing or malformed segments compare as 0.
55
+ const sa = a[i];
56
+ const sb = b[i];
57
+ const result = compareDigits(
58
+ sa !== undefined && DIGITS.test(sa) ? sa : "0",
59
+ sb !== undefined && DIGITS.test(sb) ? sb : "0",
60
+ );
61
+ if (result !== 0) return result;
62
+ }
63
+ return 0;
64
+ }
65
+
66
+ /** Exact integer comparison of digit strings, avoiding float overflow. */
67
+ function compareDigits(a: string, b: string): number {
68
+ const na = a.replace(/^0+/, "") || "0";
69
+ const nb = b.replace(/^0+/, "") || "0";
70
+ if (na.length !== nb.length) return na.length < nb.length ? -1 : 1;
71
+ if (na < nb) return -1;
72
+ if (na > nb) return 1;
73
+ return 0;
74
+ }
75
+
76
+ /** SemVer-2.0 prerelease ordering; null means a plain release, which wins. */
77
+ function comparePrerelease(a: string[] | null, b: string[] | null): number {
78
+ if (a === null || b === null) {
79
+ return a === b ? 0 : a === null ? 1 : -1;
80
+ }
81
+ const length = Math.max(a.length, b.length);
82
+ for (let i = 0; i < length; i++) {
83
+ const ia = a[i];
84
+ const ib = b[i];
85
+ if (ia === undefined) return -1;
86
+ if (ib === undefined) return 1;
87
+ const aNumeric = DIGITS.test(ia);
88
+ const bNumeric = DIGITS.test(ib);
89
+ if (aNumeric && bNumeric) {
90
+ const result = compareDigits(ia, ib);
91
+ if (result !== 0) return result;
92
+ } else if (aNumeric !== bNumeric) {
93
+ return aNumeric ? -1 : 1;
94
+ } else if (ia !== ib) {
95
+ return ia < ib ? -1 : 1;
96
+ }
97
+ }
98
+ return 0;
99
+ }
@@ -0,0 +1,218 @@
1
+ /** Cell rendition tracked by the virtual terminal. */
2
+ export interface CellAttributes {
3
+ bold: boolean;
4
+ dim: boolean;
5
+ italic: boolean;
6
+ underline: boolean;
7
+ inverse: boolean;
8
+ strikethrough: boolean;
9
+ overline: boolean;
10
+ fgMode: 0 | 1 | 2;
11
+ fg: number;
12
+ bgMode: 0 | 1 | 2;
13
+ bg: number;
14
+ }
15
+
16
+ /** A mutable terminal grid cell. */
17
+ export interface CellData {
18
+ chars: string;
19
+ width: number;
20
+ attrs: CellAttributes;
21
+ }
22
+
23
+ /** Creates the default rendition. */
24
+ export function defaultAttributes(): CellAttributes {
25
+ return {
26
+ bold: false,
27
+ dim: false,
28
+ italic: false,
29
+ underline: false,
30
+ inverse: false,
31
+ strikethrough: false,
32
+ overline: false,
33
+ fgMode: 0,
34
+ fg: 0,
35
+ bgMode: 0,
36
+ bg: 0,
37
+ };
38
+ }
39
+
40
+ function cloneAttributes(attrs: CellAttributes): CellAttributes {
41
+ return { ...attrs };
42
+ }
43
+
44
+ /** Creates an empty cell with the supplied rendition. */
45
+ export function blankCell(attrs: CellAttributes = defaultAttributes()): CellData {
46
+ return { chars: "", width: 1, attrs: cloneAttributes(attrs) };
47
+ }
48
+
49
+ /** Proposed xterm-compatible cell readback object. */
50
+ export class BufferCell {
51
+ #cell: CellData = blankCell();
52
+
53
+ /** Reuses this object for another grid cell. */
54
+ setFrom(cell: CellData): this {
55
+ this.#cell = cell;
56
+ return this;
57
+ }
58
+
59
+ /** Returns the grapheme stored in this cell. */
60
+ getChars(): string {
61
+ return this.#cell.chars;
62
+ }
63
+
64
+ /** Returns the cell width, with zero denoting a wide-cell continuation. */
65
+ getWidth(): number {
66
+ return this.#cell.width;
67
+ }
68
+
69
+ /** Returns the packed foreground palette index or RGB value. */
70
+ getFgColor(): number {
71
+ return this.#cell.attrs.fg;
72
+ }
73
+
74
+ /** Returns the packed background palette index or RGB value. */
75
+ getBgColor(): number {
76
+ return this.#cell.attrs.bg;
77
+ }
78
+
79
+ /** Reports bold rendition. */
80
+ isBold(): number {
81
+ return Number(this.#cell.attrs.bold);
82
+ }
83
+
84
+ /** Reports dim rendition. */
85
+ isDim(): number {
86
+ return Number(this.#cell.attrs.dim);
87
+ }
88
+
89
+ /** Reports italic rendition. */
90
+ isItalic(): number {
91
+ return Number(this.#cell.attrs.italic);
92
+ }
93
+
94
+ /** Reports underline rendition. */
95
+ isUnderline(): number {
96
+ return Number(this.#cell.attrs.underline);
97
+ }
98
+
99
+ /** Reports inverse rendition. */
100
+ isInverse(): number {
101
+ return Number(this.#cell.attrs.inverse);
102
+ }
103
+
104
+ /** Reports strikethrough rendition. */
105
+ isStrikethrough(): number {
106
+ return Number(this.#cell.attrs.strikethrough);
107
+ }
108
+
109
+ /** Reports overline rendition. */
110
+ isOverline(): number {
111
+ return Number(this.#cell.attrs.overline);
112
+ }
113
+
114
+ /** Reports a true-color foreground. */
115
+ isFgRGB(): boolean {
116
+ return this.#cell.attrs.fgMode === 2;
117
+ }
118
+
119
+ /** Reports a true-color background. */
120
+ isBgRGB(): boolean {
121
+ return this.#cell.attrs.bgMode === 2;
122
+ }
123
+
124
+ /** Reports a palette foreground. */
125
+ isFgPalette(): boolean {
126
+ return this.#cell.attrs.fgMode === 1;
127
+ }
128
+
129
+ /** Reports a palette background. */
130
+ isBgPalette(): boolean {
131
+ return this.#cell.attrs.bgMode === 1;
132
+ }
133
+ }
134
+
135
+ /** One physical row in a terminal buffer. */
136
+ export class BufferLine {
137
+ cells: CellData[];
138
+ isWrapped = false;
139
+
140
+ constructor(columns: number, attrs: CellAttributes = defaultAttributes()) {
141
+ this.cells = Array.from({ length: columns }, () => blankCell(attrs));
142
+ }
143
+
144
+ /** Number of grid columns in the line. */
145
+ get length(): number {
146
+ return this.cells.length;
147
+ }
148
+
149
+ /** Reads a cell, optionally reusing the caller's object. */
150
+ getCell(column: number, cell = new BufferCell()): BufferCell | undefined {
151
+ const value = this.cells[column];
152
+ return value ? cell.setFrom(value) : undefined;
153
+ }
154
+
155
+ /** Converts a column range to text. */
156
+ translateToString(trimRight = false, startColumn = 0, endColumn = this.cells.length): string {
157
+ const start = Math.max(0, startColumn);
158
+ let end = Math.min(endColumn, this.cells.length);
159
+ if (trimRight) {
160
+ while (end > start && !this.cells[end - 1]!.chars) end--;
161
+ }
162
+ let text = "";
163
+ for (let column = start; column < end; column++) {
164
+ const cell = this.cells[column]!;
165
+ if (cell.width !== 0) text += cell.chars || " ";
166
+ }
167
+ return text;
168
+ }
169
+ }
170
+
171
+ /** Storage backing one terminal screen and its history. */
172
+ export interface BufferState {
173
+ lines: BufferLine[];
174
+ baseY: number;
175
+ viewportY: number;
176
+ cursorX: number;
177
+ cursorY: number;
178
+ }
179
+
180
+ /** Public xterm-compatible view over a buffer state. */
181
+ export class BufferView {
182
+ constructor(private readonly state: () => BufferState) {}
183
+
184
+ /** Number of physical lines, including scrollback. */
185
+ get length(): number {
186
+ return this.state().lines.length;
187
+ }
188
+
189
+ /** First row of the live screen in the full buffer. */
190
+ get baseY(): number {
191
+ return this.state().baseY;
192
+ }
193
+
194
+ /** First row currently exposed by the viewport. */
195
+ get viewportY(): number {
196
+ return this.state().viewportY;
197
+ }
198
+
199
+ /** Cursor column in the live screen. */
200
+ get cursorX(): number {
201
+ return this.state().cursorX;
202
+ }
203
+
204
+ /** Cursor row in the live screen. */
205
+ get cursorY(): number {
206
+ return this.state().cursorY;
207
+ }
208
+
209
+ /** Reads a physical buffer line. */
210
+ getLine(row: number): BufferLine | undefined {
211
+ return this.state().lines[row];
212
+ }
213
+
214
+ /** Creates a reusable empty cell readback object. */
215
+ getNullCell(): BufferCell {
216
+ return new BufferCell();
217
+ }
218
+ }