happy-imou-cloud 2.0.1 → 2.0.3

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 (27) hide show
  1. package/dist/{BaseReasoningProcessor-DQE2l7Xu.mjs → BaseReasoningProcessor-B37yOHxo.mjs} +2 -2
  2. package/dist/{BaseReasoningProcessor-01KqA3Kz.cjs → BaseReasoningProcessor-_wxlqKB8.cjs} +4 -4
  3. package/dist/{api-B8v4tczT.cjs → api-D9dIR956.cjs} +97 -44
  4. package/dist/{api-B5Ui8Fw0.mjs → api-DpQIC-DJ.mjs} +56 -3
  5. package/dist/{command-D8yNlaDo.cjs → command-CdXv1zNF.cjs} +3 -3
  6. package/dist/{command-BfIuJmeo.mjs → command-DRqrBuHM.mjs} +3 -3
  7. package/dist/{index-BByhFIIq.mjs → index-CriPm_z9.mjs} +15 -17
  8. package/dist/{index-BOqJ9hwi.cjs → index-LYPXVO_L.cjs} +98 -100
  9. package/dist/index.cjs +3 -3
  10. package/dist/index.mjs +3 -3
  11. package/dist/lib.cjs +1 -1
  12. package/dist/lib.d.cts +6 -0
  13. package/dist/lib.d.mts +6 -0
  14. package/dist/lib.mjs +1 -1
  15. package/dist/{persistence-CzpZpiL3.mjs → persistence-CqgPgbzN.mjs} +29 -7
  16. package/dist/{persistence-C33AMdtv.cjs → persistence-PzKU0QCa.cjs} +54 -32
  17. package/dist/{registerKillSessionHandler-BkzQulD9.cjs → registerKillSessionHandler-BDBPoQSA.cjs} +2 -2
  18. package/dist/{registerKillSessionHandler-BtSK7IOa.mjs → registerKillSessionHandler-C3M_-4Zg.mjs} +2 -2
  19. package/dist/{runClaude-C_WLfM6c.mjs → runClaude-D6Pdkevn.mjs} +250 -46
  20. package/dist/{runClaude-CNVufgZb.cjs → runClaude-IeRSC5qX.cjs} +270 -66
  21. package/dist/{runCodex-8eWjTPJr.mjs → runCodex-CsfUU1Wb.mjs} +216 -401
  22. package/dist/{runCodex-Dzy8anlX.cjs → runCodex-WRmgSK6L.cjs} +216 -401
  23. package/dist/{runGemini-nbr0mm-S.mjs → runGemini-CrH3dQ0Y.mjs} +5 -5
  24. package/dist/{runGemini-CgsVKP7m.cjs → runGemini-qBh6zs5G.cjs} +5 -5
  25. package/package.json +1 -2
  26. package/dist/future-Dq4Ha1Dn.cjs +0 -24
  27. package/dist/future-xRdLl3vf.mjs +0 -22
@@ -1,7 +1,7 @@
1
- import { readFile, unlink, open, stat, mkdir, writeFile, rename } from 'node:fs/promises';
1
+ import { readFile, unlink, mkdir, open, stat, writeFile, rename } from 'node:fs/promises';
2
2
  import { existsSync, unlinkSync, writeFileSync, readdirSync, readFileSync, constants } from 'node:fs';
3
3
  import { join, dirname } from 'node:path';
4
- import { c as configuration, l as logger, e as encodeBase64 } from './api-B5Ui8Fw0.mjs';
4
+ import { c as configuration, l as logger, e as encodeBase64 } from './api-DpQIC-DJ.mjs';
5
5
  import * as z from 'zod';
6
6
  import 'axios';
7
7
  import 'chalk';
