repowise 0.1.7 → 0.1.9

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.
@@ -866,7 +866,7 @@ var init_progress_renderer = __esm({
866
866
  }
867
867
  });
868
868
 
869
- // ../listener/src/service-installer.ts
869
+ // ../listener/dist/service-installer.js
870
870
  var service_installer_exports = {};
871
871
  __export(service_installer_exports, {
872
872
  install: () => install,
@@ -878,9 +878,16 @@ import { writeFile as writeFile4, mkdir as mkdir4, unlink as unlink2 } from "fs/
878
878
  import { homedir as homedir3 } from "os";
879
879
  import { join as join4 } from "path";
880
880
  import { createRequire } from "module";
881
- function resolveListenerMainPath() {
882
- const require2 = createRequire(import.meta.url);
883
- return require2.resolve("@repowise/listener/main");
881
+ import { fileURLToPath } from "url";
882
+ function resolveListenerCommand() {
883
+ try {
884
+ const require2 = createRequire(import.meta.url);
885
+ const mainPath = require2.resolve("@repowise/listener/main");
886
+ return { script: mainPath, args: [] };
887
+ } catch {
888
+ const bundlePath = fileURLToPath(import.meta.url);
889
+ return { script: bundlePath, args: ["__listener"] };
890
+ }
884
891
  }
885
892
  function exec(cmd, args) {
886
893
  return new Promise((resolve, reject) => {
@@ -900,8 +907,9 @@ function logDir() {
900
907
  return join4(homedir3(), ".repowise", "logs");
901
908
  }
902
909
  function buildPlist() {
903
- const listenerPath = resolveListenerMainPath();
910
+ const cmd = resolveListenerCommand();
904
911
  const logs = logDir();
912
+ const programArgs = [process.execPath, cmd.script, ...cmd.args].map((a) => ` <string>${a}</string>`).join("\n");
905
913
  return `<?xml version="1.0" encoding="UTF-8"?>
906
914
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
907
915
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -911,8 +919,7 @@ function buildPlist() {
911
919
  <string>${PLIST_LABEL}</string>
912
920
  <key>ProgramArguments</key>
913
921
  <array>
914
- <string>${process.execPath}</string>
915
- <string>${listenerPath}</string>
922
+ ${programArgs}
916
923
  </array>
917
924
  <key>RunAtLoad</key>
918
925
  <true/>
@@ -955,7 +962,8 @@ function unitPath() {
955
962
  return join4(homedir3(), ".config", "systemd", "user", `${SYSTEMD_SERVICE}.service`);
956
963
  }
957
964
  function buildUnit() {
958
- const listenerPath = resolveListenerMainPath();
965
+ const cmd = resolveListenerCommand();
966
+ const execStart = [process.execPath, cmd.script, ...cmd.args].join(" ");
959
967
  const logs = logDir();
960
968
  return `[Unit]
961
969
  Description=RepoWise Listener
@@ -964,7 +972,7 @@ Wants=network-online.target
964
972
 
965
973
  [Service]
966
974
  Type=simple
967
- ExecStart=${process.execPath} ${listenerPath}
975
+ ExecStart=${execStart}
968
976
  Restart=on-failure
969
977
  RestartSec=10
970
978
  StandardOutput=append:${join4(logs, "listener-stdout.log")}
@@ -1009,13 +1017,14 @@ async function linuxIsInstalled() {
1009
1017
  }
1010
1018
  async function win32Install() {
1011
1019
  await mkdir4(logDir(), { recursive: true });
1012
- const listenerPath = resolveListenerMainPath();
1020
+ const cmd = resolveListenerCommand();
1021
+ const taskCmd = [process.execPath, cmd.script, ...cmd.args].map((a) => `"${a}"`).join(" ");
1013
1022
  await exec("schtasks", [
1014
1023
  "/create",
1015
1024
  "/tn",
1016
1025
  TASK_NAME,
1017
1026
  "/tr",
1018
- `"${process.execPath}" "${listenerPath}"`,
1027
+ taskCmd,
1019
1028
  "/sc",
1020
1029
  "onlogon",
1021
1030
  "/ru",
@@ -1086,7 +1095,7 @@ async function isInstalled() {
1086
1095
  }
1087
1096
  var PLIST_LABEL, SYSTEMD_SERVICE, TASK_NAME;
1088
1097
  var init_service_installer = __esm({
1089
- "../listener/src/service-installer.ts"() {
1098
+ "../listener/dist/service-installer.js"() {
1090
1099
  "use strict";
1091
1100
  PLIST_LABEL = "com.repowise.listener";
1092
1101
  SYSTEMD_SERVICE = "repowise-listener";
@@ -1094,7 +1103,7 @@ var init_service_installer = __esm({
1094
1103
  }
1095
1104
  });
1096
1105
 
1097
- // ../listener/src/process-manager.ts
1106
+ // ../listener/dist/process-manager.js
1098
1107
  var process_manager_exports = {};
1099
1108
  __export(process_manager_exports, {
1100
1109
  getStatus: () => getStatus,
@@ -1108,9 +1117,16 @@ import { readFile as readFile4, writeFile as writeFile5, mkdir as mkdir5, unlink
1108
1117
  import { homedir as homedir4 } from "os";
1109
1118
  import { join as join5 } from "path";
1110
1119
  import { createRequire as createRequire2 } from "module";
1111
- function resolveListenerMainPath2() {
1112
- const require2 = createRequire2(import.meta.url);
1113
- return require2.resolve("@repowise/listener/main");
1120
+ import { fileURLToPath as fileURLToPath2 } from "url";
1121
+ function resolveListenerCommand2() {
1122
+ try {
1123
+ const require2 = createRequire2(import.meta.url);
1124
+ const mainPath = require2.resolve("@repowise/listener/main");
1125
+ return { script: mainPath, args: [] };
1126
+ } catch {
1127
+ const bundlePath = fileURLToPath2(import.meta.url);
1128
+ return { script: bundlePath, args: ["__listener"] };
1129
+ }
1114
1130
  }
1115
1131
  async function readPid() {
1116
1132
  try {
@@ -1118,7 +1134,8 @@ async function readPid() {
1118
1134
  const pid = parseInt(content.trim(), 10);
1119
1135
  return Number.isNaN(pid) ? null : pid;
1120
1136
  } catch (err) {
1121
- if (err.code === "ENOENT") return null;
1137
+ if (err.code === "ENOENT")
1138
+ return null;
1122
1139
  throw err;
1123
1140
  }
1124
1141
  }
@@ -1132,10 +1149,10 @@ function isAlive(pid) {
1132
1149
  }
1133
1150
  async function startBackground() {
1134
1151
  await mkdir5(LOG_DIR, { recursive: true });
1135
- const listenerPath = resolveListenerMainPath2();
1152
+ const cmd = resolveListenerCommand2();
1136
1153
  const stdoutFd = openSync(join5(LOG_DIR, "listener-stdout.log"), "a");
1137
1154
  const stderrFd = openSync(join5(LOG_DIR, "listener-stderr.log"), "a");
1138
- const child = spawn(process.execPath, [listenerPath], {
1155
+ const child = spawn(process.execPath, [cmd.script, ...cmd.args], {
1139
1156
  detached: true,
1140
1157
  stdio: ["ignore", stdoutFd, stderrFd],
1141
1158
  cwd: homedir4(),
@@ -1145,13 +1162,15 @@ async function startBackground() {
1145
1162
  closeSync(stdoutFd);
1146
1163
  closeSync(stderrFd);
1147
1164
  const pid = child.pid;
1148
- if (!pid) throw new Error("Failed to spawn listener process");
1165
+ if (!pid)
1166
+ throw new Error("Failed to spawn listener process");
1149
1167
  await writeFile5(PID_PATH, String(pid));
1150
1168
  return pid;
1151
1169
  }
1152
1170
  async function stopProcess() {
1153
1171
  const pid = await readPid();
1154
- if (pid === null) return;
1172
+ if (pid === null)
1173
+ return;
1155
1174
  if (!isAlive(pid)) {
1156
1175
  await removePidFile();
1157
1176
  return;
@@ -1174,12 +1193,14 @@ async function stopProcess() {
1174
1193
  }
1175
1194
  async function isRunning() {
1176
1195
  const pid = await readPid();
1177
- if (pid === null) return false;
1196
+ if (pid === null)
1197
+ return false;
1178
1198
  return isAlive(pid);
1179
1199
  }
1180
1200
  async function getStatus() {
1181
1201
  const pid = await readPid();
1182
- if (pid === null) return { running: false, pid: null };
1202
+ if (pid === null)
1203
+ return { running: false, pid: null };
1183
1204
  const alive = isAlive(pid);
1184
1205
  return { running: alive, pid: alive ? pid : null };
1185
1206
  }
@@ -1191,7 +1212,7 @@ async function removePidFile() {
1191
1212
  }
1192
1213
  var REPOWISE_DIR, PID_PATH, LOG_DIR;
1193
1214
  var init_process_manager = __esm({
1194
- "../listener/src/process-manager.ts"() {
1215
+ "../listener/dist/process-manager.js"() {
1195
1216
  "use strict";
1196
1217
  REPOWISE_DIR = join5(homedir4(), ".repowise");
1197
1218
  PID_PATH = join5(REPOWISE_DIR, "listener.pid");
@@ -1613,7 +1634,7 @@ var init_sync = __esm({
1613
1634
  }
1614
1635
  });
1615
1636
 
1616
- // ../listener/src/lib/config.ts
1637
+ // ../listener/dist/lib/config.js
1617
1638
  import { readFile as readFile6 } from "fs/promises";
1618
1639
  import { homedir as homedir6 } from "os";
1619
1640
  import { join as join7 } from "path";
@@ -1622,9 +1643,7 @@ async function getListenerConfig() {
1622
1643
  try {
1623
1644
  const data = await readFile6(CONFIG_PATH2, "utf-8");
1624
1645
  const raw = JSON.parse(data);
1625
- const validRepos = (raw.repos ?? []).filter(
1626
- (r) => typeof r === "object" && r !== null && typeof r.repoId === "string" && typeof r.localPath === "string"
1627
- );
1646
+ const validRepos = (raw.repos ?? []).filter((r) => typeof r === "object" && r !== null && typeof r.repoId === "string" && typeof r.localPath === "string");
1628
1647
  return {
1629
1648
  apiUrl: raw.apiUrl ?? apiUrl,
1630
1649
  repos: validRepos
@@ -1635,7 +1654,7 @@ async function getListenerConfig() {
1635
1654
  }
1636
1655
  var CONFIG_DIR3, CONFIG_PATH2, DEFAULT_API_URL;
1637
1656
  var init_config2 = __esm({
1638
- "../listener/src/lib/config.ts"() {
1657
+ "../listener/dist/lib/config.js"() {
1639
1658
  "use strict";
1640
1659
  CONFIG_DIR3 = join7(homedir6(), ".repowise");
1641
1660
  CONFIG_PATH2 = join7(CONFIG_DIR3, "config.json");
@@ -1643,7 +1662,7 @@ var init_config2 = __esm({
1643
1662
  }
1644
1663
  });
1645
1664
 
1646
- // ../listener/src/lib/state.ts
1665
+ // ../listener/dist/lib/state.js
1647
1666
  import { readFile as readFile7, writeFile as writeFile6, mkdir as mkdir6, chmod as chmod2 } from "fs/promises";
1648
1667
  import { homedir as homedir7 } from "os";
1649
1668
  import { join as join8 } from "path";
@@ -1668,14 +1687,14 @@ async function saveState(state) {
1668
1687
  }
1669
1688
  var CONFIG_DIR4, STATE_PATH2;
1670
1689
  var init_state = __esm({
1671
- "../listener/src/lib/state.ts"() {
1690
+ "../listener/dist/lib/state.js"() {
1672
1691
  "use strict";
1673
1692
  CONFIG_DIR4 = join8(homedir7(), ".repowise");
1674
1693
  STATE_PATH2 = join8(CONFIG_DIR4, "listener-state.json");
1675
1694
  }
1676
1695
  });
1677
1696
 
1678
- // ../listener/src/lib/auth.ts
1697
+ // ../listener/dist/lib/auth.js
1679
1698
  import { readFile as readFile8, writeFile as writeFile7, mkdir as mkdir7, chmod as chmod3 } from "fs/promises";
1680
1699
  import { homedir as homedir8 } from "os";
1681
1700
  import { join as join9 } from "path";
@@ -1729,7 +1748,8 @@ async function storeCredentials2(credentials) {
1729
1748
  }
1730
1749
  async function getValidCredentials2() {
1731
1750
  const creds = await getStoredCredentials2();
1732
- if (!creds) return null;
1751
+ if (!creds)
1752
+ return null;
1733
1753
  if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
1734
1754
  try {
1735
1755
  const refreshed = await refreshTokens2(creds.refreshToken);
@@ -1743,17 +1763,17 @@ async function getValidCredentials2() {
1743
1763
  }
1744
1764
  var CONFIG_DIR5, CREDENTIALS_PATH2;
1745
1765
  var init_auth2 = __esm({
1746
- "../listener/src/lib/auth.ts"() {
1766
+ "../listener/dist/lib/auth.js"() {
1747
1767
  "use strict";
1748
1768
  CONFIG_DIR5 = join9(homedir8(), ".repowise");
1749
1769
  CREDENTIALS_PATH2 = join9(CONFIG_DIR5, "credentials.json");
1750
1770
  }
1751
1771
  });
1752
1772
 
1753
- // ../listener/src/poll-client.ts
1773
+ // ../listener/dist/poll-client.js
1754
1774
  var POLL_TIMEOUT_MS, AuthError, PollClient;
1755
1775
  var init_poll_client = __esm({
1756
- "../listener/src/poll-client.ts"() {
1776
+ "../listener/dist/poll-client.js"() {
1757
1777
  "use strict";
1758
1778
  init_auth2();
1759
1779
  POLL_TIMEOUT_MS = 3e4;
@@ -1803,10 +1823,10 @@ var init_poll_client = __esm({
1803
1823
  }
1804
1824
  });
1805
1825
 
1806
- // ../listener/src/reconnection.ts
1826
+ // ../listener/dist/reconnection.js
1807
1827
  var DEFAULT_CONFIG, BackoffCalculator;
1808
1828
  var init_reconnection = __esm({
1809
- "../listener/src/reconnection.ts"() {
1829
+ "../listener/dist/reconnection.js"() {
1810
1830
  "use strict";
1811
1831
  DEFAULT_CONFIG = {
1812
1832
  initialDelay: 1e3,
@@ -1820,10 +1840,7 @@ var init_reconnection = __esm({
1820
1840
  this.config = { ...DEFAULT_CONFIG, ...config2 };
1821
1841
  }
1822
1842
  nextDelay() {
1823
- const baseDelay = Math.min(
1824
- this.config.initialDelay * Math.pow(2, this.attempt),
1825
- this.config.maxDelay
1826
- );
1843
+ const baseDelay = Math.min(this.config.initialDelay * Math.pow(2, this.attempt), this.config.maxDelay);
1827
1844
  const jitter = Math.random() * this.config.jitterMax;
1828
1845
  this.attempt++;
1829
1846
  return baseDelay + jitter;
@@ -1838,7 +1855,7 @@ var init_reconnection = __esm({
1838
1855
  }
1839
1856
  });
1840
1857
 
1841
- // ../listener/src/notification.ts
1858
+ // ../listener/dist/notification.js
1842
1859
  import notifier from "node-notifier";
1843
1860
  function notifyConnectionLost() {
1844
1861
  try {
@@ -1869,14 +1886,14 @@ function notifyContextUpdated(repoId, fileCount) {
1869
1886
  }
1870
1887
  var TITLE, notify;
1871
1888
  var init_notification = __esm({
1872
- "../listener/src/notification.ts"() {
1889
+ "../listener/dist/notification.js"() {
1873
1890
  "use strict";
1874
1891
  TITLE = "RepoWise";
1875
1892
  notify = notifier.notify.bind(notifier);
1876
1893
  }
1877
1894
  });
1878
1895
 
1879
- // ../listener/src/file-writer.ts
1896
+ // ../listener/dist/file-writer.js
1880
1897
  import { access } from "fs/promises";
1881
1898
  import { join as join10 } from "path";
1882
1899
  async function verifyContextFolder(localPath) {
@@ -1888,12 +1905,12 @@ async function verifyContextFolder(localPath) {
1888
1905
  }
1889
1906
  }
1890
1907
  var init_file_writer = __esm({
1891
- "../listener/src/file-writer.ts"() {
1908
+ "../listener/dist/file-writer.js"() {
1892
1909
  "use strict";
1893
1910
  }
1894
1911
  });
1895
1912
 
1896
- // ../listener/src/context-fetcher.ts
1913
+ // ../listener/dist/context-fetcher.js
1897
1914
  import { execFile as execFile2 } from "child_process";
1898
1915
  import { promisify } from "util";
1899
1916
  async function fetchContextUpdates(localPath) {
@@ -1935,14 +1952,14 @@ async function fetchContextUpdates(localPath) {
1935
1952
  }
1936
1953
  var execFileAsync;
1937
1954
  var init_context_fetcher = __esm({
1938
- "../listener/src/context-fetcher.ts"() {
1955
+ "../listener/dist/context-fetcher.js"() {
1939
1956
  "use strict";
1940
1957
  init_file_writer();
1941
1958
  execFileAsync = promisify(execFile2);
1942
1959
  }
1943
1960
  });
1944
1961
 
1945
- // ../listener/src/main.ts
1962
+ // ../listener/dist/main.js
1946
1963
  var main_exports = {};
1947
1964
  __export(main_exports, {
1948
1965
  startListener: () => startListener,
@@ -1968,9 +1985,7 @@ async function handleStalePid() {
1968
1985
  if (!Number.isNaN(pid) && pid !== process.pid) {
1969
1986
  try {
1970
1987
  process.kill(pid, 0);
1971
- console.error(
1972
- `Listener already running (PID: ${pid}). Stop it first with \`repowise stop\`.`
1973
- );
1988
+ console.error(`Listener already running (PID: ${pid}). Stop it first with \`repowise stop\`.`);
1974
1989
  process.exitCode = 1;
1975
1990
  return true;
1976
1991
  } catch {
@@ -1994,7 +2009,8 @@ function sleep(ms) {
1994
2009
  sleepResolve = null;
1995
2010
  resolve();
1996
2011
  }, ms);
1997
- if (typeof timer === "object" && "unref" in timer) timer.unref();
2012
+ if (typeof timer === "object" && "unref" in timer)
2013
+ timer.unref();
1998
2014
  });
1999
2015
  }
2000
2016
  async function processNotifications(notifications, state, repoLocalPaths) {
@@ -2018,13 +2034,15 @@ async function processNotifications(notifications, state, repoLocalPaths) {
2018
2034
  return updateCount;
2019
2035
  }
2020
2036
  async function handleCatchUp(offlineState, pollClient, repoIds, state, repoLocalPaths) {
2021
- if (!offlineState.offlineSince) return;
2037
+ if (!offlineState.offlineSince)
2038
+ return;
2022
2039
  const offlineDuration = Date.now() - new Date(offlineState.offlineSince).getTime();
2023
2040
  if (offlineDuration >= TWENTY_FOUR_HOURS_MS) {
2024
2041
  let syncCount = 0;
2025
2042
  for (const [, localPath] of repoLocalPaths) {
2026
2043
  const result = await fetchContextUpdates(localPath);
2027
- if (result.success) syncCount++;
2044
+ if (result.success)
2045
+ syncCount++;
2028
2046
  }
2029
2047
  notifyBackOnline(syncCount);
2030
2048
  } else {
@@ -2038,7 +2056,8 @@ async function handleCatchUp(offlineState, pollClient, repoIds, state, repoLocal
2038
2056
  async function startListener() {
2039
2057
  running = true;
2040
2058
  const alreadyRunning = await handleStalePid();
2041
- if (alreadyRunning) return;
2059
+ if (alreadyRunning)
2060
+ return;
2042
2061
  await writePidFile();
2043
2062
  const config2 = await getListenerConfig();
2044
2063
  if (config2.repos.length === 0) {
@@ -2098,7 +2117,8 @@ async function startListener() {
2098
2117
  pollIntervalMs = response.pollIntervalMs;
2099
2118
  await sleep(pollIntervalMs);
2100
2119
  } catch (err) {
2101
- if (!running) break;
2120
+ if (!running)
2121
+ break;
2102
2122
  if (err instanceof AuthError) {
2103
2123
  console.error(err.message);
2104
2124
  process.exitCode = 1;
@@ -2113,9 +2133,7 @@ async function startListener() {
2113
2133
  offlineState.attemptCount++;
2114
2134
  const delay = backoff.nextDelay();
2115
2135
  const message = err instanceof Error ? err.message : "Unknown error";
2116
- console.error(
2117
- `Poll failed (attempt ${offlineState.attemptCount}): ${message}. Retrying in ${Math.round(delay / 1e3)}s`
2118
- );
2136
+ console.error(`Poll failed (attempt ${offlineState.attemptCount}): ${message}. Retrying in ${Math.round(delay / 1e3)}s`);
2119
2137
  await sleep(delay);
2120
2138
  }
2121
2139
  }
@@ -2123,7 +2141,7 @@ async function startListener() {
2123
2141
  }
2124
2142
  var TWENTY_FOUR_HOURS_MS, PID_PATH2, running, sleepResolve, isDirectRun;
2125
2143
  var init_main = __esm({
2126
- "../listener/src/main.ts"() {
2144
+ "../listener/dist/main.js"() {
2127
2145
  "use strict";
2128
2146
  init_config2();
2129
2147
  init_state();
@@ -2310,4 +2328,9 @@ program.command("config").description("Manage configuration").action(async () =>
2310
2328
  const { config: config2 } = await Promise.resolve().then(() => (init_config3(), config_exports));
2311
2329
  config2();
2312
2330
  });
2313
- program.parse();
2331
+ if (process.argv[2] === "__listener") {
2332
+ const { startListener: startListener2 } = await Promise.resolve().then(() => (init_main(), main_exports));
2333
+ await startListener2();
2334
+ } else {
2335
+ program.parse();
2336
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repowise",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "AI-optimized codebase context generator",
6
6
  "bin": {