@xiaoso/dsh-tool-plus 0.1.7-beta.0 → 0.1.7

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 (243) hide show
  1. package/lib/index.mjs +11 -9
  2. package/lib/{scrapers-D8oWspgW.mjs → scrapers-CtQrQ5kG.mjs} +1 -1
  3. package/lib/types/client/BashPlusCard.d.ts +53 -0
  4. package/lib/types/client/ToolPlusSection.d.ts +36 -0
  5. package/lib/types/client/forms.d.ts +42 -0
  6. package/lib/types/client/index.d.ts +29 -0
  7. package/lib/types/client/locales.d.ts +19 -0
  8. package/lib/types/client/rm-safe-status-text.d.ts +15 -0
  9. package/lib/types/client/rows.d.ts +107 -0
  10. package/lib/types/client/web-connection-rpc.d.ts +22 -0
  11. package/lib/types/config/fields.d.ts +85 -0
  12. package/lib/types/config/omp-settings.d.ts +21 -0
  13. package/lib/types/config/settings.d.ts +212 -0
  14. package/lib/types/config/truncate.d.ts +27 -0
  15. package/lib/types/host/browser-probe-rpc.d.ts +29 -0
  16. package/lib/types/index.d.ts +6 -0
  17. package/lib/types/tools/ast-edit/adapter/index.d.ts +26 -0
  18. package/lib/types/tools/ast-edit/adapter/sdk.d.ts +49 -0
  19. package/lib/types/tools/ast-grep/adapter/index.d.ts +31 -0
  20. package/lib/types/tools/ast-grep/adapter/sdk.d.ts +44 -0
  21. package/lib/types/tools/bash/adapter/spill.d.ts +34 -0
  22. package/lib/types/tools/bash/background.d.ts +40 -0
  23. package/lib/types/tools/bash/bash-executor.d.ts +102 -0
  24. package/lib/types/tools/bash/bash-interceptor.d.ts +33 -0
  25. package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
  26. package/lib/types/tools/bash/logger.d.ts +18 -0
  27. package/lib/types/tools/bash/non-interactive-env.d.ts +5 -0
  28. package/lib/types/tools/bash/render.d.ts +46 -0
  29. package/lib/types/tools/bash/rm-safe-status.d.ts +62 -0
  30. package/lib/types/tools/bash/rm-safe.d.ts +18 -0
  31. package/lib/types/tools/bash/sanitize-text.d.ts +34 -0
  32. package/lib/types/tools/bash/shell-snapshot.d.ts +31 -0
  33. package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
  34. package/lib/types/tools/bash/streaming-output.d.ts +32 -0
  35. package/lib/types/tools/bash/trash-cli-main.d.ts +1 -0
  36. package/lib/types/tools/bash/trash-cli.d.ts +77 -0
  37. package/lib/types/tools/bash/types.d.ts +107 -0
  38. package/lib/types/tools/bash/which.d.ts +20 -0
  39. package/lib/types/tools/bash/windows-shell.d.ts +31 -0
  40. package/lib/types/tools/bash/yield.d.ts +71 -0
  41. package/lib/types/tools/edit/adapter/index.d.ts +57 -0
  42. package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +10 -0
  43. package/lib/types/tools/edit/adapter/tools/output-meta.d.ts +34 -0
  44. package/lib/types/tools/edit/adapter/tools/plan-mode-guard.d.ts +21 -0
  45. package/lib/types/tools/glob/adapter/index.d.ts +52 -0
  46. package/lib/types/tools/grep/adapter/index.d.ts +53 -0
  47. package/lib/types/tools/grep/adapter/match-path.d.ts +1 -0
  48. package/lib/types/tools/hashline/native/diff-preview.d.ts +37 -0
  49. package/lib/types/tools/hashline/native/index.d.ts +109 -0
  50. package/lib/types/tools/hashline/native/normalize.d.ts +29 -0
  51. package/lib/types/tools/hashline/native/policy.d.ts +98 -0
  52. package/lib/types/tools/hashline/native/writer.d.ts +42 -0
  53. package/lib/types/tools/omp/browser/launch.d.ts +28 -0
  54. package/lib/types/tools/omp/browser/readable.d.ts +17 -0
  55. package/lib/types/tools/omp/config/settings-schema.d.ts +12 -0
  56. package/lib/types/tools/omp/config/settings.d.ts +59 -0
  57. package/lib/types/tools/omp/edit/apply-patch/parser.d.ts +34 -0
  58. package/lib/types/tools/omp/edit/details.d.ts +54 -0
  59. package/lib/types/tools/omp/edit/diff.d.ts +60 -0
  60. package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
  61. package/lib/types/tools/omp/edit/file-snapshot-store.d.ts +81 -0
  62. package/lib/types/tools/omp/edit/hashline/execute.d.ts +40 -0
  63. package/lib/types/tools/omp/edit/hashline/params.d.ts +6 -0
  64. package/lib/types/tools/omp/edit/modes/apply-patch.d.ts +25 -0
  65. package/lib/types/tools/omp/edit/modes/patch.d.ts +109 -0
  66. package/lib/types/tools/omp/edit/modes/replace.d.ts +151 -0
  67. package/lib/types/tools/omp/edit/normalize.d.ts +31 -0
  68. package/lib/types/tools/omp/edit/notebook.d.ts +50 -0
  69. package/lib/types/tools/omp/edit/read-file.d.ts +2 -0
  70. package/lib/types/tools/omp/edit/snapshot-details.d.ts +33 -0
  71. package/lib/types/tools/omp/extensibility/skills.d.ts +22 -0
  72. package/lib/types/tools/omp/internal-urls/index.d.ts +100 -0
  73. package/lib/types/tools/omp/internal-urls/local-protocol.d.ts +12 -0
  74. package/lib/types/tools/omp/internal-urls/parse.d.ts +31 -0
  75. package/lib/types/tools/omp/internal-urls/types.d.ts +189 -0
  76. package/lib/types/tools/omp/internal-urls/xd-protocol.d.ts +19 -0
  77. package/lib/types/tools/omp/markit/converters/docx.d.ts +6 -0
  78. package/lib/types/tools/omp/markit/converters/epub.d.ts +15 -0
  79. package/lib/types/tools/omp/markit/converters/pdf/index.d.ts +7 -0
  80. package/lib/types/tools/omp/markit/converters/pptx.d.ts +57 -0
  81. package/lib/types/tools/omp/markit/converters/xlsx.d.ts +25 -0
  82. package/lib/types/tools/omp/markit/index.d.ts +2 -0
  83. package/lib/types/tools/omp/markit/registry.d.ts +16 -0
  84. package/lib/types/tools/omp/markit/types.d.ts +30 -0
  85. package/lib/types/tools/omp/sdk.d.ts +103 -0
  86. package/lib/types/tools/omp/session/agent-storage.d.ts +154 -0
  87. package/lib/types/tools/omp/session/streaming-output.d.ts +244 -0
  88. package/lib/types/tools/omp/task/spawn-policy.d.ts +22 -0
  89. package/lib/types/tools/omp/tools/approval.d.ts +62 -0
  90. package/lib/types/tools/omp/tools/ast-edit.d.ts +73 -0
  91. package/lib/types/tools/omp/tools/ast-grep.d.ts +61 -0
  92. package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
  93. package/lib/types/tools/omp/tools/conflict-detect.d.ts +237 -0
  94. package/lib/types/tools/omp/tools/fetch.d.ts +103 -0
  95. package/lib/types/tools/omp/tools/file-recorder.d.ts +13 -0
  96. package/lib/types/tools/omp/tools/fs-cache-invalidation.d.ts +15 -0
  97. package/lib/types/tools/omp/tools/glob.d.ts +86 -0
  98. package/lib/types/tools/omp/tools/grep.d.ts +102 -0
  99. package/lib/types/tools/omp/tools/grouped-file-output.d.ts +70 -0
  100. package/lib/types/tools/omp/tools/index.d.ts +23 -0
  101. package/lib/types/tools/omp/tools/list-limit.d.ts +12 -0
  102. package/lib/types/tools/omp/tools/match-line-format.d.ts +11 -0
  103. package/lib/types/tools/omp/tools/output-meta.d.ts +160 -0
  104. package/lib/types/tools/omp/tools/path-utils.d.ts +326 -0
  105. package/lib/types/tools/omp/tools/plan-mode-guard.d.ts +33 -0
  106. package/lib/types/tools/omp/tools/read-archive.d.ts +16 -0
  107. package/lib/types/tools/omp/tools/read-format.d.ts +104 -0
  108. package/lib/types/tools/omp/tools/read-path-resolution.d.ts +19 -0
  109. package/lib/types/tools/omp/tools/read-selector.d.ts +27 -0
  110. package/lib/types/tools/omp/tools/read-sqlite.d.ts +16 -0
  111. package/lib/types/tools/omp/tools/read-summary.d.ts +15 -0
  112. package/lib/types/tools/omp/tools/read.d.ts +70 -0
  113. package/lib/types/tools/omp/tools/render-utils.d.ts +28 -0
  114. package/lib/types/tools/omp/tools/report-tool-issue.d.ts +149 -0
  115. package/lib/types/tools/omp/tools/resolve.d.ts +127 -0
  116. package/lib/types/tools/omp/tools/sqlite-reader.d.ts +114 -0
  117. package/lib/types/tools/omp/tools/tool-errors.d.ts +33 -0
  118. package/lib/types/tools/omp/tools/tool-result.d.ts +33 -0
  119. package/lib/types/tools/omp/tools/tool-timeouts.d.ts +57 -0
  120. package/lib/types/tools/omp/tools/write.d.ts +53 -0
  121. package/lib/types/tools/omp/tools/writethrough.d.ts +24 -0
  122. package/lib/types/tools/omp/utils/block-context.d.ts +35 -0
  123. package/lib/types/tools/omp/utils/cpuprofile.d.ts +51 -0
  124. package/lib/types/tools/omp/utils/edit-mode.d.ts +13 -0
  125. package/lib/types/tools/omp/utils/file-display-mode.d.ts +27 -0
  126. package/lib/types/tools/omp/utils/image-loading.d.ts +51 -0
  127. package/lib/types/tools/omp/utils/image-resize.d.ts +42 -0
  128. package/lib/types/tools/omp/utils/lang-from-path.d.ts +9 -0
  129. package/lib/types/tools/omp/utils/markit-cache.d.ts +23 -0
  130. package/lib/types/tools/omp/utils/markit.d.ts +30 -0
  131. package/lib/types/tools/omp/utils/profile-tree.d.ts +47 -0
  132. package/lib/types/tools/omp/utils/sample-profile.d.ts +67 -0
  133. package/lib/types/tools/omp/utils/sixel.d.ts +21 -0
  134. package/lib/types/tools/omp/utils/tools-manager.d.ts +11 -0
  135. package/lib/types/tools/omp/utils/turndown.d.ts +15 -0
  136. package/lib/types/tools/omp/utils/zip.d.ts +129 -0
  137. package/lib/types/tools/omp/web/browser-render.d.ts +50 -0
  138. package/lib/types/tools/omp/web/parallel.d.ts +68 -0
  139. package/lib/types/tools/omp/web/scrapers/artifacthub.d.ts +6 -0
  140. package/lib/types/tools/omp/web/scrapers/arxiv.d.ts +5 -0
  141. package/lib/types/tools/omp/web/scrapers/aur.d.ts +5 -0
  142. package/lib/types/tools/omp/web/scrapers/biorxiv.d.ts +5 -0
  143. package/lib/types/tools/omp/web/scrapers/bluesky.d.ts +5 -0
  144. package/lib/types/tools/omp/web/scrapers/brew.d.ts +5 -0
  145. package/lib/types/tools/omp/web/scrapers/cheatsh.d.ts +8 -0
  146. package/lib/types/tools/omp/web/scrapers/chocolatey.d.ts +5 -0
  147. package/lib/types/tools/omp/web/scrapers/choosealicense.d.ts +2 -0
  148. package/lib/types/tools/omp/web/scrapers/cisa-kev.d.ts +5 -0
  149. package/lib/types/tools/omp/web/scrapers/clojars.d.ts +5 -0
  150. package/lib/types/tools/omp/web/scrapers/coingecko.d.ts +5 -0
  151. package/lib/types/tools/omp/web/scrapers/crates-io.d.ts +5 -0
  152. package/lib/types/tools/omp/web/scrapers/crossref.d.ts +2 -0
  153. package/lib/types/tools/omp/web/scrapers/devto.d.ts +5 -0
  154. package/lib/types/tools/omp/web/scrapers/discogs.d.ts +8 -0
  155. package/lib/types/tools/omp/web/scrapers/discourse.d.ts +5 -0
  156. package/lib/types/tools/omp/web/scrapers/dockerhub.d.ts +5 -0
  157. package/lib/types/tools/omp/web/scrapers/docs-rs.d.ts +9 -0
  158. package/lib/types/tools/omp/web/scrapers/fdroid.d.ts +5 -0
  159. package/lib/types/tools/omp/web/scrapers/firefox-addons.d.ts +2 -0
  160. package/lib/types/tools/omp/web/scrapers/flathub.d.ts +2 -0
  161. package/lib/types/tools/omp/web/scrapers/github-gist.d.ts +5 -0
  162. package/lib/types/tools/omp/web/scrapers/github.d.ts +34 -0
  163. package/lib/types/tools/omp/web/scrapers/gitlab.d.ts +5 -0
  164. package/lib/types/tools/omp/web/scrapers/go-pkg.d.ts +5 -0
  165. package/lib/types/tools/omp/web/scrapers/hackage.d.ts +5 -0
  166. package/lib/types/tools/omp/web/scrapers/hackernews.d.ts +2 -0
  167. package/lib/types/tools/omp/web/scrapers/hex.d.ts +5 -0
  168. package/lib/types/tools/omp/web/scrapers/huggingface.d.ts +2 -0
  169. package/lib/types/tools/omp/web/scrapers/iacr.d.ts +5 -0
  170. package/lib/types/tools/omp/web/scrapers/index.d.ts +84 -0
  171. package/lib/types/tools/omp/web/scrapers/jetbrains-marketplace.d.ts +2 -0
  172. package/lib/types/tools/omp/web/scrapers/lemmy.d.ts +2 -0
  173. package/lib/types/tools/omp/web/scrapers/lobsters.d.ts +5 -0
  174. package/lib/types/tools/omp/web/scrapers/mastodon.d.ts +5 -0
  175. package/lib/types/tools/omp/web/scrapers/maven.d.ts +6 -0
  176. package/lib/types/tools/omp/web/scrapers/mdn.d.ts +2 -0
  177. package/lib/types/tools/omp/web/scrapers/metacpan.d.ts +5 -0
  178. package/lib/types/tools/omp/web/scrapers/musicbrainz.d.ts +5 -0
  179. package/lib/types/tools/omp/web/scrapers/npm.d.ts +5 -0
  180. package/lib/types/tools/omp/web/scrapers/nuget.d.ts +5 -0
  181. package/lib/types/tools/omp/web/scrapers/nvd.d.ts +5 -0
  182. package/lib/types/tools/omp/web/scrapers/ollama.d.ts +2 -0
  183. package/lib/types/tools/omp/web/scrapers/open-vsx.d.ts +5 -0
  184. package/lib/types/tools/omp/web/scrapers/opencorporates.d.ts +5 -0
  185. package/lib/types/tools/omp/web/scrapers/openlibrary.d.ts +5 -0
  186. package/lib/types/tools/omp/web/scrapers/orcid.d.ts +5 -0
  187. package/lib/types/tools/omp/web/scrapers/osv.d.ts +5 -0
  188. package/lib/types/tools/omp/web/scrapers/packagist.d.ts +5 -0
  189. package/lib/types/tools/omp/web/scrapers/pub-dev.d.ts +5 -0
  190. package/lib/types/tools/omp/web/scrapers/pubmed.d.ts +5 -0
  191. package/lib/types/tools/omp/web/scrapers/pypi.d.ts +5 -0
  192. package/lib/types/tools/omp/web/scrapers/rawg.d.ts +2 -0
  193. package/lib/types/tools/omp/web/scrapers/readthedocs.d.ts +2 -0
  194. package/lib/types/tools/omp/web/scrapers/reddit.d.ts +5 -0
  195. package/lib/types/tools/omp/web/scrapers/repology.d.ts +5 -0
  196. package/lib/types/tools/omp/web/scrapers/rfc.d.ts +5 -0
  197. package/lib/types/tools/omp/web/scrapers/rubygems.d.ts +5 -0
  198. package/lib/types/tools/omp/web/scrapers/searchcode.d.ts +2 -0
  199. package/lib/types/tools/omp/web/scrapers/sec-edgar.d.ts +5 -0
  200. package/lib/types/tools/omp/web/scrapers/semantic-scholar.d.ts +2 -0
  201. package/lib/types/tools/omp/web/scrapers/snapcraft.d.ts +2 -0
  202. package/lib/types/tools/omp/web/scrapers/sourcegraph.d.ts +2 -0
  203. package/lib/types/tools/omp/web/scrapers/spdx.d.ts +5 -0
  204. package/lib/types/tools/omp/web/scrapers/spotify.d.ts +8 -0
  205. package/lib/types/tools/omp/web/scrapers/stackoverflow.d.ts +6 -0
  206. package/lib/types/tools/omp/web/scrapers/terraform.d.ts +5 -0
  207. package/lib/types/tools/omp/web/scrapers/tldr.d.ts +7 -0
  208. package/lib/types/tools/omp/web/scrapers/twitter.d.ts +5 -0
  209. package/lib/types/tools/omp/web/scrapers/types.d.ts +90 -0
  210. package/lib/types/tools/omp/web/scrapers/utils.d.ts +26 -0
  211. package/lib/types/tools/omp/web/scrapers/vimeo.d.ts +5 -0
  212. package/lib/types/tools/omp/web/scrapers/vscode-marketplace.d.ts +5 -0
  213. package/lib/types/tools/omp/web/scrapers/w3c.d.ts +2 -0
  214. package/lib/types/tools/omp/web/scrapers/wikidata.d.ts +5 -0
  215. package/lib/types/tools/omp/web/scrapers/wikipedia.d.ts +5 -0
  216. package/lib/types/tools/omp/web/scrapers/youtube.d.ts +5 -0
  217. package/lib/types/tools/omp/web/search/providers/utils.d.ts +49 -0
  218. package/lib/types/tools/omp/web/search/types.d.ts +501 -0
  219. package/lib/types/tools/omp/web/search/utils.d.ts +4 -0
  220. package/lib/types/tools/omp/workspace-tree.d.ts +42 -0
  221. package/lib/types/tools/read/adapter/index.d.ts +49 -0
  222. package/lib/types/tools/read/adapter/internal-urls/artifact-protocol.d.ts +15 -0
  223. package/lib/types/tools/read/adapter/internal-urls/registry-helpers.d.ts +44 -0
  224. package/lib/types/tools/read/adapter/registry/agent-registry.d.ts +29 -0
  225. package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -0
  226. package/lib/types/tools/shared/browser-detect.d.ts +54 -0
  227. package/lib/types/tools/shared/browser-rpc-channel.d.ts +40 -0
  228. package/lib/types/tools/shared/bun-ffi-shim.d.ts +13 -0
  229. package/lib/types/tools/shared/bun-named-shim.d.ts +42 -0
  230. package/lib/types/tools/shared/bun-shim.d.ts +138 -0
  231. package/lib/types/tools/shared/bun-sqlite-shim.d.ts +49 -0
  232. package/lib/types/tools/shared/fs-promises-shim.d.ts +15 -0
  233. package/lib/types/tools/shared/image-bridge.d.ts +98 -0
  234. package/lib/types/tools/shared/omp-prompt.d.ts +47 -0
  235. package/lib/types/tools/shared/sandbox-policy.d.ts +38 -0
  236. package/lib/types/tools/shared/session-state.d.ts +51 -0
  237. package/lib/types/tools/shared/tool-errors.d.ts +33 -0
  238. package/lib/types/tools/shared/win-path-fixes.d.ts +16 -0
  239. package/lib/types/tools/write/adapter/index.d.ts +31 -0
  240. package/lib/{utils-CCfhUQen.mjs → utils-ECAwvaPQ.mjs} +1 -1
  241. package/package.json +2 -2
  242. package/presets/package.json +1 -1
  243. package/scripts/patch-pi-natives.mjs +108 -108
