@linxiraos/pi-utils 1.1.7 → 1.1.9

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 (188) hide show
  1. package/CHANGELOG.md +2 -8
  2. package/README.md +18 -18
  3. package/package.json +57 -63
  4. package/src/acp/connection.ts +6 -10
  5. package/src/ar/entries.ts +1 -1
  6. package/src/ar/sevenzip.ts +17 -2
  7. package/src/async.ts +25 -4
  8. package/src/browsers.ts +11 -5
  9. package/src/dirs.ts +15 -10
  10. package/src/dom/core.ts +4 -4
  11. package/src/env.ts +12 -0
  12. package/src/fetch-retry.ts +36 -1
  13. package/src/format.ts +1 -1
  14. package/src/frontmatter.ts +1 -0
  15. package/src/incoming-json.ts +856 -0
  16. package/src/index.ts +2 -0
  17. package/src/json-lexer.ts +413 -0
  18. package/src/json-parse.ts +93 -350
  19. package/src/marked/core.ts +8 -1
  20. package/src/materialize-string.ts +10 -0
  21. package/src/path.ts +14 -0
  22. package/src/postmortem.ts +33 -6
  23. package/src/prompt.ts +1 -0
  24. package/src/ring.ts +1 -0
  25. package/src/temp.ts +16 -4
  26. package/src/template.ts +2 -2
  27. package/src/tls-fetch.ts +2 -16
  28. package/src/turndown/html.ts +1 -1
  29. package/src/vterm/query-responder.ts +76 -0
  30. package/src/vterm.ts +1 -0
  31. package/THIRD-PARTY-NOTICES.txt +0 -22909
  32. package/dist/types/abortable.d.ts +0 -32
  33. package/dist/types/acp/connection.d.ts +0 -118
  34. package/dist/types/acp/protocol.d.ts +0 -526
  35. package/dist/types/acp/schema.d.ts +0 -41
  36. package/dist/types/acp/stream.d.ts +0 -8
  37. package/dist/types/acp/transport.d.ts +0 -88
  38. package/dist/types/acp.d.ts +0 -6
  39. package/dist/types/ar/arj.d.ts +0 -5
  40. package/dist/types/ar/asar.d.ts +0 -7
  41. package/dist/types/ar/bytes.d.ts +0 -20
  42. package/dist/types/ar/cab.d.ts +0 -5
  43. package/dist/types/ar/checksums.d.ts +0 -10
  44. package/dist/types/ar/codecs/bzip2.d.ts +0 -4
  45. package/dist/types/ar/codecs/gzip.d.ts +0 -6
  46. package/dist/types/ar/codecs/lzma.d.ts +0 -6
  47. package/dist/types/ar/codecs/lzw.d.ts +0 -4
  48. package/dist/types/ar/codecs/lzx.d.ts +0 -7
  49. package/dist/types/ar/codecs/xz.d.ts +0 -4
  50. package/dist/types/ar/codecs/zstd.d.ts +0 -6
  51. package/dist/types/ar/cpio.d.ts +0 -7
  52. package/dist/types/ar/deb.d.ts +0 -5
  53. package/dist/types/ar/entries.d.ts +0 -22
  54. package/dist/types/ar/error.d.ts +0 -8
  55. package/dist/types/ar/index.d.ts +0 -11
  56. package/dist/types/ar/iso.d.ts +0 -5
  57. package/dist/types/ar/limits.d.ts +0 -33
  58. package/dist/types/ar/lzh.d.ts +0 -7
  59. package/dist/types/ar/open.d.ts +0 -45
  60. package/dist/types/ar/paths.d.ts +0 -18
  61. package/dist/types/ar/rar/rar4-decoder.d.ts +0 -6
  62. package/dist/types/ar/rar/rar5-decoder.d.ts +0 -6
  63. package/dist/types/ar/rar.d.ts +0 -5
  64. package/dist/types/ar/reader.d.ts +0 -28
  65. package/dist/types/ar/registry.d.ts +0 -17
  66. package/dist/types/ar/rpm.d.ts +0 -5
  67. package/dist/types/ar/sevenzip/decode.d.ts +0 -33
  68. package/dist/types/ar/sevenzip.d.ts +0 -5
  69. package/dist/types/ar/source.d.ts +0 -54
  70. package/dist/types/ar/tar.d.ts +0 -9
  71. package/dist/types/ar/types.d.ts +0 -99
  72. package/dist/types/ar/unix-ar.d.ts +0 -7
  73. package/dist/types/ar/write.d.ts +0 -10
  74. package/dist/types/ar/zip.d.ts +0 -10
  75. package/dist/types/async.d.ts +0 -22
  76. package/dist/types/binary.d.ts +0 -23
  77. package/dist/types/browsers.d.ts +0 -68
  78. package/dist/types/chalk.d.ts +0 -125
  79. package/dist/types/cli.d.ts +0 -134
  80. package/dist/types/color.d.ts +0 -136
  81. package/dist/types/dates.d.ts +0 -7
  82. package/dist/types/dirs.d.ts +0 -325
  83. package/dist/types/docx/converter.d.ts +0 -46
  84. package/dist/types/docx/xml.d.ts +0 -26
  85. package/dist/types/docx.d.ts +0 -11
  86. package/dist/types/dom/core.d.ts +0 -431
  87. package/dist/types/dom/parser.d.ts +0 -7
  88. package/dist/types/dom/selector.d.ts +0 -5
  89. package/dist/types/dom.d.ts +0 -5
  90. package/dist/types/env.d.ts +0 -124
  91. package/dist/types/fetch-retry.d.ts +0 -96
  92. package/dist/types/file-lock.d.ts +0 -23
  93. package/dist/types/format.d.ts +0 -37
  94. package/dist/types/frontmatter.d.ts +0 -46
  95. package/dist/types/fs-error.d.ts +0 -31
  96. package/dist/types/glob.d.ts +0 -28
  97. package/dist/types/headers.d.ts +0 -34
  98. package/dist/types/index.d.ts +0 -41
  99. package/dist/types/json-parse.d.ts +0 -83
  100. package/dist/types/json.d.ts +0 -20
  101. package/dist/types/logger/rotating-file.d.ts +0 -18
  102. package/dist/types/logger.d.ts +0 -96
  103. package/dist/types/loop-phase.d.ts +0 -10
  104. package/dist/types/lru.d.ts +0 -46
  105. package/dist/types/marked/core.d.ts +0 -445
  106. package/dist/types/marked.d.ts +0 -2
  107. package/dist/types/math-delimiters.d.ts +0 -45
  108. package/dist/types/mermaid-ascii.d.ts +0 -11
  109. package/dist/types/mime.d.ts +0 -29
  110. package/dist/types/module-timer.d.ts +0 -1
  111. package/dist/types/path-tree.d.ts +0 -76
  112. package/dist/types/path.d.ts +0 -2
  113. package/dist/types/peek-file.d.ts +0 -29
  114. package/dist/types/postmortem.d.ts +0 -174
  115. package/dist/types/process-name.d.ts +0 -7
  116. package/dist/types/procmgr.d.ts +0 -74
  117. package/dist/types/prompt.d.ts +0 -18
  118. package/dist/types/ptree.d.ts +0 -124
  119. package/dist/types/readability/readability.d.ts +0 -9
  120. package/dist/types/readability/readerable.d.ts +0 -10
  121. package/dist/types/readability/types.d.ts +0 -70
  122. package/dist/types/readability.d.ts +0 -4
  123. package/dist/types/ring.d.ts +0 -93
  124. package/dist/types/runtime-install.d.ts +0 -85
  125. package/dist/types/sanitize-text.d.ts +0 -29
  126. package/dist/types/snowflake.d.ts +0 -25
  127. package/dist/types/sqlite.d.ts +0 -26
  128. package/dist/types/stderr-guard.d.ts +0 -22
  129. package/dist/types/stream.d.ts +0 -75
  130. package/dist/types/tab-spacing.d.ts +0 -24
  131. package/dist/types/temp.d.ts +0 -17
  132. package/dist/types/template.d.ts +0 -62
  133. package/dist/types/timing-buffer.d.ts +0 -22
  134. package/dist/types/tls-fetch.d.ts +0 -37
  135. package/dist/types/turndown/gfm.d.ts +0 -11
  136. package/dist/types/turndown/html.d.ts +0 -5
  137. package/dist/types/turndown/service.d.ts +0 -21
  138. package/dist/types/turndown/types.d.ts +0 -70
  139. package/dist/types/turndown.d.ts +0 -4
  140. package/dist/types/type-guards.d.ts +0 -5
  141. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +0 -41
  142. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +0 -89
  143. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +0 -7
  144. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +0 -12
  145. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +0 -66
  146. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +0 -48
  147. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +0 -43
  148. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +0 -7
  149. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +0 -56
  150. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +0 -65
  151. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +0 -27
  152. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +0 -17
  153. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +0 -7
  154. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +0 -11
  155. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +0 -34
  156. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +0 -11
  157. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +0 -11
  158. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +0 -26
  159. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +0 -31
  160. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +0 -11
  161. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +0 -59
  162. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +0 -17
  163. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +0 -30
  164. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +0 -55
  165. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +0 -206
  166. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +0 -51
  167. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +0 -2
  168. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +0 -6
  169. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +0 -102
  170. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +0 -6
  171. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +0 -76
  172. package/dist/types/vendor/mermaid-ascii/index.d.ts +0 -1
  173. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +0 -9
  174. package/dist/types/vendor/mermaid-ascii/parser.d.ts +0 -7
  175. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +0 -6
  176. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +0 -130
  177. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +0 -23
  178. package/dist/types/vendor/mermaid-ascii/types.d.ts +0 -114
  179. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +0 -25
  180. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +0 -6
  181. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +0 -145
  182. package/dist/types/version.d.ts +0 -18
  183. package/dist/types/vterm/buffer.d.ts +0 -99
  184. package/dist/types/vterm/terminal.d.ts +0 -44
  185. package/dist/types/vterm.d.ts +0 -8
  186. package/dist/types/which.d.ts +0 -37
  187. package/dist/types/worker-host.d.ts +0 -51
  188. package/dist/types/xml.d.ts +0 -31
