@songtonyli/dsh-cli 0.1.57 → 0.1.59

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 (139) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +1 -0
  4. package/node_modules/@deepseek-ai/dsh-api-session-controller/lib/client.js +1 -0
  5. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  6. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  7. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  8. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +59 -4
  9. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +73 -0
  10. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +166 -0
  11. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +166 -0
  12. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +227 -0
  13. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +704 -0
  14. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/package.json +62 -0
  15. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.i18n.yaml +2 -2
  16. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.md +1 -1
  17. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.zh.md +1 -1
  18. package/node_modules/@deepseek-ai/dsh-sandbox-policy/lib/index.js +23 -0
  19. package/node_modules/@deepseek-ai/dsh-session/lib/index.js +1 -0
  20. package/node_modules/@deepseek-ai/dsh-session/lib/types/known-event-types.js +1 -0
  21. package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/worker.cjs +1 -0
  22. package/node_modules/@deepseek-ai/dsh-system-prompt/lib/index.js +1 -0
  23. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +22 -0
  24. package/node_modules/@deepseek-ai/dsh-tool-fs/README.i18n.yaml +2 -2
  25. package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
  26. package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
  27. package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +24 -0
  28. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.i18n.yaml +4 -4
  29. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.md +2 -2
  30. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.zh.md +2 -2
  31. package/node_modules/@deepseek-ai/dsh-tool-fs-search/lib/index.js +28 -3
  32. package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +7 -2
  33. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.i18n.yaml +2 -2
  34. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.md +1 -1
  35. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.zh.md +1 -1
  36. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/lib/index.js +14 -6
  37. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
  38. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +6 -5
  39. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +6 -5
  40. package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +20 -0
  41. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +42 -31
  42. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +1 -0
  43. package/node_modules/@deepseek-ai/libreoffice-kit/README.md +20 -5
  44. package/node_modules/@deepseek-ai/libreoffice-kit/README.zh.md +21 -6
  45. package/node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js +499 -253
  46. package/node_modules/@deepseek-ai/libreoffice-kit/lib/font-snapshot-worker.js +37 -26
  47. package/node_modules/@deepseek-ai/libreoffice-kit/lib/index.js +498 -252
  48. package/node_modules/@deepseek-ai/libreoffice-kit/lib/worker.js +39 -13
  49. package/node_modules/@deepseek-ai/libreoffice-kit/package.json +5 -3
  50. package/node_modules/@earendil-works/pi-ai/README.md +4 -3
  51. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +117 -18
  52. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  53. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +19 -8
  54. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +1 -0
  55. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -0
  56. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +1 -0
  57. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -0
  58. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +5 -0
  59. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +24 -2
  60. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  61. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  62. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  63. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  64. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  65. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  66. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  67. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  68. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  69. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  70. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  71. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -1
  72. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +3 -2
  73. package/node_modules/@earendil-works/pi-ai/package.json +6 -2
  74. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  75. package/node_modules/@shikijs/core/dist/index.mjs +15 -12
  76. package/node_modules/@shikijs/core/package.json +4 -4
  77. package/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs +2 -4
  78. package/node_modules/@shikijs/engine-javascript/dist/engine-raw.mjs +2 -4
  79. package/node_modules/@shikijs/engine-javascript/dist/index.mjs +1 -1
  80. package/node_modules/@shikijs/engine-javascript/dist/string-TLTPtCPs.mjs +115 -0
  81. package/node_modules/@shikijs/engine-javascript/package.json +3 -3
  82. package/node_modules/@shikijs/engine-oniguruma/package.json +3 -3
  83. package/node_modules/@shikijs/langs/dist/ada.mjs +1 -1
  84. package/node_modules/@shikijs/langs/dist/ahk.mjs +1 -1
  85. package/node_modules/@shikijs/langs/dist/beancount.mjs +1 -1
  86. package/node_modules/@shikijs/langs/dist/coq.mjs +1 -1
  87. package/node_modules/@shikijs/langs/dist/csharp.mjs +1 -1
  88. package/node_modules/@shikijs/langs/dist/css.mjs +1 -1
  89. package/node_modules/@shikijs/langs/dist/dart.mjs +1 -1
  90. package/node_modules/@shikijs/langs/dist/dotenv.mjs +1 -1
  91. package/node_modules/@shikijs/langs/dist/emacs-lisp.mjs +1 -1
  92. package/node_modules/@shikijs/langs/dist/gn.mjs +1 -1
  93. package/node_modules/@shikijs/langs/dist/handlebars.mjs +1 -1
  94. package/node_modules/@shikijs/langs/dist/julia.mjs +1 -1
  95. package/node_modules/@shikijs/langs/dist/latex.mjs +1 -1
  96. package/node_modules/@shikijs/langs/dist/luau.mjs +1 -1
  97. package/node_modules/@shikijs/langs/dist/marko.mjs +1 -1
  98. package/node_modules/@shikijs/langs/dist/moonbit.mjs +1 -1
  99. package/node_modules/@shikijs/langs/dist/nextflow-groovy.mjs +1 -1
  100. package/node_modules/@shikijs/langs/dist/nextflow.mjs +1 -1
  101. package/node_modules/@shikijs/langs/dist/nushell.mjs +1 -1
  102. package/node_modules/@shikijs/langs/dist/php.mjs +1 -1
  103. package/node_modules/@shikijs/langs/dist/powershell.mjs +1 -1
  104. package/node_modules/@shikijs/langs/dist/ruby.mjs +1 -1
  105. package/node_modules/@shikijs/langs/dist/rust.mjs +1 -1
  106. package/node_modules/@shikijs/langs/dist/sql.mjs +1 -1
  107. package/node_modules/@shikijs/langs/dist/svelte.mjs +1 -1
  108. package/node_modules/@shikijs/langs/dist/twig.mjs +3 -3
  109. package/node_modules/@shikijs/langs/dist/typespec.mjs +1 -1
  110. package/node_modules/@shikijs/langs/package.json +3 -3
  111. package/node_modules/@shikijs/primitive/dist/index.mjs +2 -1
  112. package/node_modules/@shikijs/primitive/package.json +3 -3
  113. package/node_modules/@shikijs/themes/dist/monokai.mjs +1 -1
  114. package/node_modules/@shikijs/themes/dist/one-dark-pro.mjs +1 -1
  115. package/node_modules/@shikijs/themes/dist/red.mjs +1 -1
  116. package/node_modules/@shikijs/themes/dist/solarized-dark.mjs +1 -1
  117. package/node_modules/@shikijs/themes/dist/solarized-light.mjs +1 -1
  118. package/node_modules/@shikijs/themes/package.json +3 -3
  119. package/node_modules/@shikijs/types/package.json +1 -1
  120. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +33 -11
  121. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
  122. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/exceptions.js +33 -11
  123. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +3 -0
  124. package/node_modules/@smithy/core/package.json +1 -1
  125. package/node_modules/node-addon-native-custom-loader/lib/index.js +23 -10
  126. package/node_modules/node-addon-native-custom-loader/package.json +6 -1
  127. package/node_modules/node-addon-require-builtin/package.json +7 -2
  128. package/node_modules/powershell-utils/index.js +40 -19
  129. package/node_modules/powershell-utils/package.json +1 -1
  130. package/node_modules/powershell-utils/readme.md +69 -13
  131. package/node_modules/shiki/package.json +10 -10
  132. package/node_modules/wsl-utils/index.js +18 -37
  133. package/node_modules/wsl-utils/package.json +2 -2
  134. package/package.json +33 -29
  135. package/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs +0 -77
  136. package/node_modules/open/node_modules/powershell-utils/index.js +0 -79
  137. package/node_modules/open/node_modules/powershell-utils/license +0 -9
  138. package/node_modules/open/node_modules/powershell-utils/package.json +0 -47
  139. package/node_modules/open/node_modules/powershell-utils/readme.md +0 -209
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@songtonyli/dsh-cli",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "The dsh terminal agent: an interactive TUI over the DeepSeek Harness, with its whole Node runtime bundled in one install.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -224,6 +224,7 @@
224
224
  "@deepseek-ai/dsh-pwsh-sandbox": "0.2.0-rc.2",
