kaven-cli 0.4.1-alpha.0 → 0.5.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.
Files changed (68) hide show
  1. package/README.md +154 -215
  2. package/dist/EnvManager-NMS3NMIE.js +15 -0
  3. package/dist/MarketplaceClient-YCFH2VU4.js +1 -0
  4. package/dist/chunk-JHLQ46NG.js +1 -0
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.js +215 -301
  7. package/dist/tier-table-DQMPQSI2.js +6 -0
  8. package/package.json +26 -11
  9. package/dist/EnvManager-GQMEZ6NV.js +0 -158
  10. package/dist/MarketplaceClient-IJGRQRC4.js +0 -7
  11. package/dist/chunk-3RG5ZIWI.js +0 -10
  12. package/dist/chunk-GHZX5OAA.js +0 -455
  13. package/dist/commands/aiox/index.js +0 -20
  14. package/dist/commands/auth/login.js +0 -122
  15. package/dist/commands/auth/logout.js +0 -23
  16. package/dist/commands/auth/whoami.js +0 -36
  17. package/dist/commands/cache/index.js +0 -43
  18. package/dist/commands/config/features.js +0 -161
  19. package/dist/commands/config/index.js +0 -95
  20. package/dist/commands/index.js +0 -2
  21. package/dist/commands/init/aiox-bootstrap.js +0 -83
  22. package/dist/commands/init/index.js +0 -210
  23. package/dist/commands/init-ci/index.js +0 -153
  24. package/dist/commands/license/index.js +0 -10
  25. package/dist/commands/license/status.js +0 -44
  26. package/dist/commands/license/tier-table.js +0 -46
  27. package/dist/commands/marketplace/browse.js +0 -186
  28. package/dist/commands/marketplace/install.js +0 -263
  29. package/dist/commands/marketplace/list.js +0 -122
  30. package/dist/commands/module/activate.js +0 -245
  31. package/dist/commands/module/add.js +0 -69
  32. package/dist/commands/module/doctor.js +0 -175
  33. package/dist/commands/module/list.js +0 -51
  34. package/dist/commands/module/publish.js +0 -258
  35. package/dist/commands/module/remove.js +0 -58
  36. package/dist/commands/telemetry/view.js +0 -27
  37. package/dist/commands/upgrade/check.js +0 -162
  38. package/dist/commands/upgrade/index.js +0 -185
  39. package/dist/core/AuthService.js +0 -222
  40. package/dist/core/CacheManager.js +0 -154
  41. package/dist/core/ConfigManager.js +0 -166
  42. package/dist/core/EnvManager.js +0 -196
  43. package/dist/core/ErrorRecovery.js +0 -192
  44. package/dist/core/LicenseService.js +0 -83
  45. package/dist/core/ManifestParser.js +0 -52
  46. package/dist/core/MarkerService.js +0 -62
  47. package/dist/core/ModuleDoctor.js +0 -451
  48. package/dist/core/ModuleInstaller.js +0 -169
  49. package/dist/core/ProjectInitializer.js +0 -183
  50. package/dist/core/RegistryResolver.js +0 -95
  51. package/dist/core/SchemaActivator.js +0 -278
  52. package/dist/core/ScriptRunner.js +0 -73
  53. package/dist/core/SignatureVerifier.js +0 -75
  54. package/dist/core/index.js +0 -2
  55. package/dist/infrastructure/Container.js +0 -37
  56. package/dist/infrastructure/MarketplaceClient.js +0 -425
  57. package/dist/infrastructure/TelemetryBuffer.js +0 -73
  58. package/dist/infrastructure/TransactionalFileSystem.js +0 -77
  59. package/dist/infrastructure/errors.js +0 -63
  60. package/dist/infrastructure/index.js +0 -2
  61. package/dist/lib/capabilities-catalog.js +0 -73
  62. package/dist/lib/module-registry.js +0 -47
  63. package/dist/lib/schema-modifier.js +0 -40
  64. package/dist/tier-table-LAL6PAVW.js +0 -52
  65. package/dist/types/auth.js +0 -2
  66. package/dist/types/manifest.js +0 -45
  67. package/dist/types/markers.js +0 -10
  68. package/dist/types/marketplace.js +0 -2
