@codebakers/cli 3.3.11 → 3.3.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/lib/api.d.ts CHANGED
@@ -53,3 +53,141 @@ export declare function checkForUpdates(): Promise<{
53
53
  * This helps identify problematic versions for blocking
54
54
  */
55
55
  export declare function reportCliError(errorType: string, errorMessage: string, context?: Record<string, unknown>): Promise<void>;
56
+ export interface ProjectSyncData {
57
+ project?: {
58
+ status?: 'discovery' | 'planning' | 'building' | 'testing' | 'completed' | 'paused' | 'failed';
59
+ overallProgress?: number;
60
+ prdContent?: string;
61
+ discoveryAnswers?: Record<string, unknown>;
62
+ patternsUsed?: string[];
63
+ detectedStack?: Record<string, string>;
64
+ };
65
+ phases?: Array<{
66
+ id?: string;
67
+ phaseNumber: number;
68
+ phaseName: string;
69
+ phaseDescription?: string;
70
+ status?: 'pending' | 'in_progress' | 'completed' | 'skipped' | 'failed';
71
+ progress?: number;
72
+ requiredPatterns?: string[];
73
+ aiConfidence?: number;
74
+ aiNotes?: string;
75
+ alternativesConsidered?: string[];
76
+ requiresApproval?: boolean;
77
+ }>;
78
+ events?: Array<{
79
+ eventType: string;
80
+ eventTitle: string;
81
+ eventDescription?: string;
82
+ eventData?: Record<string, unknown>;
83
+ phaseId?: string;
84
+ featureId?: string;
85
+ filePath?: string;
86
+ fileAction?: string;
87
+ linesChanged?: number;
88
+ aiConfidence?: number;
89
+ riskLevel?: 'low' | 'medium' | 'high' | 'critical';
90
+ riskReason?: string;
91
+ }>;
92
+ testRuns?: Array<{
93
+ testType: string;
94
+ testCommand?: string;
95
+ passed: boolean;
96
+ totalTests: number;
97
+ passedTests: number;
98
+ failedTests: number;
99
+ skippedTests: number;
100
+ durationMs?: number;
101
+ phaseId?: string;
102
+ featureId?: string;
103
+ }>;
104
+ files?: Array<{
105
+ filePath: string;
106
+ fileName: string;
107
+ fileType?: string;
108
+ lineCount?: number;
109
+ complexity?: number;
110
+ parentPath?: string;
111
+ depth?: number;
112
+ status?: 'active' | 'deleted' | 'renamed';
113
+ featureId?: string;
114
+ }>;
115
+ dependencies?: Array<{
116
+ sourceFile: string;
117
+ sourceType?: string;
118
+ targetFile: string;
119
+ targetType?: string;
120
+ dependencyType?: string;
121
+ importName?: string;
122
+ featureId?: string;
123
+ }>;
124
+ riskFlags?: Array<{
125
+ riskLevel: 'low' | 'medium' | 'high' | 'critical';
126
+ riskCategory: string;
127
+ riskTitle: string;
128
+ riskDescription?: string;
129
+ triggerFile?: string;
130
+ triggerCode?: string;
131
+ triggerReason?: string;
132
+ aiRecommendation?: string;
133
+ phaseId?: string;
134
+ featureId?: string;
135
+ }>;
136
+ resources?: Array<{
137
+ resourceType: string;
138
+ apiEndpoint?: string;
139
+ apiMethod?: string;
140
+ inputTokens?: number;
141
+ outputTokens?: number;
142
+ totalTokens?: number;
143
+ durationMs?: number;
144
+ estimatedCostMillicents?: number;
145
+ phaseId?: string;
146
+ featureId?: string;
147
+ }>;
148
+ createSnapshot?: {
149
+ snapshotName: string;
150
+ snapshotDescription?: string;
151
+ isAutomatic?: boolean;
152
+ gitCommitHash?: string;
153
+ gitBranch?: string;
154
+ projectState?: Record<string, unknown>;
155
+ fileTree?: Array<Record<string, unknown>>;
156
+ phaseId?: string;
157
+ };
158
+ }
159
+ export interface ProjectSyncResult {
160
+ projectId: string;
161
+ synced: {
162
+ project: boolean;
163
+ phases: number;
164
+ events: number;
165
+ testRuns: number;
166
+ files: number;
167
+ dependencies: number;
168
+ riskFlags: number;
169
+ resources: number;
170
+ snapshot: boolean;
171
+ };
172
+ }
173
+ /**
174
+ * Get or create a project on the server
175
+ */
176
+ export declare function getOrCreateProject(projectHash: string, projectName: string, projectDescription?: string, detectedStack?: Record<string, string>, authHeaders?: Record<string, string>): Promise<{
177
+ projectId: string;
178
+ isNew: boolean;
179
+ }>;
180
+ /**
181
+ * Sync project data to the server
182
+ * This is the main endpoint for keeping the server updated with local state
183
+ */
184
+ export declare function syncProjectData(projectId: string, data: ProjectSyncData, authHeaders?: Record<string, string>): Promise<ProjectSyncResult>;
185
+ /**
186
+ * Get project dashboard data from the server
187
+ */
188
+ export declare function getProjectDashboard(projectId: string, authHeaders?: Record<string, string>): Promise<Record<string, unknown>>;
189
+ /**
190
+ * Create a project hash from the project directory
191
+ * Uses a combination of directory path and package.json name for uniqueness
192
+ */
193
+ export declare function createProjectHash(projectDir: string, packageName?: string): string;
package/dist/lib/api.js CHANGED
@@ -8,6 +8,10 @@ exports.checkApiKeyValidity = checkApiKeyValidity;
8
8
  exports.getCliVersion = getCliVersion;
9
9
  exports.checkForUpdates = checkForUpdates;
10
10
  exports.reportCliError = reportCliError;
11
+ exports.getOrCreateProject = getOrCreateProject;
12
+ exports.syncProjectData = syncProjectData;
13
+ exports.getProjectDashboard = getProjectDashboard;
14
+ exports.createProjectHash = createProjectHash;
11
15
  const config_js_1 = require("../config.js");
12
16
  /**
13
17
  * Validate an API key format
@@ -226,3 +230,80 @@ async function reportCliError(errorType, errorMessage, context) {
226
230
  // Never fail on error reporting
227
231
  }
228
232
  }
233
+ /**
234
+ * Get or create a project on the server
235
+ */
236
+ async function getOrCreateProject(projectHash, projectName, projectDescription, detectedStack, authHeaders) {
237
+ const apiUrl = (0, config_js_1.getApiUrl)();
238
+ const response = await fetch(`${apiUrl}/api/projects`, {
239
+ method: 'POST',
240
+ headers: {
241
+ 'Content-Type': 'application/json',
242
+ ...authHeaders,
243
+ },
244
+ body: JSON.stringify({
245
+ projectHash,
246
+ projectName,
247
+ projectDescription,
248
+ detectedStack,
249
+ }),
250
+ });
251
+ if (!response.ok) {
252
+ const error = await response.json().catch(() => ({ error: 'Unknown error' }));
253
+ throw createApiError(error.error || 'Failed to create/get project', 'PROJECT_ERROR', ['Check your internet connection', 'Verify your API key is valid']);
254
+ }
255
+ const result = await response.json();
256
+ return {
257
+ projectId: result.data?.id || result.id,
258
+ isNew: result.data?.isNew || result.isNew || false,
259
+ };
260
+ }
261
+ /**
262
+ * Sync project data to the server
263
+ * This is the main endpoint for keeping the server updated with local state
264
+ */
265
+ async function syncProjectData(projectId, data, authHeaders) {
266
+ const apiUrl = (0, config_js_1.getApiUrl)();
267
+ const response = await fetch(`${apiUrl}/api/projects/${projectId}/sync`, {
268
+ method: 'POST',
269
+ headers: {
270
+ 'Content-Type': 'application/json',
271
+ ...authHeaders,
272
+ },
273
+ body: JSON.stringify(data),
274
+ });
275
+ if (!response.ok) {
276
+ const error = await response.json().catch(() => ({ error: 'Unknown error' }));
277
+ throw createApiError(error.error || 'Failed to sync project data', 'SYNC_ERROR', ['Check your internet connection', 'Try again in a few moments']);
278
+ }
279
+ const result = await response.json();
280
+ return result.data || result;
281
+ }
282
+ /**
283
+ * Get project dashboard data from the server
284
+ */
285
+ async function getProjectDashboard(projectId, authHeaders) {
286
+ const apiUrl = (0, config_js_1.getApiUrl)();
287
+ const response = await fetch(`${apiUrl}/api/projects/${projectId}`, {
288
+ method: 'GET',
289
+ headers: {
290
+ 'Accept': 'application/json',
291
+ ...authHeaders,
292
+ },
293
+ });
294
+ if (!response.ok) {
295
+ const error = await response.json().catch(() => ({ error: 'Unknown error' }));
296
+ throw createApiError(error.error || 'Failed to get project dashboard', 'PROJECT_ERROR', ['Check your internet connection', 'Verify the project exists']);
297
+ }
298
+ const result = await response.json();
299
+ return result.data || result;
300
+ }
301
+ /**
302
+ * Create a project hash from the project directory
303
+ * Uses a combination of directory path and package.json name for uniqueness
304
+ */
305
+ function createProjectHash(projectDir, packageName) {
306
+ const crypto = require('crypto');
307
+ const hashInput = packageName ? `${projectDir}:${packageName}` : projectDir;
308
+ return crypto.createHash('sha256').update(hashInput).digest('hex').substring(0, 16);
309
+ }