225
225
  "@deepseek-ai/dsh-repeat-tool-reminder": "0.2.0-rc.2",
226
226
  "@deepseek-ai/dsh-sandbox": "0.2.0-rc.2",
227
+ "@deepseek-ai/dsh-sandbox-apple-container": "0.2.0-rc.2",
227
228
  "@deepseek-ai/dsh-sandbox-local": "0.2.0-rc.2",
228
229
  "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
229
230
  "@deepseek-ai/dsh-sandbox-windows-acl": "0.2.0-rc.2",
@@ -331,11 +332,11 @@
331
332
  "@deepseek-ai/dsh-workflow-ptc": "0.2.0-rc.2",
332
333
  "@deepseek-ai/dsh-workspace": "0.2.0-rc.2",
333
334
  "@deepseek-ai/dsh-workspace-changes": "0.2.0-rc.2",
334
- "@deepseek-ai/libreoffice-kit": "0.1.2",
335
+ "@deepseek-ai/libreoffice-kit": "0.1.5",
335
336
  "@deepseek-ai/node-addon-system": "0.1.2",
336
337
  "@deepseek-ai/schemastery": "3.18.4",
337
- "@earendil-works/pi-ai": "0.99.1",
338
- "@earendil-works/pi-telemetry": "0.99.1",
338
+ "@earendil-works/pi-ai": "0.99.2",
339
+ "@earendil-works/pi-telemetry": "0.99.2",
339
340
  "@earendil-works/pi-tui": "0.85.1",
