@dexto/agent-management 1.2.5

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.
Files changed (110) hide show
  1. package/LICENSE +44 -0
  2. package/dist/AgentOrchestrator.cjs +263 -0
  3. package/dist/AgentOrchestrator.d.ts +191 -0
  4. package/dist/AgentOrchestrator.d.ts.map +1 -0
  5. package/dist/AgentOrchestrator.js +239 -0
  6. package/dist/config/config-enrichment.cjs +117 -0
  7. package/dist/config/config-enrichment.d.ts +31 -0
  8. package/dist/config/config-enrichment.d.ts.map +1 -0
  9. package/dist/config/config-enrichment.js +82 -0
  10. package/dist/config/config-manager.cjs +57 -0
  11. package/dist/config/config-manager.d.ts +51 -0
  12. package/dist/config/config-manager.d.ts.map +1 -0
  13. package/dist/config/config-manager.js +32 -0
  14. package/dist/config/error-codes.cjs +39 -0
  15. package/dist/config/error-codes.d.ts +16 -0
  16. package/dist/config/error-codes.d.ts.map +1 -0
  17. package/dist/config/error-codes.js +15 -0
  18. package/dist/config/errors.cjs +125 -0
  19. package/dist/config/errors.d.ts +34 -0
  20. package/dist/config/errors.d.ts.map +1 -0
  21. package/dist/config/errors.js +101 -0
  22. package/dist/config/index.cjs +44 -0
  23. package/dist/config/index.d.ts +6 -0
  24. package/dist/config/index.d.ts.map +1 -0
  25. package/dist/config/index.js +14 -0
  26. package/dist/config/loader.cjs +118 -0
  27. package/dist/config/loader.d.ts +18 -0
  28. package/dist/config/loader.d.ts.map +1 -0
  29. package/dist/config/loader.js +84 -0
  30. package/dist/index.cjs +132 -0
  31. package/dist/index.d.ts +20 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +104 -0
  34. package/dist/preferences/constants.cjs +28 -0
  35. package/dist/preferences/constants.d.ts +2 -0
  36. package/dist/preferences/constants.d.ts.map +1 -0
  37. package/dist/preferences/constants.js +4 -0
  38. package/dist/preferences/error-codes.cjs +35 -0
  39. package/dist/preferences/error-codes.d.ts +8 -0
  40. package/dist/preferences/error-codes.d.ts.map +1 -0
  41. package/dist/preferences/error-codes.js +11 -0
  42. package/dist/preferences/errors.cjs +74 -0
  43. package/dist/preferences/errors.d.ts +18 -0
  44. package/dist/preferences/errors.d.ts.map +1 -0
  45. package/dist/preferences/errors.js +49 -0
  46. package/dist/preferences/index.cjs +55 -0
  47. package/dist/preferences/index.d.ts +6 -0
  48. package/dist/preferences/index.d.ts.map +1 -0
  49. package/dist/preferences/index.js +31 -0
  50. package/dist/preferences/loader.cjs +138 -0
  51. package/dist/preferences/loader.d.ts +50 -0
  52. package/dist/preferences/loader.d.ts.map +1 -0
  53. package/dist/preferences/loader.js +109 -0
  54. package/dist/preferences/schemas.cjs +75 -0
  55. package/dist/preferences/schemas.d.ts +110 -0
  56. package/dist/preferences/schemas.d.ts.map +1 -0
  57. package/dist/preferences/schemas.js +48 -0
  58. package/dist/registry/error-codes.cjs +44 -0
  59. package/dist/registry/error-codes.d.ts +21 -0
  60. package/dist/registry/error-codes.d.ts.map +1 -0
  61. package/dist/registry/error-codes.js +20 -0
  62. package/dist/registry/errors.cjs +187 -0
  63. package/dist/registry/errors.d.ts +63 -0
  64. package/dist/registry/errors.d.ts.map +1 -0
  65. package/dist/registry/errors.js +163 -0
  66. package/dist/registry/registry.cjs +479 -0
  67. package/dist/registry/registry.d.ts +130 -0
  68. package/dist/registry/registry.d.ts.map +1 -0
  69. package/dist/registry/registry.js +452 -0
  70. package/dist/registry/types.cjs +74 -0
  71. package/dist/registry/types.d.ts +142 -0
  72. package/dist/registry/types.d.ts.map +1 -0
  73. package/dist/registry/types.js +47 -0
  74. package/dist/registry/user-registry.cjs +140 -0
  75. package/dist/registry/user-registry.d.ts +34 -0
  76. package/dist/registry/user-registry.d.ts.map +1 -0
  77. package/dist/registry/user-registry.js +104 -0
  78. package/dist/resolver.cjs +182 -0
  79. package/dist/resolver.d.ts +14 -0
  80. package/dist/resolver.d.ts.map +1 -0
  81. package/dist/resolver.js +151 -0
  82. package/dist/utils/api-key-resolver.cjs +62 -0
  83. package/dist/utils/api-key-resolver.d.ts +21 -0
  84. package/dist/utils/api-key-resolver.d.ts.map +1 -0
  85. package/dist/utils/api-key-resolver.js +36 -0
  86. package/dist/utils/api-key-store.cjs +56 -0
  87. package/dist/utils/api-key-store.d.ts +18 -0
  88. package/dist/utils/api-key-store.d.ts.map +1 -0
  89. package/dist/utils/api-key-store.js +30 -0
  90. package/dist/utils/env-file.cjs +118 -0
  91. package/dist/utils/env-file.d.ts +5 -0
  92. package/dist/utils/env-file.d.ts.map +1 -0
  93. package/dist/utils/env-file.js +84 -0
  94. package/dist/utils/execution-context.cjs +85 -0
  95. package/dist/utils/execution-context.d.ts +20 -0
  96. package/dist/utils/execution-context.d.ts.map +1 -0
  97. package/dist/utils/execution-context.js +49 -0
  98. package/dist/utils/fs-walk.cjs +52 -0
  99. package/dist/utils/fs-walk.d.ts +8 -0
  100. package/dist/utils/fs-walk.d.ts.map +1 -0
  101. package/dist/utils/fs-walk.js +18 -0
  102. package/dist/utils/path.cjs +205 -0
  103. package/dist/utils/path.d.ts +58 -0
  104. package/dist/utils/path.d.ts.map +1 -0
  105. package/dist/utils/path.js +167 -0
  106. package/dist/writer.cjs +182 -0
  107. package/dist/writer.d.ts +34 -0
  108. package/dist/writer.d.ts.map +1 -0
  109. package/dist/writer.js +146 -0
  110. package/package.json +41 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-walk.d.ts","sourceRoot":"","sources":["../../src/utils/fs-walk.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACxC,MAAM,GAAG,IAAI,CAef"}
