@fractary/codex 0.12.0 → 0.12.2

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/index.js CHANGED
@@ -3,7 +3,8 @@ import * as path3 from 'path';
3
3
  import path3__default from 'path';
4
4
  import { execFile, execSync } from 'child_process';
5
5
  import { z } from 'zod';
6
- import yaml from 'js-yaml';
6
+ import * as yaml2 from 'js-yaml';
7
+ import yaml2__default from 'js-yaml';
7
8
  import * as fs3 from 'fs/promises';
8
9
  import fs3__default from 'fs/promises';
9
10
  import { promisify } from 'util';
@@ -1021,7 +1022,7 @@ function parseMetadata(content, options = {}) {
1021
1022
  const rawFrontmatter = frontmatterMatch[1];
1022
1023
  const documentContent = frontmatterMatch[2];
1023
1024
  try {
1024
- const parsed = yaml.load(rawFrontmatter);
1025
+ const parsed = yaml2__default.load(rawFrontmatter);
1025
1026
  const normalized = normalizeLegacyMetadata(parsed);
1026
1027
  const metadata = strict ? MetadataSchema.parse(normalized) : MetadataSchema.safeParse(normalized).data || {};
1027
1028
  return {
@@ -3929,17 +3930,17 @@ var SyncManager = class {
3929
3930
  if (file.operation === "create" || file.operation === "update") {
3930
3931
  const sourcePath = `${plan.source}/${file.path}`;
3931
3932
  const targetPath = `${plan.target}/${file.path}`;
3932
- const fs5 = await import('fs/promises');
3933
+ const fs6 = await import('fs/promises');
3933
3934
  const path7 = await import('path');
3934
3935
  const targetDir = path7.dirname(targetPath);
3935
- await fs5.mkdir(targetDir, { recursive: true });
3936
- await fs5.copyFile(sourcePath, targetPath);
3936
+ await fs6.mkdir(targetDir, { recursive: true });
3937
+ await fs6.copyFile(sourcePath, targetPath);
3937
3938
  synced++;
3938
3939
  } else if (file.operation === "delete") {
3939
3940
  const targetPath = `${plan.target}/${file.path}`;
3940
- const fs5 = await import('fs/promises');
3941
+ const fs6 = await import('fs/promises');
3941
3942
  try {
3942
- await fs5.unlink(targetPath);
3943
+ await fs6.unlink(targetPath);
3943
3944
  synced++;
3944
3945
  } catch (error) {
3945
3946
  if (error.code !== "ENOENT") {
@@ -4944,6 +4945,176 @@ function generateReferenceMigrationSummary(results) {
4944
4945
  return lines.join("\n");
4945
4946
  }
4946
4947
 
4947
- export { AutoSyncPatternSchema, BUILT_IN_TYPES, CODEX_URI_PREFIX, CacheManager, CachePersistence, CodexConfigSchema, CodexError, CommonRules, ConfigurationError, CustomTypeSchema, DEFAULT_CACHE_DIR, DEFAULT_FETCH_OPTIONS, DEFAULT_MIGRATION_OPTIONS, DEFAULT_PERMISSION_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TYPE, FilePluginFileNotFoundError, FilePluginStorage, GitHubStorage, HttpStorage, LEGACY_PATTERNS, LEGACY_REF_PREFIX, LocalStorage, MetadataSchema, PERMISSION_LEVEL_ORDER, PermissionDeniedError, PermissionManager, StorageManager, SyncManager, SyncRulesSchema, TTL, TypeRegistry, TypesConfigSchema, ValidationError, buildUri, calculateCachePath, calculateContentHash, convertLegacyReference, convertLegacyReferences, convertToUri, createCacheEntry, createCacheManager, createCachePersistence, createDefaultRegistry, createEmptyModernConfig, createEmptySyncPlan, createGitHubStorage, createHttpStorage, createLocalStorage, createPermissionManager, createRule, createRulesFromPatterns, createStorageManager, createSyncManager, createSyncPlan, deserializeCacheEntry, detectContentType, detectCurrentProject, detectVersion, estimateSyncTime, evaluatePath, evaluatePaths, evaluatePatterns, evaluatePermission, evaluatePermissions, extendType, extractOrgFromRepoName, extractRawFrontmatter, filterByPatterns, filterByPermission, filterPlanOperations, filterSyncablePaths, findLegacyReferences, formatPlanSummary, generateMigrationReport, generateReferenceMigrationSummary, getBuiltInType, getBuiltInTypeNames, getCacheEntryAge, getCacheEntryStatus, getCurrentContext, getCustomSyncDestinations, getDefaultCacheManager, getDefaultConfig, getDefaultDirectories, getDefaultPermissionManager, getDefaultRules, getDefaultStorageManager, getDirectory, getExtension, getFilename, getMigrationRequirements, getPlanStats, getRelativeCachePath, getRemainingTtl, getTargetRepos, hasContentChanged, hasFrontmatter, hasLegacyReferences, hasPermission as hasPermissionLevel, isBuiltInType, isCacheEntryFresh, isCacheEntryValid, isCurrentProjectUri, isLegacyConfig, isLegacyReference, isModernConfig, isAllowed as isPermissionAllowed, isValidUri, levelGrants, loadConfig, loadCustomTypes, matchAnyPattern, matchPattern, maxLevel, mergeFetchOptions, mergeRules, mergeTypes, migrateConfig, migrateFileReferences, minLevel, needsMigration, parseCustomDestination, parseMetadata, parseReference, parseTtl, resolveOrganization, resolveReference, resolveReferences, ruleMatchesAction, ruleMatchesContext, ruleMatchesPath, sanitizePath, serializeCacheEntry, setDefaultCacheManager, setDefaultPermissionManager, setDefaultStorageManager, shouldSyncToRepo, summarizeEvaluations, touchCacheEntry, validateCustomTypes, validateMetadata, validateMigratedConfig, validateOrg, validatePath, validateRules2 as validatePermissionRules, validateProject, validateRules, validateUri };
4948
+ // src/core/env/index.ts
4949
+ function expandEnvVars(value, options = {}) {
4950
+ const env = options.env ?? process.env;
4951
+ return value.replace(/\$\{([^}]+)\}/g, (match, varName) => {
4952
+ const envValue = env[varName];
4953
+ if (envValue === void 0) {
4954
+ if (options.warnOnMissing) {
4955
+ console.warn(`Warning: Environment variable ${varName} is not set`);
4956
+ }
4957
+ if (options.onMissing) {
4958
+ options.onMissing(varName);
4959
+ }
4960
+ return match;
4961
+ }
4962
+ return envValue;
4963
+ });
4964
+ }
4965
+ function expandEnvVarsInConfig(config, options = {}) {
4966
+ if (typeof config === "string") {
4967
+ return expandEnvVars(config, options);
4968
+ }
4969
+ if (Array.isArray(config)) {
4970
+ return config.map((item) => expandEnvVarsInConfig(item, options));
4971
+ }
4972
+ if (config !== null && typeof config === "object") {
4973
+ const result = {};
4974
+ for (const [key, value] of Object.entries(config)) {
4975
+ result[key] = expandEnvVarsInConfig(value, options);
4976
+ }
4977
+ return result;
4978
+ }
4979
+ return config;
4980
+ }
4981
+ function hasEnvVars(value) {
4982
+ return /\$\{[^}]+\}/.test(value);
4983
+ }
4984
+ function extractEnvVarNames(value) {
4985
+ const matches = value.matchAll(/\$\{([^}]+)\}/g);
4986
+ const names = [];
4987
+ for (const match of matches) {
4988
+ if (match[1]) {
4989
+ names.push(match[1]);
4990
+ }
4991
+ }
4992
+ return names;
4993
+ }
4994
+ async function readCodexConfig(configPath, options = {}) {
4995
+ const content = await fs3.readFile(configPath, "utf-8");
4996
+ const rawConfig = yaml2.load(content);
4997
+ let config;
4998
+ if (rawConfig?.codex && typeof rawConfig.codex === "object") {
4999
+ config = rawConfig.codex;
5000
+ } else {
5001
+ config = rawConfig;
5002
+ }
5003
+ if (!config.organization) {
5004
+ throw new Error("Invalid config: organization is required");
5005
+ }
5006
+ if (options.expandEnv !== false) {
5007
+ const envOptions = {
5008
+ env: options.env,
5009
+ warnOnMissing: options.warnOnMissingEnv
5010
+ };
5011
+ config = expandEnvVarsInConfig(config, envOptions);
5012
+ }
5013
+ return config;
5014
+ }
5015
+ async function readUnifiedConfig(configPath, options = {}) {
5016
+ const content = await fs3.readFile(configPath, "utf-8");
5017
+ let config = yaml2.load(content);
5018
+ if (options.expandEnv !== false) {
5019
+ const envOptions = {
5020
+ env: options.env,
5021
+ warnOnMissing: options.warnOnMissingEnv
5022
+ };
5023
+ config = expandEnvVarsInConfig(config, envOptions);
5024
+ }
5025
+ return config;
5026
+ }
5027
+ function isUnifiedConfig(config) {
5028
+ if (config === null || typeof config !== "object") {
5029
+ return false;
5030
+ }
5031
+ const maybeUnified = config;
5032
+ return "codex" in maybeUnified && maybeUnified.codex !== null && typeof maybeUnified.codex === "object";
5033
+ }
5034
+
5035
+ // src/core/utils/index.ts
5036
+ var DURATION_MULTIPLIERS = {
5037
+ s: 1,
5038
+ // seconds
5039
+ m: 60,
5040
+ // minutes
5041
+ h: 3600,
5042
+ // hours
5043
+ d: 86400,
5044
+ // days
5045
+ w: 604800,
5046
+ // weeks (7 days)
5047
+ M: 2592e3,
5048
+ // months (30 days)
5049
+ y: 31536e3
5050
+ // years (365 days)
5051
+ };
5052
+ var SIZE_MULTIPLIERS = {
5053
+ B: 1,
5054
+ KB: 1024,
5055
+ MB: 1024 * 1024,
5056
+ GB: 1024 * 1024 * 1024,
5057
+ TB: 1024 * 1024 * 1024 * 1024
5058
+ };
5059
+ function parseDuration(duration) {
5060
+ if (typeof duration === "number") {
5061
+ return duration;
5062
+ }
5063
+ const match = duration.match(/^(\d+(?:\.\d+)?)\s*([smhdwMy])$/);
5064
+ if (!match || !match[1] || !match[2]) {
5065
+ throw new Error(`Invalid duration format: ${duration}. Use format like "1h", "7d", "1M"`);
5066
+ }
5067
+ const valueStr = match[1];
5068
+ const unit = match[2];
5069
+ const value = parseFloat(valueStr);
5070
+ const multiplier = DURATION_MULTIPLIERS[unit];
5071
+ if (multiplier === void 0) {
5072
+ throw new Error(`Unknown duration unit: ${unit}`);
5073
+ }
5074
+ return Math.round(value * multiplier);
5075
+ }
5076
+ function parseSize(size) {
5077
+ if (typeof size === "number") {
5078
+ return size;
5079
+ }
5080
+ const match = size.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|TB)$/i);
5081
+ if (!match || !match[1] || !match[2]) {
5082
+ throw new Error(`Invalid size format: ${size}. Use format like "100MB", "1GB"`);
5083
+ }
5084
+ const valueStr = match[1];
5085
+ const unit = match[2];
5086
+ const value = parseFloat(valueStr);
5087
+ const multiplier = SIZE_MULTIPLIERS[unit.toUpperCase()];
5088
+ if (multiplier === void 0) {
5089
+ throw new Error(`Unknown size unit: ${unit}`);
5090
+ }
5091
+ return Math.round(value * multiplier);
5092
+ }
5093
+ function formatBytes2(bytes) {
5094
+ if (bytes < 1024) return `${bytes} B`;
5095
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
5096
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
5097
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
5098
+ }
5099
+ function formatDuration(ms) {
5100
+ if (ms < 1e3) return `${ms}ms`;
5101
+ if (ms < 6e4) return `${(ms / 1e3).toFixed(1)}s`;
5102
+ if (ms < 36e5) return `${(ms / 6e4).toFixed(1)}m`;
5103
+ return `${(ms / 36e5).toFixed(1)}h`;
5104
+ }
5105
+ function formatSeconds(seconds) {
5106
+ if (seconds < 60) return `${seconds}s`;
5107
+ if (seconds < 3600) return `${(seconds / 60).toFixed(1)}m`;
5108
+ if (seconds < 86400) return `${(seconds / 3600).toFixed(1)}h`;
5109
+ return `${(seconds / 86400).toFixed(1)}d`;
5110
+ }
5111
+ function isValidDuration(value) {
5112
+ return /^\d+(?:\.\d+)?\s*[smhdwMy]$/.test(value);
5113
+ }
5114
+ function isValidSize(value) {
5115
+ return /^\d+(?:\.\d+)?\s*(B|KB|MB|GB|TB)$/i.test(value);
5116
+ }
5117
+
5118
+ export { AutoSyncPatternSchema, BUILT_IN_TYPES, CODEX_URI_PREFIX, CacheManager, CachePersistence, CodexConfigSchema, CodexError, CommonRules, ConfigurationError, CustomTypeSchema, DEFAULT_CACHE_DIR, DEFAULT_FETCH_OPTIONS, DEFAULT_MIGRATION_OPTIONS, DEFAULT_PERMISSION_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TYPE, FilePluginFileNotFoundError, FilePluginStorage, GitHubStorage, HttpStorage, LEGACY_PATTERNS, LEGACY_REF_PREFIX, LocalStorage, MetadataSchema, PERMISSION_LEVEL_ORDER, PermissionDeniedError, PermissionManager, StorageManager, SyncManager, SyncRulesSchema, TTL, TypeRegistry, TypesConfigSchema, ValidationError, buildUri, calculateCachePath, calculateContentHash, convertLegacyReference, convertLegacyReferences, convertToUri, createCacheEntry, createCacheManager, createCachePersistence, createDefaultRegistry, createEmptyModernConfig, createEmptySyncPlan, createGitHubStorage, createHttpStorage, createLocalStorage, createPermissionManager, createRule, createRulesFromPatterns, createStorageManager, createSyncManager, createSyncPlan, deserializeCacheEntry, detectContentType, detectCurrentProject, detectVersion, estimateSyncTime, evaluatePath, evaluatePaths, evaluatePatterns, evaluatePermission, evaluatePermissions, expandEnvVars, expandEnvVarsInConfig, extendType, extractEnvVarNames, extractOrgFromRepoName, extractRawFrontmatter, filterByPatterns, filterByPermission, filterPlanOperations, filterSyncablePaths, findLegacyReferences, formatBytes2 as formatBytes, formatDuration, formatPlanSummary, formatSeconds, generateMigrationReport, generateReferenceMigrationSummary, getBuiltInType, getBuiltInTypeNames, getCacheEntryAge, getCacheEntryStatus, getCurrentContext, getCustomSyncDestinations, getDefaultCacheManager, getDefaultConfig, getDefaultDirectories, getDefaultPermissionManager, getDefaultRules, getDefaultStorageManager, getDirectory, getExtension, getFilename, getMigrationRequirements, getPlanStats, getRelativeCachePath, getRemainingTtl, getTargetRepos, hasContentChanged, hasEnvVars, hasFrontmatter, hasLegacyReferences, hasPermission as hasPermissionLevel, isBuiltInType, isCacheEntryFresh, isCacheEntryValid, isCurrentProjectUri, isLegacyConfig, isLegacyReference, isModernConfig, isAllowed as isPermissionAllowed, isUnifiedConfig, isValidDuration, isValidSize, isValidUri, levelGrants, loadConfig, loadCustomTypes, matchAnyPattern, matchPattern, maxLevel, mergeFetchOptions, mergeRules, mergeTypes, migrateConfig, migrateFileReferences, minLevel, needsMigration, parseCustomDestination, parseDuration, parseMetadata, parseReference, parseSize, parseTtl, readCodexConfig, readUnifiedConfig, resolveOrganization, resolveReference, resolveReferences, ruleMatchesAction, ruleMatchesContext, ruleMatchesPath, sanitizePath, serializeCacheEntry, setDefaultCacheManager, setDefaultPermissionManager, setDefaultStorageManager, shouldSyncToRepo, summarizeEvaluations, touchCacheEntry, validateCustomTypes, validateMetadata, validateMigratedConfig, validateOrg, validatePath, validateRules2 as validatePermissionRules, validateProject, validateRules, validateUri };
4948
5119
  //# sourceMappingURL=index.js.map
4949
5120
  //# sourceMappingURL=index.js.map