@@ -1,192 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ErrorRecovery = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const os_1 = __importDefault(require("os"));
10
- const chalk_1 = __importDefault(require("chalk"));
11
- const ora_1 = __importDefault(require("ora"));
12
- /**
13
- * C2.7: Error recovery and validation system
14
- */
15
- class ErrorRecovery {
16
- backupDir;
17
- constructor() {
18
- this.backupDir = path_1.default.join(os_1.default.homedir(), ".kaven", "backups");
19
- }
20
- /**
21
- * Create a backup of the project state before operation
22
- */
23
- async createBackup(projectPath, operationName) {
24
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-").substring(0, 19);
25
- const backupName = `${operationName}-${timestamp}`;
26
- const backupPath = path_1.default.join(this.backupDir, backupName);
27
- try {
28
- await fs_extra_1.default.ensureDir(this.backupDir);
29
- // Backup key files
30
- const files = ["package.json", "pnpm-lock.yaml", ".env", "prisma/schema.prisma"];
31
- for (const file of files) {
32
- const source = path_1.default.join(projectPath, file);
33
- const dest = path_1.default.join(backupPath, file);
34
- if (await fs_extra_1.default.pathExists(source)) {
35
- await fs_extra_1.default.ensureDir(path_1.default.dirname(dest));
36
- await fs_extra_1.default.copy(source, dest);
37
- }
38
- }
39
- return backupPath;
40
- }
41
- catch (error) {
42
- throw new Error(`Failed to create backup: ${error instanceof Error ? error.message : String(error)}`);
43
- }
44
- }
45
- /**
46
- * Rollback from backup
47
- */
48
- async rollback(projectPath, backupPath) {
49
- try {
50
- if (!(await fs_extra_1.default.pathExists(backupPath))) {
51
- throw new Error(`Backup not found at ${backupPath}`);
52
- }
53
- const files = ["package.json", "pnpm-lock.yaml", ".env", "prisma/schema.prisma"];
54
- for (const file of files) {
55
- const source = path_1.default.join(backupPath, file);
56
- const dest = path_1.default.join(projectPath, file);
57
- if (await fs_extra_1.default.pathExists(source)) {
58
- await fs_extra_1.default.copy(source, dest, { overwrite: true });
59
- }
60
- }
61
- }
62
- catch (error) {
63
- throw new Error(`Failed to rollback: ${error instanceof Error ? error.message : String(error)}`);
64
- }
65
- }
66
- /**
67
- * Pre-operation validation
68
- */
69
- async validatePreConditions(projectPath) {
70
- const errors = [];
71
- // Check package.json exists
72
- if (!(await fs_extra_1.default.pathExists(path_1.default.join(projectPath, "package.json")))) {
73
- errors.push("package.json not found");
74
- }
75
- // Check node_modules exists
76
- if (!(await fs_extra_1.default.pathExists(path_1.default.join(projectPath, "node_modules")))) {
77
- errors.push("Dependencies not installed. Run: pnpm install");
78
- }
79
- // Check if git repo (for safety)
80
- const gitDir = path_1.default.join(projectPath, ".git");
81
- if (!(await fs_extra_1.default.pathExists(gitDir))) {
82
- errors.push("Not a git repository. Initialize with: git init && git add . && git commit");
83
- }
84
- return {
85
- valid: errors.length === 0,
86
- errors,
87
- };
88
- }
89
- /**
90
- * Post-operation health check
91
- */
92
- async validatePostConditions(projectPath) {
93
- const issues = [];
94
- // Check package.json is valid JSON
95
- try {
96
- const packageJson = await fs_extra_1.default.readJson(path_1.default.join(projectPath, "package.json"));
97
- if (!packageJson.name) {
98
- issues.push("package.json missing name field");
99
- }
100
- }
101
- catch {
102
- issues.push("package.json is invalid JSON");
103
- }
104
- // Check prisma schema if it exists
105
- const schemaPath = path_1.default.join(projectPath, "prisma", "schema.prisma");
106
- if (await fs_extra_1.default.pathExists(schemaPath)) {
107
- const content = await fs_extra_1.default.readFile(schemaPath, "utf-8");
108
- if (!content.includes("datasource db")) {
109
- issues.push("prisma/schema.prisma missing datasource");
110
- }
111
- }
112
- // Check .env exists or .env.example exists
113
- const envPath = path_1.default.join(projectPath, ".env");
114
- const envExamplePath = path_1.default.join(projectPath, ".env.example");
115
- if (!(await fs_extra_1.default.pathExists(envPath)) && !(await fs_extra_1.default.pathExists(envExamplePath))) {
116
- issues.push("No .env or .env.example file found");
117
- }
118
- return {
119
- healthy: issues.length === 0,
120
- issues,
121
- };
122
- }
123
- /**
124
- * Run operation with automatic rollback on failure
125
- */
126
- async withRollback(projectPath, operationName, operation) {
127
- // Pre-validation
128
- const preCheck = await this.validatePreConditions(projectPath);
129
- if (!preCheck.valid) {
130
- throw new Error(`Pre-conditions not met:\n${preCheck.errors.map((e) => ` - ${e}`).join("\n")}`);
131
- }
132
- // Create backup
133
- const spinner = (0, ora_1.default)("Creating backup...").start();
134
- const backupPath = await this.createBackup(projectPath, operationName);
135
- spinner.succeed(`Backup created at ${backupPath}`);
136
- try {
137
- // Run operation
138
- const result = await operation();
139
- // Post-validation
140
- const postCheck = await this.validatePostConditions(projectPath);
141
- if (!postCheck.healthy) {
142
- spinner.warn("Post-operation issues detected:");
143
- for (const issue of postCheck.issues) {
144
- console.log(chalk_1.default.yellow(` ⚠ ${issue}`));
145
- }
146
- }
147
- return result;
148
- }
149
- catch (error) {
150
- // Rollback on failure
151
- spinner.start("Rolling back...");
152
- try {
153
- await this.rollback(projectPath, backupPath);
154
- spinner.succeed("Rolled back successfully");
155
- }
156
- catch (rollbackError) {
157
- spinner.fail(`Rollback failed: ${rollbackError}`);
158
- console.error(chalk_1.default.red("Manual intervention required:"));
159
- console.error(chalk_1.default.gray(`Backup available at: ${backupPath}`));
160
- }
161
- throw error;
162
- }
163
- }
164
- /**
165
- * List available backups
166
- */
167
- async listBackups() {
168
- if (!(await fs_extra_1.default.pathExists(this.backupDir))) {
169
- return [];
170
- }
171
- const entries = await fs_extra_1.default.readdir(this.backupDir);
172
- return entries.map((name) => ({
173
- name,
174
- path: path_1.default.join(this.backupDir, name),
175
- timestamp: name.substring(name.lastIndexOf("-") + 1),
176
- }));
177
- }
178
- /**
179
- * Clean old backups (keep last N)
180
- */
181
- async cleanupBackups(keepCount = 5) {
182
- const backups = await this.listBackups();
183
- if (backups.length <= keepCount) {
184
- return;
185
- }
186
- const toDelete = backups.slice(keepCount);
187
- for (const backup of toDelete) {
188
- await fs_extra_1.default.remove(backup.path);
189
- }
190
- }
191
- }
192
- exports.ErrorRecovery = ErrorRecovery;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LicenseService = void 0;
7
- const promises_1 = __importDefault(require("fs/promises"));
8
- const path_1 = __importDefault(require("path"));
9
- const os_1 = __importDefault(require("os"));
10
- const CACHE_FILE = path_1.default.join(os_1.default.homedir(), '.kaven', 'cache', 'licenses.json');
11
- const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
12
- class LicenseService {
13
- cacheDir = path_1.default.join(os_1.default.homedir(), '.kaven', 'cache');
14
- /** Luhn mod-31 checksum format check (KAVEN-{TIER}-{8RANDOM}-{CHECKSUM}) */
15
- isValidFormat(licenseKey) {
16
- const pattern = /^KAVEN-(STARTER|COMPLETE|PRO|ENTERPRISE)-[A-Z0-9]{8}-[A-Z0-9]{2}$/;
17
- return pattern.test(licenseKey);
18
- }
19
- async readCache() {
20
- try {
21
- const raw = await promises_1.default.readFile(CACHE_FILE, 'utf-8');
22
- return JSON.parse(raw);
23
- }
24
- catch {
25
- return {};
26
- }
27
- }
28
- async writeCache(cache) {
29
- await promises_1.default.mkdir(this.cacheDir, { recursive: true });
30
- await promises_1.default.writeFile(CACHE_FILE, JSON.stringify(cache, null, 2), 'utf-8');
31
- }
32
- isCacheValid(entry) {
33
- return Date.now() - entry.validatedAt < CACHE_TTL_MS;
34
- }
35
- async getCached(licenseKey) {
36
- const cache = await this.readCache();
37
- const entry = cache[licenseKey];
38
- if (entry && this.isCacheValid(entry))
39
- return entry;
40
- return null;
41
- }
42
- async setCached(entry) {
43
- const cache = await this.readCache();
44
- cache[entry.key] = { ...entry, validatedAt: Date.now() };
45
- await this.writeCache(cache);
46
- }
47
- async validateLicense(licenseKey, requiredTier) {
48
- // 1. Check cache first
49
- const cached = await this.getCached(licenseKey);
50
- if (cached) {
51
- return { valid: true, tier: cached.tier, expiresAt: cached.expiresAt, source: 'cache' };
52
- }
53
- // 2. Format check (offline Luhn-style)
54
- if (!this.isValidFormat(licenseKey)) {
55
- throw new Error('Invalid license key format');
56
- }
57
- // 3. API validation
58
- const { MarketplaceClient } = await import('../infrastructure/MarketplaceClient.js');
59
- const client = new MarketplaceClient();
60
- const result = await client.validateLicense(licenseKey, requiredTier);
61
- // Cache on success
62
- await this.setCached({
63
- key: licenseKey,
64
- tier: result.tier,
65
- expiresAt: result.expiresAt,
66
- validatedAt: Date.now(),
67
- });
68
- return { ...result, source: 'api' };
69
- }
70
- async getLicenseStatus(licenseKey) {
71
- const { MarketplaceClient } = await import('../infrastructure/MarketplaceClient.js');
72
- const client = new MarketplaceClient();
73
- return client.getLicenseStatus(licenseKey);
74
- }
75
- tierLevel(tier) {
76
- const levels = { STARTER: 1, COMPLETE: 2, PRO: 3, ENTERPRISE: 4 };
77
- return levels[tier.toUpperCase()] ?? 0;
78
- }
79
- userHasRequiredTier(userTier, requiredTier) {
80
- return this.tierLevel(userTier) >= this.tierLevel(requiredTier);
81
- }
82
- }
83
- exports.LicenseService = LicenseService;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ManifestParser = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const manifest_1 = require("../types/manifest");
9
- const zod_1 = require("zod");
10
- class ManifestParser {
11
- async parse(manifestPath) {
12
- if (!(await fs_extra_1.default.pathExists(manifestPath))) {
13
- throw new Error(`Manifest not found: ${manifestPath}`);
14
- }
15
- const content = await fs_extra_1.default.readFile(manifestPath, "utf-8");
16
- let json;
17
- try {
18
- json = JSON.parse(content);
19
- }
20
- catch {
21
- throw new Error(`Failed to parse manifest JSON: ${manifestPath}`);
22
- }
23
- try {
24
- return manifest_1.ModuleManifestSchema.parse(json);
25
- }
26
- catch (error) {
27
- if (error instanceof zod_1.ZodError) {
28
- throw new Error(`Invalid manifest: \n${this.formatZodError(error)}`);
29
- }
30
- throw error;
31
- }
32
- }
33
- async validate(manifestPath) {
34
- try {
35
- await this.parse(manifestPath);
36
- return { valid: true, errors: [] };
37
- }
38
- catch (error) {
39
- const errorMessage = error instanceof Error ? error.message : String(error);
40
- return {
41
- valid: false,
42
- errors: [errorMessage],
43
- };
44
- }
45
- }
46
- formatZodError(error) {
47
- return error.issues
48
- .map((err) => ` - ${err.path.map(String).join(".")}: ${err.message}`)
49
- .join("\n");
50
- }
51
- }
52
- exports.ManifestParser = ManifestParser;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MarkerService = void 0;
4
- const markers_1 = require("../types/markers");
5
- class MarkerService {
6
- hasModule(fileContent, moduleName) {
7
- const marker = (0, markers_1.createMarker)(moduleName);
8
- return (fileContent.includes(marker.beginMarker) &&
9
- fileContent.includes(marker.endMarker));
10
- }
11
- detectMarkers(fileContent, moduleName) {
12
- const marker = (0, markers_1.createMarker)(moduleName);
13
- const lines = fileContent.split("\n");
14
- let beginLine;
15
- let endLine;
16
- for (let i = 0; i < lines.length; i++) {
17
- if (lines[i].includes(marker.beginMarker)) {
18
- beginLine = i;
19
- }
20
- if (lines[i].includes(marker.endMarker)) {
21
- endLine = i;
22
- break;
23
- }
24
- }
25
- if (beginLine !== undefined && endLine !== undefined) {
26
- const content = lines.slice(beginLine + 1, endLine).join("\n");
27
- return {
28
- found: true,
29
- beginLine,
30
- endLine,
31
- content,
32
- };
33
- }
34
- return { found: false };
35
- }
36
- injectModule(fileContent, anchor, moduleName, code) {
37
- if (this.hasModule(fileContent, moduleName)) {
38
- throw new Error(`Module ${moduleName} already injected`);
39
- }
40
- if (!fileContent.includes(anchor)) {
41
- throw new Error(`Anchor not found: ${anchor}`);
42
- }
43
- const marker = (0, markers_1.createMarker)(moduleName);
44
- const markedCode = `\n${marker.beginMarker}\n${code}\n${marker.endMarker}\n`;
45
- return fileContent.replace(anchor, `${anchor}${markedCode}`);
46
- }
47
- removeModule(fileContent, moduleName) {
48
- const marker = (0, markers_1.createMarker)(moduleName);
49
- const beginMarker = this.escapeRegex(marker.beginMarker);
50
- const endMarker = this.escapeRegex(marker.endMarker);
51
- const regex = new RegExp(`\\n?${beginMarker}[\\s\\S]*?${endMarker}\\n?`, "g");
52
- const result = fileContent.replace(regex, "");
53
- if (result === fileContent) {
54
- throw new Error(`Module ${moduleName} not found in file`);
55
- }
56
- return result;
57
- }
58
- escapeRegex(str) {
59
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
60
- }
61
- }
62
- exports.MarkerService = MarkerService;