@ace-sdk/core 2.0.0 → 2.1.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 (35) hide show
  1. package/dist/cache/project-index.d.ts +152 -0
  2. package/dist/cache/project-index.d.ts.map +1 -0
  3. package/dist/cache/project-index.js +290 -0
  4. package/dist/cache/project-index.js.map +1 -0
  5. package/dist/config/loader.d.ts.map +1 -1
  6. package/dist/config/loader.js +15 -0
  7. package/dist/config/loader.js.map +1 -1
  8. package/dist/index.d.ts +13 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +10 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/services/bootstrap-stream.d.ts +113 -0
  13. package/dist/services/bootstrap-stream.d.ts.map +1 -0
  14. package/dist/services/bootstrap-stream.js +261 -0
  15. package/dist/services/bootstrap-stream.js.map +1 -0
  16. package/dist/services/import-graph.d.ts +111 -0
  17. package/dist/services/import-graph.d.ts.map +1 -0
  18. package/dist/services/import-graph.js +292 -0
  19. package/dist/services/import-graph.js.map +1 -0
  20. package/dist/services/language-detector.d.ts +120 -0
  21. package/dist/services/language-detector.d.ts.map +1 -0
  22. package/dist/services/language-detector.js +210 -0
  23. package/dist/services/language-detector.js.map +1 -0
  24. package/dist/types/bootstrap-events.d.ts +251 -0
  25. package/dist/types/bootstrap-events.d.ts.map +1 -0
  26. package/dist/types/bootstrap-events.js +103 -0
  27. package/dist/types/bootstrap-events.js.map +1 -0
  28. package/dist/types/config.d.ts +5 -0
  29. package/dist/types/config.d.ts.map +1 -1
  30. package/dist/types/config.js.map +1 -1
  31. package/dist/types/project-dna.d.ts +151 -0
  32. package/dist/types/project-dna.d.ts.map +1 -0
  33. package/dist/types/project-dna.js +42 -0
  34. package/dist/types/project-dna.js.map +1 -0
  35. package/package.json +3 -2
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Bootstrap Streaming Client
3
+ *
4
+ * Connects to server SSE endpoint for streaming bootstrap progress.
5
+ * Handles event parsing, timeout, and error recovery.
6
+ *
7
+ * Updated to match ACE Server v3.13.0 response format.
8
+ *
9
+ * @package @ace-sdk/core
10
+ */
11
+ import type { BootstrapSSEEvent, PlaybookSection, BootstrapStatistics } from '../types/bootstrap-events.js';
12
+ import type { ProjectDNA } from '../types/project-dna.js';
13
+ import type { BootstrapMode } from '../types/pattern.js';
14
+ import type { VerbosityLevel } from '../types/config.js';
15
+ export type { BootstrapMode, VerbosityLevel };
16
+ /**
17
+ * Options for bootstrap streaming
18
+ */
19
+ export interface BootstrapStreamOptions {
20
+ /** ACE Server URL (without trailing slash) */
21
+ serverUrl: string;
22
+ /** Organization ID */
23
+ orgId: string;
24
+ /** Project ID */
25
+ projectId: string;
26
+ /** Bootstrap mode (default: 'hybrid') */
27
+ mode?: BootstrapMode;
28
+ /** Code blocks to send for bootstrap */
29
+ codeBlocks: string[];
30
+ /** Metadata about the bootstrap request */
31
+ metadata?: {
32
+ files_scanned?: number;
33
+ blocks_extracted?: number;
34
+ thoroughness?: string;
35
+ };
36
+ /** Project DNA to store (optional) */
37
+ projectDNA?: ProjectDNA;
38
+ /** API token for authentication */
39
+ apiToken?: string;
40
+ /** Callback for each SSE event */
41
+ onEvent: (event: BootstrapSSEEvent) => void;
42
+ /** Callback for errors */
43
+ onError?: (error: Error) => void;
44
+ /** Timeout in milliseconds (default: 120000 = 2 minutes) */
45
+ timeout?: number;
46
+ /** Verbosity level for SSE events (default: 'compact') */
47
+ verbosity?: VerbosityLevel;
48
+ }
49
+ /**
50
+ * Result of bootstrap streaming
51
+ */
52
+ export interface BootstrapStreamResult {
53
+ /** Whether bootstrap succeeded */
54
+ success: boolean;
55
+ /** Bootstrap statistics on success */
56
+ statistics?: BootstrapStatistics;
57
+ /** Playbook summary on success (derived from statistics) */
58
+ playbook?: {
59
+ totalPatterns: number;
60
+ bySection: Record<PlaybookSection, number>;
61
+ };
62
+ /** Error info on failure */
63
+ error?: {
64
+ code: string;
65
+ message: string;
66
+ retryable: boolean;
67
+ };
68
+ /** Processing time in seconds */
69
+ processingTime?: number;
70
+ }
71
+ /**
72
+ * Stream bootstrap progress from ACE Server
73
+ *
74
+ * Connects to the server's SSE endpoint and receives progress updates
75
+ * as the bootstrap processes code blocks.
76
+ *
77
+ * @param options - Bootstrap streaming options
78
+ * @returns Promise that resolves when bootstrap completes or fails
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const result = await bootstrapWithStreaming({
83
+ * serverUrl: 'https://ace-api.code-engine.app',
84
+ * orgId: 'myorg',
85
+ * projectId: 'myproject',
86
+ * mode: 'hybrid',
87
+ * codeBlocks: ['function foo() { ... }', '// STRATEGY: Use DI'],
88
+ * onEvent: (event) => {
89
+ * console.log(`[${event.stage}] ${event.message}`);
90
+ * if (event.stage === 'done') {
91
+ * const stats = event.data as DoneStageData;
92
+ * console.log(`Patterns: ${stats.patterns_extracted}`);
93
+ * }
94
+ * }
95
+ * });
96
+ *
97
+ * if (result.success) {
98
+ * console.log(`Bootstrap complete: ${result.playbook?.totalPatterns} patterns`);
99
+ * }
100
+ * ```
101
+ */
102
+ export declare function bootstrapWithStreaming(options: BootstrapStreamOptions): Promise<BootstrapStreamResult>;
103
+ /**
104
+ * Non-streaming bootstrap fallback
105
+ *
106
+ * For servers that don't support SSE streaming, this function
107
+ * makes a regular POST request and waits for the response.
108
+ *
109
+ * @param options - Bootstrap options (same as streaming but without onEvent)
110
+ * @returns Promise that resolves with bootstrap result
111
+ */
112
+ export declare function bootstrapWithoutStreaming(options: Omit<BootstrapStreamOptions, 'onEvent'>): Promise<BootstrapStreamResult>;
113
+ //# sourceMappingURL=bootstrap-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-stream.d.ts","sourceRoot":"","sources":["../../src/services/bootstrap-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAGjB,eAAe,EACf,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAEtC,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B,SAAS,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;KAC5C,CAAC;IACF,4BAA4B;IAC5B,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IACF,iCAAiC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CA4KhC;AAMD;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE,SAAS,CAAC,GAC/C,OAAO,CAAC,qBAAqB,CAAC,CAoFhC"}
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Bootstrap Streaming Client
3
+ *
4
+ * Connects to server SSE endpoint for streaming bootstrap progress.
5
+ * Handles event parsing, timeout, and error recovery.
6
+ *
7
+ * Updated to match ACE Server v3.13.0 response format.
8
+ *
9
+ * @package @ace-sdk/core
10
+ */
11
+ import { isTerminalEvent, isDoneEvent, isErrorEvent } from '../types/bootstrap-events.js';
12
+ // =============================================================================
13
+ // Bootstrap Stream Function
14
+ // =============================================================================
15
+ /**
16
+ * Stream bootstrap progress from ACE Server
17
+ *
18
+ * Connects to the server's SSE endpoint and receives progress updates
19
+ * as the bootstrap processes code blocks.
20
+ *
21
+ * @param options - Bootstrap streaming options
22
+ * @returns Promise that resolves when bootstrap completes or fails
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const result = await bootstrapWithStreaming({
27
+ * serverUrl: 'https://ace-api.code-engine.app',
28
+ * orgId: 'myorg',
29
+ * projectId: 'myproject',
30
+ * mode: 'hybrid',
31
+ * codeBlocks: ['function foo() { ... }', '// STRATEGY: Use DI'],
32
+ * onEvent: (event) => {
33
+ * console.log(`[${event.stage}] ${event.message}`);
34
+ * if (event.stage === 'done') {
35
+ * const stats = event.data as DoneStageData;
36
+ * console.log(`Patterns: ${stats.patterns_extracted}`);
37
+ * }
38
+ * }
39
+ * });
40
+ *
41
+ * if (result.success) {
42
+ * console.log(`Bootstrap complete: ${result.playbook?.totalPatterns} patterns`);
43
+ * }
44
+ * ```
45
+ */
46
+ export async function bootstrapWithStreaming(options) {
47
+ const { serverUrl, orgId, projectId, mode = 'hybrid', codeBlocks, metadata, projectDNA, apiToken, onEvent, onError, timeout = 120000, verbosity = 'compact' } = options;
48
+ const controller = new AbortController();
49
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
50
+ let result = { success: false };
51
+ try {
52
+ // Build request headers
53
+ const headers = {
54
+ 'Content-Type': 'application/json',
55
+ 'Accept': 'text/event-stream',
56
+ 'X-ACE-Org': orgId,
57
+ 'X-ACE-Project': projectId
58
+ };
59
+ if (apiToken) {
60
+ headers['Authorization'] = `Bearer ${apiToken}`;
61
+ }
62
+ // Build request body (matches server v3.13.0 BootstrapStreamRequest)
63
+ const body = JSON.stringify({
64
+ mode,
65
+ code_blocks: codeBlocks,
66
+ metadata: metadata || {
67
+ project_dna: projectDNA
68
+ },
69
+ verbosity
70
+ });
71
+ // Make streaming request
72
+ const response = await fetch(`${serverUrl}/bootstrap/stream`, {
73
+ method: 'POST',
74
+ headers,
75
+ body,
76
+ signal: controller.signal
77
+ });
78
+ if (!response.ok) {
79
+ throw new Error(`Bootstrap request failed: ${response.status} ${response.statusText}`);
80
+ }
81
+ // Get response body reader
82
+ const reader = response.body?.getReader();
83
+ const decoder = new TextDecoder();
84
+ if (!reader) {
85
+ throw new Error('No response body available');
86
+ }
87
+ let buffer = '';
88
+ // Read SSE stream
89
+ while (true) {
90
+ const { done, value } = await reader.read();
91
+ if (done)
92
+ break;
93
+ // Append chunk to buffer
94
+ buffer += decoder.decode(value, { stream: true });
95
+ // Parse complete lines from buffer
96
+ const lines = buffer.split('\n');
97
+ buffer = lines.pop() || ''; // Keep incomplete line in buffer
98
+ for (const line of lines) {
99
+ // Skip empty lines and comments
100
+ if (!line || line.startsWith(':'))
101
+ continue;
102
+ // Parse SSE data line
103
+ if (line.startsWith('data: ')) {
104
+ const json = line.slice(6);
105
+ try {
106
+ const event = JSON.parse(json);
107
+ // Call user's event handler
108
+ onEvent(event);
109
+ // Check for terminal events
110
+ if (isTerminalEvent(event)) {
111
+ if (isDoneEvent(event)) {
112
+ const data = event.data;
113
+ result = {
114
+ success: data.success,
115
+ statistics: data.bootstrap_statistics,
116
+ playbook: {
117
+ totalPatterns: data.patterns_extracted,
118
+ bySection: data.bootstrap_statistics.by_section
119
+ },
120
+ processingTime: data.analysis_time_seconds
121
+ };
122
+ }
123
+ else if (isErrorEvent(event)) {
124
+ const data = event.data;
125
+ result = {
126
+ success: false,
127
+ error: {
128
+ code: data.error_code,
129
+ message: data.message,
130
+ retryable: data.retryable
131
+ }
132
+ };
133
+ }
134
+ return result;
135
+ }
136
+ }
137
+ catch (parseError) {
138
+ console.warn('Failed to parse SSE event:', json, parseError);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ // Stream ended without terminal event
144
+ if (!result.success && !result.error) {
145
+ result = {
146
+ success: false,
147
+ error: {
148
+ code: 'STREAM_ENDED',
149
+ message: 'Stream ended without completion or error event',
150
+ retryable: true
151
+ }
152
+ };
153
+ }
154
+ return result;
155
+ }
156
+ catch (error) {
157
+ const err = error;
158
+ // Handle abort (timeout)
159
+ if (err.name === 'AbortError') {
160
+ result = {
161
+ success: false,
162
+ error: {
163
+ code: 'TIMEOUT',
164
+ message: `Bootstrap timed out after ${timeout}ms`,
165
+ retryable: true
166
+ }
167
+ };
168
+ }
169
+ else {
170
+ result = {
171
+ success: false,
172
+ error: {
173
+ code: 'NETWORK_ERROR',
174
+ message: err.message,
175
+ retryable: true
176
+ }
177
+ };
178
+ }
179
+ // Call error handler if provided
180
+ if (onError) {
181
+ onError(err);
182
+ }
183
+ return result;
184
+ }
185
+ finally {
186
+ clearTimeout(timeoutId);
187
+ }
188
+ }
189
+ // =============================================================================
190
+ // Fallback: Non-Streaming Bootstrap
191
+ // =============================================================================
192
+ /**
193
+ * Non-streaming bootstrap fallback
194
+ *
195
+ * For servers that don't support SSE streaming, this function
196
+ * makes a regular POST request and waits for the response.
197
+ *
198
+ * @param options - Bootstrap options (same as streaming but without onEvent)
199
+ * @returns Promise that resolves with bootstrap result
200
+ */
201
+ export async function bootstrapWithoutStreaming(options) {
202
+ const { serverUrl, orgId, projectId, mode = 'hybrid', codeBlocks, metadata, projectDNA, apiToken, onError, timeout = 120000 } = options;
203
+ const controller = new AbortController();
204
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
205
+ try {
206
+ const headers = {
207
+ 'Content-Type': 'application/json',
208
+ 'X-ACE-Org': orgId,
209
+ 'X-ACE-Project': projectId
210
+ };
211
+ if (apiToken) {
212
+ headers['Authorization'] = `Bearer ${apiToken}`;
213
+ }
214
+ const body = JSON.stringify({
215
+ mode,
216
+ code_blocks: codeBlocks,
217
+ metadata: metadata || {
218
+ project_dna: projectDNA
219
+ }
220
+ });
221
+ const response = await fetch(`${serverUrl}/bootstrap`, {
222
+ method: 'POST',
223
+ headers,
224
+ body,
225
+ signal: controller.signal
226
+ });
227
+ if (!response.ok) {
228
+ throw new Error(`Bootstrap request failed: ${response.status} ${response.statusText}`);
229
+ }
230
+ const data = await response.json();
231
+ // Handle both old and new response formats
232
+ const totalPatterns = data.patterns_extracted || data.total_patterns || 0;
233
+ const bySection = data.bootstrap_statistics?.by_section || data.by_section || {};
234
+ return {
235
+ success: true,
236
+ statistics: data.bootstrap_statistics,
237
+ playbook: {
238
+ totalPatterns,
239
+ bySection
240
+ }
241
+ };
242
+ }
243
+ catch (error) {
244
+ const err = error;
245
+ if (onError) {
246
+ onError(err);
247
+ }
248
+ return {
249
+ success: false,
250
+ error: {
251
+ code: err.name === 'AbortError' ? 'TIMEOUT' : 'NETWORK_ERROR',
252
+ message: err.message,
253
+ retryable: true
254
+ }
255
+ };
256
+ }
257
+ finally {
258
+ clearTimeout(timeoutId);
259
+ }
260
+ }
261
+ //# sourceMappingURL=bootstrap-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-stream.js","sourceRoot":"","sources":["../../src/services/bootstrap-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAqE1F,gFAAgF;AAChF,4BAA4B;AAC5B,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAA+B;IAE/B,MAAM,EACJ,SAAS,EACT,KAAK,EACL,SAAS,EACT,IAAI,GAAG,QAAQ,EACf,UAAU,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO,GAAG,MAAM,EAChB,SAAS,GAAG,SAAS,EACtB,GAAG,OAAO,CAAC;IAEZ,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IAEhE,IAAI,MAAM,GAA0B,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAEvD,IAAI,CAAC;QACH,wBAAwB;QACxB,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,QAAQ,EAAE,mBAAmB;YAC7B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,SAAS;SAC3B,CAAC;QAEF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,QAAQ,EAAE,CAAC;QAClD,CAAC;QAED,qEAAqE;QACrE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,IAAI;YACJ,WAAW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AAI,IAAI,CAAC,UAAU,IAAI,EAAqC,CAAC;QAEpH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI,CAAC,oBAAoB;YACrC,QAAQ,EAAE;gBACR,aAAa;gBACb,SAAS;aACV;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAc,CAAC;QAE3B,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe;gBAC7D,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,SAAS,EAAE,IAAI;aAChB;SACF,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Import Graph Analysis Service
3
+ *
4
+ * Uses Skott for JS/TS dependency graph analysis with dead code detection.
5
+ * Routes to appropriate analyzer based on primary language.
6
+ *
7
+ * @package @ace-sdk/core
8
+ */
9
+ import type { GraphMetrics, CodeHealthMetrics } from '../types/project-dna.js';
10
+ /**
11
+ * Represents a node in the import graph
12
+ */
13
+ export interface FileNode {
14
+ /** File path relative to repo root */
15
+ path: string;
16
+ /** Files this file imports */
17
+ imports: string[];
18
+ /** Files that import this file */
19
+ importedBy: string[];
20
+ /** Has no dependents (entry point) */
21
+ isEntryPoint: boolean;
22
+ /** Has 5+ importers */
23
+ isHub: boolean;
24
+ /** Has no dependencies */
25
+ isLeaf: boolean;
26
+ }
27
+ /**
28
+ * Complete import graph analysis result
29
+ */
30
+ export interface ImportGraph {
31
+ /** All file nodes in the graph */
32
+ nodes: Map<string, FileNode>;
33
+ /** Files with no dependents */
34
+ entryPoints: string[];
35
+ /** Files with 5+ importers */
36
+ hubFiles: string[];
37
+ /** Files with no dependencies */
38
+ leafFiles: string[];
39
+ /** Circular dependency chains */
40
+ circularDeps: string[][];
41
+ /** Dead code files (never imported) */
42
+ deadCode: string[];
43
+ /** Unused dependencies from package.json */
44
+ unusedDeps: string[];
45
+ }
46
+ /**
47
+ * Options for building import graph
48
+ */
49
+ export interface ImportGraphOptions {
50
+ /** Root path to analyze */
51
+ repoPath: string;
52
+ /** Entry points to start from (optional) */
53
+ entryPoints?: string[];
54
+ /** Paths to ignore */
55
+ ignorePaths?: string[];
56
+ /** Maximum files to analyze */
57
+ maxFiles?: number;
58
+ }
59
+ /**
60
+ * Default paths to ignore during analysis
61
+ */
62
+ export declare const DEFAULT_IGNORE_PATHS: string[];
63
+ /**
64
+ * Minimum number of importers to be considered a hub
65
+ */
66
+ export declare const HUB_THRESHOLD = 5;
67
+ /**
68
+ * Build import graph with language-based routing
69
+ *
70
+ * Routes to the best analyzer based on primary language:
71
+ * - TypeScript/JavaScript: Skott (fast, dead code detection)
72
+ * - Other languages: Git co-occurrence fallback
73
+ *
74
+ * @param options - Import graph options
75
+ * @returns Complete import graph analysis
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const graph = await buildImportGraph({ repoPath: '/path/to/repo' });
80
+ *
81
+ * console.log(`Entry points: ${graph.entryPoints.length}`);
82
+ * console.log(`Hub files: ${graph.hubFiles.length}`);
83
+ * console.log(`Dead code: ${graph.deadCode.length}`);
84
+ * console.log(`Circular deps: ${graph.circularDeps.length}`);
85
+ * ```
86
+ */
87
+ export declare function buildImportGraph(options: ImportGraphOptions): Promise<ImportGraph>;
88
+ /**
89
+ * Select priority files from import graph for bootstrap
90
+ *
91
+ * Priority order:
92
+ * 1. Entry points (always include)
93
+ * 2. Hub files (most imported - high value)
94
+ * 3. Files in circular deps (need attention)
95
+ * 4. Leaf files with many exports (API surface)
96
+ * 5. Fill remaining with diverse sampling
97
+ *
98
+ * @param graph - Import graph to select from
99
+ * @param maxFiles - Maximum files to select
100
+ * @returns Array of priority file paths
101
+ */
102
+ export declare function selectPriorityFiles(graph: ImportGraph, maxFiles: number): string[];
103
+ /**
104
+ * Convert import graph to GraphMetrics for ProjectDNA
105
+ */
106
+ export declare function graphToMetrics(graph: ImportGraph): GraphMetrics;
107
+ /**
108
+ * Calculate code health metrics from import graph
109
+ */
110
+ export declare function calculateHealthMetrics(graph: ImportGraph, totalFiles: number, avgFileSize: number, maxFileSize: number): CodeHealthMetrics;
111
+ //# sourceMappingURL=import-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-graph.d.ts","sourceRoot":"","sources":["../../src/services/import-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAM/E;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kCAAkC;IAClC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,sCAAsC;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,uBAAuB;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,0BAA0B;IAC1B,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7B,+BAA+B;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iCAAiC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,iCAAiC;IACjC,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,EAAE,CAA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