package/src/temp.ts CHANGED
@@ -78,10 +78,12 @@ function normalizePrefix(prefix?: string): string {
78
78
  }
79
79
 
80
80
  const kRemoveOptions = { recursive: true, force: true } as const;
81
- const kRemoveRetries = 40;
82
- // 50ms × 40 retries = 2s total retry window. Windows holds file locks on
83
- // SQLite DBs for up to ~1.5s after close(); the previous 25ms (1s total)
84
- // was too short for some test cleanup scenarios.
81
+ const kRemoveRetries = 150;
82
+ // 50ms × 150 retries = 7.5s total retry window. Windows releases file locks on
83
+ // SQLite DBs (and spawned-process CWDs) asynchronously after close(); the
84
+ // measured release latency reaches ~730ms–5s when a child process just died
85
+ // holding the directory, and the previous 2s window flaked suites that clean
86
+ // up temp trees containing agent.db.
85
87
  const kRemoveRetryDelayMs = 50;
86
88
  const kRetryableRemoveErrorCodes = new Set(["EBUSY", "EPERM", "ENOTEMPTY"]);
87
89
  const kSleepBuffer = new Int32Array(new SharedArrayBuffer(4));
@@ -132,3 +134,13 @@ function sleepSync(ms: number): void {
132
134
  }
