axconfig 3.1.0 → 3.2.0

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.
@@ -9,6 +9,7 @@ import type { AgentCli } from "axshared";
9
9
  type GetAgentConfigEnvironmentResult = {
10
10
  ok: true;
11
11
  env: Record<string, string>;
12
+ warning: string | undefined;
12
13
  } | {
13
14
  ok: false;
14
15
  error: string;
@@ -20,27 +21,28 @@ type GetAgentConfigEnvironmentResult = {
20
21
  * config and data directories. This handles agents that require env vars to
21
22
  * point to parent directories (e.g., HOME for gemini, XDG paths for opencode).
22
23
  *
23
- * For agents that support separate config and data directories (OpenCode),
24
- * both paths can differ. For agents that don't support separation, dataDirectory
25
- * defaults to configDirectory.
24
+ * **Agents without separation** (Claude, Codex, Gemini, Copilot):
25
+ * - `configDirectory` and `dataDirectory` are interchangeable
26
+ * - Either can be provided alone to set both locations
27
+ *
28
+ * **Agents with separation** (OpenCode):
29
+ * - Directories are independent
30
+ * - If only `configDirectory` provided, data uses default location
31
+ * - If only `dataDirectory` provided, config uses default location
26
32
  *
27
33
  * @param agent - The agent CLI identifier
28
- * @param configDirectory - The config directory path (must end with expected suffix for some agents)
29
- * @param dataDirectory - The data directory path (defaults to configDirectory)
30
- * @returns Result with agent-specific env vars, or error if directories are invalid
34
+ * @param configDirectory - Custom config directory (optional)
35
+ * @param dataDirectory - Custom data directory (optional)
36
+ * @returns Result with agent-specific env vars, warning, or error
31
37
  *
32
38
  * @example
33
39
  * // Claude: env var points directly to config dir
34
40
  * getAgentConfigEnvironment("claude", "/tmp/test/.claude")
35
- * // Returns: { ok: true, env: { CLAUDE_CONFIG_DIR: "/tmp/test/.claude" } }
36
- *
37
- * // Gemini: env var points to parent (HOME), config is in .gemini subdirectory
38
- * getAgentConfigEnvironment("gemini", "/tmp/test/.gemini")
39
- * // Returns: { ok: true, env: { HOME: "/tmp/test", GEMINI_FORCE_FILE_STORAGE: "true" } }
41
+ * // Returns: { ok: true, env: { CLAUDE_CONFIG_DIR: "/tmp/test/.claude" }, warning: undefined }
40
42
  *
41
- * // OpenCode: separate config and data directories
42
- * getAgentConfigEnvironment("opencode", "/tmp/config/opencode", "/tmp/data/opencode")
43
- * // Returns: { ok: true, env: { XDG_CONFIG_HOME: "/tmp/config", XDG_DATA_HOME: "/tmp/data" } }
43
+ * // OpenCode with only configDir: data uses default
44
+ * getAgentConfigEnvironment("opencode", "/tmp/config/opencode")
45
+ * // Returns: { ok: true, env: { XDG_CONFIG_HOME: "/tmp/config", XDG_DATA_HOME: "/home/user/.local/share" }, warning: "..." }
44
46
  */
45
- declare function getAgentConfigEnvironment(agent: AgentCli, configDirectory: string, dataDirectory?: string): GetAgentConfigEnvironmentResult;
47
+ declare function getAgentConfigEnvironment(agent: AgentCli, configDirectory?: string, dataDirectory?: string): GetAgentConfigEnvironmentResult;
46
48
  export { getAgentConfigEnvironment, type GetAgentConfigEnvironmentResult };
@@ -5,7 +5,7 @@
5
5
  * with custom config directories. Delegates to axshared for path info.
6
6
  */
7
7
  import path from "node:path";
8
- import { buildAgentRuntimeEnvironment, getAgentPathInfo } from "axshared";
8
+ import { buildAgentRuntimeEnvironment, getAgentPathInfo, resolveAgentConfigDirectory, resolveAgentDataDirectory, resolveCustomDirectories, } from "axshared";
9
9
  /**
10
10
  * Get agent-specific environment variables for custom directories.
11
11
  *
@@ -13,35 +13,46 @@ import { buildAgentRuntimeEnvironment, getAgentPathInfo } from "axshared";
13
13
  * config and data directories. This handles agents that require env vars to
14
14
  * point to parent directories (e.g., HOME for gemini, XDG paths for opencode).
15
15
  *
16
- * For agents that support separate config and data directories (OpenCode),
17
- * both paths can differ. For agents that don't support separation, dataDirectory
18
- * defaults to configDirectory.
16
+ * **Agents without separation** (Claude, Codex, Gemini, Copilot):
17
+ * - `configDirectory` and `dataDirectory` are interchangeable
18
+ * - Either can be provided alone to set both locations
19
+ *
20
+ * **Agents with separation** (OpenCode):
21
+ * - Directories are independent
22
+ * - If only `configDirectory` provided, data uses default location
23
+ * - If only `dataDirectory` provided, config uses default location
19
24
  *
20
25
  * @param agent - The agent CLI identifier
21
- * @param configDirectory - The config directory path (must end with expected suffix for some agents)
22
- * @param dataDirectory - The data directory path (defaults to configDirectory)
23
- * @returns Result with agent-specific env vars, or error if directories are invalid
26
+ * @param configDirectory - Custom config directory (optional)
27
+ * @param dataDirectory - Custom data directory (optional)
28
+ * @returns Result with agent-specific env vars, warning, or error
24
29
  *
25
30
  * @example
26
31
  * // Claude: env var points directly to config dir
27
32
  * getAgentConfigEnvironment("claude", "/tmp/test/.claude")
28
- * // Returns: { ok: true, env: { CLAUDE_CONFIG_DIR: "/tmp/test/.claude" } }
29
- *
30
- * // Gemini: env var points to parent (HOME), config is in .gemini subdirectory
31
- * getAgentConfigEnvironment("gemini", "/tmp/test/.gemini")
32
- * // Returns: { ok: true, env: { HOME: "/tmp/test", GEMINI_FORCE_FILE_STORAGE: "true" } }
33
+ * // Returns: { ok: true, env: { CLAUDE_CONFIG_DIR: "/tmp/test/.claude" }, warning: undefined }
33
34
  *
34
- * // OpenCode: separate config and data directories
35
- * getAgentConfigEnvironment("opencode", "/tmp/config/opencode", "/tmp/data/opencode")
36
- * // Returns: { ok: true, env: { XDG_CONFIG_HOME: "/tmp/config", XDG_DATA_HOME: "/tmp/data" } }
35
+ * // OpenCode with only configDir: data uses default
36
+ * getAgentConfigEnvironment("opencode", "/tmp/config/opencode")
37
+ * // Returns: { ok: true, env: { XDG_CONFIG_HOME: "/tmp/config", XDG_DATA_HOME: "/home/user/.local/share" }, warning: "..." }
37
38
  */
38
- function getAgentConfigEnvironment(agent, configDirectory, dataDirectory = configDirectory) {
39
+ function getAgentConfigEnvironment(agent, configDirectory, dataDirectory) {
39
40
  const pathInfo = getAgentPathInfo(agent);
40
- const resolvedConfigDirectory = path.resolve(configDirectory);
41
- const resolvedDataDirectory = path.resolve(dataDirectory);
41
+ // Resolve directories based on agent capabilities
42
+ const resolved = resolveCustomDirectories(agent, configDirectory, dataDirectory);
43
+ if (!resolved.ok) {
44
+ return { ok: false, error: resolved.error };
45
+ }
46
+ // Determine effective directories using resolved values or defaults
47
+ const effectiveConfigDirectory = resolved.configDir
48
+ ? path.resolve(resolved.configDir)
49
+ : resolveAgentConfigDirectory(agent);
50
+ const effectiveDataDirectory = resolved.dataDir
51
+ ? path.resolve(resolved.dataDir)
52
+ : resolveAgentDataDirectory(agent);
42
53
  // Validate config subdirectory suffix for agents that require it
43
54
  if (pathInfo.subdirectory !== undefined) {
44
- const actualSuffix = path.basename(resolvedConfigDirectory);
55
+ const actualSuffix = path.basename(effectiveConfigDirectory);
45
56
  if (actualSuffix !== pathInfo.subdirectory) {
46
57
  return {
47
58
  ok: false,
@@ -53,7 +64,7 @@ function getAgentConfigEnvironment(agent, configDirectory, dataDirectory = confi
53
64
  // Validate data subdirectory suffix for agents that require it
54
65
  const dataSubdirectory = pathInfo.dataSubdirectory ?? pathInfo.subdirectory;
55
66
  if (dataSubdirectory !== undefined) {
56
- const actualSuffix = path.basename(resolvedDataDirectory);
67
+ const actualSuffix = path.basename(effectiveDataDirectory);
57
68
  if (actualSuffix !== dataSubdirectory) {
58
69
  return {
59
70
  ok: false,
@@ -64,7 +75,8 @@ function getAgentConfigEnvironment(agent, configDirectory, dataDirectory = confi
64
75
  }
65
76
  return {
66
77
  ok: true,
67
- env: buildAgentRuntimeEnvironment(agent, resolvedConfigDirectory, resolvedDataDirectory),
78
+ env: buildAgentRuntimeEnvironment(agent, effectiveConfigDirectory, effectiveDataDirectory),
79
+ warning: resolved.warning,
68
80
  };
69
81
  }
70
82
  export { getAgentConfigEnvironment };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "axconfig",
3
3
  "author": "Łukasz Jerciński",
4
4
  "license": "MIT",
5
- "version": "3.1.0",
5
+ "version": "3.2.0",
6
6
  "description": "Unified configuration management for AI coding agents - common API for permissions, settings, and config across Claude Code, Codex, Gemini CLI, and OpenCode",
7
7
  "repository": {
8
8
  "type": "git",
@@ -68,7 +68,7 @@
68
68
  "dependencies": {
69
69
  "@commander-js/extra-typings": "^14.0.0",
70
70
  "@iarna/toml": "^2.2.5",
71
- "axshared": "^1.4.0",
71
+ "axshared": "^1.5.0",
72
72
  "commander": "^14.0.2"
73
73
  },
74
74
  "devDependencies": {