@cccarv82/freya 3.8.0 → 3.8.2

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.
@@ -34,14 +34,16 @@ function run(cmd, args, cwd, extraEnv) {
34
34
  const env = extraEnv ? { ...process.env, ...extraEnv } : process.env;
35
35
  try {
36
36
  if (process.platform === 'win32') {
37
- const escapedArgs = args.map(a => {
38
- const escaped = String(a).replace(/'/g, "''");
39
- return `'${escaped}'`;
40
- });
41
- const psCommand = `& '${cmd}' ${escapedArgs.join(' ')}`;
42
- child = spawn('powershell.exe', [
43
- '-NoLogo', '-Command', psCommand
44
- ], { cwd, env, windowsHide: true });
37
+ // If we have a full path to the executable, use it directly with spawn
38
+ // (no shell needed — avoids PowerShell argument mangling).
39
+ // Only fall back to cmd.exe for bare command names.
40
+ if (path.isAbsolute(cmd) || cmd.includes('\\') || cmd.includes('/')) {
41
+ child = spawn(cmd, args, { cwd, env, windowsHide: true });
42
+ } else {
43
+ // Bare command name — use cmd.exe to resolve from PATH
44
+ const comspec = process.env.ComSpec || 'cmd.exe';
45
+ child = spawn(comspec, ['/d', '/s', '/c', cmd, ...args], { cwd, shell: false, env });
46
+ }
45
47
  } else {
46
48
  child = spawn(cmd, args, { cwd, shell: true, env });
47
49
  }
package/cli/web.js CHANGED
@@ -971,17 +971,16 @@ function run(cmd, args, cwd, extraEnv, stdinData) {
971
971
 
972
972
  try {
973
973
  if (process.platform === 'win32') {
974
- // Use PowerShell fnm/nvm set PATH only in PowerShell profile,
975
- // so cmd.exe (shell:true) can't find npm global .cmd shims like copilot.
976
- // Do NOT use -NoProfile: the profile is what loads fnm/nvm PATH entries.
977
- const escapedArgs = args.map(a => {
978
- const escaped = String(a).replace(/'/g, "''");
979
- return `'${escaped}'`;
980
- });
981
- const psCommand = `& '${cmd}' ${escapedArgs.join(' ')}`;
982
- child = spawn('powershell.exe', [
983
- '-NoLogo', '-Command', psCommand
984
- ], { cwd, env, windowsHide: true });
974
+ // getCopilotCmd() resolves the full path via PowerShell/where.
975
+ // Once we have the full path, spawn directly no shell needed.
976
+ // This avoids PowerShell argument mangling issues.
977
+ if (path.isAbsolute(cmd) || cmd.includes('\\') || cmd.includes('/')) {
978
+ child = spawn(cmd, args, { cwd, env, windowsHide: true });
979
+ } else {
980
+ // Bare command name — use cmd.exe to resolve from PATH
981
+ const comspec = process.env.ComSpec || 'cmd.exe';
982
+ child = spawn(comspec, ['/d', '/s', '/c', cmd, ...args], { cwd, shell: false, env });
983
+ }
985
984
  } else {
986
985
  child = spawn(cmd, args, { cwd, shell: true, env });
987
986
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cccarv82/freya",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
4
  "description": "Personal AI Assistant with local-first persistence",
5
5
  "scripts": {
6
6
  "health": "node scripts/validate-data.js && node scripts/validate-structure.js",
@@ -100,15 +100,37 @@ class SqlJsDatabase {
100
100
 
101
101
  /**
102
102
  * Persist the in-memory database to disk.
103
+ * Retries with backoff on EBUSY (OneDrive/cloud sync locking).
103
104
  */
104
105
  _save() {
105
106
  if (!this._filePath) return;
106
- try {
107
- const data = this._db.export();
108
- const buffer = Buffer.from(data);
109
- fs.writeFileSync(this._filePath, buffer);
110
- } catch (err) {
111
- console.error('[DataLayer] Failed to save database:', err.message);
107
+ const data = this._db.export();
108
+ const buffer = Buffer.from(data);
109
+ const maxRetries = 5;
110
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
111
+ try {
112
+ // Write to temp file + rename for atomic operation
113
+ const tmpPath = this._filePath + '.tmp';
114
+ fs.writeFileSync(tmpPath, buffer);
115
+ try {
116
+ fs.renameSync(tmpPath, this._filePath);
117
+ } catch (renameErr) {
118
+ // On Windows, rename can fail if target is locked; fall back to direct write
119
+ try { fs.unlinkSync(tmpPath); } catch { }
120
+ fs.writeFileSync(this._filePath, buffer);
121
+ }
122
+ return; // success
123
+ } catch (err) {
124
+ if ((err.code === 'EBUSY' || err.code === 'EPERM') && attempt < maxRetries) {
125
+ // Wait with exponential backoff: 100ms, 200ms, 400ms, 800ms, 1600ms
126
+ const delay = 100 * Math.pow(2, attempt);
127
+ const start = Date.now();
128
+ while (Date.now() - start < delay) { /* busy wait — sync context */ }
129
+ continue;
130
+ }
131
+ console.error('[DataLayer] Failed to save database:', err.message);
132
+ return;
133
+ }
112
134
  }
113
135
  }
114
136
 
@@ -100,15 +100,37 @@ class SqlJsDatabase {
100
100
 
101
101
  /**
102
102
  * Persist the in-memory database to disk.
103
+ * Retries with backoff on EBUSY (OneDrive/cloud sync locking).
103
104
  */
104
105
  _save() {
105
106
  if (!this._filePath) return;
106
- try {
107
- const data = this._db.export();
108
- const buffer = Buffer.from(data);
109
- fs.writeFileSync(this._filePath, buffer);
110
- } catch (err) {
111
- console.error('[DataLayer] Failed to save database:', err.message);
107
+ const data = this._db.export();
108
+ const buffer = Buffer.from(data);
109
+ const maxRetries = 5;
110
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
111
+ try {
112
+ // Write to temp file + rename for atomic operation
113
+ const tmpPath = this._filePath + '.tmp';
114
+ fs.writeFileSync(tmpPath, buffer);
115
+ try {
116
+ fs.renameSync(tmpPath, this._filePath);
117
+ } catch (renameErr) {
118
+ // On Windows, rename can fail if target is locked; fall back to direct write
119
+ try { fs.unlinkSync(tmpPath); } catch { }
120
+ fs.writeFileSync(this._filePath, buffer);
121
+ }
122
+ return; // success
123
+ } catch (err) {
124
+ if ((err.code === 'EBUSY' || err.code === 'EPERM') && attempt < maxRetries) {
125
+ // Wait with exponential backoff: 100ms, 200ms, 400ms, 800ms, 1600ms
126
+ const delay = 100 * Math.pow(2, attempt);
127
+ const start = Date.now();
128
+ while (Date.now() - start < delay) { /* busy wait — sync context */ }
129
+ continue;
130
+ }
131
+ console.error('[DataLayer] Failed to save database:', err.message);
132
+ return;
133
+ }
112
134
  }
113
135
  }
114
136