shoud-cli 1.0.4 → 1.0.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/tools/index.js +11 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoud-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "SHOUD Terminal Agent: Give your computer a job.",
5
5
  "main": "bin/shoud.js",
6
6
  "bin": {
@@ -21,23 +21,22 @@ function sanitizePath(inputPath) {
21
21
  return resolved;
22
22
  }
23
23
 
24
+ /**
25
+ * Execute a shell command and return plain text output.
26
+ * On Windows, we use PowerShell with `Out-String` to get text.
27
+ */
24
28
  function executeShell(commandString) {
25
29
  if (!commandString || commandString.trim().length === 0) {
26
30
  throw new Error('Empty command.');
27
31
  }
28
32
 
29
- // ✅ On Windows, ensure PowerShell outputs text (not objects)
30
33
  let finalCommand = commandString;
31
34
  if (os.platform() === 'win32') {
32
- // Convert simple commands to PowerShell-friendly format
33
- if (commandString.trim() === 'Get-ChildItem') {
34
- finalCommand = 'Get-ChildItem | Out-String -Width 4096';
35
- } else if (commandString.trim() === 'dir') {
36
- finalCommand = 'cmd.exe /c dir';
37
- } else if (commandString.trim() === 'ls') {
38
- // ls is not a native PowerShell command – use Get-ChildItem
39
- finalCommand = 'Get-ChildItem | Out-String -Width 4096';
40
- }
35
+ // Force PowerShell to output plain text
36
+ // Escape double quotes in the command
37
+ const escaped = commandString.replace(/"/g, '`"');
38
+ // Wrap in a PowerShell script block and pipe to Out-String
39
+ finalCommand = `& { ${escaped} } | Out-String -Width 4096`;
41
40
  }
42
41
 
43
42
  try {
@@ -52,11 +51,12 @@ function executeShell(commandString) {
52
51
  const trimmed = output.trim();
53
52
  return trimmed || 'Command executed successfully with no output.';
54
53
  } catch (err) {
54
+ // If the command fails, return the error message
55
55
  if (err.stderr) {
56
56
  return `Error: ${err.stderr.trim()}`;
57
57
  }
58
- // If the command fails but there's output, return it
59
58
  if (err.stdout) {
59
+ // Some commands output to stdout even on failure (e.g., `dir`)
60
60
  return err.stdout.trim();
61
61
  }
62
62
  throw new Error(`Command execution failed: ${err.message}`);