340
341
  "@eslint-community/regexpp": "4.12.2",
341
342
  "@google/genai": "2.21.0",
@@ -372,17 +373,17 @@
372
373
  "@protobufjs/pool": "1.1.0",
373
374
  "@protobufjs/utf8": "1.1.2",
374
375
  "@sec-ant/readable-stream": "0.4.1",
375
- "@shikijs/core": "4.4.3",
376
- "@shikijs/engine-javascript": "4.4.3",
377
- "@shikijs/engine-oniguruma": "4.4.3",
378
- "@shikijs/langs": "4.4.3",
379
- "@shikijs/primitive": "4.4.3",
380
- "@shikijs/themes": "4.4.3",
381
- "@shikijs/types": "4.4.3",
376
+ "@shikijs/core": "4.5.0",
377
+ "@shikijs/engine-javascript": "4.5.0",
378
+ "@shikijs/engine-oniguruma": "4.5.0",
379
+ "@shikijs/langs": "4.5.0",
380
+ "@shikijs/primitive": "4.5.0",
381
+ "@shikijs/themes": "4.5.0",
382
+ "@shikijs/types": "4.5.0",
382
383
  "@shikijs/vscode-textmate": "10.0.2",
383
384
  "@sindresorhus/is": "7.2.0",
384
385
  "@sindresorhus/merge-streams": "4.0.0",
385
- "@smithy/core": "3.35.0",
386
+ "@smithy/core": "3.35.1",
386
387
  "@smithy/credential-provider-imds": "4.5.2",
387
388
  "@smithy/fetch-http-handler": "5.8.0",
388
389
  "@smithy/node-http-handler": "4.12.1",
@@ -501,8 +502,8 @@
501
502
  "ms": "2.1.3",
502
503
  "negotiator": "0.6.4",
503
504
  "node-addon-api": "7.1.1",
504
- "node-addon-native-custom-loader": "0.1.6",
505
- "node-addon-require-builtin": "0.1.6",
505
+ "node-addon-native-custom-loader": "0.1.7",
506
+ "node-addon-require-builtin": "0.1.7",
506
507
  "node-domexception": "1.0.0",
507
508
  "node-fetch": "3.3.2",
508
509
  "node-pty": "1.2.0-beta.15",
@@ -522,7 +523,7 @@
522
523
  "picocolors": "1.1.1",
523
524
  "picomatch": "4.0.7",
524
525
  "pkce-challenge": "5.0.1",
525
- "powershell-utils": "0.1.0",
526
+ "powershell-utils": "0.2.1",
526
527
  "pretty-ms": "9.3.1",
527
528
  "property-information": "7.2.0",
528
529
  "protobufjs": "7.6.6",
@@ -546,7 +547,7 @@
546
547
  "shebang-command": "2.0.0",
547
548
  "shebang-regex": "3.0.0",
548
549
  "sherpa-onnx-node": "1.13.8",
549
- "shiki": "4.4.3",
550
+ "shiki": "4.5.0",
550
551
  "signal-exit": "4.1.0",
551
552
  "space-separated-tokens": "2.0.2",
