@plexor-dev/claude-code-plugin 0.1.0-beta.23 → 0.1.0-beta.24

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexor-dev/claude-code-plugin",
3
- "version": "0.1.0-beta.23",
3
+ "version": "0.1.0-beta.24",
4
4
  "description": "LLM cost optimization plugin for Claude Code - Save up to 90% on AI costs",
5
5
  "main": "lib/constants.js",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  const fs = require('fs');
11
11
  const path = require('path');
12
12
  const os = require('os');
13
+ const { execSync } = require('child_process');
13
14
 
14
15
  /**
15
16
  * Get the correct home directory, accounting for sudo.
@@ -30,6 +31,43 @@ function getHomeDir() {
30
31
  return os.homedir();
31
32
  }
32
33
 
34
+ /**
35
+ * Get uid/gid for the target user (handles sudo case).
36
+ * Returns null if not running with sudo or on Windows.
37
+ */
38
+ function getTargetUserIds() {
39
+ const sudoUser = process.env.SUDO_USER;
40
+ if (!sudoUser || os.platform() === 'win32') {
41
+ return null;
42
+ }
43
+
44
+ try {
45
+ // Get uid and gid for the sudo user
46
+ const uid = parseInt(execSync(`id -u ${sudoUser}`, { encoding: 'utf8' }).trim(), 10);
47
+ const gid = parseInt(execSync(`id -g ${sudoUser}`, { encoding: 'utf8' }).trim(), 10);
48
+ return { uid, gid, user: sudoUser };
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Recursively chown a directory and all its contents.
56
+ */
57
+ function chownRecursive(dirPath, uid, gid) {
58
+ if (!fs.existsSync(dirPath)) return;
59
+
60
+ const stat = fs.statSync(dirPath);
61
+ fs.chownSync(dirPath, uid, gid);
62
+
63
+ if (stat.isDirectory()) {
64
+ const entries = fs.readdirSync(dirPath);
65
+ for (const entry of entries) {
66
+ chownRecursive(path.join(dirPath, entry), uid, gid);
67
+ }
68
+ }
69
+ }
70
+
33
71
  const HOME_DIR = getHomeDir();
34
72
  const COMMANDS_SOURCE = path.join(__dirname, '..', 'commands');
35
73
  const CLAUDE_COMMANDS_DIR = path.join(HOME_DIR, '.claude', 'commands');
@@ -54,6 +92,9 @@ const DEFAULT_CONFIG = {
54
92
 
55
93
  function main() {
56
94
  try {
95
+ // Get target user info for chown (if running with sudo)
96
+ const targetUser = getTargetUserIds();
97
+
57
98
  // Create ~/.claude/commands/ if not exists
58
99
  fs.mkdirSync(CLAUDE_COMMANDS_DIR, { recursive: true });
59
100
 
@@ -120,6 +161,16 @@ function main() {
120
161
  jsInstalled.push(file);
121
162
  }
122
163
 
164
+ // Fix file ownership when running with sudo
165
+ // Files are created as root but should be owned by the original user
166
+ if (targetUser) {
167
+ const { uid, gid } = targetUser;
168
+ // Chown the .claude directory and all contents we created
169
+ chownRecursive(path.join(HOME_DIR, '.claude'), uid, gid);
170
+ // Chown the .plexor directory and all contents
171
+ chownRecursive(PLEXOR_CONFIG_DIR, uid, gid);
172
+ }
173
+
123
174
  // Detect shell type
124
175
  const shell = process.env.SHELL || '';
125
176
  const isZsh = shell.includes('zsh');
@@ -141,6 +192,9 @@ function main() {
141
192
  if (jsInstalled.length > 0) {
142
193
  console.log(` ✓ Installed ${jsInstalled.length} executors to ~/.claude/plugins/plexor/`);
143
194
  }
195
+ if (targetUser) {
196
+ console.log(` ✓ Set file ownership to ${targetUser.user}`);
197
+ }
144
198
  console.log('');
145
199
 
146
200
  // CRITICAL: Make the required step VERY obvious