@hasna/cloud 0.1.37 → 0.1.39

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/dist/cli/index.js CHANGED
@@ -8956,7 +8956,7 @@ var require_dist = __commonJS((exports) => {
8956
8956
  function parse(stream, callback) {
8957
8957
  const parser = new parser_1.Parser;
8958
8958
  stream.on("data", (buffer) => parser.parse(buffer, callback));
8959
- return new Promise((resolve) => stream.on("end", () => resolve()));
8959
+ return new Promise((resolve2) => stream.on("end", () => resolve2()));
8960
8960
  }
8961
8961
  exports.parse = parse;
8962
8962
  });
@@ -9635,12 +9635,12 @@ var require_client = __commonJS((exports, module) => {
9635
9635
  this._connect(callback);
9636
9636
  return;
9637
9637
  }
9638
- return new this._Promise((resolve, reject) => {
9638
+ return new this._Promise((resolve2, reject) => {
9639
9639
  this._connect((error) => {
9640
9640
  if (error) {
9641
9641
  reject(error);
9642
9642
  } else {
9643
- resolve(this);
9643
+ resolve2(this);
9644
9644
  }
9645
9645
  });
9646
9646
  });
@@ -9972,8 +9972,8 @@ var require_client = __commonJS((exports, module) => {
9972
9972
  readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
9973
9973
  query = new Query(config, values, callback);
9974
9974
  if (!query.callback) {
9975
- result = new this._Promise((resolve, reject) => {
9976
- query.callback = (err, res) => err ? reject(err) : resolve(res);
9975
+ result = new this._Promise((resolve2, reject) => {
9976
+ query.callback = (err, res) => err ? reject(err) : resolve2(res);
9977
9977
  }).catch((err) => {
9978
9978
  Error.captureStackTrace(err);
9979
9979
  throw err;
@@ -10048,8 +10048,8 @@ var require_client = __commonJS((exports, module) => {
10048
10048
  if (cb) {
10049
10049
  this.connection.once("end", cb);
10050
10050
  } else {
10051
- return new this._Promise((resolve) => {
10052
- this.connection.once("end", resolve);
10051
+ return new this._Promise((resolve2) => {
10052
+ this.connection.once("end", resolve2);
10053
10053
  });
10054
10054
  }
10055
10055
  }
@@ -10096,8 +10096,8 @@ var require_pg_pool = __commonJS((exports, module) => {
10096
10096
  const cb = function(err, client) {
10097
10097
  err ? rej(err) : res(client);
10098
10098
  };
10099
- const result = new Promise2(function(resolve, reject) {
10100
- res = resolve;
10099
+ const result = new Promise2(function(resolve2, reject) {
10100
+ res = resolve2;
10101
10101
  rej = reject;
10102
10102
  }).catch((err) => {
10103
10103
  Error.captureStackTrace(err);
@@ -10158,7 +10158,7 @@ var require_pg_pool = __commonJS((exports, module) => {
10158
10158
  if (typeof Promise2.try === "function") {
10159
10159
  return Promise2.try(f);
10160
10160
  }
10161
- return new Promise2((resolve) => resolve(f()));
10161
+ return new Promise2((resolve2) => resolve2(f()));
10162
10162
  }
10163
10163
  _isFull() {
10164
10164
  return this._clients.length >= this.options.max;
@@ -10534,8 +10534,8 @@ var require_query2 = __commonJS((exports, module) => {
10534
10534
  NativeQuery.prototype._getPromise = function() {
10535
10535
  if (this._promise)
10536
10536
  return this._promise;
10537
- this._promise = new Promise(function(resolve, reject) {
10538
- this._once("end", resolve);
10537
+ this._promise = new Promise(function(resolve2, reject) {
10538
+ this._once("end", resolve2);
10539
10539
  this._once("error", reject);
10540
10540
  }.bind(this));
10541
10541
  return this._promise;
@@ -10709,12 +10709,12 @@ var require_client2 = __commonJS((exports, module) => {
10709
10709
  this._connect(callback);
10710
10710
  return;
10711
10711
  }
10712
- return new this._Promise((resolve, reject) => {
10712
+ return new this._Promise((resolve2, reject) => {
10713
10713
  this._connect((error) => {
10714
10714
  if (error) {
10715
10715
  reject(error);
10716
10716
  } else {
10717
- resolve(this);
10717
+ resolve2(this);
10718
10718
  }
10719
10719
  });
10720
10720
  });
@@ -10738,8 +10738,8 @@ var require_client2 = __commonJS((exports, module) => {
10738
10738
  query = new NativeQuery(config, values, callback);
10739
10739
  if (!query.callback) {
10740
10740
  let resolveOut, rejectOut;
10741
- result = new this._Promise((resolve, reject) => {
10742
- resolveOut = resolve;
10741
+ result = new this._Promise((resolve2, reject) => {
10742
+ resolveOut = resolve2;
10743
10743
  rejectOut = reject;
10744
10744
  }).catch((err) => {
10745
10745
  Error.captureStackTrace(err);
@@ -10797,8 +10797,8 @@ var require_client2 = __commonJS((exports, module) => {
10797
10797
  }
10798
10798
  let result;
10799
10799
  if (!cb) {
10800
- result = new this._Promise(function(resolve, reject) {
10801
- cb = (err) => err ? reject(err) : resolve();
10800
+ result = new this._Promise(function(resolve2, reject) {
10801
+ cb = (err) => err ? reject(err) : resolve2();
10802
10802
  });
10803
10803
  }
10804
10804
  this.native.end(function() {
@@ -11238,7 +11238,7 @@ var init_adapter = __esm(() => {
11238
11238
 
11239
11239
  // src/dotfile.ts
11240
11240
  import {
11241
- existsSync as existsSync2,
11241
+ existsSync as existsSync3,
11242
11242
  mkdirSync,
11243
11243
  readdirSync,
11244
11244
  copyFileSync
@@ -11257,9 +11257,9 @@ function getDbPath(serviceName) {
11257
11257
  function migrateDotfile(serviceName) {
11258
11258
  const legacyDir = join2(homedir2(), `.${serviceName}`);
11259
11259
  const newDir = join2(HASNA_DIR, serviceName);
11260
- if (!existsSync2(legacyDir))
11260
+ if (!existsSync3(legacyDir))
11261
11261
  return [];
11262
- if (existsSync2(newDir))
11262
+ if (existsSync3(newDir))
11263
11263
  return [];
11264
11264
  mkdirSync(newDir, { recursive: true });
11265
11265
  const migrated = [];
@@ -11299,7 +11299,7 @@ __export(exports_discover, {
11299
11299
  SYNC_EXCLUDED_TABLE_PATTERNS: () => SYNC_EXCLUDED_TABLE_PATTERNS,
11300
11300
  KNOWN_PG_SERVICES: () => KNOWN_PG_SERVICES
11301
11301
  });
11302
- import { readdirSync as readdirSync2, existsSync as existsSync3 } from "fs";
11302
+ import { readdirSync as readdirSync2, existsSync as existsSync4 } from "fs";
11303
11303
  import { join as join3 } from "path";
11304
11304
  import { homedir as homedir3 } from "os";
11305
11305
  function isSyncExcludedTable(table) {
@@ -11307,7 +11307,7 @@ function isSyncExcludedTable(table) {
11307
11307
  }
11308
11308
  function discoverServices() {
11309
11309
  const dataDir = join3(homedir3(), ".hasna");
11310
- if (!existsSync3(dataDir))
11310
+ if (!existsSync4(dataDir))
11311
11311
  return [];
11312
11312
  try {
11313
11313
  const entries = readdirSync2(dataDir, { withFileTypes: true });
@@ -11329,7 +11329,7 @@ function discoverSyncableServices() {
11329
11329
  }
11330
11330
  function getServiceDbPath(service) {
11331
11331
  const dataDir = join3(homedir3(), ".hasna", service);
11332
- if (!existsSync3(dataDir))
11332
+ if (!existsSync4(dataDir))
11333
11333
  return null;
11334
11334
  const candidates = [
11335
11335
  join3(dataDir, `${service}.db`),
@@ -11345,7 +11345,7 @@ function getServiceDbPath(service) {
11345
11345
  }
11346
11346
  } catch {}
11347
11347
  for (const p of candidates) {
11348
- if (existsSync3(p))
11348
+ if (existsSync4(p))
11349
11349
  return p;
11350
11350
  }
11351
11351
  return null;
@@ -11400,9 +11400,9 @@ var init_discover = __esm(() => {
11400
11400
 
11401
11401
  // src/machines.ts
11402
11402
  import { spawnSync } from "child_process";
11403
- import { existsSync as existsSync4 } from "fs";
11403
+ import { existsSync as existsSync5 } from "fs";
11404
11404
  import { homedir as homedir4, hostname, platform, arch, userInfo } from "os";
11405
- import { dirname, join as join4 } from "path";
11405
+ import { dirname as dirname2, join as join4 } from "path";
11406
11406
  function quoteSqlString(value) {
11407
11407
  return `'${value.replace(/'/g, "''")}'`;
11408
11408
  }
@@ -11417,7 +11417,7 @@ function detectWorkspacePath() {
11417
11417
  const home = homedir4();
11418
11418
  const candidates = [join4(home, "workspace"), join4(home, "Workspace")];
11419
11419
  for (const candidate of candidates) {
11420
- if (existsSync4(candidate))
11420
+ if (existsSync5(candidate))
11421
11421
  return candidate;
11422
11422
  }
11423
11423
  const cwd = process.cwd();
@@ -11432,7 +11432,7 @@ function detectWorkspacePath() {
11432
11432
  return cwd;
11433
11433
  }
11434
11434
  function detectBunPath() {
11435
- return dirname(process.execPath);
11435
+ return dirname2(process.execPath);
11436
11436
  }
11437
11437
  function toFlag(value, fallback = 0) {
11438
11438
  if (value === undefined)
@@ -11814,7 +11814,7 @@ __export(exports_config, {
11814
11814
  createDatabase: () => createDatabase,
11815
11815
  CloudConfigSchema: () => CloudConfigSchema
11816
11816
  });
11817
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "fs";
11817
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
11818
11818
  import { homedir as homedir5 } from "os";
11819
11819
  import { join as join5 } from "path";
11820
11820
  function getConfigDir() {
@@ -11824,11 +11824,11 @@ function getConfigPath() {
11824
11824
  return CONFIG_PATH;
11825
11825
  }
11826
11826
  function getCloudConfig() {
11827
- if (!existsSync5(CONFIG_PATH)) {
11827
+ if (!existsSync6(CONFIG_PATH)) {
11828
11828
  return CloudConfigSchema.parse({});
11829
11829
  }
11830
11830
  try {
11831
- const raw = readFileSync(CONFIG_PATH, "utf-8");
11831
+ const raw = readFileSync2(CONFIG_PATH, "utf-8");
11832
11832
  return CloudConfigSchema.parse(JSON.parse(raw));
11833
11833
  } catch {
11834
11834
  return CloudConfigSchema.parse({});
@@ -12603,6 +12603,31 @@ function collectValues(value, previous) {
12603
12603
  return previous;
12604
12604
  }
12605
12605
 
12606
+ // src/version.ts
12607
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
12608
+ import { dirname, resolve } from "node:path";
12609
+ import { fileURLToPath } from "node:url";
12610
+ var cachedPackageVersion;
12611
+ function getPackageVersion() {
12612
+ if (cachedPackageVersion)
12613
+ return cachedPackageVersion;
12614
+ const here = dirname(fileURLToPath(import.meta.url));
12615
+ const candidates = [
12616
+ resolve(here, "../package.json"),
12617
+ resolve(here, "../../package.json")
12618
+ ];
12619
+ for (const path of candidates) {
12620
+ if (!existsSync2(path))
12621
+ continue;
12622
+ const pkg = JSON.parse(readFileSync(path, "utf8"));
12623
+ if (typeof pkg.version === "string" && pkg.version.length > 0) {
12624
+ cachedPackageVersion = pkg.version;
12625
+ return cachedPackageVersion;
12626
+ }
12627
+ }
12628
+ throw new Error("Unable to resolve @hasna/cloud package version");
12629
+ }
12630
+
12606
12631
  // src/cli/cmd-setup.ts
12607
12632
  init_config();
12608
12633
 
@@ -13194,8 +13219,8 @@ async function ensureAllPgDatabases() {
13194
13219
 
13195
13220
  // src/sync-schedule.ts
13196
13221
  init_config();
13197
- import { join as join6, dirname as dirname2 } from "path";
13198
- import { existsSync as existsSync6, writeFileSync as writeFileSync2, unlinkSync, mkdirSync as mkdirSync3 } from "fs";
13222
+ import { join as join6, dirname as dirname3 } from "path";
13223
+ import { existsSync as existsSync7, writeFileSync as writeFileSync2, unlinkSync, mkdirSync as mkdirSync3 } from "fs";
13199
13224
  import { homedir as homedir6, platform as platform2 } from "os";
13200
13225
  var SERVICE_NAME = "hasna-cloud-sync";
13201
13226
  var CONFIG_DIR2 = join6(homedir6(), ".hasna", "cloud");
@@ -13238,11 +13263,11 @@ function minutesToCron(minutes) {
13238
13263
  return `*/${minutes} * * * *`;
13239
13264
  }
13240
13265
  function getWorkerPath() {
13241
- const dir = typeof import.meta.dir === "string" ? import.meta.dir : dirname2(import.meta.url.replace("file://", ""));
13266
+ const dir = typeof import.meta.dir === "string" ? import.meta.dir : dirname3(import.meta.url.replace("file://", ""));
13242
13267
  const tsPath = join6(dir, "scheduled-sync.ts");
13243
13268
  const jsPath = join6(dir, "scheduled-sync.js");
13244
13269
  try {
13245
- if (existsSync6(tsPath))
13270
+ if (existsSync7(tsPath))
13246
13271
  return tsPath;
13247
13272
  } catch {}
13248
13273
  return jsPath;
@@ -13254,7 +13279,7 @@ function getBunPath() {
13254
13279
  "/usr/bin/bun"
13255
13280
  ];
13256
13281
  for (const p of candidates) {
13257
- if (existsSync6(p))
13282
+ if (existsSync7(p))
13258
13283
  return p;
13259
13284
  }
13260
13285
  return "bun";
@@ -13299,7 +13324,7 @@ function createLaunchdPlist(intervalMinutes) {
13299
13324
  }
13300
13325
  async function registerLaunchd(intervalMinutes) {
13301
13326
  const plistPath = getLaunchdPlistPath();
13302
- const plistDir = dirname2(plistPath);
13327
+ const plistDir = dirname3(plistPath);
13303
13328
  mkdirSync3(plistDir, { recursive: true });
13304
13329
  try {
13305
13330
  await Bun.spawn(["launchctl", "unload", plistPath]).exited;
@@ -13403,9 +13428,9 @@ function getSyncScheduleStatus() {
13403
13428
  let mechanism = "none";
13404
13429
  if (registered) {
13405
13430
  if (platform2() === "darwin") {
13406
- mechanism = existsSync6(getLaunchdPlistPath()) ? "launchd" : "none";
13431
+ mechanism = existsSync7(getLaunchdPlistPath()) ? "launchd" : "none";
13407
13432
  } else {
13408
- mechanism = existsSync6(join6(getSystemdDir(), `${SERVICE_NAME}.timer`)) ? "systemd" : "none";
13433
+ mechanism = existsSync7(join6(getSystemdDir(), `${SERVICE_NAME}.timer`)) ? "systemd" : "none";
13409
13434
  }
13410
13435
  }
13411
13436
  return {
@@ -13597,7 +13622,7 @@ function purgeResolvedConflicts(db) {
13597
13622
  // src/scheduled-sync.ts
13598
13623
  init_config();
13599
13624
  init_adapter();
13600
- import { existsSync as existsSync7, readdirSync as readdirSync3 } from "fs";
13625
+ import { existsSync as existsSync8, readdirSync as readdirSync3 } from "fs";
13601
13626
  import { join as join7 } from "path";
13602
13627
 
13603
13628
  // src/sync-incremental.ts
@@ -13806,7 +13831,7 @@ function discoverSyncableServices2() {
13806
13831
  if (!entry.isDirectory())
13807
13832
  continue;
13808
13833
  const dbPath = join7(hasnaDir, entry.name, `${entry.name}.db`);
13809
- if (existsSync7(dbPath)) {
13834
+ if (existsSync8(dbPath)) {
13810
13835
  services.push(entry.name);
13811
13836
  }
13812
13837
  }
@@ -13829,7 +13854,7 @@ async function runScheduledSync() {
13829
13854
  };
13830
13855
  try {
13831
13856
  const dbPath = join7(getDataDir(service), `${service}.db`);
13832
- if (!existsSync7(dbPath)) {
13857
+ if (!existsSync8(dbPath)) {
13833
13858
  continue;
13834
13859
  }
13835
13860
  const local = new SqliteAdapter(dbPath);
@@ -13872,7 +13897,7 @@ async function runScheduledSync() {
13872
13897
  }
13873
13898
 
13874
13899
  // src/cli/cmd-sync.ts
13875
- import { existsSync as existsSync9, statSync as statSync5 } from "fs";
13900
+ import { existsSync as existsSync10, statSync as statSync5 } from "fs";
13876
13901
  import { join as join9 } from "path";
13877
13902
  import { homedir as homedir8 } from "os";
13878
13903
 
@@ -13883,9 +13908,9 @@ init_discover();
13883
13908
  init_dotfile();
13884
13909
  import { spawn as spawn2 } from "child_process";
13885
13910
  import {
13886
- existsSync as existsSync8,
13911
+ existsSync as existsSync9,
13887
13912
  mkdirSync as mkdirSync4,
13888
- readFileSync as readFileSync3,
13913
+ readFileSync as readFileSync4,
13889
13914
  statSync as statSync4,
13890
13915
  writeFileSync as writeFileSync3
13891
13916
  } from "fs";
@@ -13959,11 +13984,11 @@ function createDefaultDaemonState() {
13959
13984
  };
13960
13985
  }
13961
13986
  function readDaemonState() {
13962
- if (!existsSync8(DAEMON_STATE_PATH)) {
13987
+ if (!existsSync9(DAEMON_STATE_PATH)) {
13963
13988
  return createDefaultDaemonState();
13964
13989
  }
13965
13990
  try {
13966
- const raw = JSON.parse(readFileSync3(DAEMON_STATE_PATH, "utf-8"));
13991
+ const raw = JSON.parse(readFileSync4(DAEMON_STATE_PATH, "utf-8"));
13967
13992
  const defaults2 = createDefaultDaemonState();
13968
13993
  return {
13969
13994
  ...defaults2,
@@ -14132,7 +14157,7 @@ function runDaemonPass(config, state = createDefaultDaemonState(), options = {})
14132
14157
  }
14133
14158
  for (const service of services) {
14134
14159
  const dbPath = adapterFactory.getLocalDbPath(service);
14135
- if (!existsSync8(dbPath))
14160
+ if (!existsSync9(dbPath))
14136
14161
  continue;
14137
14162
  const serviceState = getServiceState(nextState, service);
14138
14163
  let local = null;
@@ -14632,7 +14657,7 @@ function registerStatusCommand(syncCmd) {
14632
14657
  const statuses = [];
14633
14658
  for (const service of services) {
14634
14659
  const dbPath = getDbPath(service);
14635
- const localExists = existsSync9(dbPath);
14660
+ const localExists = existsSync10(dbPath);
14636
14661
  let localSize = "—";
14637
14662
  let tableCount = 0;
14638
14663
  if (localExists) {
@@ -15124,14 +15149,14 @@ function registerFeedbackCommand(program3) {
15124
15149
  init_config();
15125
15150
  init_adapter();
15126
15151
  init_discover();
15127
- import { existsSync as existsSync10 } from "fs";
15152
+ import { existsSync as existsSync11 } from "fs";
15128
15153
  import { join as join10 } from "path";
15129
15154
  import { homedir as homedir9 } from "os";
15130
15155
  function registerDoctorCommand(program3) {
15131
15156
  program3.command("doctor").description("Comprehensive health check for cloud sync setup").action(async () => {
15132
15157
  const checks = [];
15133
15158
  const configPath = join10(homedir9(), ".hasna", "cloud", "config.json");
15134
- checks.push(existsSync10(configPath) ? { name: "Config file", status: "pass", detail: configPath } : { name: "Config file", status: "fail", detail: "Missing. Run `cloud setup`." });
15159
+ checks.push(existsSync11(configPath) ? { name: "Config file", status: "pass", detail: configPath } : { name: "Config file", status: "fail", detail: "Missing. Run `cloud setup`." });
15135
15160
  const config = getCloudConfig();
15136
15161
  checks.push(config.mode === "hybrid" || config.mode === "cloud" ? { name: "Sync mode", status: "pass", detail: config.mode } : { name: "Sync mode", status: "fail", detail: `"${config.mode}" — sync disabled. Run \`cloud setup --mode hybrid\`.` });
15137
15162
  checks.push(config.rds.host ? { name: "RDS host", status: "pass", detail: config.rds.host } : { name: "RDS host", status: "fail", detail: "Not configured. Run `cloud setup`." });
@@ -15150,7 +15175,7 @@ function registerDoctorCommand(program3) {
15150
15175
  checks.push({ name: "PG connection", status: "fail", detail: "Skipped — missing host or password" });
15151
15176
  }
15152
15177
  const caPath = process.env.NODE_EXTRA_CA_CERTS;
15153
- if (caPath && existsSync10(caPath)) {
15178
+ if (caPath && existsSync11(caPath)) {
15154
15179
  checks.push({ name: "SSL CA cert", status: "pass", detail: caPath });
15155
15180
  } else if (caPath) {
15156
15181
  checks.push({ name: "SSL CA cert", status: "warn", detail: `NODE_EXTRA_CA_CERTS set but file missing: ${caPath}` });
@@ -15191,7 +15216,7 @@ init_zod();
15191
15216
  init_adapter();
15192
15217
  init_dotfile();
15193
15218
  init_machines();
15194
- import { existsSync as existsSync11, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
15219
+ import { existsSync as existsSync12, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
15195
15220
  import { homedir as homedir10 } from "os";
15196
15221
  import { join as join11 } from "path";
15197
15222
  var DaemonConfigSchema2 = exports_external.object({
@@ -15228,11 +15253,11 @@ var CloudConfigSchema2 = exports_external.object({
15228
15253
  var CONFIG_DIR3 = join11(homedir10(), ".hasna", "cloud");
15229
15254
  var CONFIG_PATH2 = join11(CONFIG_DIR3, "config.json");
15230
15255
  function getCloudConfig2() {
15231
- if (!existsSync11(CONFIG_PATH2)) {
15256
+ if (!existsSync12(CONFIG_PATH2)) {
15232
15257
  return CloudConfigSchema2.parse({});
15233
15258
  }
15234
15259
  try {
15235
- const raw = readFileSync4(CONFIG_PATH2, "utf-8");
15260
+ const raw = readFileSync5(CONFIG_PATH2, "utf-8");
15236
15261
  return CloudConfigSchema2.parse(JSON.parse(raw));
15237
15262
  } catch {
15238
15263
  return CloudConfigSchema2.parse({});
@@ -15313,7 +15338,7 @@ class PgAdapterAsync2 {
15313
15338
 
15314
15339
  // src/cli/index.ts
15315
15340
  var program3 = new Command;
15316
- program3.name("cloud").description("Shared cloud infrastructure \u2014 database adapter, sync engine, feedback, dotfile migration").version("0.1.13");
15341
+ program3.name("cloud").description("Shared cloud infrastructure \u2014 database adapter, sync engine, feedback, dotfile migration").version(getPackageVersion());
15317
15342
  registerEventsCommands(program3, { source: "cloud" });
15318
15343
  registerSetupCommand(program3);
15319
15344
  program3.command("status").description("Show current cloud configuration and connection health").action(async () => {
package/dist/mcp/bin.js CHANGED
@@ -25964,6 +25964,31 @@ async function sendFeedback(feedback, db) {
25964
25964
  init_dotfile();
25965
25965
  init_adapter();
25966
25966
 
25967
+ // src/version.ts
25968
+ import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
25969
+ import { dirname as dirname2, resolve } from "node:path";
25970
+ import { fileURLToPath } from "node:url";
25971
+ var cachedPackageVersion;
25972
+ function getPackageVersion() {
25973
+ if (cachedPackageVersion)
25974
+ return cachedPackageVersion;
25975
+ const here = dirname2(fileURLToPath(import.meta.url));
25976
+ const candidates = [
25977
+ resolve(here, "../package.json"),
25978
+ resolve(here, "../../package.json")
25979
+ ];
25980
+ for (const path of candidates) {
25981
+ if (!existsSync5(path))
25982
+ continue;
25983
+ const pkg = JSON.parse(readFileSync2(path, "utf8"));
25984
+ if (typeof pkg.version === "string" && pkg.version.length > 0) {
25985
+ cachedPackageVersion = pkg.version;
25986
+ return cachedPackageVersion;
25987
+ }
25988
+ }
25989
+ throw new Error("Unable to resolve @hasna/cloud package version");
25990
+ }
25991
+
25967
25992
  // src/mcp/http.ts
25968
25993
  import { createServer } from "node:http";
25969
25994
 
@@ -26378,7 +26403,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
26378
26403
  });
26379
26404
  if (!chunk) {
26380
26405
  if (i === 1) {
26381
- await new Promise((resolve) => setTimeout(resolve));
26406
+ await new Promise((resolve2) => setTimeout(resolve2));
26382
26407
  maxReadCount = 3;
26383
26408
  continue;
26384
26409
  }
@@ -26829,9 +26854,9 @@ data:
26829
26854
  const initRequest = messages.find((m) => isInitializeRequest(m));
26830
26855
  const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
26831
26856
  if (this._enableJsonResponse) {
26832
- return new Promise((resolve) => {
26857
+ return new Promise((resolve2) => {
26833
26858
  this._streamMapping.set(streamId, {
26834
- resolveJson: resolve,
26859
+ resolveJson: resolve2,
26835
26860
  cleanup: () => {
26836
26861
  this._streamMapping.delete(streamId);
26837
26862
  }
@@ -27098,7 +27123,7 @@ init_adapter();
27098
27123
  function buildServer() {
27099
27124
  const server = new McpServer({
27100
27125
  name: "cloud",
27101
- version: "0.1.0"
27126
+ version: getPackageVersion()
27102
27127
  });
27103
27128
  server.tool("cloud_status", "Show cloud configuration and connection health", {}, async () => {
27104
27129
  const config2 = getCloudConfig();
@@ -27374,17 +27399,33 @@ Done. ${results.length} services, ${totalApplied} migrations applied.`);
27374
27399
  // src/mcp/http.ts
27375
27400
  var DEFAULT_MCP_HTTP_PORT = 8852;
27376
27401
  var MCP_SERVICE_NAME = "cloud";
27402
+ var MIN_PORT = 0;
27403
+ var MAX_PORT = 65535;
27404
+ function invalidPortMessage(source, value) {
27405
+ return `Invalid ${source} "${value}". Expected an integer between ${MIN_PORT} and ${MAX_PORT}.`;
27406
+ }
27407
+ function validatePort(port, source) {
27408
+ if (!Number.isInteger(port) || port < MIN_PORT || port > MAX_PORT) {
27409
+ throw new Error(invalidPortMessage(source, String(port)));
27410
+ }
27411
+ return port;
27412
+ }
27413
+ function parsePortValue(value, source) {
27414
+ const trimmed = value.trim();
27415
+ if (!/^\d+$/.test(trimmed)) {
27416
+ throw new Error(invalidPortMessage(source, value));
27417
+ }
27418
+ return validatePort(Number(trimmed), source);
27419
+ }
27377
27420
  function isStdioMode(argv = process.argv) {
27378
27421
  return argv.includes("--stdio") || process.env.MCP_STDIO === "1";
27379
27422
  }
27380
27423
  function resolveMcpHttpPort(explicit) {
27381
- if (explicit != null && !Number.isNaN(explicit))
27382
- return explicit;
27424
+ if (explicit != null)
27425
+ return validatePort(explicit, "--port");
27383
27426
  const env = process.env.MCP_HTTP_PORT;
27384
- if (env) {
27385
- const parsed = parseInt(env, 10);
27386
- if (!Number.isNaN(parsed))
27387
- return parsed;
27427
+ if (env && env.trim() !== "") {
27428
+ return parsePortValue(env, "MCP_HTTP_PORT");
27388
27429
  }
27389
27430
  return DEFAULT_MCP_HTTP_PORT;
27390
27431
  }
@@ -27394,9 +27435,17 @@ function isHttpMode(argv = process.argv) {
27394
27435
  function parseHttpArgv(argv = process.argv) {
27395
27436
  const http = isHttpMode(argv);
27396
27437
  let port;
27438
+ const portEqualsArg = argv.find((arg) => arg.startsWith("--port="));
27439
+ if (portEqualsArg) {
27440
+ port = parsePortValue(portEqualsArg.slice("--port=".length), "--port");
27441
+ }
27397
27442
  const portIdx = argv.indexOf("--port");
27398
- if (portIdx !== -1 && argv[portIdx + 1]) {
27399
- port = parseInt(argv[portIdx + 1], 10);
27443
+ if (portIdx !== -1) {
27444
+ const value = argv[portIdx + 1];
27445
+ if (value === undefined) {
27446
+ throw new Error(invalidPortMessage("--port", ""));
27447
+ }
27448
+ port = parsePortValue(value, "--port");
27400
27449
  }
27401
27450
  return { http, port };
27402
27451
  }
@@ -27442,16 +27491,16 @@ async function startMcpHttpServer(options = {}) {
27442
27491
  res.writeHead(404);
27443
27492
  res.end("Not found");
27444
27493
  });
27445
- await new Promise((resolve, reject) => {
27494
+ await new Promise((resolve2, reject) => {
27446
27495
  httpServer.once("error", reject);
27447
- httpServer.listen(port, host, () => resolve());
27496
+ httpServer.listen(port, host, () => resolve2());
27448
27497
  });
27449
27498
  const address = httpServer.address();
27450
27499
  const boundPort = typeof address === "object" && address ? address.port : port;
27451
27500
  return {
27452
27501
  port: boundPort,
27453
- close: () => new Promise((resolve, reject) => {
27454
- httpServer.close((err) => err ? reject(err) : resolve());
27502
+ close: () => new Promise((resolve2, reject) => {
27503
+ httpServer.close((err) => err ? reject(err) : resolve2());
27455
27504
  })
27456
27505
  };
27457
27506
  }
@@ -27465,7 +27514,7 @@ async function runMcpHttpServer(options = {}) {
27465
27514
  function buildServer2() {
27466
27515
  const server = new McpServer({
27467
27516
  name: "cloud",
27468
- version: "0.1.0"
27517
+ version: getPackageVersion()
27469
27518
  });
27470
27519
  server.tool("cloud_status", "Show cloud configuration and connection health", {}, async () => {
27471
27520
  const config2 = getCloudConfig();
@@ -27738,13 +27787,13 @@ Done. ${results.length} services, ${totalApplied} migrations applied.`);
27738
27787
  return server;
27739
27788
  }
27740
27789
  async function main() {
27741
- const { port } = parseHttpArgv();
27742
27790
  if (isStdioMode()) {
27743
27791
  const server = buildServer2();
27744
27792
  const transport = new StdioServerTransport;
27745
27793
  await server.connect(transport);
27746
27794
  return;
27747
27795
  }
27796
+ const { port } = parseHttpArgv();
27748
27797
  await runMcpHttpServer({ port: resolveMcpHttpPort(port) });
27749
27798
  }
27750
27799
 
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAElE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ5D;AAED,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAEjE;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAQ7F;AAUD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,SAAS,GAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAe,GAC5D,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAyB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE/F;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACV,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAuC7D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAuBxC,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAElE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAO5D;AAED,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAEjE;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAgB7F;AAUD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,SAAS,GAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAe,GAC5D,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAyB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE/F;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACV,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAuC7D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAcpE,wBAAgB,WAAW,IAAI,SAAS,CAwVvC;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAW1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAepE,wBAAgB,WAAW,IAAI,SAAS,CAwVvC;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAW1C"}
package/dist/mcp/index.js CHANGED
@@ -16321,7 +16321,7 @@ __export(exports_discover2, {
16321
16321
  SYNC_EXCLUDED_TABLE_PATTERNS: () => SYNC_EXCLUDED_TABLE_PATTERNS2,
16322
16322
  KNOWN_PG_SERVICES: () => KNOWN_PG_SERVICES2
16323
16323
  });
16324
- import { readdirSync as readdirSync4, existsSync as existsSync7 } from "fs";
16324
+ import { readdirSync as readdirSync4, existsSync as existsSync8 } from "fs";
16325
16325
  import { join as join7 } from "path";
16326
16326
  import { homedir as homedir7 } from "os";
16327
16327
  function isSyncExcludedTable2(table) {
@@ -16329,7 +16329,7 @@ function isSyncExcludedTable2(table) {
16329
16329
  }
16330
16330
  function discoverServices2() {
16331
16331
  const dataDir = join7(homedir7(), ".hasna");
16332
- if (!existsSync7(dataDir))
16332
+ if (!existsSync8(dataDir))
16333
16333
  return [];
16334
16334
  try {
16335
16335
  const entries = readdirSync4(dataDir, { withFileTypes: true });
@@ -16351,7 +16351,7 @@ function discoverSyncableServices2() {
16351
16351
  }
16352
16352
  function getServiceDbPath2(service) {
16353
16353
  const dataDir = join7(homedir7(), ".hasna", service);
16354
- if (!existsSync7(dataDir))
16354
+ if (!existsSync8(dataDir))
16355
16355
  return null;
16356
16356
  const candidates = [
16357
16357
  join7(dataDir, `${service}.db`),
@@ -16367,7 +16367,7 @@ function getServiceDbPath2(service) {
16367
16367
  }
16368
16368
  } catch {}
16369
16369
  for (const p of candidates) {
16370
- if (existsSync7(p))
16370
+ if (existsSync8(p))
16371
16371
  return p;
16372
16372
  }
16373
16373
  return null;
@@ -26284,6 +26284,31 @@ class PgAdapterAsync2 {
26284
26284
  }
26285
26285
  }
26286
26286
 
26287
+ // src/version.ts
26288
+ import { existsSync as existsSync7, readFileSync as readFileSync3 } from "node:fs";
26289
+ import { dirname as dirname2, resolve } from "node:path";
26290
+ import { fileURLToPath } from "node:url";
26291
+ var cachedPackageVersion;
26292
+ function getPackageVersion() {
26293
+ if (cachedPackageVersion)
26294
+ return cachedPackageVersion;
26295
+ const here = dirname2(fileURLToPath(import.meta.url));
26296
+ const candidates = [
26297
+ resolve(here, "../package.json"),
26298
+ resolve(here, "../../package.json")
26299
+ ];
26300
+ for (const path of candidates) {
26301
+ if (!existsSync7(path))
26302
+ continue;
26303
+ const pkg = JSON.parse(readFileSync3(path, "utf8"));
26304
+ if (typeof pkg.version === "string" && pkg.version.length > 0) {
26305
+ cachedPackageVersion = pkg.version;
26306
+ return cachedPackageVersion;
26307
+ }
26308
+ }
26309
+ throw new Error("Unable to resolve @hasna/cloud package version");
26310
+ }
26311
+
26287
26312
  // src/mcp/http.ts
26288
26313
  import { createServer } from "node:http";
26289
26314
 
@@ -26698,7 +26723,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
26698
26723
  });
26699
26724
  if (!chunk) {
26700
26725
  if (i === 1) {
26701
- await new Promise((resolve) => setTimeout(resolve));
26726
+ await new Promise((resolve2) => setTimeout(resolve2));
26702
26727
  maxReadCount = 3;
26703
26728
  continue;
26704
26729
  }
@@ -27149,9 +27174,9 @@ data:
27149
27174
  const initRequest = messages.find((m) => isInitializeRequest(m));
27150
27175
  const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
27151
27176
  if (this._enableJsonResponse) {
27152
- return new Promise((resolve) => {
27177
+ return new Promise((resolve2) => {
27153
27178
  this._streamMapping.set(streamId, {
27154
- resolveJson: resolve,
27179
+ resolveJson: resolve2,
27155
27180
  cleanup: () => {
27156
27181
  this._streamMapping.delete(streamId);
27157
27182
  }
@@ -27413,17 +27438,33 @@ class StreamableHTTPServerTransport {
27413
27438
  // src/mcp/http.ts
27414
27439
  var DEFAULT_MCP_HTTP_PORT = 8852;
27415
27440
  var MCP_SERVICE_NAME = "cloud";
27441
+ var MIN_PORT = 0;
27442
+ var MAX_PORT = 65535;
27443
+ function invalidPortMessage(source, value) {
27444
+ return `Invalid ${source} "${value}". Expected an integer between ${MIN_PORT} and ${MAX_PORT}.`;
27445
+ }
27446
+ function validatePort(port, source) {
27447
+ if (!Number.isInteger(port) || port < MIN_PORT || port > MAX_PORT) {
27448
+ throw new Error(invalidPortMessage(source, String(port)));
27449
+ }
27450
+ return port;
27451
+ }
27452
+ function parsePortValue(value, source) {
27453
+ const trimmed = value.trim();
27454
+ if (!/^\d+$/.test(trimmed)) {
27455
+ throw new Error(invalidPortMessage(source, value));
27456
+ }
27457
+ return validatePort(Number(trimmed), source);
27458
+ }
27416
27459
  function isStdioMode(argv = process.argv) {
27417
27460
  return argv.includes("--stdio") || process.env.MCP_STDIO === "1";
27418
27461
  }
27419
27462
  function resolveMcpHttpPort(explicit) {
27420
- if (explicit != null && !Number.isNaN(explicit))
27421
- return explicit;
27463
+ if (explicit != null)
27464
+ return validatePort(explicit, "--port");
27422
27465
  const env = process.env.MCP_HTTP_PORT;
27423
- if (env) {
27424
- const parsed = parseInt(env, 10);
27425
- if (!Number.isNaN(parsed))
27426
- return parsed;
27466
+ if (env && env.trim() !== "") {
27467
+ return parsePortValue(env, "MCP_HTTP_PORT");
27427
27468
  }
27428
27469
  return DEFAULT_MCP_HTTP_PORT;
27429
27470
  }
@@ -27433,9 +27474,17 @@ function isHttpMode(argv = process.argv) {
27433
27474
  function parseHttpArgv(argv = process.argv) {
27434
27475
  const http = isHttpMode(argv);
27435
27476
  let port;
27477
+ const portEqualsArg = argv.find((arg) => arg.startsWith("--port="));
27478
+ if (portEqualsArg) {
27479
+ port = parsePortValue(portEqualsArg.slice("--port=".length), "--port");
27480
+ }
27436
27481
  const portIdx = argv.indexOf("--port");
27437
- if (portIdx !== -1 && argv[portIdx + 1]) {
27438
- port = parseInt(argv[portIdx + 1], 10);
27482
+ if (portIdx !== -1) {
27483
+ const value = argv[portIdx + 1];
27484
+ if (value === undefined) {
27485
+ throw new Error(invalidPortMessage("--port", ""));
27486
+ }
27487
+ port = parsePortValue(value, "--port");
27439
27488
  }
27440
27489
  return { http, port };
27441
27490
  }
@@ -27481,16 +27530,16 @@ async function startMcpHttpServer(options = {}) {
27481
27530
  res.writeHead(404);
27482
27531
  res.end("Not found");
27483
27532
  });
27484
- await new Promise((resolve, reject) => {
27533
+ await new Promise((resolve2, reject) => {
27485
27534
  httpServer.once("error", reject);
27486
- httpServer.listen(port, host, () => resolve());
27535
+ httpServer.listen(port, host, () => resolve2());
27487
27536
  });
27488
27537
  const address = httpServer.address();
27489
27538
  const boundPort = typeof address === "object" && address ? address.port : port;
27490
27539
  return {
27491
27540
  port: boundPort,
27492
- close: () => new Promise((resolve, reject) => {
27493
- httpServer.close((err) => err ? reject(err) : resolve());
27541
+ close: () => new Promise((resolve2, reject) => {
27542
+ httpServer.close((err) => err ? reject(err) : resolve2());
27494
27543
  })
27495
27544
  };
27496
27545
  }
@@ -27504,7 +27553,7 @@ async function runMcpHttpServer(options = {}) {
27504
27553
  function buildServer() {
27505
27554
  const server = new McpServer({
27506
27555
  name: "cloud",
27507
- version: "0.1.0"
27556
+ version: getPackageVersion()
27508
27557
  });
27509
27558
  server.tool("cloud_status", "Show cloud configuration and connection health", {}, async () => {
27510
27559
  const config2 = getCloudConfig();
@@ -27777,13 +27826,13 @@ Done. ${results.length} services, ${totalApplied} migrations applied.`);
27777
27826
  return server;
27778
27827
  }
27779
27828
  async function main() {
27780
- const { port } = parseHttpArgv();
27781
27829
  if (isStdioMode()) {
27782
27830
  const server = buildServer();
27783
27831
  const transport = new StdioServerTransport;
27784
27832
  await server.connect(transport);
27785
27833
  return;
27786
27834
  }
27835
+ const { port } = parseHttpArgv();
27787
27836
  await runMcpHttpServer({ port: resolveMcpHttpPort(port) });
27788
27837
  }
27789
27838
  export {
@@ -0,0 +1,2 @@
1
+ export declare function getPackageVersion(): string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,wBAAgB,iBAAiB,IAAI,MAAM,CAmB1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/cloud",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "description": "Shared cloud infrastructure — database adapter (SQLite + PostgreSQL), sync engine, feedback system, unified dotfile config",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",