@fractary/codex-cli 0.10.11 → 0.10.13

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.js CHANGED
@@ -3,8 +3,8 @@ import * as path5 from 'path';
3
3
  import { dirname, join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import * as fs from 'fs/promises';
6
- import * as yaml from 'js-yaml';
7
- import { ValidationError, PermissionDeniedError, ConfigurationError, CodexError } from '@fractary/codex';
6
+ import * as yaml2 from 'js-yaml';
7
+ import { readCodexConfig, expandEnvVarsInConfig, expandEnvVars, parseSize, parseDuration, ValidationError, PermissionDeniedError, ConfigurationError, CodexError } from '@fractary/codex';
8
8
  import * as os from 'os';
9
9
  import { spawn } from 'child_process';
10
10
  import { Command } from 'commander';
@@ -38,7 +38,7 @@ __export(migrate_config_exports, {
38
38
  getDefaultYamlConfig: () => getDefaultYamlConfig,
39
39
  isLegacyConfig: () => isLegacyConfig,
40
40
  migrateConfig: () => migrateConfig,
41
- readYamlConfig: () => readYamlConfig,
41
+ readYamlConfig: () => readCodexConfig,
42
42
  writeYamlConfig: () => writeYamlConfig
43
43
  });
44
44
  async function isLegacyConfig(configPath) {
@@ -163,7 +163,7 @@ async function migrateConfig(legacyConfigPath, options) {
163
163
  async function writeYamlConfig(config, outputPath) {
164
164
  const dir = path5.dirname(outputPath);
165
165
  await fs.mkdir(dir, { recursive: true });
166
- const yamlContent = yaml.dump(config, {
166
+ const yamlContent = yaml2.dump(config, {
167
167
  indent: 2,
168
168
  lineWidth: 80,
169
169
  noRefs: true,
@@ -228,20 +228,6 @@ function getDefaultYamlConfig(organization) {
228
228
  }
229
229
  };
230
230
  }
231
- async function readYamlConfig(configPath) {
232
- const content = await fs.readFile(configPath, "utf-8");
233
- const rawConfig = yaml.load(content);
234
- let config;
235
- if (rawConfig.codex && typeof rawConfig.codex === "object") {
236
- config = rawConfig.codex;
237
- } else {
238
- config = rawConfig;
239
- }
240
- if (!config.organization) {
241
- throw new Error("Invalid config: organization is required");
242
- }
243
- return config;
244
- }
245
231
  var init_migrate_config = __esm({
246
232
  "src/config/migrate-config.ts"() {
247
233
  init_esm_shims();
@@ -253,89 +239,9 @@ var config_types_exports = {};
253
239
  __export(config_types_exports, {
254
240
  parseDuration: () => parseDuration,
255
241
  parseSize: () => parseSize,
256
- resolveEnvVars: () => resolveEnvVars,
257
- resolveEnvVarsInConfig: () => resolveEnvVarsInConfig
242
+ resolveEnvVars: () => expandEnvVars,
243
+ resolveEnvVarsInConfig: () => expandEnvVarsInConfig
258
244
  });
259
- function parseDuration(duration) {
260
- if (typeof duration === "number") {
261
- return duration;
262
- }
263
- const match = duration.match(/^(\d+)([smhdwMy])$/);
264
- if (!match) {
265
- throw new Error(`Invalid duration format: ${duration}`);
266
- }
267
- const [, valueStr, unit] = match;
268
- const value = parseInt(valueStr, 10);
269
- switch (unit) {
270
- case "s":
271
- return value;
272
- case "m":
273
- return value * 60;
274
- case "h":
275
- return value * 3600;
276
- case "d":
277
- return value * 86400;
278
- case "w":
279
- return value * 604800;
280
- case "M":
281
- return value * 2592e3;
282
- // 30 days
283
- case "y":
284
- return value * 31536e3;
285
- // 365 days
286
- default:
287
- throw new Error(`Unknown duration unit: ${unit}`);
288
- }
289
- }
290
- function parseSize(size) {
291
- if (typeof size === "number") {
292
- return size;
293
- }
294
- const match = size.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i);
295
- if (!match) {
296
- throw new Error(`Invalid size format: ${size}`);
297
- }
298
- const [, valueStr, unit] = match;
299
- const value = parseFloat(valueStr);
300
- switch (unit.toUpperCase()) {
301
- case "B":
302
- return value;
303
- case "KB":
304
- return value * 1024;
305
- case "MB":
306
- return value * 1024 * 1024;
307
- case "GB":
308
- return value * 1024 * 1024 * 1024;
309
- default:
310
- throw new Error(`Unknown size unit: ${unit}`);
311
- }
312
- }
313
- function resolveEnvVars(value) {
314
- return value.replace(/\$\{([^}]+)\}/g, (_, varName) => {
315
- const envValue = process.env[varName];
316
- if (envValue === void 0) {
317
- console.warn(`Warning: Environment variable ${varName} is not set`);
318
- return `\${${varName}}`;
319
- }
320
- return envValue;
321
- });
322
- }
323
- function resolveEnvVarsInConfig(config) {
324
- if (typeof config === "string") {
325
- return resolveEnvVars(config);
326
- }
327
- if (Array.isArray(config)) {
328
- return config.map((item) => resolveEnvVarsInConfig(item));
329
- }
330
- if (config !== null && typeof config === "object") {
331
- const result = {};
332
- for (const [key, value] of Object.entries(config)) {
333
- result[key] = resolveEnvVarsInConfig(value);
334
- }
335
- return result;
336
- }
337
- return config;
338
- }
339
245
  var init_config_types = __esm({
340
246
  "src/config/config-types.ts"() {
341
247
  init_esm_shims();
@@ -388,14 +294,14 @@ var init_codex_client = __esm({
388
294
  CodexError: CodexError2,
389
295
  ConfigurationError: ConfigurationError2
390
296
  } = await import('@fractary/codex');
391
- const { readYamlConfig: readYamlConfig2 } = await Promise.resolve().then(() => (init_migrate_config(), migrate_config_exports));
392
- const { resolveEnvVarsInConfig: resolveEnvVarsInConfig2 } = await Promise.resolve().then(() => (init_config_types(), config_types_exports));
297
+ const { readYamlConfig } = await Promise.resolve().then(() => (init_migrate_config(), migrate_config_exports));
298
+ const { resolveEnvVarsInConfig } = await Promise.resolve().then(() => (init_config_types(), config_types_exports));
393
299
  try {
394
300
  const configPath = path5.join(process.cwd(), ".fractary", "config.yaml");
395
301
  let config;
396
302
  try {
397
- config = await readYamlConfig2(configPath);
398
- config = resolveEnvVarsInConfig2(config);
303
+ config = await readYamlConfig(configPath);
304
+ config = resolveEnvVarsInConfig(config);
399
305
  } catch (error) {
400
306
  throw new ConfigurationError2(
401
307
  `Failed to load configuration from ${configPath}. Run "fractary codex init" to create a configuration.`
@@ -932,7 +838,7 @@ function getDefaultUnifiedConfig(organization, project, codexRepo) {
932
838
  async function readUnifiedConfig(configPath) {
933
839
  try {
934
840
  const content = await fs.readFile(configPath, "utf-8");
935
- const config = yaml.load(content);
841
+ const config = yaml2.load(content);
936
842
  return config;
937
843
  } catch (error) {
938
844
  if (error.code === "ENOENT") {
@@ -944,7 +850,7 @@ async function readUnifiedConfig(configPath) {
944
850
  async function writeUnifiedConfig(config, outputPath) {
945
851
  const dir = path5.dirname(outputPath);
946
852
  await fs.mkdir(dir, { recursive: true });
947
- const yamlContent = yaml.dump(config, {
853
+ const yamlContent = yaml2.dump(config, {
948
854
  indent: 2,
949
855
  lineWidth: 120,
950
856
  noRefs: true,
@@ -1539,7 +1445,7 @@ async function checkConfiguration() {
1539
1445
  details: 'Run "fractary codex init" to create configuration'
1540
1446
  };
1541
1447
  }
1542
- const config = await readYamlConfig(configPath);
1448
+ const config = await readCodexConfig(configPath);
1543
1449
  if (!config.organization) {
1544
1450
  return {
1545
1451
  name: "Configuration",
@@ -1630,7 +1536,7 @@ async function checkCache() {
1630
1536
  async function checkStorage() {
1631
1537
  const configPath = path5.join(process.cwd(), ".fractary", "config.yaml");
1632
1538
  try {
1633
- const config = await readYamlConfig(configPath);
1539
+ const config = await readCodexConfig(configPath);
1634
1540
  const providers = config.storage || [];
1635
1541
  if (providers.length === 0) {
1636
1542
  return {
@@ -1789,7 +1695,7 @@ function syncCommand() {
1789
1695
  const configPath = path5.join(process.cwd(), ".fractary", "config.yaml");
1790
1696
  let config;
1791
1697
  try {
1792
- config = await readYamlConfig(configPath);
1698
+ config = await readCodexConfig(configPath);
1793
1699
  } catch (error) {
1794
1700
  console.error(chalk7.red("Error:"), "Codex not initialized.");
1795
1701
  console.log(chalk7.dim('Run "fractary codex init" first.'));
@@ -2357,7 +2263,7 @@ function typesAddCommand() {
2357
2263
  process.exit(1);
2358
2264
  }
2359
2265
  const configPath = path5.join(process.cwd(), ".fractary", "config.yaml");
2360
- const config = await readYamlConfig(configPath);
2266
+ const config = await readCodexConfig(configPath);
2361
2267
  if (!config.types) {
2362
2268
  config.types = { custom: {} };
2363
2269
  }
@@ -2426,7 +2332,7 @@ function typesRemoveCommand() {
2426
2332
  }
2427
2333
  const typeInfo = registry.get(name);
2428
2334
  const configPath = path5.join(process.cwd(), ".fractary", "config.yaml");
2429
- const config = await readYamlConfig(configPath);
2335
+ const config = await readCodexConfig(configPath);
2430
2336
  if (!config.types?.custom?.[name]) {
2431
2337
  console.error(chalk7.red("Error:"), `Custom type "${name}" not found in configuration.`);
2432
2338
  process.exit(1);