@fangyb/ahchat-bridge 0.1.16 → 0.1.18

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.cjs CHANGED
@@ -46793,6 +46793,34 @@ var AgentManager = class {
46793
46793
  this.queryFn = QA$;
46794
46794
  return this.queryFn;
46795
46795
  }
46796
+ fallbackCwd(agentConfig, scope, requestedCwd) {
46797
+ const normalized = requestedCwd.trim();
46798
+ const basename = normalized ? import_node_path8.default.basename(import_node_path8.default.normalize(normalized)) : "";
46799
+ const suffix = basename && basename !== "." && basename !== import_node_path8.default.sep ? basename : scope.kind === "group" ? `Group-${scope.groupId}` : agentConfig.id;
46800
+ return import_node_path8.default.join(this.workspacesDir, suffix);
46801
+ }
46802
+ async resolveRuntimeCwd(agentConfig, scope, requestedCwd) {
46803
+ let cwd = requestedCwd;
46804
+ if (isRunningAsRoot() && cwd.startsWith("/root/")) {
46805
+ cwd = this.fallbackCwd(agentConfig, scope, cwd);
46806
+ }
46807
+ try {
46808
+ await import_promises8.default.mkdir(cwd, { recursive: true });
46809
+ return cwd;
46810
+ } catch (e7) {
46811
+ const fallback = this.fallbackCwd(agentConfig, scope, cwd);
46812
+ if (fallback === cwd) throw e7;
46813
+ logger10.warn("Working directory inaccessible; using local fallback", {
46814
+ agentId: agentConfig.id,
46815
+ scope: scopeKey(scope),
46816
+ requested: cwd,
46817
+ fallback,
46818
+ error: e7
46819
+ });
46820
+ await import_promises8.default.mkdir(fallback, { recursive: true });
46821
+ return fallback;
46822
+ }
46823
+ }
46796
46824
  /**
46797
46825
  * Parse agent.config and resolve any subscriptionId reference into the legacy
46798
46826
  * inline fields (subscriptionType / apiKey / apiBaseUrl). Downstream code in
@@ -47005,8 +47033,7 @@ var AgentManager = class {
47005
47033
  return existing;
47006
47034
  }
47007
47035
  const inputController = new InputController();
47008
- const agentCwd = isRunningAsRoot() && cwd.startsWith("/root/") ? import_node_path8.default.join(this.workspacesDir, agentConfig.id) : cwd;
47009
- await import_promises8.default.mkdir(agentCwd, { recursive: true });
47036
+ const agentCwd = await this.resolveRuntimeCwd(agentConfig, scope, cwd);
47010
47037
  const cfg = await this.resolveAgentConfig(agentConfig);
47011
47038
  if (cfg.instructions?.trim()) {
47012
47039
  await import_promises8.default.writeFile(import_node_path8.default.join(agentCwd, "CLAUDE.md"), cfg.instructions.trim(), "utf-8");
@@ -52032,6 +52059,25 @@ function isProtocolRegistered() {
52032
52059
 
52033
52060
  // src/cli.ts
52034
52061
  var logger30 = createModuleLogger("bridge");
52062
+ function resolveDataDir(dataDir) {
52063
+ const userHome = process.env.USERPROFILE || import_node_os13.default.homedir();
52064
+ if (/^~[/\\]/.test(dataDir)) {
52065
+ return import_node_path21.default.join(import_node_os13.default.homedir(), dataDir.slice(2));
52066
+ }
52067
+ if (dataDir === "$env:USERPROFILE") {
52068
+ return userHome;
52069
+ }
52070
+ if (dataDir.startsWith("$env:USERPROFILE\\") || dataDir.startsWith("$env:USERPROFILE/")) {
52071
+ return import_node_path21.default.join(userHome, dataDir.slice("$env:USERPROFILE".length + 1));
52072
+ }
52073
+ if (dataDir === "%USERPROFILE%") {
52074
+ return userHome;
52075
+ }
52076
+ if (dataDir.startsWith("%USERPROFILE%\\") || dataDir.startsWith("%USERPROFILE%/")) {
52077
+ return import_node_path21.default.join(userHome, dataDir.slice("%USERPROFILE%".length + 1));
52078
+ }
52079
+ return dataDir;
52080
+ }
52035
52081
  function parseAhchatUrl(url2) {
52036
52082
  try {
52037
52083
  if (!url2.startsWith("ahchat://")) return null;
@@ -52058,7 +52104,7 @@ async function run(args) {
52058
52104
  }
52059
52105
  if (args.token) config2 = { ...config2, bridgeToken: args.token };
52060
52106
  if (args.dataDir) {
52061
- const resolved = /^~[/\\]/.test(args.dataDir) ? import_node_path21.default.join(import_node_os13.default.homedir(), args.dataDir.slice(2)) : args.dataDir;
52107
+ const resolved = resolveDataDir(args.dataDir);
52062
52108
  config2 = { ...config2, dataDir: resolved };
52063
52109
  }
52064
52110
  if (args.logLevel) config2 = { ...config2, logLevel: args.logLevel };