133
135
  Atomics.wait(kSleepBuffer, 0, 0, ms);
134
136
  }
137
+
138
+ /**
139
+ * Create a directory symlink in a platform-correct way. Windows denies
140
+ * unprivileged file/dir symlinks (EPERM on `fs.symlink` without a type), but
141
+ * allows directory *junctions*, which every test that links temp directories
142
+ * should use instead. POSIX ignores the type argument.
143
+ */
144
+ export function symlinkDirectorySync(target: string, linkPath: string): void {
145
+ fs.symlinkSync(target, linkPath, process.platform === "win32" ? "junction" : "dir");
146
+ }
package/src/template.ts CHANGED
@@ -549,7 +549,7 @@ export function compile<T = unknown>(source: string, options: CompileOptions = {
549
549
  const nodes = parseTemplate(stripStandalone(source));
550
550
  return (context, runtime = {}) => {
551
551
  const root = context ?? {};
552
- const frame: Frame = { context: root, parents: [], root, data: { root, ...(runtime.data ?? {}) } };
552
+ const frame: Frame = { context: root, parents: [], root, data: { root, ...runtime.data } };
553
553
  return renderNodes(nodes, frame, { helpers, partials, options, runtime });
554
554
  };
555
555
  }
@@ -579,7 +579,7 @@ export class TemplateEngine {
579
579
  const nodes = parseTemplate(stripStandalone(source));
580
580
  return (context, runtime = {}) => {
581
581
  const root = context ?? {};
582
- const frame: Frame = { context: root, parents: [], root, data: { root, ...(runtime.data ?? {}) } };
582
+ const frame: Frame = { context: root, parents: [], root, data: { root, ...runtime.data } };
583
583
  return renderNodes(nodes, frame, { helpers: this.#helpers, partials: this.#partials, options, runtime });
584
584
  };
585
585
  }
package/src/tls-fetch.ts CHANGED
@@ -76,7 +76,7 @@ let cacheValue: string | undefined;
76
76
  * path, matching Node's "extensionless filename is still a path" contract.
77
77
  * `ENOENT` becomes {@link ExtraCaError}; other I/O errors bubble.
78
78
  */
79
- function resolveExtraCa(): string | undefined {
79
+ export function resolveExtraCa(): string | undefined {
80
80
  const raw = $env.NODE_EXTRA_CA_CERTS?.trim();
81
81
  if (!raw) return undefined;
82
82
 
@@ -122,7 +122,7 @@ export function __resetExtraCaCache(): void {
122
122
  * Anthropic Foundry's mTLS options, which already seed
123
123
  * `tls.rootCertificates`), only the extra CA is appended.
124
124
  */
125
- function withExtraCaInit(init: RequestInit | undefined, extraCa: string): RequestInit {
125
+ export function withExtraCaInit(init: RequestInit | undefined, extraCa: string): RequestInit {
126
126
  const existingTls = (init as BunTlsRequestInit | undefined)?.tls;
127
127
  const existingCa = existingTls?.ca;
128
128
  let mergedCa: string[];
@@ -162,17 +162,3 @@ export function wrapFetchForExtraCa(fetchImpl: FetchImpl): FetchImpl {
162
162
  );
163
163
  return wrapped;
164
164
  }
165
-
166
- /**
167
- * Convenience for options-bag composition (e.g. the stream-entry path in
168
- * `@linxiraos/pi-ai`'s `stream.ts`, which mirrors `withRequestDebugFetch` so
169
- * the proxy/debug/extra-CA wrappers compose uniformly). No-op when the env
170
- * var is unset.
171
- */
172
- export function withExtraCaFetch<T extends { fetch?: FetchImpl } | undefined>(options: T): T {
173
- if (!$env.NODE_EXTRA_CA_CERTS?.trim()) return options;
174
- const fetchImpl = options?.fetch ?? (globalThis.fetch as FetchImpl);
175
- const wrapped = wrapFetchForExtraCa(fetchImpl);
176
- if (wrapped === fetchImpl && options?.fetch !== undefined) return options;
177
- return { ...(options ?? {}), fetch: wrapped } as T;
178
- }
@@ -222,7 +222,7 @@ export function parseHtmlFragment(html: string): TurndownNode {
222
222
  const stack: HtmlNode[] = [root];
223
223
  for (const token of htmlTokens(html)) {
224
224
  const parent = stack[stack.length - 1] ?? root;
225
- if (token.startsWith("<!--") || /^<!/i.test(token)) continue;
225
+ if (token.startsWith("<!--") || token.startsWith("<!")) continue;
226
226
  if (!token.startsWith("<")) {
227
227
  parent.append(new HtmlText(decodeEntities(token)));
228
228
  continue;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Answers terminal capability queries emitted by programs on a headless PTY.
3
+ *
4
+ * A PTY that advertises `TERM=xterm-256color` but has no terminal behind it
5
+ * leaves capability probes unanswered: a program writes a query escape to
6
+ * stdout and blocks on stdin until the reply arrives (or its timeout expires,
7
+ * seconds later). This scanner watches raw PTY output for the standard queries
8
+ * and returns the bytes a real xterm-class terminal would send back, so the
9
+ * caller can write them into the PTY. It keeps no screen state — cursor
10
+ * position reports are answered with the home position — which makes it cheap
11
+ * enough to run on every byte of a long-lived supervised process. Use the full
12
+ * {@link Terminal} when the caller also renders the output.
13
+ *
14
+ * Queries can straddle chunk boundaries, so an unfinished trailing escape is
15
+ * carried into the next {@link feed}.
16
+ */
17
+ export class TerminalQueryResponder {
18
+ /** Trailing bytes that may be the start of an unfinished query escape. */
19
+ #residual = "";
20
+
21
+ /**
22
+ * Feed one raw PTY output chunk. Returns the reply bytes to write back into
23
+ * the PTY, or an empty string when the chunk held no answerable query.
24
+ */
25
+ feed(chunk: string): string {
26
+ const buffer = this.#residual + chunk;
27
+ let replies = "";
28
+ let lastEnd = 0;
29
+ QUERY.lastIndex = 0;
30
+ for (let match = QUERY.exec(buffer); match !== null; match = QUERY.exec(buffer)) {
31
+ lastEnd = match.index + match[0].length;
32
+ replies += replyFor(match);
33
+ }
34
+ // Keep only a short unmatched trailing escape: a query split across
35
+ // chunks completes on the next feed, while a long tail is ordinary output
36
+ // that can never become a query.
37
+ const tailEscape = buffer.lastIndexOf("\x1b");
38
+ this.#residual =
39
+ tailEscape >= lastEnd && buffer.length - tailEscape <= MAX_PARTIAL_QUERY ? buffer.slice(tailEscape) : "";
40
+ return replies;
41
+ }
42
+ }
43
+
44
+ /** Longest query escape we answer, bounding the cross-chunk residual. */
45
+ const MAX_PARTIAL_QUERY = 32;
46
+
47
+ /**
48
+ * CSI DSR/DA queries (final byte `n` or `c`) and OSC 10/11 color queries. Only
49
+ * forms with canned answers are matched; everything else stays plain output.
50
+ */
51
+ const QUERY = /\x1b\[([?>=]?)([0-9;]*)([nc])|\x1b\](10|11);\?(\x07|\x1b\\)/gu;
52
+
53
+ /** Reply a real xterm-class terminal would send for one matched query. */
54
+ function replyFor(match: RegExpExecArray): string {
55
+ const final = match[3];
56
+ if (final !== undefined) {
57
+ const intermediate = match[1];
58
+ const params = match[2] ?? "";
59
+ if (final === "c") {
60
+ if (intermediate === ">") return "\x1b[>0;10;1c"; // secondary DA: VT100-class, firmware 10
61
+ if (intermediate === "" || intermediate === "0") return "\x1b[?1;2c"; // primary DA: VT100 with AVO
62
+ return ""; // tertiary (`=`) DA has no widely expected reply
63
+ }
64
+ if (intermediate !== "") return ""; // private DSR forms (DECXCPR, appearance) stay unanswered
65
+ const selector = params.split(";", 1)[0];
66
+ if (selector === "6") return "\x1b[1;1R"; // cursor position: home, there is no screen
67
+ if (selector === "5") return "\x1b[0n"; // device status: OK
68
+ return "";
69
+ }
70
+ // OSC color queries: neutral colors, terminated the way the request was.
71
+ const selector = match[4];
72
+ const terminator = match[5] ?? "\x07";
73
+ if (selector === "10") return `\x1b]10;rgb:ffff/ffff/ffff${terminator}`; // foreground
74
+ if (selector === "11") return `\x1b]11;rgb:0000/0000/0000${terminator}`; // background
75
+ return "";
76
+ }
package/src/vterm.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /** Behavior-compatible reimplementation of @xterm/headless's used surface. */
2
2
  export * from "./vterm/buffer";
3
+ export * from "./vterm/query-responder";
3
4
  export * from "./vterm/terminal";
4
5
 
5
6
  import { Terminal } from "./vterm/terminal";