@@ -0,0 +1,18 @@
1
+ import * as path from "path";
2
+ function walkUpDirectories(startPath, predicate) {
3
+ let currentPath = path.resolve(startPath);
4
+ const rootPath = path.parse(currentPath).root;
5
+ while (true) {
6
+ if (predicate(currentPath)) {
7
+ return currentPath;
8
+ }
9
+ if (currentPath === rootPath) break;
10
+ const parent = path.dirname(currentPath);
11
+ if (parent === currentPath) break;
12
+ currentPath = parent;
13
+ }
14
+ return null;
15
+ }
16
+ export {
17
+ walkUpDirectories
18
+ };
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var path_exports = {};
30
+ __export(path_exports, {
31
+ copyDirectory: () => copyDirectory,
32
+ ensureDextoGlobalDirectory: () => ensureDextoGlobalDirectory,
33
+ findPackageRoot: () => findPackageRoot,
34
+ getDextoEnvPath: () => getDextoEnvPath,
35
+ getDextoGlobalPath: () => getDextoGlobalPath,
36
+ getDextoPath: () => getDextoPath,
37
+ isPath: () => isPath,
38
+ resolveBundledScript: () => resolveBundledScript
39
+ });
40
+ module.exports = __toCommonJS(path_exports);
41
+ var path = __toESM(require("path"), 1);
42
+ var import_fs = require("fs");
43
+ var import_fs2 = require("fs");
44
+ var import_os = require("os");
45
+ var import_module = require("module");
46
+ var import_url = require("url");
47
+ var import_fs_walk = require("./fs-walk.js");
48
+ var import_execution_context = require("./execution-context.js");
49
+ const import_meta = {};
50
+ function getDextoPath(type, filename, startPath) {
51
+ const context = (0, import_execution_context.getExecutionContext)(startPath);
52
+ let basePath;
53
+ switch (context) {
54
+ case "dexto-source": {
55
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
56
+ if (isDevMode) {
57
+ const sourceRoot = (0, import_execution_context.findDextoSourceRoot)(startPath);
58
+ if (!sourceRoot) {
59
+ throw new Error("Not in dexto source context");
60
+ }
61
+ basePath = path.join(sourceRoot, ".dexto", type);
62
+ } else {
63
+ basePath = path.join((0, import_os.homedir)(), ".dexto", type);
64
+ }
65
+ break;
66
+ }
67
+ case "dexto-project": {
68
+ const projectRoot = (0, import_execution_context.findDextoProjectRoot)(startPath);
69
+ if (!projectRoot) {
70
+ throw new Error("Not in dexto project context");
71
+ }
72
+ basePath = path.join(projectRoot, ".dexto", type);
73
+ break;
74
+ }
75
+ case "global-cli": {
76
+ basePath = path.join((0, import_os.homedir)(), ".dexto", type);
77
+ break;
78
+ }
79
+ default: {
80
+ throw new Error(`Unknown execution context: ${context}`);
81
+ }
82
+ }
83
+ return filename ? path.join(basePath, filename) : basePath;
84
+ }
85
+ function getDextoGlobalPath(type, filename) {
86
+ const basePath = path.join((0, import_os.homedir)(), ".dexto", type);
87
+ return filename ? path.join(basePath, filename) : basePath;
88
+ }
89
+ async function copyDirectory(src, dest) {
90
+ await import_fs2.promises.mkdir(dest, { recursive: true });
91
+ const entries = await import_fs2.promises.readdir(src, { withFileTypes: true });
92
+ for (const entry of entries) {
93
+ const srcPath = path.join(src, entry.name);
94
+ const destPath = path.join(dest, entry.name);
95
+ if (entry.isDirectory()) {
96
+ await copyDirectory(srcPath, destPath);
97
+ } else {
98
+ await import_fs2.promises.copyFile(srcPath, destPath);
99
+ }
100
+ }
101
+ }
102
+ function isPath(str) {
103
+ if (path.isAbsolute(str)) return true;
104
+ if (/[\\/]/.test(str)) return true;
105
+ if (/\.(ya?ml|json)$/i.test(str)) return true;
106
+ return false;
107
+ }
108
+ function findPackageRoot(startPath = process.cwd()) {
109
+ return (0, import_fs_walk.walkUpDirectories)(startPath, (dirPath) => {
110
+ const pkgPath = path.join(dirPath, "package.json");
111
+ return (0, import_fs.existsSync)(pkgPath);
112
+ });
113
+ }
114
+ function resolveBundledScript(scriptPath) {
115
+ const candidates = scriptPath.startsWith("dist/") ? [scriptPath, scriptPath.replace(/^dist\//, "")] : [`dist/${scriptPath}`, scriptPath];
116
+ const triedAbs = [];
117
+ const tryRoots = (roots) => {
118
+ for (const root of roots) {
119
+ if (!root) continue;
120
+ for (const rel of candidates) {
121
+ const abs = path.resolve(root, rel);
122
+ if ((0, import_fs.existsSync)(abs)) return abs;
123
+ triedAbs.push(abs);
124
+ }
125
+ }
126
+ return null;
127
+ };
128
+ const envRoot = process?.env?.DEXTO_PACKAGE_ROOT;
129
+ const fromEnv = tryRoots([envRoot]);
130
+ if (fromEnv) return fromEnv;
131
+ try {
132
+ const require2 = (0, import_module.createRequire)(import_meta.url);
133
+ const pkgJson = require2.resolve("dexto/package.json");
134
+ const pkgRoot = path.dirname(pkgJson);
135
+ const fromPkg = tryRoots([pkgRoot]);
136
+ if (fromPkg) return fromPkg;
137
+ } catch {
138
+ }
139
+ try {
140
+ const thisModuleDir = path.dirname((0, import_url.fileURLToPath)(import_meta.url));
141
+ const sourceRoot = (0, import_execution_context.findDextoSourceRoot)(thisModuleDir);
142
+ const fromSource = tryRoots([sourceRoot ?? void 0]);
143
+ if (fromSource) return fromSource;
144
+ } catch {
145
+ }
146
+ const repoRoot = findPackageRoot();
147
+ const fromCwd = tryRoots([repoRoot ?? void 0]);
148
+ if (fromCwd) return fromCwd;
149
+ throw new Error(
150
+ `Bundled script not found: ${scriptPath} (tried absolute: ${triedAbs.join(", ")})`
151
+ );
152
+ }
153
+ async function ensureDextoGlobalDirectory() {
154
+ const dextoDir = path.join((0, import_os.homedir)(), ".dexto");
155
+ try {
156
+ await import_fs2.promises.mkdir(dextoDir, { recursive: true });
157
+ } catch (error) {
158
+ if (error.code !== "EEXIST") {
159
+ throw error;
160
+ }
161
+ }
162
+ }
163
+ function getDextoEnvPath(startPath = process.cwd()) {
164
+ const context = (0, import_execution_context.getExecutionContext)(startPath);
165
+ let envPath = "";
166
+ switch (context) {
167
+ case "dexto-source": {
168
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
169
+ if (isDevMode) {
170
+ const sourceRoot = (0, import_execution_context.findDextoSourceRoot)(startPath);
171
+ if (!sourceRoot) {
172
+ throw new Error("Not in dexto source context");
173
+ }
174
+ envPath = path.join(sourceRoot, ".env");
175
+ } else {
176
+ envPath = path.join((0, import_os.homedir)(), ".dexto", ".env");
177
+ }
178
+ break;
179
+ }
180
+ case "dexto-project": {
181
+ const projectRoot = (0, import_execution_context.findDextoProjectRoot)(startPath);
182
+ if (!projectRoot) {
183
+ throw new Error("Not in dexto project context");
184
+ }
185
+ envPath = path.join(projectRoot, ".env");
186
+ break;
187
+ }
188
+ case "global-cli": {
189
+ envPath = path.join((0, import_os.homedir)(), ".dexto", ".env");
190
+ break;
191
+ }
192
+ }
193
+ return envPath;
194
+ }
195
+ // Annotate the CommonJS export names for ESM import in node:
196
+ 0 && (module.exports = {
197
+ copyDirectory,
198
+ ensureDextoGlobalDirectory,
199
+ findPackageRoot,
200
+ getDextoEnvPath,
201
+ getDextoGlobalPath,
202
+ getDextoPath,
203
+ isPath,
204
+ resolveBundledScript
205
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Standard path resolver for logs/db/config/anything in dexto projects
3
+ * Context-aware with dev mode support:
4
+ * - dexto-source + DEXTO_DEV_MODE=true: Use local repo .dexto (isolated testing)
5
+ * - dexto-source (normal): Use global ~/.dexto (user experience)
6
+ * - dexto-project: Use project-local .dexto
7
+ * - global-cli: Use global ~/.dexto
8
+ * @param type Path type (logs, database, config, etc.)
9
+ * @param filename Optional filename to append
10
+ * @param startPath Starting directory for project detection
11
+ * @returns Absolute path to the requested location
12
+ */
13
+ export declare function getDextoPath(type: string, filename?: string, startPath?: string): string;
14
+ /**
15
+ * Global path resolver that ALWAYS returns paths in the user's home directory
16
+ * Used for agent registry and other global-only resources that should not be project-relative
17
+ * @param type Path type (agents, cache, etc.)
18
+ * @param filename Optional filename to append
19
+ * @returns Absolute path to the global location (~/.dexto/...)
20
+ */
21
+ export declare function getDextoGlobalPath(type: string, filename?: string): string;
22
+ /**
23
+ * Copy entire directory recursively
24
+ * @param src Source directory path
25
+ * @param dest Destination directory path
26
+ */
27
+ export declare function copyDirectory(src: string, dest: string): Promise<void>;
28
+ /**
29
+ * Check if string looks like a file path vs registry name
30
+ * @param str String to check
31
+ * @returns True if looks like a path, false if looks like a registry name
32
+ */
33
+ export declare function isPath(str: string): boolean;
34
+ /**
35
+ * Find package root (for other utilities)
36
+ * @param startPath Starting directory path
37
+ * @returns Directory containing package.json or null
38
+ */
39
+ export declare function findPackageRoot(startPath?: string): string | null;
40
+ /**
41
+ * Resolve bundled script paths for MCP servers
42
+ * @param scriptPath Relative script path
43
+ * @returns Absolute path to bundled script
44
+ */
45
+ export declare function resolveBundledScript(scriptPath: string): string;
46
+ /**
47
+ * Ensure ~/.dexto directory exists for global storage
48
+ */
49
+ export declare function ensureDextoGlobalDirectory(): Promise<void>;
50
+ /**
51
+ * Get the appropriate .env file path for saving API keys.
52
+ * Uses the same project detection logic as other dexto paths.
53
+ *
54
+ * @param startPath Starting directory for project detection
55
+ * @returns Absolute path to .env file for saving
56
+ */
57
+ export declare function getDextoEnvPath(startPath?: string): string;
58
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAwD/D;AAED;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,CAkCzE"}
@@ -0,0 +1,167 @@
1
+ import * as path from "path";
2
+ import { existsSync } from "fs";
3
+ import { promises as fs } from "fs";
4
+ import { homedir } from "os";
5
+ import { createRequire } from "module";
6
+ import { fileURLToPath } from "url";
7
+ import { walkUpDirectories } from "./fs-walk.js";
8
+ import {
9
+ getExecutionContext,
10
+ findDextoSourceRoot,
11
+ findDextoProjectRoot
12
+ } from "./execution-context.js";
13
+ function getDextoPath(type, filename, startPath) {
14
+ const context = getExecutionContext(startPath);
15
+ let basePath;
16
+ switch (context) {
17
+ case "dexto-source": {
18
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
19
+ if (isDevMode) {
20
+ const sourceRoot = findDextoSourceRoot(startPath);
21
+ if (!sourceRoot) {
22
+ throw new Error("Not in dexto source context");
23
+ }
24
+ basePath = path.join(sourceRoot, ".dexto", type);
25
+ } else {
26
+ basePath = path.join(homedir(), ".dexto", type);
27
+ }
28
+ break;
29
+ }
30
+ case "dexto-project": {
31
+ const projectRoot = findDextoProjectRoot(startPath);
32
+ if (!projectRoot) {
33
+ throw new Error("Not in dexto project context");
34
+ }
35
+ basePath = path.join(projectRoot, ".dexto", type);
36
+ break;
37
+ }
38
+ case "global-cli": {
39
+ basePath = path.join(homedir(), ".dexto", type);
40
+ break;
41
+ }
42
+ default: {
43
+ throw new Error(`Unknown execution context: ${context}`);
44
+ }
45
+ }
46
+ return filename ? path.join(basePath, filename) : basePath;
47
+ }
48
+ function getDextoGlobalPath(type, filename) {
49
+ const basePath = path.join(homedir(), ".dexto", type);
50
+ return filename ? path.join(basePath, filename) : basePath;
51
+ }
52
+ async function copyDirectory(src, dest) {
53
+ await fs.mkdir(dest, { recursive: true });
54
+ const entries = await fs.readdir(src, { withFileTypes: true });
55
+ for (const entry of entries) {
56
+ const srcPath = path.join(src, entry.name);
57
+ const destPath = path.join(dest, entry.name);
58
+ if (entry.isDirectory()) {
59
+ await copyDirectory(srcPath, destPath);
60
+ } else {
61
+ await fs.copyFile(srcPath, destPath);
62
+ }
63
+ }
64
+ }
65
+ function isPath(str) {
66
+ if (path.isAbsolute(str)) return true;
67
+ if (/[\\/]/.test(str)) return true;
68
+ if (/\.(ya?ml|json)$/i.test(str)) return true;
69
+ return false;
70
+ }
71
+ function findPackageRoot(startPath = process.cwd()) {
72
+ return walkUpDirectories(startPath, (dirPath) => {
73
+ const pkgPath = path.join(dirPath, "package.json");
74
+ return existsSync(pkgPath);
75
+ });
76
+ }
77
+ function resolveBundledScript(scriptPath) {
78
+ const candidates = scriptPath.startsWith("dist/") ? [scriptPath, scriptPath.replace(/^dist\//, "")] : [`dist/${scriptPath}`, scriptPath];
79
+ const triedAbs = [];
80
+ const tryRoots = (roots) => {
81
+ for (const root of roots) {
82
+ if (!root) continue;
83
+ for (const rel of candidates) {
84
+ const abs = path.resolve(root, rel);
85
+ if (existsSync(abs)) return abs;
86
+ triedAbs.push(abs);
87
+ }
88
+ }
89
+ return null;
90
+ };
91
+ const envRoot = process?.env?.DEXTO_PACKAGE_ROOT;
92
+ const fromEnv = tryRoots([envRoot]);
93
+ if (fromEnv) return fromEnv;
94
+ try {
95
+ const require2 = createRequire(import.meta.url);
96
+ const pkgJson = require2.resolve("dexto/package.json");
97
+ const pkgRoot = path.dirname(pkgJson);
98
+ const fromPkg = tryRoots([pkgRoot]);
99
+ if (fromPkg) return fromPkg;
100
+ } catch {
101
+ }
102
+ try {
103
+ const thisModuleDir = path.dirname(fileURLToPath(import.meta.url));
104
+ const sourceRoot = findDextoSourceRoot(thisModuleDir);
105
+ const fromSource = tryRoots([sourceRoot ?? void 0]);
106
+ if (fromSource) return fromSource;
107
+ } catch {
108
+ }
109
+ const repoRoot = findPackageRoot();
110
+ const fromCwd = tryRoots([repoRoot ?? void 0]);
111
+ if (fromCwd) return fromCwd;
112
+ throw new Error(
113
+ `Bundled script not found: ${scriptPath} (tried absolute: ${triedAbs.join(", ")})`
114
+ );
115
+ }
116
+ async function ensureDextoGlobalDirectory() {
117
+ const dextoDir = path.join(homedir(), ".dexto");
118
+ try {
119
+ await fs.mkdir(dextoDir, { recursive: true });
120
+ } catch (error) {
121
+ if (error.code !== "EEXIST") {
122
+ throw error;
123
+ }
124
+ }
125
+ }
126
+ function getDextoEnvPath(startPath = process.cwd()) {
127
+ const context = getExecutionContext(startPath);
128
+ let envPath = "";
129
+ switch (context) {
130
+ case "dexto-source": {
131
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
132
+ if (isDevMode) {
133
+ const sourceRoot = findDextoSourceRoot(startPath);
134
+ if (!sourceRoot) {
135
+ throw new Error("Not in dexto source context");
136
+ }
137
+ envPath = path.join(sourceRoot, ".env");
138
+ } else {
139
+ envPath = path.join(homedir(), ".dexto", ".env");
140
+ }
141
+ break;
142
+ }
143
+ case "dexto-project": {
144
+ const projectRoot = findDextoProjectRoot(startPath);
145
+ if (!projectRoot) {
146
+ throw new Error("Not in dexto project context");
147
+ }
148
+ envPath = path.join(projectRoot, ".env");
149
+ break;
150
+ }
151
+ case "global-cli": {
152
+ envPath = path.join(homedir(), ".dexto", ".env");
153
+ break;
154
+ }
155
+ }
156
+ return envPath;
157
+ }
158
+ export {
159
+ copyDirectory,
160
+ ensureDextoGlobalDirectory,
161
+ findPackageRoot,
162
+ getDextoEnvPath,
163
+ getDextoGlobalPath,
164
+ getDextoPath,
165
+ isPath,
166
+ resolveBundledScript
167
+ };
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var writer_exports = {};
30
+ __export(writer_exports, {
31
+ writeConfigFile: () => writeConfigFile,
32
+ writeLLMPreferences: () => writeLLMPreferences,
33
+ writePreferencesToAgent: () => writePreferencesToAgent
34
+ });
35
+ module.exports = __toCommonJS(writer_exports);
36
+ var import_fs = require("fs");
37
+ var import_yaml = require("yaml");
38
+ var path = __toESM(require("path"), 1);
39
+ var import_core = require("@dexto/core");
40
+ var import_config = require("./config/index.js");
41
+ async function writeConfigFile(configPath, config) {
42
+ const absolutePath = path.resolve(configPath);
43
+ try {
44
+ const yamlContent = (0, import_yaml.stringify)(config, { indent: 2 });
45
+ await import_fs.promises.writeFile(absolutePath, yamlContent, "utf-8");
46
+ import_core.logger.debug(`Wrote dexto config to: ${absolutePath}`);
47
+ } catch (error) {
48
+ throw import_config.ConfigError.fileWriteError(
49
+ absolutePath,
50
+ error instanceof Error ? error.message : String(error)
51
+ );
52
+ }
53
+ }
54
+ async function writeLLMPreferences(configPath, preferences, overrides) {
55
+ import_core.logger.debug(`Writing LLM preferences to: ${configPath}`, {
56
+ provider: overrides?.provider ?? preferences.llm.provider,
57
+ model: overrides?.model ?? preferences.llm.model,
58
+ hasApiKeyOverride: Boolean(overrides?.apiKey),
59
+ hasPreferenceApiKey: Boolean(preferences.llm.apiKey)
60
+ });
61
+ import_core.logger.debug(`Reading config file: ${configPath}`);
62
+ let fileContent;
63
+ try {
64
+ fileContent = await import_fs.promises.readFile(configPath, "utf-8");
65
+ import_core.logger.debug(`Successfully read config file (${fileContent.length} chars)`);
66
+ } catch (error) {
67
+ import_core.logger.error(`Failed to read config file: ${configPath}`, { error });
68
+ throw import_config.ConfigError.fileReadError(
69
+ configPath,
70
+ error instanceof Error ? error.message : String(error)
71
+ );
72
+ }
73
+ let config;
74
+ try {
75
+ config = (0, import_yaml.parse)(fileContent);
76
+ import_core.logger.debug(`Successfully parsed YAML config`, {
77
+ hasLlmSection: Boolean(config.llm),
78
+ existingProvider: config.llm?.provider,
79
+ existingModel: config.llm?.model
80
+ });
81
+ } catch (error) {
82
+ import_core.logger.error(`Failed to parse YAML config: ${configPath}`, { error });
83
+ throw import_config.ConfigError.parseError(
84
+ configPath,
85
+ error instanceof Error ? error.message : String(error)
86
+ );
87
+ }
88
+ const provider = overrides?.provider ?? preferences.llm.provider;
89
+ const model = overrides?.model ?? preferences.llm.model;
90
+ const apiKey = overrides?.apiKey ?? preferences.llm.apiKey;
91
+ import_core.logger.debug(`Applying LLM preferences`, {
92
+ finalProvider: provider,
93
+ finalModel: model,
94
+ hasApiKey: Boolean(apiKey),
95
+ source: overrides ? "CLI overrides + preferences" : "preferences only"
96
+ });
97
+ config.llm = {
98
+ ...config.llm,
99
+ // Preserve temperature, router, maxTokens, etc.
100
+ provider,
101
+ // Write user preference
102
+ model,
103
+ // Write user preference
104
+ apiKey
105
+ // Write user preference
106
+ };
107
+ await writeConfigFile(configPath, config);
108
+ import_core.logger.info(`\u2713 Applied preferences to: ${path.basename(configPath)} (${provider}/${model})`);
109
+ }
110
+ async function writePreferencesToAgent(installedPath, preferences, overrides) {
111
+ let stat;
112
+ try {
113
+ stat = await import_fs.promises.stat(installedPath);
114
+ } catch (error) {
115
+ throw import_config.ConfigError.fileReadError(
116
+ installedPath,
117
+ error instanceof Error ? error.message : String(error)
118
+ );
119
+ }
120
+ if (stat.isFile()) {
121
+ if (installedPath.endsWith(".yml") || installedPath.endsWith(".yaml")) {
122
+ await writeLLMPreferences(installedPath, preferences, overrides);
123
+ import_core.logger.info(`\u2713 Applied preferences to: ${path.basename(installedPath)}`, null, "green");
124
+ } else {
125
+ import_core.logger.warn(`Skipping non-YAML file: ${installedPath}`, null, "yellow");
126
+ }
127
+ } else if (stat.isDirectory()) {
128
+ await writePreferencesToDirectory(installedPath, preferences, overrides);
129
+ } else {
130
+ throw import_config.ConfigError.fileReadError(installedPath, "Path is neither a file nor directory");
131
+ }
132
+ }
133
+ async function writePreferencesToDirectory(installedDir, preferences, overrides) {
134
+ const configFiles = await findAgentConfigFiles(installedDir);
135
+ if (configFiles.length === 0) {
136
+ import_core.logger.warn(`No YAML config files found in: ${installedDir}`);
137
+ return;
138
+ }
139
+ let successCount = 0;
140
+ const oldProvider = preferences.llm.provider;
141
+ const oldModel = preferences.llm.model;
142
+ const newProvider = overrides?.provider ?? preferences.llm.provider;
143
+ const newModel = overrides?.model ?? preferences.llm.model;
144
+ for (const configPath of configFiles) {
145
+ try {
146
+ await writeLLMPreferences(configPath, preferences, overrides);
147
+ import_core.logger.debug(`Applied preferences to: ${path.relative(installedDir, configPath)}`);
148
+ successCount++;
149
+ } catch (error) {
150
+ import_core.logger.warn(
151
+ `Failed to write preferences to ${configPath}: ${error instanceof Error ? error.message : String(error)}`
152
+ );
153
+ }
154
+ }
155
+ import_core.logger.info(
156
+ `\u2713 Applied preferences to ${successCount}/${configFiles.length} config files (${oldProvider}\u2192${newProvider}, ${oldModel}\u2192${newModel})`
157
+ );
158
+ }
159
+ async function findAgentConfigFiles(dir) {
160
+ const configFiles = [];
161
+ async function walkDir(currentDir) {
162
+ const entries = await import_fs.promises.readdir(currentDir, { withFileTypes: true });
163
+ for (const entry of entries) {
164
+ const fullPath = path.join(currentDir, entry.name);
165
+ if (entry.isDirectory()) {
166
+ if (!["docs", "data"].includes(entry.name)) {
167
+ await walkDir(fullPath);
168
+ }
169
+ } else if (entry.name.endsWith(".yml") || entry.name.endsWith(".yaml")) {
170
+ configFiles.push(fullPath);
171
+ }
172
+ }
173
+ }
174
+ await walkDir(dir);
175
+ return configFiles;
176
+ }
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ writeConfigFile,
180
+ writeLLMPreferences,
181
+ writePreferencesToAgent
182
+ });
@@ -0,0 +1,34 @@
1
+ import type { LLMProvider, AgentConfig } from '@dexto/core';
2
+ import { type GlobalPreferences } from './preferences/schemas.js';
3
+ export interface LLMOverrides {
4
+ provider?: LLMProvider;
5
+ model?: string;
6
+ apiKey?: string;
7
+ }
8
+ /**
9
+ * Asynchronously writes the given agent configuration object to a YAML file.
10
+ * This function handles the serialization of the config object to YAML format
11
+ * and writes it to the specified file path.
12
+ *
13
+ * @param configPath - Path where the configuration file should be written (absolute or relative)
14
+ * @param config - The `AgentConfig` object to be written to the file
15
+ * @returns A Promise that resolves when the file has been successfully written
16
+ * @throws {ConfigError} with FILE_WRITE_ERROR if an error occurs during YAML stringification or file writing
17
+ */
18
+ export declare function writeConfigFile(configPath: string, config: AgentConfig): Promise<void>;
19
+ /**
20
+ * Write global LLM preferences to an agent config file
21
+ * @param configPath Absolute path to agent configuration file
22
+ * @param preferences Global preferences to write
23
+ * @param overrides Optional CLI overrides
24
+ * @throws DextoRuntimeError for write failures
25
+ */
26
+ export declare function writeLLMPreferences(configPath: string, preferences: GlobalPreferences, overrides?: LLMOverrides): Promise<void>;
27
+ /**
28
+ * Write preferences to an installed agent (file or directory)
29
+ * @param installedPath Path to installed agent file or directory
30
+ * @param preferences Global preferences to write
31
+ * @param overrides Optional CLI overrides
32
+ */
33
+ export declare function writePreferencesToAgent(installedPath: string, preferences: GlobalPreferences, overrides?: LLMOverrides): Promise<void>;
34
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5F;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACrC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAiEf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CACzC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAyBf"}