@linxiraos/pi-utils 1.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.
Files changed (244) hide show
  1. package/CHANGELOG.md +449 -0
  2. package/README.md +36 -0
  3. package/dist/types/abortable.d.ts +32 -0
  4. package/dist/types/acp/connection.d.ts +118 -0
  5. package/dist/types/acp/protocol.d.ts +526 -0
  6. package/dist/types/acp/schema.d.ts +41 -0
  7. package/dist/types/acp/stream.d.ts +8 -0
  8. package/dist/types/acp/transport.d.ts +81 -0
  9. package/dist/types/acp.d.ts +6 -0
  10. package/dist/types/async.d.ts +20 -0
  11. package/dist/types/binary.d.ts +17 -0
  12. package/dist/types/browsers.d.ts +68 -0
  13. package/dist/types/chalk.d.ts +125 -0
  14. package/dist/types/cli.d.ts +134 -0
  15. package/dist/types/color.d.ts +102 -0
  16. package/dist/types/dates.d.ts +7 -0
  17. package/dist/types/dirs.d.ts +282 -0
  18. package/dist/types/docx/converter.d.ts +46 -0
  19. package/dist/types/docx/xml.d.ts +26 -0
  20. package/dist/types/docx/zip.d.ts +6 -0
  21. package/dist/types/docx.d.ts +11 -0
  22. package/dist/types/dom/core.d.ts +431 -0
  23. package/dist/types/dom/parser.d.ts +7 -0
  24. package/dist/types/dom/selector.d.ts +5 -0
  25. package/dist/types/dom.d.ts +5 -0
  26. package/dist/types/env.d.ts +124 -0
  27. package/dist/types/fetch-retry.d.ts +96 -0
  28. package/dist/types/file-lock.d.ts +23 -0
  29. package/dist/types/format.d.ts +37 -0
  30. package/dist/types/frontmatter.d.ts +46 -0
  31. package/dist/types/fs-error.d.ts +31 -0
  32. package/dist/types/glob.d.ts +28 -0
  33. package/dist/types/headers.d.ts +34 -0
  34. package/dist/types/index.d.ts +39 -0
  35. package/dist/types/json-parse.d.ts +74 -0
  36. package/dist/types/json.d.ts +14 -0
  37. package/dist/types/logger/rotating-file.d.ts +18 -0
  38. package/dist/types/logger.d.ts +96 -0
  39. package/dist/types/loop-phase.d.ts +10 -0
  40. package/dist/types/lru.d.ts +46 -0
  41. package/dist/types/marked/core.d.ts +445 -0
  42. package/dist/types/marked.d.ts +2 -0
  43. package/dist/types/mermaid-ascii.d.ts +11 -0
  44. package/dist/types/mime.d.ts +29 -0
  45. package/dist/types/module-timer.d.ts +1 -0
  46. package/dist/types/path-tree.d.ts +76 -0
  47. package/dist/types/path.d.ts +2 -0
  48. package/dist/types/peek-file.d.ts +29 -0
  49. package/dist/types/postmortem.d.ts +104 -0
  50. package/dist/types/process-name.d.ts +7 -0
  51. package/dist/types/procmgr.d.ts +74 -0
  52. package/dist/types/prompt.d.ts +18 -0
  53. package/dist/types/ptree.d.ts +110 -0
  54. package/dist/types/readability/readability.d.ts +9 -0
  55. package/dist/types/readability/readerable.d.ts +10 -0
  56. package/dist/types/readability/types.d.ts +70 -0
  57. package/dist/types/readability.d.ts +4 -0
  58. package/dist/types/ring.d.ts +93 -0
  59. package/dist/types/runtime-install.d.ts +78 -0
  60. package/dist/types/sanitize-text.d.ts +29 -0
  61. package/dist/types/snowflake.d.ts +25 -0
  62. package/dist/types/stderr-guard.d.ts +22 -0
  63. package/dist/types/stream.d.ts +67 -0
  64. package/dist/types/tab-spacing.d.ts +24 -0
  65. package/dist/types/temp.d.ts +17 -0
  66. package/dist/types/template.d.ts +62 -0
  67. package/dist/types/timing-buffer.d.ts +22 -0
  68. package/dist/types/tls-fetch.d.ts +37 -0
  69. package/dist/types/turndown/gfm.d.ts +11 -0
  70. package/dist/types/turndown/html.d.ts +5 -0
  71. package/dist/types/turndown/service.d.ts +21 -0
  72. package/dist/types/turndown/types.d.ts +70 -0
  73. package/dist/types/turndown.d.ts +4 -0
  74. package/dist/types/type-guards.d.ts +5 -0
  75. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
  76. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
  77. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
  78. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
  79. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
  80. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
  81. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
  82. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
  83. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
  84. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
  85. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
  86. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
  87. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
  88. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
  89. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
  90. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
  91. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
  92. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
  93. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
  94. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
  95. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
  96. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
  97. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
  98. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
  99. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
  100. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
  101. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
  102. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
  103. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
  104. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
  105. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
  106. package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
  107. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
  108. package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
  109. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
  110. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
  111. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
  112. package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
  113. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
  114. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
  115. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
  116. package/dist/types/version.d.ts +18 -0
  117. package/dist/types/vterm/buffer.d.ts +99 -0
  118. package/dist/types/vterm/terminal.d.ts +44 -0
  119. package/dist/types/vterm.d.ts +8 -0
  120. package/dist/types/which.d.ts +37 -0
  121. package/dist/types/worker-host.d.ts +51 -0
  122. package/dist/types/xml.d.ts +31 -0
  123. package/package.json +59 -0
  124. package/src/abortable.ts +109 -0
  125. package/src/acp/connection.ts +344 -0
  126. package/src/acp/protocol.ts +466 -0
  127. package/src/acp/schema.ts +160 -0
  128. package/src/acp/stream.ts +82 -0
  129. package/src/acp/transport.ts +213 -0
  130. package/src/acp.ts +6 -0
  131. package/src/async.ts +91 -0
  132. package/src/binary.ts +50 -0
  133. package/src/browsers.ts +501 -0
  134. package/src/chalk.ts +312 -0
  135. package/src/cli.ts +529 -0
  136. package/src/color.ts +302 -0
  137. package/src/dates.ts +194 -0
  138. package/src/dirs.ts +1026 -0
  139. package/src/docx/converter.ts +681 -0
  140. package/src/docx/xml.ts +166 -0
  141. package/src/docx/zip.ts +87 -0
  142. package/src/docx.ts +20 -0
  143. package/src/dom/core.ts +1254 -0
  144. package/src/dom/parser.ts +370 -0
  145. package/src/dom/selector.ts +290 -0
  146. package/src/dom.ts +33 -0
  147. package/src/env.ts +400 -0
  148. package/src/fetch-retry.ts +379 -0
  149. package/src/file-lock.ts +69 -0
  150. package/src/format.ts +113 -0
  151. package/src/frontmatter.ts +205 -0
  152. package/src/fs-error.ts +56 -0
  153. package/src/glob.ts +189 -0
  154. package/src/headers.ts +167 -0
  155. package/src/index.ts +59 -0
  156. package/src/json-parse.ts +821 -0
  157. package/src/json.ts +23 -0
  158. package/src/logger/rotating-file.ts +149 -0
  159. package/src/logger.ts +798 -0
  160. package/src/loop-phase.ts +49 -0
  161. package/src/lru.ts +185 -0
  162. package/src/marked/core.ts +1576 -0
  163. package/src/marked.ts +2 -0
  164. package/src/mermaid-ascii.ts +31 -0
  165. package/src/mime.ts +159 -0
  166. package/src/module-timer.ts +148 -0
  167. package/src/path-tree.ts +147 -0
  168. package/src/path.ts +28 -0
  169. package/src/peek-file.ts +188 -0
  170. package/src/postmortem.ts +433 -0
  171. package/src/process-name.ts +57 -0
  172. package/src/procmgr.ts +247 -0
  173. package/src/prompt.ts +545 -0
  174. package/src/ptree.ts +412 -0
  175. package/src/readability/readability.ts +533 -0
  176. package/src/readability/readerable.ts +51 -0
  177. package/src/readability/types.ts +72 -0
  178. package/src/readability.ts +11 -0
  179. package/src/ring.ts +169 -0
  180. package/src/runtime-install.ts +393 -0
  181. package/src/sanitize-text.ts +96 -0
  182. package/src/snowflake.ts +121 -0
  183. package/src/stderr-guard.ts +155 -0
  184. package/src/stream.ts +454 -0
  185. package/src/tab-spacing.ts +336 -0
  186. package/src/temp.ts +134 -0
  187. package/src/template.ts +586 -0
  188. package/src/timing-buffer.ts +47 -0
  189. package/src/tls-fetch.ts +178 -0
  190. package/src/turndown/gfm.ts +106 -0
  191. package/src/turndown/html.ts +257 -0
  192. package/src/turndown/service.ts +334 -0
  193. package/src/turndown/types.ts +81 -0
  194. package/src/turndown.ts +5 -0
  195. package/src/type-guards.ts +17 -0
  196. package/src/vendor/mermaid-ascii/NOTICE +33 -0
  197. package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
  198. package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
  199. package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
  200. package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
  201. package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
  202. package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
  203. package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
  204. package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
  205. package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
  206. package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
  207. package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
  208. package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
  209. package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
  210. package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
  211. package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
  212. package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
  213. package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
  214. package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
  215. package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
  216. package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
  217. package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
  218. package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
  219. package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
  220. package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
  221. package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
  222. package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
  223. package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
  224. package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
  225. package/src/vendor/mermaid-ascii/class/types.ts +121 -0
  226. package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
  227. package/src/vendor/mermaid-ascii/er/types.ts +91 -0
  228. package/src/vendor/mermaid-ascii/index.ts +14 -0
  229. package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
  230. package/src/vendor/mermaid-ascii/parser.ts +645 -0
  231. package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
  232. package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
  233. package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
  234. package/src/vendor/mermaid-ascii/types.ts +164 -0
  235. package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
  236. package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
  237. package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
  238. package/src/version.ts +99 -0
  239. package/src/vterm/buffer.ts +218 -0
  240. package/src/vterm/terminal.ts +773 -0
  241. package/src/vterm.ts +8 -0
  242. package/src/which.ts +234 -0
  243. package/src/worker-host.ts +100 -0
  244. package/src/xml.ts +313 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,449 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Changed
