@decentnetwork/lan 0.1.56 → 0.1.58

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.
@@ -1,4 +1,4 @@
1
- import { readFileSync } from "fs";
1
+ import { readFileSync, existsSync } from "fs";
2
2
  import { resolve, dirname } from "path";
3
3
  import { mkdirSync } from "fs";
4
4
  import { homedir } from "os";
@@ -67,9 +67,22 @@ export const DEFAULT_DORA_USERID = DEFAULT_DORAS[0].userid;
67
67
  export const DEFAULT_DORA_ADDRESS = DEFAULT_DORAS[0].address;
68
68
  export class ConfigLoader {
69
69
  static defaultConfigPath() {
70
- return DEFAULT_CONFIG_FILE;
70
+ return resolve(this.defaultConfigDir(), "config.yaml");
71
71
  }
72
72
  static defaultConfigDir() {
73
+ // Work around the sudo HOME trap: `agentnet init` (run as a normal user)
74
+ // writes ~/.agentnet, but `sudo agentnet up` runs with HOME=/root and
75
+ // would look in an empty /root/.agentnet -> "Not initialized". When we're
76
+ // under sudo, root has no config, and the invoking user DOES, transparently
77
+ // use the invoking user's ~/.agentnet so `sudo agentnet up` just works.
78
+ const sudoUser = process.env.SUDO_USER;
79
+ if (sudoUser && sudoUser !== "root" && !existsSync(DEFAULT_CONFIG_FILE)) {
80
+ for (const home of [`/home/${sudoUser}`, `/Users/${sudoUser}`]) {
81
+ const cand = resolve(home, ".agentnet");
82
+ if (existsSync(resolve(cand, "config.yaml")))
83
+ return cand;
84
+ }
85
+ }
73
86
  return DEFAULT_CONFIG_DIR;
74
87
  }
75
88
  static async load(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/lan",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "Private virtual LAN for self-hosted services and AI agents, built on Elastos Carrier. NAT-traversal, name service, ACL, all over a peer-to-peer mesh — no public IP required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@decentnetwork/dora": "^0.1.6",
78
- "@decentnetwork/peer": "^0.1.22",
78
+ "@decentnetwork/peer": "^0.1.23",
79
79
  "js-yaml": "^4.1.0",
80
80
  "yargs": "^17.7.2"
81
81
  },