@@ -185,16 +185,37 @@ async function updateSettings(updater) {
185
185
  const LOCK_RETRY_INTERVAL_MS = 100;
186
186
  const MAX_LOCK_ATTEMPTS = 50;
187
187
  const STALE_LOCK_TIMEOUT_MS = 1e4;
188
+ const LOCK_CONTENTION_CODES = /* @__PURE__ */ new Set(["EEXIST", "EPERM", "EACCES", "EBUSY"]);
189
+ const LOCK_RELEASE_RETRYABLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
188
190
  const lockFile = configuration.settingsFile + ".lock";
189
- const tmpFile = `${configuration.settingsFile}.${process.pid}.${Date.now()}.tmp`;
191
+ const tmpFile = `${configuration.settingsFile}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
190
192
  let fileHandle;
191
193
  let attempts = 0;
194
+ if (!existsSync(configuration.happyCloudHomeDir)) {
195
+ await mkdir(configuration.happyCloudHomeDir, { recursive: true });
196
+ }
197
+ async function removeFileWithRetry(path) {
198
+ for (let attempt = 1; attempt <= 20; attempt++) {
199
+ try {
200
+ await unlink(path);
201
+ return;
202
+ } catch (err) {
203
+ if (err?.code === "ENOENT") {
204
+ return;
205
+ }
206
+ if (!LOCK_RELEASE_RETRYABLE_CODES.has(err?.code) || attempt === 20) {
207
+ throw err;
208
+ }
209
+ await new Promise((resolve) => setTimeout(resolve, 25));
210
+ }
211
+ }
212
+ }
192
213
  while (attempts < MAX_LOCK_ATTEMPTS) {
193
214
  try {
194
215
  fileHandle = await open(lockFile, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY);
195
216
  break;
196
217
  } catch (err) {
197
- if (err.code === "EEXIST") {
218
+ if (LOCK_CONTENTION_CODES.has(err?.code)) {
198
219
  attempts++;
199
220
  await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_INTERVAL_MS));
200
221
  try {
@@ -224,11 +245,12 @@ async function updateSettings(updater) {
224
245
  return updated;
225
246
  } finally {
226
247
  if (existsSync(tmpFile)) {
227
- await unlink(tmpFile).catch(() => {
248
+ await removeFileWithRetry(tmpFile).catch(() => {
228
249
  });
229
250
  }
230
- await fileHandle.close();
231
- await unlink(lockFile).catch(() => {
251
+ await fileHandle.close().catch(() => {
252
+ });
253
+ await removeFileWithRetry(lockFile).catch(() => {
232
254
  });
233
255
  }
234
256
  }
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var promises = require('node:fs/promises');
4
- var fs = require('node:fs');
5
- var path = require('node:path');
6
- var api = require('./api-B8v4tczT.cjs');
4
+ var node_fs = require('node:fs');
5
+ var node_path = require('node:path');
6
+ var api = require('./api-D9dIR956.cjs');
7
7
  var z = require('zod');
8
8
  require('axios');
9
9
  require('chalk');
@@ -169,7 +169,7 @@ function migrateSettings(raw, fromVersion) {
169
169
  return migrated;
170
170
  }
171
171
  async function readSettings() {
172
- if (!fs.existsSync(api.configuration.settingsFile)) {
172
+ if (!node_fs.existsSync(api.configuration.settingsFile)) {
173
173
  return { ...defaultSettings };
174
174
  }
175
175
  try {
@@ -206,16 +206,37 @@ async function updateSettings(updater) {
206
206
  const LOCK_RETRY_INTERVAL_MS = 100;
207
207
  const MAX_LOCK_ATTEMPTS = 50;
208
208
  const STALE_LOCK_TIMEOUT_MS = 1e4;
209
+ const LOCK_CONTENTION_CODES = /* @__PURE__ */ new Set(["EEXIST", "EPERM", "EACCES", "EBUSY"]);
210
+ const LOCK_RELEASE_RETRYABLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
209
211
  const lockFile = api.configuration.settingsFile + ".lock";
210
- const tmpFile = `${api.configuration.settingsFile}.${process.pid}.${Date.now()}.tmp`;
212
+ const tmpFile = `${api.configuration.settingsFile}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
211
213
  let fileHandle;
212
214
  let attempts = 0;
215
+ if (!node_fs.existsSync(api.configuration.happyCloudHomeDir)) {
216
+ await promises.mkdir(api.configuration.happyCloudHomeDir, { recursive: true });
217
+ }
218
+ async function removeFileWithRetry(path) {
219
+ for (let attempt = 1; attempt <= 20; attempt++) {
220
+ try {
221
+ await promises.unlink(path);
222
+ return;
223
+ } catch (err) {
224
+ if (err?.code === "ENOENT") {
225
+ return;
226
+ }
227
+ if (!LOCK_RELEASE_RETRYABLE_CODES.has(err?.code) || attempt === 20) {
228
+ throw err;
229
+ }
230
+ await new Promise((resolve) => setTimeout(resolve, 25));
231
+ }
232
+ }
233
+ }
213
234
  while (attempts < MAX_LOCK_ATTEMPTS) {
214
235
  try {
215
- fileHandle = await promises.open(lockFile, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY);
236
+ fileHandle = await promises.open(lockFile, node_fs.constants.O_CREAT | node_fs.constants.O_EXCL | node_fs.constants.O_WRONLY);
216
237
  break;
217
238
  } catch (err) {
218
- if (err.code === "EEXIST") {
239
+ if (LOCK_CONTENTION_CODES.has(err?.code)) {
219
240
  attempts++;
220
241
  await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_INTERVAL_MS));
221
242
  try {
@@ -237,19 +258,20 @@ async function updateSettings(updater) {
237
258
  try {
238
259
  const current = await readSettings() || { ...defaultSettings };
239
260
  const updated = await updater(current);
240
- if (!fs.existsSync(api.configuration.happyCloudHomeDir)) {
261
+ if (!node_fs.existsSync(api.configuration.happyCloudHomeDir)) {
241
262
  await promises.mkdir(api.configuration.happyCloudHomeDir, { recursive: true });
242
263
  }
243
264
  await promises.writeFile(tmpFile, JSON.stringify(updated, null, 2));
244
265
  await promises.rename(tmpFile, api.configuration.settingsFile);
245
266
  return updated;
246
267
  } finally {
247
- if (fs.existsSync(tmpFile)) {
248
- await promises.unlink(tmpFile).catch(() => {
268
+ if (node_fs.existsSync(tmpFile)) {
269
+ await removeFileWithRetry(tmpFile).catch(() => {
249
270
  });
250
271
  }
251
- await fileHandle.close();
252
- await promises.unlink(lockFile).catch(() => {
272
+ await fileHandle.close().catch(() => {
273
+ });
274
+ await removeFileWithRetry(lockFile).catch(() => {
253
275
  });
254
276
  }
255
277
  }
@@ -269,7 +291,7 @@ const credentialsSchema = z__namespace.object({
269
291
  }).nullish()
270
292
  });
271
293
  async function readCredentials() {
272
- if (!fs.existsSync(api.configuration.privateKeyFile)) {
294
+ if (!node_fs.existsSync(api.configuration.privateKeyFile)) {
273
295
  return null;
274
296
  }
275
297
  try {
@@ -301,7 +323,7 @@ async function readCredentials() {
301
323
  return null;
302
324
  }
303
325
  async function writeCredentialsLegacy(credentials) {
304
- if (!fs.existsSync(api.configuration.happyCloudHomeDir)) {
326
+ if (!node_fs.existsSync(api.configuration.happyCloudHomeDir)) {
305
327
  await promises.mkdir(api.configuration.happyCloudHomeDir, { recursive: true });
306
328
  }
307
329
  await promises.writeFile(api.configuration.privateKeyFile, JSON.stringify({
@@ -311,7 +333,7 @@ async function writeCredentialsLegacy(credentials) {
311
333
  }, null, 2));
312
334
  }
313
335
  async function writeCredentialsDataKey(credentials) {
314
- if (!fs.existsSync(api.configuration.happyCloudHomeDir)) {
336
+ if (!node_fs.existsSync(api.configuration.happyCloudHomeDir)) {
315
337
  await promises.mkdir(api.configuration.happyCloudHomeDir, { recursive: true });
316
338
  }
317
339
  await promises.writeFile(api.configuration.privateKeyFile, JSON.stringify({
@@ -321,7 +343,7 @@ async function writeCredentialsDataKey(credentials) {
321
343
  }, null, 2));
322
344
  }
323
345
  async function clearCredentials() {
324
- if (fs.existsSync(api.configuration.privateKeyFile)) {
346
+ if (node_fs.existsSync(api.configuration.privateKeyFile)) {
325
347
  await promises.unlink(api.configuration.privateKeyFile);
326
348
  }
327
349
  }
@@ -333,7 +355,7 @@ async function clearMachineId() {
333
355
  }
334
356
  async function readDaemonState() {
335
357
  try {
336
- if (!fs.existsSync(api.configuration.daemonStateFile)) {
358
+ if (!node_fs.existsSync(api.configuration.daemonStateFile)) {
337
359
  return null;
338
360
  }
339
361
  const content = await promises.readFile(api.configuration.daemonStateFile, "utf-8");
@@ -344,13 +366,13 @@ async function readDaemonState() {
344
366
  }
345
367
  }
346
368
  function writeDaemonState(state) {
347
- fs.writeFileSync(api.configuration.daemonStateFile, JSON.stringify(state, null, 2), "utf-8");
369
+ node_fs.writeFileSync(api.configuration.daemonStateFile, JSON.stringify(state, null, 2), "utf-8");
348
370
  }
349
371
  async function clearDaemonState() {
350
- if (fs.existsSync(api.configuration.daemonStateFile)) {
372
+ if (node_fs.existsSync(api.configuration.daemonStateFile)) {
351
373
  await promises.unlink(api.configuration.daemonStateFile);
352
374
  }
353
- if (fs.existsSync(api.configuration.daemonLockFile)) {
375
+ if (node_fs.existsSync(api.configuration.daemonLockFile)) {
354
376
  try {
355
377
  await promises.unlink(api.configuration.daemonLockFile);
356
378
  } catch {
@@ -359,7 +381,7 @@ async function clearDaemonState() {
359
381
  }
360
382
  async function acquireDaemonLock(maxAttempts = 3, delayIncrementMs = 1e3) {
361
383
  const lockFileName = `daemon.lock.${process.pid}.${Date.now()}`;
362
- const lockFile = path.join(path.dirname(api.configuration.daemonLockFile), lockFileName);
384
+ const lockFile = node_path.join(node_path.dirname(api.configuration.daemonLockFile), lockFileName);
363
385
  api.logger.debug(`[ACQUIRE LOCK] Attempting to acquire lock: ${lockFile}`);
364
386
  api.logger.debug(`[ACQUIRE LOCK] Platform: ${process.platform}, PID: ${process.pid}`);
365
387
  const isPidAlive = (pid) => {
@@ -372,8 +394,8 @@ async function acquireDaemonLock(maxAttempts = 3, delayIncrementMs = 1e3) {
372
394
  };
373
395
  const readLockPid = () => {
374
396
  try {
375
- if (fs.existsSync(lockFile)) {
376
- const content = fs.readFileSync(lockFile, "utf-8").trim();
397
+ if (node_fs.existsSync(lockFile)) {
398
+ const content = node_fs.readFileSync(lockFile, "utf-8").trim();
377
399
  const pid = parseInt(content, 10);
378
400
  if (!isNaN(pid) && pid > 0) {
379
401
  return pid;
@@ -384,7 +406,7 @@ async function acquireDaemonLock(maxAttempts = 3, delayIncrementMs = 1e3) {
384
406
  return null;
385
407
  };
386
408
  const writeLockPid = (pid) => {
387
- fs.writeFileSync(lockFile, String(pid), "utf-8");
409
+ node_fs.writeFileSync(lockFile, String(pid), "utf-8");
388
410
  };
389
411
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
390
412
  api.logger.debug(`[ACQUIRE LOCK] Attempt ${attempt}/${maxAttempts}`);
@@ -401,9 +423,9 @@ async function acquireDaemonLock(maxAttempts = 3, delayIncrementMs = 1e3) {
401
423
  api.logger.debug(`[ACQUIRE LOCK] No existing lock file`);
402
424
  }
403
425
  try {
404
- if (fs.existsSync(lockFile)) {
426
+ if (node_fs.existsSync(lockFile)) {
405
427
  try {
406
- fs.unlinkSync(lockFile);
428
+ node_fs.unlinkSync(lockFile);
407
429
  api.logger.debug(`[ACQUIRE LOCK] Removed existing lock file`);
408
430
  } catch (unlinkError) {
409
431
  api.logger.debug(`[ACQUIRE LOCK] Could not remove lock file, trying anyway`);
@@ -450,17 +472,17 @@ async function releaseDaemonLock(lockHandle) {
450
472
  } catch {
451
473
  }
452
474
  try {
453
- if (fs.existsSync(api.configuration.daemonLockFile)) {
454
- fs.unlinkSync(api.configuration.daemonLockFile);
475
+ if (node_fs.existsSync(api.configuration.daemonLockFile)) {
476
+ node_fs.unlinkSync(api.configuration.daemonLockFile);
455
477
  api.logger.debug(`[RELEASE LOCK] Released daemon lock`);
456
478
  }
457
- const lockDir = path.dirname(api.configuration.daemonLockFile);
479
+ const lockDir = node_path.dirname(api.configuration.daemonLockFile);
458
480
  try {
459
- const files = fs.readdirSync(lockDir);
481
+ const files = node_fs.readdirSync(lockDir);
460
482
  for (const file of files) {
461
483
  if (file.startsWith("daemon.lock.") && file.includes(`.${process.pid}.`)) {
462
- const lockPath = path.join(lockDir, file);
463
- fs.unlinkSync(lockPath);
484
+ const lockPath = node_path.join(lockDir, file);
485
+ node_fs.unlinkSync(lockPath);
464
486
  api.logger.debug(`[RELEASE LOCK] Released lock: ${file}`);
465
487
  }
466
488
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-BOqJ9hwi.cjs');
4
- var api = require('./api-B8v4tczT.cjs');
3
+ var index = require('./index-LYPXVO_L.cjs');
4
+ var api = require('./api-D9dIR956.cjs');
5
5
  var crypto = require('crypto');
6
6
  require('axios');
7
7
  require('node:events');
@@ -1,5 +1,5 @@
1
- import { f as formatDisplayMessage } from './index-BByhFIIq.mjs';
2
- import { l as logger } from './api-B5Ui8Fw0.mjs';
1
+ import { f as formatDisplayMessage } from './index-CriPm_z9.mjs';
2
+ import { l as logger } from './api-DpQIC-DJ.mjs';
3
3
  import { createHash } from 'crypto';
4
4
  import 'axios';
5
5
  import 'node:events';