6
+
7
+ - Reset the version to 1.0.0 and republished under the `@linxiraos/*` scope, breaking from the `@oh-my-pi` version lineage.
8
+ ## [17.2.11] - 2026-08-07
9
+
10
+ ### Added
11
+
12
+ - Added `repair` and `rawKeys` options to `parseFrontmatter` to support spec-conformant loading (disabling lenient recovery and preserving keys verbatim), and exported `normalizeFrontmatterKeys` for manual key normalization.
13
+
14
+ ### Fixed
15
+
16
+ - Fixed the in-house `marked` list tokenizer incorrectly consuming trailing blank lines at the end of input, ensuring correct list tightness and token generation matching standard `marked` behavior.
17
+
18
+ ## [17.2.10] - 2026-08-06
19
+
20
+ ### Added
21
+
22
+ - Introduced zero-dependency in-house modules replacing external packages, importable via `@oh-my-pi/pi-utils/<module>`: `acp` (Agent Client Protocol), `browsers` (Chrome for Testing discovery/install), `chalk` (ANSI styling), `dates` (date formatting), `dom` (HTML parser, WHATWG DOM subset, and CSS selectors), `docx` (DOCX to HTML), `headers` (browser header generation), `lru` (LRU cache), `marked` (GFM markdown lexer/parser), `readability` (article extraction), `template` (Handlebars-compatible templating), `turndown` (HTML to Markdown), `vterm` (headless terminal emulator), and `xml` (XML parser).
23
+ - Added postmortem fatal recovery hint providers to allow applications to print actionable recovery commands before cleanup starts.
24
+
25
+ ### Changed
26
+
27
+ - Rewrote the logger file backend in-house, maintaining the identical line format, daily rotation, and pruning behavior without external dependencies.
28
+
29
+ ### Fixed
30
+
31
+ - Fixed PowerShell (`powershell.exe` / `pwsh`) support when used as a custom `shellPath` by correctly passing `-NoLogo -Command` (and `-NoProfile` under `PI_BASH_NO_LOGIN`) instead of POSIX flags.
32
+ - Fixed the in-house `marked` list tokenizer consuming the trailing blank line into the list token when the next top-level line was a plain paragraph. The blank now always becomes a separate `space` token (matching real marked), so a list's token shape no longer depends on what follows it — restoring the TUI streaming lexer's freeze invariant — and a list followed by a paragraph is tight, not loose, per CommonMark.
33
+ - Added the missing Handlebars built-in `lookup` helper to the in-house `template` engine (`{{lookup obj key}}`, proto-safe property access; a user-registered `lookup` helper still takes precedence).
34
+
35
+ ### Removed
36
+
37
+ - Removed external dependencies on `handlebars`, `winston`, and `winston-daily-rotate-file`.
38
+
39
+ ## [17.2.9] - 2026-08-05
40
+
41
+ ### Added
42
+
43
+ - Added a public `compareVersions` utility (`@oh-my-pi/pi-utils`) that compares two version strings with SemVer-2.0 prerelease ordering, build-metadata stripping, and numeric segment comparison without float overflow; never throws.
44
+
45
+ ### Fixed
46
+
47
+ - Honor the current process `PATH` when caching executable lookups, preventing stale tool paths after environment reloads.
48
+ - Parsed account-cap reset windows such as “Your limit will reset in 13 minutes” so credential backoff honors the provider's full reset duration.
49
+
50
+ ## [17.2.6] - 2026-08-03
51
+
52
+ ### Added
53
+
54
+ - Added a shared `file-lock` utility backed by process-owned native OS locks with automatic crash release and bounded asynchronous retry.
55
+
56
+ ## [17.2.5] - 2026-08-03
57
+
58
+ ### Added
59
+
60
+ - Added utility functions `parseFlag()`, `getBrowserRelayDir()`, and `getGlobalDaemonRuntimeDir()` to support browser relay mode and global daemon runtime directory resolution.
61
+
62
+ ### Changed
63
+
64
+ - Updated the lightweight CLI runner to support static command metadata, allowing root help to render without importing full command implementations.
65
+
66
+ ## [17.2.4] - 2026-08-01
67
+
68
+ ### Added
69
+
70
+ - Added `getSecretPlaceholderKeyPath()`, `getDaemonRuntimeDir()`, `getProviderInFlightRoot()`, and `getMarketplacesRegistryPath()` to resolve secret key, daemon runtime, provider in-flight, and marketplace registry paths under their respective XDG categories (state, data) instead of the config root.
71
+ - Existing installs enabling XDG keep their data: a legacy `~/.omp/agent/secret-placeholder.key` or `~/.omp/marketplaces.json` is copied to its XDG location on first resolution, so persisted transcripts still deobfuscate and added marketplaces survive the move.
72
+
73
+ ### Changed
74
+
75
+ - Headless hosts (print/RPC/ACP/eval/SDK) now use a 1s SQLite `busy_timeout` for the session-critical databases (agent.db, history.db, stats.db) via `getDbBusyTimeoutMs()`, so lock contention no longer freezes the protocol loop for the full interactive 5s timeout; interactive hosts keep the 5s timeout.
76
+
77
+ ### Fixed
78
+
79
+ - Fixed Bun test-runtime detection treating application-owned `NODE_ENV=test` and `BUN_ENV=test` values as test-runner signals ([#7261](https://github.com/can1357/oh-my-pi/issues/7261)).
80
+
81
+ ## [17.2.1] - 2026-07-30
82
+
83
+ ### Added
84
+
85
+ - Added a `postmortem.quit` configuration option to safely handle shutdown paths when the terminal output has already disconnected.
86
+ - Added project-keyed OMP security-state directory helpers under the user state root.
87
+
88
+ ## [17.1.8] - 2026-07-28
89
+
90
+ ### Added
91
+
92
+ - Added `setProcessName` utility to set the OS-visible process name on Linux via `bun:ffi`, bypassing Bun's `process.title` limitations.
93
+
94
+ ### Fixed
95
+
96
+ - Fixed child shell environment filtering to drop launch-directory `.env` values in addition to Bun-autoloaded `.env.local` values.
97
+
98
+ ## [17.1.5] - 2026-07-27
99
+
100
+ ### Fixed
101
+
102
+ - `getShellConfig` no longer throws `No bash shell found` on Windows hosts without a discoverable bash. `resolveWindowsShell` searches Git for Windows install roots (machine, per-user, `GIT_INSTALL_ROOT`, scoop app dirs — scoop shims `sh.exe`/`git.exe` but never `bash.exe`), then `bash.exe`/`sh.exe` on PATH, and finally falls back to `cmd.exe` from ComSpec with `/c` args, so shell resolution always succeeds.
103
+
104
+ ## [17.1.4] - 2026-07-26
105
+
106
+ ### Fixed
107
+
108
+ - Fixed postmortem signal and fatal shutdown exits being intercepted by temporary `process.exit` guards during extension startup ([#6488](https://github.com/can1357/oh-my-pi/issues/6488)).
109
+ - Corrected Windows shell resolution errors to identify the active global, project, overlay, or runtime source for `shellPath` instead of directing every user to the retired `settings.json` file ([#6579](https://github.com/can1357/oh-my-pi/issues/6579)).
110
+ - Contained timed-out child lifecycle rejections so `ptree` callers cannot leak an unhandled `TimeoutError` after settling ([#6635](https://github.com/can1357/oh-my-pi/issues/6635)).
111
+ - Fixed an invalid configured `shellPath` being silently masked whenever an earlier caller had already resolved a shell in the same process; the guidance error now surfaces regardless of cache state.
112
+
113
+ ## [17.0.9] - 2026-07-23
114
+
115
+ ### Breaking Changes
116
+
117
+ - Renamed `getAutoQaDbDir` to `getAutoQaDbPath` for accuracy; update any usage accordingly
118
+
119
+ ## [17.0.5] - 2026-07-18
120
+
121
+ ### Changed
122
+
123
+ - Updated `installRuntimeModuleResolver` to return an uninstaller function that restores the stock `node:module` resolver once all runtime roots are unregistered.
124
+ - Added documentation regarding a known limitation with Bun 1.3.14's `createRequire` behavior when the module resolver patch is active.
125
+
126
+ ## [17.0.2] - 2026-07-17
127
+
128
+ ### Added
129
+
130
+ - Added a structured log sink API (`registerLogSink`, `LogEvent`, `LogLevel`) to the centralized logger, enabling out-of-band consumers (such as OpenTelemetry) to receive log events without affecting local file or console logging.
131
+
132
+ ### Changed
133
+
134
+ - Bounded default `ptree.ChildProcess` stderr retention to a 32 KiB tail to prevent memory leaks in long-lived subprocesses. Full stderr capture must now be explicitly requested at spawn time using `{ stderr: "full" }` on `spawn` or `exec`.
135
+
136
+ ### Fixed
137
+
138
+ - Fixed fatal cleanup failing to reach `process.exit()` when terminal stderr is revoked.
139
+ - Isolated rotating log files and audit state per process to prevent concurrent instances from racing during compression and rotation.
140
+
141
+ ## [17.0.1] - 2026-07-16
142
+
143
+ ### Fixed
144
+
145
+ - Added scoped graceful handling for stdio-write EPIPE rejections so protocol servers can await postmortem cleanup when their peer disconnects ([#4788](https://github.com/can1357/oh-my-pi/issues/4788)).
146
+
147
+ ## [17.0.0] - 2026-07-15
148
+
149
+ ### Fixed
150
+
151
+ - Improved SSE streaming performance by batching complete lines into a single UTF-8 decode per chunk, reducing decoder overhead.
152
+ - Fixed an issue in `parseFrontmatter` where a single malformed YAML line would corrupt sibling values by parsing each line independently.
153
+
154
+ ## [16.5.2] - 2026-07-14
155
+
156
+ ### Fixed
157
+
158
+ - Improved CLI argument and flag validation error output to display a concise error message and command usage instead of a minified code frame.
159
+ - Corrected required variadic positionals to render as `MODELS...` instead of `[MODELS]` in usage help.
160
+
161
+ ## [16.5.1] - 2026-07-14
162
+
163
+ ### Added
164
+
165
+ - Added terminal stderr guard utilities (suppressTerminalStderr and restoreTerminalStderr) to prevent macOS runtime diagnostics from corrupting TUI viewports while ensuring crash reports remain visible.
166
+
167
+ ### Fixed
168
+
169
+ - Fixed an issue in Mermaid ASCII routing where unreachable edge attachment points caused unbounded pathfinder searches.
170
+
171
+ ## [16.4.6] - 2026-07-12
172
+
173
+ ### Added
174
+
175
+ - Added `AsyncDrain`, the deferred write-batching helper previously private to the coding-agent's prompt-history storage; now shared with model-perf recording.
176
+
177
+ ## [16.4.2] - 2026-07-10
178
+
179
+ ### Added
180
+
181
+ - Added `stringifyJson` utility with support for BigInt serialization.
182
+
183
+ ## [16.3.12] - 2026-07-08
184
+
185
+ ### Added
186
+
187
+ - Added `postmortem.interceptUnhandledRejections()` to register interceptors consulted before an unhandled rejection tears the process down; a consuming interceptor (e.g. the JS eval runtime claiming rejections floated by user cell code) keeps the process alive and owns reporting.
188
+
189
+ ### Fixed
190
+
191
+ - Fixed child shell environment filtering to drop launch-directory `.env.local` values that Bun auto-loaded before OMP starts command shells. ([#4723](https://github.com/can1357/oh-my-pi/issues/4723))
192
+
193
+ ## [16.3.10] - 2026-07-06
194
+
195
+ ### Added
196
+
197
+ - Added `postmortem.markExpectedCleanupError()` / `postmortem.isExpectedCleanupError()` to tag errors thrown by routine resource teardown; the global `uncaughtException`/`unhandledRejection` handlers downgrade marked errors (walking the `cause` chain) to warnings instead of exiting the process.
198
+
199
+ ### Fixed
200
+
201
+ - Bounded postmortem cleanup with a 10s deadline so a hanging cleanup callback can no longer wedge the process indefinitely after a fatal error or signal; the process now always reaches `process.exit`.
202
+
203
+ ## [16.3.7] - 2026-07-05
204
+
205
+ ### Added
206
+
207
+ - Added `classifyJsonPrefix`, a strict RFC 8259 streaming-buffer classifier (`"complete" | "prefix" | "invalid"`). Providers use it to disambiguate identifierless streaming tool-call deltas: a `{`-prefixed chunk only advances to a sibling call when the current argument buffer cannot absorb it.
208
+
209
+ ## [16.3.1] - 2026-07-02
210
+
211
+ ### Fixed
212
+
213
+ - Fixed `parseJsonWithRepair` failing tool calls whose streamed arguments contain an unquoted string value (e.g. `{"paths": packages/foo/*, "i": "…"}`). Final parsing now recovers such barewords in object/array value position as strings, terminating at `,` / `}` / `]` / newline. Recovery deliberately refuses anything that could mask real structure or bad data — truncated values, tokens containing `"` / `{` / `[` or a key-like `:` (URL `://` and Windows `:\` colons stay literal), and non-finite atoms (`NaN`, `Infinity`, `undefined`) — and streaming partial parses still roll back unfinished barewords instead of committing them.
214
+
215
+ ## [16.3.0] - 2026-07-02
216
+
217
+ ### Added
218
+
219
+ - Added `wrapFetchForExtraCa` and `withExtraCaFetch` utility functions to apply `NODE_EXTRA_CA_CERTS` to Bun's `RequestInit.tls.ca` configuration.
220
+
221
+ ## [16.2.9] - 2026-06-30
222
+
223
+ ### Added
224
+
225
+ - Improved resilience in `fetchWithRetry()` by adding a response-body retry gate to handle deterministic provider failures that return retryable HTTP statuses.
226
+
227
+ ### Fixed
228
+
229
+ - Fixed YAML frontmatter parsing for skill descriptions containing unquoted colons (`: `), ensuring typed fields are correctly preserved without triggering unnecessary warnings.
230
+
231
+ ## [16.2.7] - 2026-06-30
232
+
233
+ ### Added
234
+
235
+ - Added a utility to detect binary files based on content sniffing.
236
+
237
+ ## [16.2.6] - 2026-06-29
238
+
239
+ ### Added
240
+
241
+ - Added `stripWindowsExtendedLengthPathPrefix()` utility to normalize `\\?\` and native Win32 path prefixes before Bun import or spawn calls.
242
+
243
+ ## [16.2.3] - 2026-06-28
244
+
245
+ ### Added
246
+
247
+ - Added `escapeXmlAttribute` utility function for safe XML attribute value encoding.
248
+
249
+ ### Fixed
250
+
251
+ - Fixed a crash in `ptree.ChildProcess.bytes()` and the `ssh://` read path when handling large subprocess outputs (over 128 KB) under Bun by ensuring it consistently returns a `Uint8Array`.
252
+
253
+ ## [16.2.0] - 2026-06-27
254
+
255
+ ### Added
256
+
257
+ - Added a relaxed JSON parser supporting single-quoted strings, unquoted keys, and comments.
258
+ - Added `parseStreamingJson` and `parseStreamingJsonThrottled` for robust, efficient parsing of truncated or incremental streaming JSON.
259
+ - Added an XDG-aware document conversion cache directory helper.
260
+ - Exported `removeWithRetries()` as a standalone asynchronous function to handle retry-on-EBUSY cleanup logic.
261
+
262
+ ### Changed
263
+
264
+ - Improved `readSseJson` to gracefully recover truncated or malformed final events using the streaming JSON parser, ending the stream cleanly instead of throwing.
265
+ - Increased the retry delay for EBUSY file-lock errors from 25ms to 50ms (extending the total retry window to 2 seconds) to improve reliability on Windows.
266
+
267
+ ## [16.1.8] - 2026-06-20
268
+
269
+ ### Added
270
+
271
+ - Exported `removeSyncWithRetries()` as a standalone function so tests that manage their own temp dirs can use the same retry-on-EBUSY cleanup logic as `TempDir.removeSync()`.
272
+
273
+ ## [16.1.3] - 2026-06-19
274
+
275
+ ### Changed
276
+
277
+ - Expanded the `TempDir` Windows retry window from 4×10ms to 40×25ms (1s total) to accommodate SQLite WAL/SHM file handle release delays
278
+
279
+ ### Fixed
280
+
281
+ - Made EPIPE rejections from IPC `send()` to worker subprocesses (`syscall: "send"`) non-fatal: the global `unhandledRejection` handler now logs and continues instead of terminating the session when an optional subsystem's pipe breaks. A broken optional subsystem (TTS/STT/tiny-title/MCP) can no longer crash the whole agent session mid-task. ([#2997](https://github.com/can1357/oh-my-pi/issues/2997))
282
+
283
+ ## [16.1.2] - 2026-06-19
284
+
285
+ ### Added
286
+
287
+ - Added `directoryExists(dir)` to `dirs`: resolves whether a path is an existing directory, returning `false` on any stat failure (ENOENT, permission, non-directory). Lets callers check a directory is safe to `chdir` into before `setProjectDir` throws.
288
+
289
+ ### Removed
290
+
291
+ - Removed the public `createAbortableStream` API from `@oh-my-pi/pi-utils`. Consumers should use the lighter, direct-reader `abortableSource` async generator inside `@oh-my-pi/pi-utils/stream` to avoid the extra ReadableStream wrapper layer and per-chunk enqueue overhead.
292
+
293
+ ## [16.0.11] - 2026-06-19
294
+
295
+ ### Removed
296
+
297
+ - Removed `getIndentation`, `setDefaultTabWidth`, and `getDefaultTabWidth` helpers
298
+
299
+ ## [16.0.8] - 2026-06-18
300
+
301
+ ### Changed
302
+
303
+ - Mermaid diagrams are now rendered to ASCII by a first-party vendored renderer (`src/vendor/mermaid-ascii`, derived from the MIT-licensed `beautiful-mermaid`, ASCII pipeline only) with terminal display width measured via `Bun.stringWidth` (grapheme-aware, correct for wide/East-Asian glyphs and emoji). Inline label formatting (HTML formatting tags and markdown emphasis) is now reduced to plain text instead of printed raw.
304
+
305
+ ### Removed
306
+
307
+ - Removed the external `beautiful-mermaid` dependency (and its transitive `elkjs`, ~3.13MB) in favor of the vendored ASCII renderer.
308
+
309
+ ## [16.0.3] - 2026-06-16
310
+
311
+ ### Added
312
+
313
+ - Added `escapeXmlText` utility to escape XML-significant characters `&`, `<`, and `>` in element body text
314
+ - Added `isTerminalHeadless()` / `setTerminalHeadless()` to centrally suppress real-terminal side effects (stdout escape/frame writes, stdin raw mode, CSI/OSC capability probes, SIGWINCH, window-title changes, emergency restore) under the test runtime. Defaults on when `bun test` sets `NODE_ENV=test`; terminal-contract tests opt out via `setTerminalHeadless(false)`
315
+
316
+ ## [15.13.3] - 2026-06-15
317
+
318
+ ### Added
319
+
320
+ - Added `installWorkerInbox(port)` / `consumeWorkerInbox()` to `@oh-my-pi/pi-utils/worker-host`. A self-dispatching CLI host that imports a Bun worker module dynamically attaches the worker's real `message` listener after Bun flushes the messages the parent posted before spawn, dropping a synchronously-posted `init`. The host installs this buffering inbox synchronously in the entry's sync prefix so a listener exists at flush time; the worker module consumes it and binds the real handler, replaying anything buffered.
321
+
322
+ ## [15.13.1] - 2026-06-15
323
+
324
+ ### Added
325
+
326
+ - Added profile-aware directory helpers and isolated profile state roots, while keeping the install ID shared across profiles.
327
+ - Added a named-profile API to the `dirs` module — `setProfile()`, `getActiveProfile()`, `getProfileRootDir()`, and `normalizeProfileName()` — plus `resolveProfileEnv()`, which selects the active profile from `OMP_PROFILE` (canonical; takes precedence) then `PI_PROFILE` (legacy fallback, consulted only when `OMP_PROFILE` is unset).
328
+ - Added support for a runtime `overrides` map in `RuntimeInstallSpec`, which is now written into generated runtime `package.json` manifests to force dependency pins (including transitive ones) across the runtime tree
329
+ - Added a lightweight loop-phase breadcrumb stack (`pushLoopPhase`/`popLoopPhase`/`currentLoopPhase`, plus `takeRecentLoopPhase` which returns the live phase or the most recently popped one and clears it) so the TUI event-loop watchdog can attribute a main-thread block to the phase that caused it — including a synchronous phase already popped before the watchdog's delayed tick runs ([#2485](https://github.com/can1357/oh-my-pi/issues/2485))
330
+ - Added `FetchWithRetryOptions.timeout` (forwarded to the underlying `fetch` call). `false` disables Bun's native ~300s pre-response timeout; a positive number overrides the ceiling. Bare browser/Node fetch ignores it ([#2422](https://github.com/can1357/oh-my-pi/issues/2422))
331
+ - Added the side-effect-free `@oh-my-pi/pi-utils/worker-host` module (`declareWorkerHostEntry()` / `workerHostEntry()`), extracted from `env` (still re-exported there) so worker spawn sites can resolve the self-dispatching CLI host entry without importing `env`'s side-effecting module graph.
332
+
333
+ ### Fixed
334
+
335
+ - Fixed profile directory isolation when a profile's agent `.env` customizes directory roots: directory-affecting keys (`XDG_DATA_HOME`/`XDG_STATE_HOME`/`XDG_CACHE_HOME`, and a default-mode `PI_CODING_AGENT_DIR`) are now honored. The `env` loader rebuilds the `dirs` resolver after applying `.env` files (`refreshDirsFromEnv()`), so a profile `.env` that points XDG roots elsewhere no longer leaks state into the home-based config dir.
336
+ - Made `TempDir` cleanup retry transient Windows `EBUSY`/`EPERM`/`ENOTEMPTY` removal failures so tests are less likely to fail when deleting just-used temp directories.
337
+ - Fixed `installRuntimeModuleResolver()` to keep bare requests from runtime-cache modules inside that registered runtime before falling back to host/workspace packages.
338
+
339
+ ## [15.12.4] - 2026-06-13
340
+
341
+ ### Fixed
342
+
343
+ - Fixed abortable stream wrappers to cancel the source stream on abort, so timeout watchdogs release upstream HTTP bodies instead of only stopping the local reader.
344
+
345
+ ## [15.12.0] - 2026-06-12
346
+
347
+ ### Added
348
+
349
+ - Added `runtime-install`: shared on-demand runtime dependency support — `ensureRuntimeInstalled()` (locked, idempotent `bun install` of a pinned dependency set into a cache dir) and a multi-root `installRuntimeModuleResolver()`/`resolveRuntimeModule()` for loading those graphs inside compiled binaries (Bun #1763). Extracted from the coding-agent tiny-model worker; now also backs Mnemopi's on-demand fastembed runtime ([#2389](https://github.com/can1357/oh-my-pi/issues/2389))
350
+ - Added `getFastembedRuntimeDir()` (~/.omp/cache/fastembed-runtime) alongside `getFastembedCacheDir()`
351
+
352
+ ## [15.11.4] - 2026-06-12
353
+
354
+ ### Added
355
+
356
+ - Added `getEditorConfigFormatting(file)`: returns the `.editorconfig`-pinned `tabSize`/`insertSpaces` (both optional, no fallback) so LSP-format callers can layer per-file defaults under it without paving over silence with the renderer's display tab width ([#2329](https://github.com/can1357/oh-my-pi/issues/2329)).
357
+
358
+ ## [15.11.3] - 2026-06-11
359
+
360
+ ### Added
361
+
362
+ - Added `getEditorConfigFormatting(file)`: returns the `.editorconfig`-pinned `tabSize`/`insertSpaces` (both optional, no fallback) so LSP-format callers can layer per-file defaults under it without paving over silence with the renderer's display tab width ([#2329](https://github.com/can1357/oh-my-pi/issues/2329)).
363
+
364
+ ## [15.11.1] - 2026-06-11
365
+
366
+ ### Fixed
367
+
368
+ - Fixed cleanup reentry noise during fatal shutdown: recursive cleanup requests now no-op idempotently instead of logging repeated `Cleanup invoked recursively` errors ([#2284](https://github.com/can1357/oh-my-pi/issues/2284)).
369
+
370
+ ## [15.11.0] - 2026-06-10
371
+
372
+ ### Added
373
+
374
+ - Added the `path-tree` module (`buildPathTree`, `walkPathTree`, `formatGroupedPaths`, `isUrlLikePath`), moved from the coding agent's grouped file output so compaction file lists can share the same prefix-folded directory-tree rendering; `formatGroupedPaths` gains an optional `annotate` callback for per-file suffixes
375
+
376
+ ### Fixed
377
+
378
+ - Fixed the `{{join}}` prompt helper joining with a literal two-character `\n` when templates pass `"\n"` as the separator — Handlebars string literals carry no escape processing. The separator now unescapes `\n`/`\t`, matching the `{{#list}}` helper's documented convention (visible as literal `\n` between paths in compaction `<read-files>` lists).
379
+
380
+ ## [15.10.11] - 2026-06-10
381
+
382
+ ### Added
383
+
384
+ - Restored `PI_DEBUG_STARTUP` streaming startup markers: `logger.time` now writes a synchronous `[startup] <op>:start` / `:done` / `:fail` stderr line per phase (independent of `PI_TIMING`), so a startup that hangs hard still names the phase it is stuck in — the `PI_TIMING` tree only prints after startup completes and is structurally unable to diagnose a hang. The CLI runner emits `cli:load:<name>` markers around each lazily-imported command module for the same reason.
385
+ - Added `logger.openSpanPath()`: ops of the currently-open timing-span chain (root → deepest), used by the coding agent's startup watchdog to name the in-flight phase of a stalled startup.
386
+ - Added `declareWorkerHostEntry()` / `workerHostEntry()` (env): self-dispatching CLI entrypoints declare `Bun.main` as the worker host so worker spawn sites can re-enter the single entry module with `WorkerOptions.argv` selectors across source, npm-bundle, and compiled distributions
387
+
388
+ ### Changed
389
+
390
+ - Changed `prompt.compile()` to cache compiled templates by the raw template string so repeated calls reuse the same compiled function without re-disambiguating
391
+ - `Snowflake.formatParts` packs the id as a single 64-bit BigInt hex format instead of stitching four 16-bit segments (simpler and ~1.7x faster), and `getTimestamp` extracts via exact double arithmetic instead of a BigInt round-trip. Output is bit-identical.
392
+ - Logger initialization is lazy: the winston logger, file transport, and log-directory creation now happen on first log emission instead of at module import (the import previously cost ~8ms of fs work on the CLI startup path); the in-memory timing infrastructure never touches winston
393
+ - `prompt.format()` post-processing got cheap per-line guards and a single-pass ASCII-symbol replacement (was 7 chained regex passes per line), roughly halving render post-processing cost; output is byte-identical
394
+
395
+ ### Fixed
396
+
397
+ - Fixed `prompt.format()` so ASCII symbol replacements such as `-->` and `!=` still run on lines containing a closing HTML comment token when not inside a comment
398
+ - `isCompiledBinary()` now also honors a define-folded `process.env.PI_COMPILED` (only `Bun.env` was checked), so builds that constant-fold `process.env` keep compiled-binary detection without relying on `import.meta.url` bunfs markers
399
+ - `omp <cmd> --help` now loads only the requested command module instead of the entire command table, so an unrelated command whose import graph hangs or crashes can no longer take down every per-command help invocation.
400
+
401
+ ## [15.10.8] - 2026-06-09
402
+
403
+ ### Removed
404
+
405
+ - Removed the exported `hookFetch` API, which previously intercepted `globalThis.fetch` via middleware handlers
406
+ - Removed `hookFetch` from the package entrypoint, so imports from `@.../utils` no longer provide this fetch interception helper
407
+
408
+ ## [15.10.0] - 2026-06-06
409
+
410
+ ### Changed
411
+
412
+ - `logger.printTimings()` (the `PI_TIMING` startup tree) now surfaces two previously-invisible regions: a `(before instrumentation)` line for runtime init / uncaptured pre-marker work, and an `(unattributed self)` line for the root span's own untimed work so the gap between visible top-level spans and `Total` is no longer swallowed. `Total` is now labelled `(since first marker)` to make the window explicit. The restored `module-timer.ts` preload can feed module spans into the report: each module records `onLoad` → final top-level marker as `total`, a prepended body marker → final marker as `body/TLA`, and resolved static imports as a bounded dependency tree so the report separates graph wait from actual top-level module work.
413
+
414
+ ## [15.9.2] - 2026-06-05
415
+
416
+ ### Added
417
+
418
+ - Added `getAuthBrokerSnapshotCachePath()` with `OMP_AUTH_BROKER_SNAPSHOT_CACHE` override support for isolating the encrypted broker snapshot cache.
419
+
420
+ ## [15.9.1] - 2026-06-04
421
+
422
+ ### Fixed
423
+
424
+ - Hardened `getIndentation` against malformed paths: any filesystem error from the `.editorconfig` probe (e.g. `ENAMETOOLONG` on oversized garbage path segments) is now swallowed and cached as a miss instead of escaping and crashing the TUI mid-render ([#1871](https://github.com/can1357/oh-my-pi/issues/1871)).
425
+ - Fixed `getIndentation` (and the edit renderer's `replaceTabs` callers) crashing with `ENAMETOOLONG`/`ENOTDIR`/etc. when handed a path with an overlong component or a non-directory in its parent chain. Editorconfig discovery now short-circuits to the default tab width on any path component above `NAME_MAX` (255 bytes) and absorbs any `FsError` while walking the editorconfig chain — best-effort discovery must never escape as an uncaught exception ([#1872](https://github.com/can1357/oh-my-pi/issues/1872)).
426
+
427
+ ## [15.9.0] - 2026-06-04
428
+
429
+ ### Added
430
+
431
+ - Added color helpers `colorLuma` (perceptual luma), `relativeLuminance` (WCAG, linearized sRGB), and `hslToHex` to the color utilities. The luminance helpers parse `#rgb`/`#rrggbb` hex and 256-color palette indices, returning `undefined` for unparseable values.
432
+ - Added `peekFileEnds`, a single-open head-and-tail file peek helper that reuses the head bytes for the tail when the file fits the head window.
433
+ - Added `peekFileTail`, the tail mirror of `peekFile`: reads up to the last `maxBytes` of a file ending at EOF, reusing the same pooled-buffer strategy (no per-call allocation for small reads).
434
+
435
+ ## [15.7.3] - 2026-05-31
436
+
437
+ ### Added
438
+
439
+ - Added `getFastembedCacheDir` to return the FastEmbed model cache directory under ~/.omp/cache/fastembed
440
+
441
+ ### Fixed
442
+
443
+ - Fixed `$flag` environment parsing to accept lowercase truthy values such as `y`, `true`, `yes`, and `on`
444
+
445
+ ## [15.6.0] - 2026-05-30
446
+
447
+ ### Added
448
+
449
+ - Added an XDG-aware tiny-title model cache directory helper for coding-agent local title models.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @linxiraos/pi-utils
2
+
3
+ Shared utilities for [oh-my-pi](https://github.com/can1357/oh-my-pi) packages. Zero ceremony, Bun-first.
4
+
5
+ ## Notable modules
6
+
7
+ | Module | Purpose |
8
+ | --- | --- |
9
+ | `logger` | Centralized logger writing to `~/.omp/logs/` with rotation (TUI-safe — never stdout) |
10
+ | `prompt` | Handlebars-based prompt templating and formatting helpers |
11
+ | `dirs` | Path helpers for omp config directories (`~/.omp`, XDG-aware on Linux) |
12
+ | `stream` | `readStream` / `readLines` helpers over `ReadableStream` |
13
+ | `ptree` / `procmgr` | Process trees, `ChildProcess` wrapper, process lifecycle management |
14
+ | `postmortem` | Cleanup callbacks on exit, signals, and fatal exceptions |
15
+ | `which` | `$which()` binary lookup with caching |
16
+ | `fetch-retry` | `fetch` with retry/backoff policies |
17
+ | `fs-error` | Errno guards (`isEnoent` and friends) |
18
+ | `env` / `worker-host` | Environment plumbing and side-effect-free worker-host entry contract (`workerHostEntry`) |
19
+ | `abortable` / `async` | AbortSignal-aware stream/promise helpers |
20
+ | `peek-file` | Read the first N bytes of a file with pooled buffers |
21
+ | `frontmatter`, `glob`, `mime`, `temp`, `format`, `color`, `snowflake`, `tab-spacing`, `path-tree`, `sanitize-text` | Smaller single-purpose helpers |
22
+
23
+ Import from the root barrel or per-module subpaths (`@linxiraos/pi-utils/<module>`).
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ bun add @linxiraos/pi-utils
29
+ ```
30
+
31
+ Ships TypeScript source directly (no build step); requires Bun ≥ 1.3.14.
32
+
33
+ ## References
34
+
35
+ - [Monorepo README](https://github.com/can1357/oh-my-pi#readme)
36
+ - [CHANGELOG](./CHANGELOG.md)
@@ -0,0 +1,32 @@
1
+ export declare class AbortError extends Error {
2
+ constructor(signal: AbortSignal);
3
+ }
4
+ /**
5
+ * Abortable async iteration over a {@link ReadableStream}. Reads the source
6
+ * reader directly and yields each chunk, so the consumer's `for await` drives a
7
+ * single read loop with no intermediate stream or per-chunk enqueue.
8
+ *
9
+ * Unlike `stream.pipeThrough(..., { signal })`, this explicitly cancels the
10
+ * source reader on abort or early `break`, propagating HTTP-client disconnects
11
+ * and watchdog timeouts to the backend request instead of only stopping the
12
+ * local consumer. On abort it throws {@link AbortError}; the lock is released
13
+ * on completion, abort, throw, or early exit. The source is cancelled only on
14
+ * abort or early exit — never on natural EOF.
15
+ */
16
+ export declare function abortableSource<T>(stream: ReadableStream<T>, signal?: AbortSignal): AsyncGenerator<T>;
17
+ /**
18
+ * Runs a promise-returning function (`pr`). If the given AbortSignal is aborted before or during
19
+ * execution, the promise is rejected with a standard error.
20
+ *
21
+ * @param signal - Optional AbortSignal to cancel the operation
22
+ * @param pr - Function returning a promise to run
23
+ * @returns Promise resolving as `pr` would, or rejecting on abort
24
+ */
25
+ export declare function untilAborted<T>(signal: AbortSignal | undefined | null, pr: Promise<T> | (() => Promise<T>)): Promise<T>;
26
+ /**
27
+ * Memoizes a function with no arguments, calling it once and caching the result.
28
+ *
29
+ * @param fn - Function to be called once
30
+ * @returns A function that returns the cached result of `fn`
31
+ */
32
+ export declare function once<T>(fn: () => T): () => T;
@@ -0,0 +1,118 @@
1
+ import type { Agent, AuthenticateRequest, AuthenticateResponse, CloseSessionRequest, CloseSessionResponse, CompleteElicitationNotification, CreateElicitationRequest, CreateElicitationResponse, CreateTerminalRequest, ForkSessionRequest, ForkSessionResponse, InitializeRequest, InitializeResponse, ListSessionsRequest, ListSessionsResponse, LoadSessionRequest, LoadSessionResponse, MaybePromise, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, RequestPermissionRequest, RequestPermissionResponse, ResumeSessionRequest, ResumeSessionResponse, SessionNotification, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, SetSessionModeRequest, SetSessionModeResponse, TerminalActionResponse, TerminalOutputResponse, WaitForTerminalExitResponse, WriteTextFileRequest, WriteTextFileResponse } from "./protocol.js";
2
+ import type { Stream } from "./stream.js";
3
+ import { RpcConnection } from "./transport.js";
4
+ /** Terminal creation response returned by a client. */
5
+ export interface CreateTerminalResponse {
6
+ terminalId: string;
7
+ }
8
+ /** Client callbacks handled by a client-side connection. */
9
+ export interface Client {
10
+ requestPermission(params: RequestPermissionRequest): MaybePromise<RequestPermissionResponse>;
11
+ sessionUpdate(params: SessionNotification): MaybePromise<void>;
12
+ readTextFile?(params: ReadTextFileRequest): MaybePromise<ReadTextFileResponse>;
13
+ writeTextFile?(params: WriteTextFileRequest): MaybePromise<WriteTextFileResponse | void>;
14
+ createTerminal?(params: CreateTerminalRequest): MaybePromise<CreateTerminalResponse>;
15
+ terminalOutput?(params: {
16
+ sessionId: string;
17
+ terminalId: string;
18
+ }): MaybePromise<TerminalOutputResponse>;
19
+ waitForTerminalExit?(params: {
20
+ sessionId: string;
21
+ terminalId: string;
22
+ }): MaybePromise<WaitForTerminalExitResponse>;
23
+ killTerminal?(params: {
24
+ sessionId: string;
25
+ terminalId: string;
26
+ }): MaybePromise<TerminalActionResponse | void>;
27
+ releaseTerminal?(params: {
28
+ sessionId: string;
29
+ terminalId: string;
30
+ }): MaybePromise<TerminalActionResponse | void>;
31
+ unstable_createElicitation?(params: CreateElicitationRequest): MaybePromise<CreateElicitationResponse>;
32
+ unstable_completeElicitation?(params: CompleteElicitationNotification): MaybePromise<void>;
33
+ extMethod?(method: string, params: Record<string, unknown>): MaybePromise<Record<string, unknown>>;
34
+ extNotification?(method: string, params: Record<string, unknown>): MaybePromise<void>;
35
+ }
36
+ /** Agent-side ACP connection. */
37
+ export declare class AgentSideConnection {
38
+ #private;
39
+ constructor(toAgent: (connection: AgentSideConnection) => Agent, stream: Stream);
40
+ /** Signal aborted when the transport closes. */
41
+ get signal(): AbortSignal;
42
+ /** Promise resolved when the transport closes. */
43
+ get closed(): Promise<void>;
44
+ /** Sends a session update notification. */
45
+ sessionUpdate(params: SessionNotification): Promise<void>;
46
+ /** Requests permission from the client. */
47
+ requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse>;
48
+ /** Reads a client-side text file. */
49
+ readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
50
+ /** Writes a client-side text file. */
51
+ writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
52
+ /** Creates a client terminal and returns its control handle. */
53
+ createTerminal(params: CreateTerminalRequest): Promise<TerminalHandle>;
54
+ /** Creates an interactive elicitation on the client. */
55
+ unstable_createElicitation(params: CreateElicitationRequest): Promise<CreateElicitationResponse>;
56
+ /** Notifies a client that URL elicitation completed. */
57
+ unstable_completeElicitation(params: CompleteElicitationNotification): Promise<void>;
58
+ /** Sends a custom request. */
59
+ request<Response = unknown, Params = unknown>(method: string, params?: Params): Promise<Response>;
60
+ /** Sends a custom notification. */
61
+ notify<Params = unknown>(method: string, params?: Params): Promise<void>;
62
+ /** Sends a legacy extension request. */
63
+ extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
64
+ /** Sends a legacy extension notification. */
65
+ extNotification(method: string, params: Record<string, unknown>): Promise<void>;
66
+ }
67
+ /** Handle for controlling a client-owned terminal. */
68
+ export declare class TerminalHandle {
69
+ #private;
70
+ /** Client terminal identifier. */
71
+ readonly id: string;
72
+ constructor(id: string, sessionId: string, connection: RpcConnection);
73
+ /** Gets current terminal output. */
74
+ currentOutput(): Promise<TerminalOutputResponse>;
75
+ /** Waits for terminal exit. */
76
+ waitForExit(): Promise<WaitForTerminalExitResponse>;
77
+ /** Kills the terminal. */
78
+ kill(): Promise<TerminalActionResponse>;
79
+ /** Releases the terminal. */
80
+ release(): Promise<TerminalActionResponse | void>;
81
+ /** Releases the terminal during async disposal. */
82
+ [Symbol.asyncDispose](): Promise<void>;
83
+ }
84
+ /** Client-side ACP connection used to call an agent. */
85
+ export declare class ClientSideConnection {
86
+ #private;
87
+ constructor(toClient: (connection: ClientSideConnection) => Client, stream: Stream);
88
+ /** Signal aborted when the transport closes. */
89
+ get signal(): AbortSignal;
90
+ /** Promise resolved when the transport closes. */
91
+ get closed(): Promise<void>;
92
+ /** Initializes protocol capabilities. */
93
+ initialize(params: InitializeRequest): Promise<InitializeResponse>;
94
+ /** Authenticates with an agent. */
95
+ authenticate(params: AuthenticateRequest): Promise<AuthenticateResponse>;
96
+ /** Creates a session. */
97
+ newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
98
+ /** Loads a session. */
99
+ loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse>;
100
+ /** Lists sessions. */
101
+ listSessions(params: ListSessionsRequest): Promise<ListSessionsResponse>;
102
+ /** Resumes a session. */
103
+ resumeSession(params: ResumeSessionRequest): Promise<ResumeSessionResponse>;
104
+ /** Forks a session. */
105
+ unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse>;
106
+ /** Closes a session. */
107
+ closeSession(params: CloseSessionRequest): Promise<CloseSessionResponse>;
108
+ /** Sets a session mode. */
109
+ setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
110
+ /** Sets a session config option. */
111
+ setSessionConfigOption(params: SetSessionConfigOptionRequest): Promise<SetSessionConfigOptionResponse>;
112
+ /** Sends a prompt. */
113
+ prompt(params: PromptRequest): Promise<PromptResponse>;
114
+ /** Cancels an active prompt. */
115
+ cancel(params: {
116
+ sessionId: string;
117
+ }): Promise<void>;
118
+ }