@@ -0,0 +1,31 @@
1
+ /**
2
+ * DSH write tool — adapter that wires the verbatim OMP write engine
3
+ * (`src/tools/write/adapter/omp/`) into DSH's `defineTool` contract.
4
+ *
5
+ * This file is pure glue. All write logic lives in `omp/` (copied verbatim);
6
+ * this adapter only:
7
+ * - builds an OMP `ToolSession` from the DSH exec context + tool-plus config,
8
+ * - constructs the verbatim `WriteTool` and calls its `execute`,
9
+ * - converts the `AgentToolResult` back to a DSH tool result.
10
+ *
11
+ * LSP/ACP/TUI are absent in DSH (plan.md §2): writethrough writes through
12
+ * ctx.fs, diagnostics are never produced, and no TUI rendering happens.
13
+ */
14
+ import type { Context } from '@deepseek-ai/cordis';
15
+ import type { RuntimeConfig } from '../../../config/settings.ts';
16
+ export type { Settings } from '../../omp/config/settings.ts';
17
+ export type { ToolSession } from '../../omp/sdk.ts';
18
+ /** DSH write 工具输出形状(output.schema 镜像)。 */
19
+ export interface WriteToolOutput {
20
+ path: string;
21
+ text: string;
22
+ }
23
+ /** 完整执行链路(defineTool.execute 与单测共用)。 */
24
+ export declare function executeWriteTool(exec: any, cfg: RuntimeConfig, args: any): Promise<WriteToolOutput>;
25
+ /**
26
+ * Register the write tool (OMP native `path` + `content` parameters).
27
+ */
28
+ export declare function registerWrite(ctx: Context, getConfig: () => RuntimeConfig): void;
29
+ export declare const applyWrite: typeof registerWrite;
30
+ export declare const registerWriteTool: typeof registerWrite;
31
+ export default registerWrite;
@@ -6267,7 +6267,7 @@ const settings = {
6267
6267
  };
