@frumu/tandem-panel 0.4.5 → 0.4.7

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/bin/setup.js CHANGED
@@ -43,6 +43,21 @@ function loadDotEnvFile(pathname) {
43
43
  return true;
44
44
  }
45
45
 
46
+ function posixHomeForUser(username) {
47
+ const name = String(username || "").trim();
48
+ if (!name) return homedir();
49
+ try {
50
+ const passwd = readFileSync("/etc/passwd", "utf8");
51
+ for (const line of passwd.split(/\r?\n/)) {
52
+ if (!line || line.startsWith("#")) continue;
53
+ const parts = line.split(":");
54
+ if (parts[0] === name && parts[5]) return parts[5];
55
+ }
56
+ } catch {}
57
+ if (process.env.USER === name || process.env.SUDO_USER === name) return homedir();
58
+ return resolve("/home", name);
59
+ }
60
+
46
61
  function parseCliArgs(argv) {
47
62
  const flags = new Set();
48
63
  const values = new Map();
@@ -704,7 +719,8 @@ async function installServices() {
704
719
  const serviceGroup = serviceUser;
705
720
  const installEngine = serviceMode === "both" || serviceMode === "engine";
706
721
  const installPanel = serviceMode === "both" || serviceMode === "panel";
707
- const stateDir = String(process.env.TANDEM_STATE_DIR || "/srv/tandem").trim();
722
+ const defaultStateDir = resolve(posixHomeForUser(serviceUser), ".local", "share", "tandem");
723
+ const stateDir = String(process.env.TANDEM_HOME || process.env.TANDEM_STATE_DIR || defaultStateDir).trim();
708
724
  const engineEnvPath = "/etc/tandem/engine.env";
709
725
  const panelEnvPath = "/etc/tandem/control-panel.env";
710
726
  const engineServiceName = "tandem-engine";
@@ -728,11 +744,11 @@ async function installServices() {
728
744
  const existingEngineEnv = existsSync(engineEnvPath)
729
745
  ? parseDotEnv(readFileSync(engineEnvPath, "utf8"))
730
746
  : {};
747
+ const { TANDEM_MEMORY_DB_PATH: _legacyMemoryDbPath, ...engineEnvBase } = existingEngineEnv;
731
748
  const engineEnv = {
732
- ...existingEngineEnv,
749
+ ...engineEnvBase,
733
750
  TANDEM_API_TOKEN: token,
734
751
  TANDEM_STATE_DIR: stateDir,
735
- TANDEM_MEMORY_DB_PATH: existingEngineEnv.TANDEM_MEMORY_DB_PATH || `${stateDir}/memory.sqlite`,
736
752
  TANDEM_ENABLE_GLOBAL_MEMORY: existingEngineEnv.TANDEM_ENABLE_GLOBAL_MEMORY || "1",
737
753
  TANDEM_DISABLE_TOOL_GUARD_BUDGETS: existingEngineEnv.TANDEM_DISABLE_TOOL_GUARD_BUDGETS || "1",
738
754
  TANDEM_TOOL_ROUTER_ENABLED: existingEngineEnv.TANDEM_TOOL_ROUTER_ENABLED || "0",