552
553
  "standardwebhooks": "1.1.1",
@@ -576,7 +577,7 @@
576
577
  "which": "2.0.2",
577
578
  "which-command": "0.1.0",
578
579
  "ws": "8.21.0",
579
- "wsl-utils": "1.0.0",
580
+ "wsl-utils": "1.0.1",
580
581
  "xmlchars": "2.2.0",
581
582
  "yaml": "2.9.1",
582
583
  "yoctocolors": "2.2.0",
@@ -584,11 +585,11 @@
584
585
  "zwitch": "2.0.4"
585
586
  },
586
587
  "optionalDependencies": {
587
- "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.1.1",
588
- "@deepseek-ai/libreoffice-kit-darwin-x64": "0.1.1",
589
- "@deepseek-ai/libreoffice-kit-win32-arm64": "0.1.2",
590
- "@deepseek-ai/libreoffice-kit-wasm": "0.1.1",
591
- "@deepseek-ai/libreoffice-kit-win32-x64": "0.1.2",
588
+ "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.1.5",
589
+ "@deepseek-ai/libreoffice-kit-win32-x64": "0.1.5",
590
+ "@deepseek-ai/libreoffice-kit-darwin-x64": "0.1.5",
591
+ "@deepseek-ai/libreoffice-kit-wasm": "0.1.5",
592
+ "@deepseek-ai/libreoffice-kit-win32-arm64": "0.1.5",
592
593
  "@deepseek-ai/node-addon-system-darwin-arm64": "0.1.2",
593
594
  "@deepseek-ai/node-addon-system-darwin-x64": "0.1.2",
594
595
  "@deepseek-ai/node-addon-system-linux-arm64": "0.1.2",
@@ -620,13 +621,15 @@
620
621
  "@koromix/koffi-darwin-x64": "3.1.1",
621
622
  "@koromix/koffi-darwin-arm64": "3.1.1",
622
623
  "@koromix/koffi-linux-loong64": "3.1.1",
623
- "node-addon-require-builtin-darwin-arm64": "0.1.6",
624
- "node-addon-require-builtin-darwin-x64": "0.1.6",
625
- "node-addon-require-builtin-linux-arm64-gnu": "0.1.6",
626
- "node-addon-require-builtin-linux-x64-gnu": "0.1.6",
627
- "node-addon-require-builtin-win32-arm64-msvc": "0.1.6",
628
- "node-addon-require-builtin-win32-x64-msvc": "0.1.6",
629
- "node-addon-require-builtin-win32-ia32-msvc": "0.1.6",
624
+ "node-addon-require-builtin-darwin-x64": "0.1.7",
625
+ "node-addon-require-builtin-darwin-arm64": "0.1.7",
626
+ "node-addon-require-builtin-linux-arm64-gnu": "0.1.7",
627
+ "node-addon-require-builtin-linux-arm64-musl": "0.1.7",
628
+ "node-addon-require-builtin-linux-x64-gnu": "0.1.7",
629
+ "node-addon-require-builtin-win32-arm64-msvc": "0.1.7",
630
+ "node-addon-require-builtin-win32-ia32-msvc": "0.1.7",
631
+ "node-addon-require-builtin-win32-x64-msvc": "0.1.7",
632
+ "node-addon-require-builtin-linux-x64-musl": "0.1.7",
630
633
  "@img/sharp-darwin-arm64": "0.35.5",
631
634
  "@img/sharp-darwin-x64": "0.35.5",
632
635
  "@img/sharp-freebsd-wasm32": "0.35.5",
@@ -870,6 +873,7 @@
870
873
  "@deepseek-ai/dsh-pwsh-sandbox",
871
874
  "@deepseek-ai/dsh-repeat-tool-reminder",
872
875
  "@deepseek-ai/dsh-sandbox",
876
+ "@deepseek-ai/dsh-sandbox-apple-container",
873
877
  "@deepseek-ai/dsh-sandbox-local",
874
878
  "@deepseek-ai/dsh-sandbox-policy",
875
879
  "@deepseek-ai/dsh-sandbox-windows-acl",
@@ -1,77 +0,0 @@
1
- //#region src/scanner.ts
2
- const MAX = 4294967295;
3
- var JavaScriptScanner = class {
4
- patterns;
5
- options;
6
- regexps;
7
- constructor(patterns, options = {}) {
8
- this.patterns = patterns;
9
- this.options = options;
10
- const { forgiving = false, cache, regexConstructor } = options;
11
- if (!regexConstructor) throw new Error("Option `regexConstructor` is not provided");
12
- this.regexps = patterns.map((p) => {
13
- if (typeof p !== "string") return p;
14
- const cached = cache?.get(p);
15
- if (cached) {
16
- if (cached instanceof RegExp) return cached;
17
- if (forgiving) return null;
18
- throw cached;
19
- }
20
- try {
21
- const regex = regexConstructor(p);
22
- cache?.set(p, regex);
23
- return regex;
24
- } catch (e) {
25
- cache?.set(p, e);
26
- if (forgiving) return null;
27
- throw e;
28
- }
29
- });
30
- }
31
- findNextMatchSync(string, startPosition, _options) {
32
- const str = typeof string === "string" ? string : string.content;
33
- const pending = [];
34
- function toResult(index, match, offset = 0) {
35
- return {
36
- index,
37
- captureIndices: match.indices.map((indice) => {
38
- if (indice == null) return {
39
- start: MAX,
40
- end: MAX,
41
- length: 0
42
- };
43
- return {
44
- start: indice[0] + offset,
45
- end: indice[1] + offset,
46
- length: indice[1] - indice[0]
47
- };
48
- })
49
- };
50
- }
51
- for (let i = 0; i < this.regexps.length; i++) {
52
- const regexp = this.regexps[i];
53
- if (!regexp) continue;
54
- try {
55
- regexp.lastIndex = startPosition;
56
- const match = regexp.exec(str);
57
- if (!match) continue;
58
- if (match.index === startPosition) return toResult(i, match, 0);
59
- pending.push([
60
- i,
61
- match,
62
- 0
63
- ]);
64
- } catch (e) {
65
- if (this.options.forgiving) continue;
66
- throw e;
67
- }
68
- }
69
- if (pending.length) {
70
- const minIndex = Math.min(...pending.map((m) => m[1].index));
71
- for (const [i, match, offset] of pending) if (match.index === minIndex) return toResult(i, match, offset);
72
- }
73
- return null;
74
- }
75
- };
76
- //#endregion
77
- export { JavaScriptScanner as t };
@@ -1,79 +0,0 @@
1
- import process from 'node:process';
2
- import {Buffer} from 'node:buffer';
3
- import {promisify} from 'node:util';
4
- import childProcess from 'node:child_process';
5
- import fs, {constants as fsConstants} from 'node:fs/promises';
6
-
7
- const execFile = promisify(childProcess.execFile);
8
-
9
- export const powerShellPath = () => `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
10
-
11
- // Cache for PowerShell accessibility check
12
- let canAccessCache;
13
-
14
- export const canAccessPowerShell = async () => {
15
- canAccessCache ??= (async () => {
16
- try {
17
- await fs.access(powerShellPath(), fsConstants.X_OK);
18
- return true;
19
- } catch {
20
- return false;
21
- }
22
- })();
23
-
24
- return canAccessCache;
25
- };
26
-
27
- const argumentsPrefix = [
28
- '-NoProfile',
29
- '-NonInteractive',
30
- '-ExecutionPolicy',
31
- 'Bypass',
32
- '-EncodedCommand',
33
- ];
34
-
35
- const encodeCommand = command => Buffer.from(command, 'utf16le').toString('base64');
36
-
37
- /*
38
- PowerShell's tokenizer treats the typographic single quotes U+2018, U+2019, U+201A, and U+201B as string delimiters, exactly like the ASCII one, and it does not require the closing quote to match the opening quote. Escaping only the ASCII quote would let any of the others terminate the string and inject a statement. Doubling works for all of them.
39
- */
40
- const escapeArgument = value => `'${String(value).replaceAll(/['‘’‚‛]/g, match => match + match)}'`;
41
-
42
- const createArguments = command => [...argumentsPrefix, encodeCommand(command)];
43
-
44
- const createExecFileOptions = options => ({
45
- encoding: 'utf8',
46
- ...options,
47
- shell: false,
48
- });
49
-
50
- export const executePowerShell = async (command, options = {}) => {
51
- const {
52
- powerShellPath: psPath,
53
- ...execFileOptions
54
- } = options;
55
-
56
- return execFile(
57
- psPath ?? powerShellPath(),
58
- createArguments(command),
59
- createExecFileOptions(execFileOptions),
60
- );
61
- };
62
-
63
- executePowerShell.argumentsPrefix = argumentsPrefix;
64
- executePowerShell.encodeCommand = encodeCommand;
65
- executePowerShell.escapeArgument = escapeArgument;
66
- executePowerShell.createArguments = createArguments;
67
-
68
- export const executePowerShellSync = (command, options = {}) => {
69
- const {
70
- powerShellPath: psPath,
71
- ...execFileOptions
72
- } = options;
73
-
74
- return childProcess.execFileSync(
75
- psPath ?? powerShellPath(),
76
- createArguments(command),
77
- createExecFileOptions(execFileOptions),
78
- );
79
- };
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,47 +0,0 @@
1
- {
2
- "name": "powershell-utils",
3
- "version": "0.2.1",
4
- "description": "Utilities for executing PowerShell commands",
5
- "license": "MIT",
6
- "repository": "sindresorhus/powershell-utils",
7
- "funding": "https://github.com/sponsors/sindresorhus",
8
- "author": {
9
- "name": "Sindre Sorhus",
10
- "email": "sindresorhus@gmail.com",
11
- "url": "https://sindresorhus.com"
12
- },
13
- "type": "module",
14
- "exports": {
15
- "types": "./index.d.ts",
16
- "default": "./index.js"
17
- },
18
- "sideEffects": false,
19
- "engines": {
20
- "node": ">=20"
21
- },
22
- "scripts": {
23
- "test": "xo && ava && tsc index.d.ts --skipLibCheck"
24
- },
25
- "files": [
26
- "index.js",
27
- "index.d.ts"
28
- ],
29
- "keywords": [
30
- "powershell",
31
- "windows",
32
- "execute",
33
- "command",
34
- "shell",
35
- "console",
36
- "terminal",
37
- "cli",
38
- "spawn",
39
- "exec",
40
- "utilities"
41
- ],
42
- "devDependencies": {
43
- "ava": "^6.4.1",
44
- "typescript": "^5.9.3",
45
- "xo": "^0.59.0"
46
- }
47
- }
@@ -1,209 +0,0 @@
1
- # powershell-utils
2
-
3
- > Utilities for executing PowerShell commands
4
-
5
- ## Install
6
-
7
- ```sh
8
- npm install powershell-utils
9
- ```
10
-
11
- ## Usage
12
-
13
- ```js
14
- import {executePowerShell, powerShellPath} from 'powershell-utils';
15
-
16
- const {stdout} = await executePowerShell('Get-Process');
17
- console.log(stdout);
18
-
19
- console.log(powerShellPath());
20
- //=> 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
21
- ```
22
-
23
- ## API
24
-
25
- ### powerShellPath()
26
-
27
- Returns: `string`
28
-
29
- Get the PowerShell executable path on Windows.
30
-
31
- ```js
32
- import {powerShellPath} from 'powershell-utils';
33
-
34
- const psPath = powerShellPath();
35
- //=> 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
36
- ```
37
-
38
- ### canAccessPowerShell()
39
-
40
- Returns: `Promise<boolean>`
41
-
42
- Check if PowerShell is accessible on Windows.
43
-
44
- This checks if the PowerShell executable exists and has execute permissions. Useful for detecting restricted environments where PowerShell may be disabled by administrators.
45
-
46
- ```js
47
- import {canAccessPowerShell} from 'powershell-utils';
48
-
49
- if (await canAccessPowerShell()) {
50
- console.log('PowerShell is available');
51
- } else {
52
- console.log('PowerShell is not accessible');
53
- }
54
- ```
55
-
56
- ### executePowerShell(command, options?)
57
-
58
- Returns: `Promise<{stdout: string, stderr: string}>`
59
-
60
- Execute a PowerShell command.
61
-
62
- ```js
63
- import {executePowerShell} from 'powershell-utils';
64
-
65
- const {stdout} = await executePowerShell('Get-Process');
66
- console.log(stdout);
67
- ```
68
-
69
- #### command
70
-
71
- Type: `string`
72
-
73
- The PowerShell command to execute.
74
-
75
- #### options
76
-
77
- Type: `object`
78
-
79
- The below option and all options except `shell` in Node.js [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) are supported. PowerShell is always executed directly to prevent shell injection.
80
-
81
- ##### powerShellPath
82
-
83
- Type: `string`\
84
- Default: `powerShellPath()`
85
-
86
- Path to PowerShell executable. Useful when calling from WSL or when PowerShell is in a non-standard location.
87
-
88
- ##### encoding
89
-
90
- Type: `string`\
91
- Default: `'utf8'`
92
-
93
- Character encoding for stdout and stderr.
94
-
95
- ### executePowerShell.argumentsPrefix
96
-
97
- Type: `string[]`
98
-
99
- Standard PowerShell arguments that prefix the encoded command: `['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand']`
100
-
101
- Exposed for debugging or for advanced use cases where you need to customize the arguments. For most cases, use `createArguments()` instead.
102
-
103
- ### executePowerShell.encodeCommand(command)
104
-
105
- Returns: `string`
106
-
107
- Encode a PowerShell command as Base64 UTF-16LE.
108
-
109
- This encoding prevents shell escaping issues and ensures complex commands with special characters are executed reliably.
110
-
111
- #### command
112
-
113
- Type: `string`
114
-
115
- The PowerShell command to encode.
116
-
117
- ```js
118
- import {executePowerShell} from 'powershell-utils';
119
-
120
- const encoded = executePowerShell.encodeCommand('Get-Process');
121
- ```
122
-
123
- ### executePowerShell.escapeArgument(value)
124
-
125
- Returns: `string`
126
-
127
- Escape a string argument for use in PowerShell single-quoted strings.
128
-
129
- > [!IMPORTANT]
130
- > This makes a value safe as a PowerShell string literal, not as an argument to a native program. PowerShell removes the outer quotes before passing a value onwards, and the receiving process then re-splits it under its own command-line rules, where spaces and double quotes are delimiters. For example, `Start-Process -ArgumentList` receives `'a b'` as two arguments rather than one.
131
- >
132
- > Escaping also does not make an untrusted value safe to use as the program that `Start-Process` runs. Validate such values against an allowlist.
133
-
134
- #### value
135
-
136
- Type: `unknown`
137
-
138
- The value to escape.
139
-
140
- ```js
141
- import {executePowerShell} from 'powershell-utils';
142
-
143
- const escaped = executePowerShell.escapeArgument("it's a test");
144
- //=> "'it''s a test'"
145
-
146
- // Use in command building
147
- const command = `Start-Process ${executePowerShell.escapeArgument(appName)}`;
148
- ```
149
-
150
- ### executePowerShell.createArguments(command)
151
-
152
- Returns: `string[]`
153
-
154
- Create the full arguments array for PowerShell execution.
155
-
156
- Combines `argumentsPrefix` with the encoded command. Useful when using `spawn()`, `execFile()`, or other process execution methods.
157
-
158
- #### command
159
-
160
- Type: `string`
161
-
162
- The PowerShell command.
163
-
164
- ```js
165
- import {spawn} from 'node:child_process';
166
- import {powerShellPath, executePowerShell} from 'powershell-utils';
167
-
168
- const args = executePowerShell.createArguments('Get-Process');
169
- spawn(powerShellPath(), args);
170
- ```
171
-
172
- ### executePowerShellSync(command, options?)
173
-
174
- Returns: `string`
175
-
176
- Execute a PowerShell command synchronously.
177
-
178
- ```js
179
- import {executePowerShellSync} from 'powershell-utils';
180
-
181
- const stdout = executePowerShellSync('Get-Process');
182
- console.log(stdout);
183
- ```
184
-
185
- #### command
186
-
187
- Type: `string`
188
-
189
- The PowerShell command to execute.
190
-
191
- #### options
192
-
193
- Type: `object`
194
-
195
- The below option and all options except `shell` in Node.js [`child_process.execFileSync()`](https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options) are supported. PowerShell is always executed directly to prevent shell injection.
196
-
197
- ##### powerShellPath
198
-
199
- Type: `string`\
200
- Default: `powerShellPath()`
201
-
202
- Path to PowerShell executable.
203
-
204
- ##### encoding
205
-
206
- Type: `string`\
207
- Default: `'utf8'`
208
-
209
- Character encoding for the output.