@fractary/codex-cli 0.10.10 → 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.cjs +23 -114
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +21 -112
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var fs$1 = require('fs/promises');
|
|
5
5
|
var path4 = require('path');
|
|
6
|
-
var
|
|
6
|
+
var yaml2 = require('js-yaml');
|
|
7
7
|
var codex = require('@fractary/codex');
|
|
8
8
|
var os = require('os');
|
|
9
9
|
var child_process = require('child_process');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
|
|
36
36
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs$1);
|
|
37
37
|
var path4__namespace = /*#__PURE__*/_interopNamespace(path4);
|
|
38
|
-
var
|
|
38
|
+
var yaml2__namespace = /*#__PURE__*/_interopNamespace(yaml2);
|
|
39
39
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
40
40
|
var chalk7__default = /*#__PURE__*/_interopDefault(chalk7);
|
|
41
41
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
@@ -71,7 +71,7 @@ __export(migrate_config_exports, {
|
|
|
71
71
|
getDefaultYamlConfig: () => getDefaultYamlConfig,
|
|
72
72
|
isLegacyConfig: () => isLegacyConfig,
|
|
73
73
|
migrateConfig: () => migrateConfig,
|
|
74
|
-
readYamlConfig: () =>
|
|
74
|
+
readYamlConfig: () => codex.readCodexConfig,
|
|
75
75
|
writeYamlConfig: () => writeYamlConfig
|
|
76
76
|
});
|
|
77
77
|
async function isLegacyConfig(configPath) {
|
|
@@ -196,7 +196,7 @@ async function migrateConfig(legacyConfigPath, options) {
|
|
|
196
196
|
async function writeYamlConfig(config, outputPath) {
|
|
197
197
|
const dir = path4__namespace.dirname(outputPath);
|
|
198
198
|
await fs__namespace.mkdir(dir, { recursive: true });
|
|
199
|
-
const yamlContent =
|
|
199
|
+
const yamlContent = yaml2__namespace.dump(config, {
|
|
200
200
|
indent: 2,
|
|
201
201
|
lineWidth: 80,
|
|
202
202
|
noRefs: true,
|
|
@@ -261,20 +261,6 @@ function getDefaultYamlConfig(organization) {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
|
-
async function readYamlConfig(configPath) {
|
|
265
|
-
const content = await fs__namespace.readFile(configPath, "utf-8");
|
|
266
|
-
const rawConfig = yaml__namespace.load(content);
|
|
267
|
-
let config;
|
|
268
|
-
if (rawConfig.codex && typeof rawConfig.codex === "object") {
|
|
269
|
-
config = rawConfig.codex;
|
|
270
|
-
} else {
|
|
271
|
-
config = rawConfig;
|
|
272
|
-
}
|
|
273
|
-
if (!config.organization) {
|
|
274
|
-
throw new Error("Invalid config: organization is required");
|
|
275
|
-
}
|
|
276
|
-
return config;
|
|
277
|
-
}
|
|
278
264
|
var init_migrate_config = __esm({
|
|
279
265
|
"src/config/migrate-config.ts"() {
|
|
280
266
|
init_cjs_shims();
|
|
@@ -284,91 +270,11 @@ var init_migrate_config = __esm({
|
|
|
284
270
|
// src/config/config-types.ts
|
|
285
271
|
var config_types_exports = {};
|
|
286
272
|
__export(config_types_exports, {
|
|
287
|
-
parseDuration: () => parseDuration,
|
|
288
|
-
parseSize: () => parseSize,
|
|
289
|
-
resolveEnvVars: () =>
|
|
290
|
-
resolveEnvVarsInConfig: () =>
|
|
273
|
+
parseDuration: () => codex.parseDuration,
|
|
274
|
+
parseSize: () => codex.parseSize,
|
|
275
|
+
resolveEnvVars: () => codex.expandEnvVars,
|
|
276
|
+
resolveEnvVarsInConfig: () => codex.expandEnvVarsInConfig
|
|
291
277
|
});
|
|
292
|
-
function parseDuration(duration) {
|
|
293
|
-
if (typeof duration === "number") {
|
|
294
|
-
return duration;
|
|
295
|
-
}
|
|
296
|
-
const match = duration.match(/^(\d+)([smhdwMy])$/);
|
|
297
|
-
if (!match) {
|
|
298
|
-
throw new Error(`Invalid duration format: ${duration}`);
|
|
299
|
-
}
|
|
300
|
-
const [, valueStr, unit] = match;
|
|
301
|
-
const value = parseInt(valueStr, 10);
|
|
302
|
-
switch (unit) {
|
|
303
|
-
case "s":
|
|
304
|
-
return value;
|
|
305
|
-
case "m":
|
|
306
|
-
return value * 60;
|
|
307
|
-
case "h":
|
|
308
|
-
return value * 3600;
|
|
309
|
-
case "d":
|
|
310
|
-
return value * 86400;
|
|
311
|
-
case "w":
|
|
312
|
-
return value * 604800;
|
|
313
|
-
case "M":
|
|
314
|
-
return value * 2592e3;
|
|
315
|
-
// 30 days
|
|
316
|
-
case "y":
|
|
317
|
-
return value * 31536e3;
|
|
318
|
-
// 365 days
|
|
319
|
-
default:
|
|
320
|
-
throw new Error(`Unknown duration unit: ${unit}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function parseSize(size) {
|
|
324
|
-
if (typeof size === "number") {
|
|
325
|
-
return size;
|
|
326
|
-
}
|
|
327
|
-
const match = size.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i);
|
|
328
|
-
if (!match) {
|
|
329
|
-
throw new Error(`Invalid size format: ${size}`);
|
|
330
|
-
}
|
|
331
|
-
const [, valueStr, unit] = match;
|
|
332
|
-
const value = parseFloat(valueStr);
|
|
333
|
-
switch (unit.toUpperCase()) {
|
|
334
|
-
case "B":
|
|
335
|
-
return value;
|
|
336
|
-
case "KB":
|
|
337
|
-
return value * 1024;
|
|
338
|
-
case "MB":
|
|
339
|
-
return value * 1024 * 1024;
|
|
340
|
-
case "GB":
|
|
341
|
-
return value * 1024 * 1024 * 1024;
|
|
342
|
-
default:
|
|
343
|
-
throw new Error(`Unknown size unit: ${unit}`);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function resolveEnvVars(value) {
|
|
347
|
-
return value.replace(/\$\{([^}]+)\}/g, (_, varName) => {
|
|
348
|
-
const envValue = process.env[varName];
|
|
349
|
-
if (envValue === void 0) {
|
|
350
|
-
console.warn(`Warning: Environment variable ${varName} is not set`);
|
|
351
|
-
return `\${${varName}}`;
|
|
352
|
-
}
|
|
353
|
-
return envValue;
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
function resolveEnvVarsInConfig(config) {
|
|
357
|
-
if (typeof config === "string") {
|
|
358
|
-
return resolveEnvVars(config);
|
|
359
|
-
}
|
|
360
|
-
if (Array.isArray(config)) {
|
|
361
|
-
return config.map((item) => resolveEnvVarsInConfig(item));
|
|
362
|
-
}
|
|
363
|
-
if (config !== null && typeof config === "object") {
|
|
364
|
-
const result = {};
|
|
365
|
-
for (const [key, value] of Object.entries(config)) {
|
|
366
|
-
result[key] = resolveEnvVarsInConfig(value);
|
|
367
|
-
}
|
|
368
|
-
return result;
|
|
369
|
-
}
|
|
370
|
-
return config;
|
|
371
|
-
}
|
|
372
278
|
var init_config_types = __esm({
|
|
373
279
|
"src/config/config-types.ts"() {
|
|
374
280
|
init_cjs_shims();
|
|
@@ -421,14 +327,14 @@ var init_codex_client = __esm({
|
|
|
421
327
|
CodexError: CodexError2,
|
|
422
328
|
ConfigurationError: ConfigurationError2
|
|
423
329
|
} = await import('@fractary/codex');
|
|
424
|
-
const { readYamlConfig
|
|
425
|
-
const { resolveEnvVarsInConfig
|
|
330
|
+
const { readYamlConfig } = await Promise.resolve().then(() => (init_migrate_config(), migrate_config_exports));
|
|
331
|
+
const { resolveEnvVarsInConfig } = await Promise.resolve().then(() => (init_config_types(), config_types_exports));
|
|
426
332
|
try {
|
|
427
333
|
const configPath = path4__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
428
334
|
let config;
|
|
429
335
|
try {
|
|
430
|
-
config = await
|
|
431
|
-
config =
|
|
336
|
+
config = await readYamlConfig(configPath);
|
|
337
|
+
config = resolveEnvVarsInConfig(config);
|
|
432
338
|
} catch (error) {
|
|
433
339
|
throw new ConfigurationError2(
|
|
434
340
|
`Failed to load configuration from ${configPath}. Run "fractary codex init" to create a configuration.`
|
|
@@ -965,7 +871,7 @@ function getDefaultUnifiedConfig(organization, project, codexRepo) {
|
|
|
965
871
|
async function readUnifiedConfig(configPath) {
|
|
966
872
|
try {
|
|
967
873
|
const content = await fs__namespace.readFile(configPath, "utf-8");
|
|
968
|
-
const config =
|
|
874
|
+
const config = yaml2__namespace.load(content);
|
|
969
875
|
return config;
|
|
970
876
|
} catch (error) {
|
|
971
877
|
if (error.code === "ENOENT") {
|
|
@@ -977,7 +883,7 @@ async function readUnifiedConfig(configPath) {
|
|
|
977
883
|
async function writeUnifiedConfig(config, outputPath) {
|
|
978
884
|
const dir = path4__namespace.dirname(outputPath);
|
|
979
885
|
await fs__namespace.mkdir(dir, { recursive: true });
|
|
980
|
-
const yamlContent =
|
|
886
|
+
const yamlContent = yaml2__namespace.dump(config, {
|
|
981
887
|
indent: 2,
|
|
982
888
|
lineWidth: 120,
|
|
983
889
|
noRefs: true,
|
|
@@ -1572,7 +1478,7 @@ async function checkConfiguration() {
|
|
|
1572
1478
|
details: 'Run "fractary codex init" to create configuration'
|
|
1573
1479
|
};
|
|
1574
1480
|
}
|
|
1575
|
-
const config = await
|
|
1481
|
+
const config = await codex.readCodexConfig(configPath);
|
|
1576
1482
|
if (!config.organization) {
|
|
1577
1483
|
return {
|
|
1578
1484
|
name: "Configuration",
|
|
@@ -1663,7 +1569,7 @@ async function checkCache() {
|
|
|
1663
1569
|
async function checkStorage() {
|
|
1664
1570
|
const configPath = path4__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
1665
1571
|
try {
|
|
1666
|
-
const config = await
|
|
1572
|
+
const config = await codex.readCodexConfig(configPath);
|
|
1667
1573
|
const providers = config.storage || [];
|
|
1668
1574
|
if (providers.length === 0) {
|
|
1669
1575
|
return {
|
|
@@ -1822,7 +1728,7 @@ function syncCommand() {
|
|
|
1822
1728
|
const configPath = path4__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
1823
1729
|
let config;
|
|
1824
1730
|
try {
|
|
1825
|
-
config = await
|
|
1731
|
+
config = await codex.readCodexConfig(configPath);
|
|
1826
1732
|
} catch (error) {
|
|
1827
1733
|
console.error(chalk7__default.default.red("Error:"), "Codex not initialized.");
|
|
1828
1734
|
console.log(chalk7__default.default.dim('Run "fractary codex init" first.'));
|
|
@@ -1961,7 +1867,10 @@ function syncCommand() {
|
|
|
1961
1867
|
config.organization,
|
|
1962
1868
|
projectName,
|
|
1963
1869
|
codexRepoPath,
|
|
1964
|
-
|
|
1870
|
+
{
|
|
1871
|
+
...syncOptions,
|
|
1872
|
+
codexRepo: "codex_repo" in config ? config.codex_repo : void 0
|
|
1873
|
+
}
|
|
1965
1874
|
);
|
|
1966
1875
|
plan = planWithRouting;
|
|
1967
1876
|
routingScan = planWithRouting.routingScan;
|
|
@@ -2387,7 +2296,7 @@ function typesAddCommand() {
|
|
|
2387
2296
|
process.exit(1);
|
|
2388
2297
|
}
|
|
2389
2298
|
const configPath = path4__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
2390
|
-
const config = await
|
|
2299
|
+
const config = await codex.readCodexConfig(configPath);
|
|
2391
2300
|
if (!config.types) {
|
|
2392
2301
|
config.types = { custom: {} };
|
|
2393
2302
|
}
|
|
@@ -2456,7 +2365,7 @@ function typesRemoveCommand() {
|
|
|
2456
2365
|
}
|
|
2457
2366
|
const typeInfo = registry.get(name);
|
|
2458
2367
|
const configPath = path4__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
2459
|
-
const config = await
|
|
2368
|
+
const config = await codex.readCodexConfig(configPath);
|
|
2460
2369
|
if (!config.types?.custom?.[name]) {
|
|
2461
2370
|
console.error(chalk7__default.default.red("Error:"), `Custom type "${name}" not found in configuration.`);
|
|
2462
2371
|
process.exit(1);
|