6268
6268
  //#endregion
6269
6269
  //#region package.json
6270
- var version = "0.1.7-beta.0";
6270
+ var version = "0.1.7";
6271
6271
  /** `.tmp` files older than this are treated as orphaned writes and swept. */
6272
6272
  const TMP_ORPHAN_MAX_AGE_MS = 3e5;
6273
6273
  function markitConversionCacheKey(bytes, extension) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xiaoso/dsh-tool-plus",
3
3
  "description": "Oh My Pi bash runtime ported as a deepseek-harness tool plugin: persistent shell session, output minimizer, managed background jobs, command interception",
4
- "version": "0.1.7-beta.0",
4
+ "version": "0.1.7",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -71,7 +71,7 @@
71
71
  }
72
72
  },
73
73
  "scripts": {
74
- "build": "tsc -p tsconfig.json && tsdown -c tsdown.config.ts && node scripts/copy-assets.mjs",
74
+ "build": "tsdown -c tsdown.config.ts && tsc -p tsconfig.json && node scripts/copy-assets.mjs",
75
75
  "typecheck": "tsc -p tsconfig.json --noEmit",
76
76
  "test": "vitest run --config vitest.config.ts",
77
77
  "presets:install": "node presets/install-presets.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaoso/dsh-tool-plus-presets",
3
- "version": "0.1.7-beta.0",
3
+ "version": "0.1.7",
4
4
  "description": "Agent-preset installer for dsh-tool-plus: installs the standard / PTC enhanced preset templates into a DeepSeek Harness home.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -1,108 +1,108 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Self-heal `@oh-my-pi/pi-natives` for Node runtimes after installs that did
4
- * NOT go through pnpm (plain npm / yarn / npx of this package).
5
- *
6
- * Background: upstream pi-natives@17.3.5 locates its prebuilt binaries with
7
- * the Bun-only API `import.meta.dir` (native/loader-state.js). Under pnpm,
8
- * `patches/@oh-my-pi__pi-natives.patch` (declared in pnpm-workspace.yaml)
9
- * fixes that line automatically; every other package manager ignores pnpm
10
- * patch declarations, so their installs keep the bug and the tool plugin
11
- * crashes on first native access. This hook folds in the SAME one-line fix,
12
- * making the dependency-tree end state identical across all managers.
13
- *
14
- * Idempotent by construction:
15
- * - file absent -> warn, exit 0 (unknown layout must not brick installs)
16
- * - line already fixed -> no-op ("already patched")
17
- * - buggy literal found -> rewrite `import.meta.dir` -> `import.meta.dirname`
18
- *
19
- * Usage: node scripts/patch-pi-natives.mjs [searchRoot]
20
- * Without argument the script walks ancestors of this file looking for a
21
- * node_modules/@oh-my-pi/pi-natives package (hoisting-safe). With an
22
- * argument, that directory is used as the walk root (for isolated tests).
23
- *
24
- * Never throws: a packaging lifecycle hook must not fail installs; if
25
- * anything unexpected happens it warns so the (pre-existing) runtime error
26
- * stays the single source of truth.
27
- */
28
-
29
- import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
30
- import { dirname, join, resolve } from "node:path";
31
- import { fileURLToPath } from "node:url";
32
-
33
- const PKG_SUBPATH = join("node_modules", "@oh-my-pi", "pi-natives");
34
- const TARGET_REL = join("native", "loader-state.js");
35
- // Exact buggy token; `\b` keeps an already-fixed `import.meta.dirname` intact.
36
- const BUGGY = /import\.meta\.dir\b/g;
37
-
38
- function log(message) {
39
- console.log(`[patch-pi-natives] ${message}`);
40
- }
41
-
42
- /** Walk upwards from `start`, yielding every candidate package directory. */
43
- function* candidatePackageDirs(start) {
44
- let current = resolve(start);
45
- for (;;) {
46
- const candidate = join(current, PKG_SUBPATH);
47
- if (existsSync(candidate)) yield candidate;
48
- const parent = dirname(current);
49
- if (parent === current) return;
50
- current = parent;
51
- }
52
- }
53
-
54
- function firstMatchedFile(packageDir) {
55
- // The known target first (byte-for-byte what the pnpm patch touches).
56
- const direct = join(packageDir, TARGET_REL);
57
- if (existsSync(direct)) return direct;
58
- // Unknown layouts: locate any loader-state.js so we can still heal them.
59
- const stack = [packageDir];
60
- while (stack.length > 0) {
61
- const entry = stack.pop();
62
- for (const item of readdirSync(entry)) {
63
- const full = join(entry, item);
64
- const stat = statSync(full);
65
- if (stat.isDirectory()) stack.push(full);
66
- else if (item === "loader-state.js") return full;
67
- }
68
- }
69
- return undefined;
70
- }
71
-
72
- function main() {
73
- // Default: walk ancestors starting at THIS script's directory (`scripts/`),
74
- // so the repo root's node_modules is covered both here and in published
75
- // layouts (where the package sits inside someone else's node_modules tree).
76
- const scriptDir = dirname(fileURLToPath(import.meta.url));
77
- const searchRoot = process.argv[2] ? resolve(process.argv[2]) : scriptDir;
78
-
79
- let inspected = 0;
80
- let healed = 0;
81
- for (const packageDir of candidatePackageDirs(searchRoot)) {
82
- inspected += 1;
83
- const file = firstMatchedFile(packageDir);
84
- if (file === undefined) {
85
- log(`WARN ${packageDir}: loader-state.js not found, skipped`);
86
- continue;
87
- }
88
- const source = readFileSync(file, "utf8");
89
- BUGGY.lastIndex = 0;
90
- if (!BUGGY.test(source)) {
91
- log(`${file}: already patched`);
92
- continue;
93
- }
94
- BUGGY.lastIndex = 0;
95
- writeFileSync(file, source.replace(BUGGY, "import.meta.dirname"));
96
- healed += 1;
97
- log(`${file}: patched import.meta.dir -> import.meta.dirname`);
98
- }
99
-
100
- if (inspected === 0) log(`WARN no @oh-my-pi/pi-natives found under ${searchRoot}`);
101
- else log(`done: ${inspected} package(s) seen, ${healed} patched`);
102
- }
103
-
104
- try {
105
- main();
106
- } catch (error) {
107
- log(`WARN self-heal skipped: ${error?.message ?? error}`);
108
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Self-heal `@oh-my-pi/pi-natives` for Node runtimes after installs that did
4
+ * NOT go through pnpm (plain npm / yarn / npx of this package).
5
+ *
6
+ * Background: upstream pi-natives@17.3.5 locates its prebuilt binaries with
7
+ * the Bun-only API `import.meta.dir` (native/loader-state.js). Under pnpm,
8
+ * `patches/@oh-my-pi__pi-natives.patch` (declared in pnpm-workspace.yaml)
9
+ * fixes that line automatically; every other package manager ignores pnpm
10
+ * patch declarations, so their installs keep the bug and the tool plugin
11
+ * crashes on first native access. This hook folds in the SAME one-line fix,
12
+ * making the dependency-tree end state identical across all managers.
13
+ *
14
+ * Idempotent by construction:
15
+ * - file absent -> warn, exit 0 (unknown layout must not brick installs)
16
+ * - line already fixed -> no-op ("already patched")
17
+ * - buggy literal found -> rewrite `import.meta.dir` -> `import.meta.dirname`
18
+ *
19
+ * Usage: node scripts/patch-pi-natives.mjs [searchRoot]
20
+ * Without argument the script walks ancestors of this file looking for a
21
+ * node_modules/@oh-my-pi/pi-natives package (hoisting-safe). With an
22
+ * argument, that directory is used as the walk root (for isolated tests).
23
+ *
24
+ * Never throws: a packaging lifecycle hook must not fail installs; if
25
+ * anything unexpected happens it warns so the (pre-existing) runtime error
26
+ * stays the single source of truth.
27
+ */
28
+
29
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
30
+ import { dirname, join, resolve } from "node:path";
31
+ import { fileURLToPath } from "node:url";
32
+
33
+ const PKG_SUBPATH = join("node_modules", "@oh-my-pi", "pi-natives");
34
+ const TARGET_REL = join("native", "loader-state.js");
35
+ // Exact buggy token; `\b` keeps an already-fixed `import.meta.dirname` intact.
36
+ const BUGGY = /import\.meta\.dir\b/g;
37
+
38
+ function log(message) {
39
+ console.log(`[patch-pi-natives] ${message}`);
40
+ }
41
+
42
+ /** Walk upwards from `start`, yielding every candidate package directory. */
43
+ function* candidatePackageDirs(start) {
44
+ let current = resolve(start);
45
+ for (;;) {
46
+ const candidate = join(current, PKG_SUBPATH);
47
+ if (existsSync(candidate)) yield candidate;
48
+ const parent = dirname(current);
49
+ if (parent === current) return;
50
+ current = parent;
51
+ }
52
+ }
53
+
54
+ function firstMatchedFile(packageDir) {
55
+ // The known target first (byte-for-byte what the pnpm patch touches).
56
+ const direct = join(packageDir, TARGET_REL);
57
+ if (existsSync(direct)) return direct;
58
+ // Unknown layouts: locate any loader-state.js so we can still heal them.
59
+ const stack = [packageDir];
60
+ while (stack.length > 0) {
61
+ const entry = stack.pop();
62
+ for (const item of readdirSync(entry)) {
63
+ const full = join(entry, item);
64
+ const stat = statSync(full);
65
+ if (stat.isDirectory()) stack.push(full);
66
+ else if (item === "loader-state.js") return full;
67
+ }
68
+ }
69
+ return undefined;
70
+ }
71
+
72
+ function main() {
73
+ // Default: walk ancestors starting at THIS script's directory (`scripts/`),
74
+ // so the repo root's node_modules is covered both here and in published
75
+ // layouts (where the package sits inside someone else's node_modules tree).
76
+ const scriptDir = dirname(fileURLToPath(import.meta.url));
77
+ const searchRoot = process.argv[2] ? resolve(process.argv[2]) : scriptDir;
78
+
79
+ let inspected = 0;
80
+ let healed = 0;
81
+ for (const packageDir of candidatePackageDirs(searchRoot)) {
82
+ inspected += 1;
83
+ const file = firstMatchedFile(packageDir);
84
+ if (file === undefined) {
85
+ log(`WARN ${packageDir}: loader-state.js not found, skipped`);
86
+ continue;
87
+ }
88
+ const source = readFileSync(file, "utf8");
89
+ BUGGY.lastIndex = 0;
90
+ if (!BUGGY.test(source)) {
91
+ log(`${file}: already patched`);
92
+ continue;
93
+ }
94
+ BUGGY.lastIndex = 0;
95
+ writeFileSync(file, source.replace(BUGGY, "import.meta.dirname"));
96
+ healed += 1;
97
+ log(`${file}: patched import.meta.dir -> import.meta.dirname`);
98
+ }
99
+
100
+ if (inspected === 0) log(`WARN no @oh-my-pi/pi-natives found under ${searchRoot}`);
101
+ else log(`done: ${inspected} package(s) seen, ${healed} patched`);
102
+ }
103
+
104
+ try {
105
+ main();
106
+ } catch (error) {
107
+ log(`WARN self-heal skipped: ${error?.message ?? error}`);
108
+ }