@cesarandreslopez/occ 0.6.1 → 0.6.3
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/README.md +67 -2
- package/dist/src/cli.js +2 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/code/command.js +14 -2
- package/dist/src/code/command.js.map +1 -1
- package/dist/src/code/output.d.ts +2 -1
- package/dist/src/code/output.js +32 -1
- package/dist/src/code/output.js.map +1 -1
- package/dist/src/code/parsers.js +35 -22
- package/dist/src/code/parsers.js.map +1 -1
- package/dist/src/code/query.d.ts +4 -0
- package/dist/src/code/query.js +42 -18
- package/dist/src/code/query.js.map +1 -1
- package/dist/src/code/session.d.ts +26 -0
- package/dist/src/code/session.js +59 -0
- package/dist/src/code/session.js.map +1 -0
- package/dist/src/doc/batch.d.ts +11 -2
- package/dist/src/doc/batch.js +50 -52
- package/dist/src/doc/batch.js.map +1 -1
- package/dist/src/workspace/analyze.d.ts +11 -0
- package/dist/src/workspace/analyze.js +190 -0
- package/dist/src/workspace/analyze.js.map +1 -0
- package/dist/src/workspace/command.d.ts +2 -0
- package/dist/src/workspace/command.js +116 -0
- package/dist/src/workspace/command.js.map +1 -0
- package/dist/src/workspace/documents.d.ts +10 -0
- package/dist/src/workspace/documents.js +68 -0
- package/dist/src/workspace/documents.js.map +1 -0
- package/dist/src/workspace/types.d.ts +307 -0
- package/dist/src/workspace/types.js +109 -0
- package/dist/src/workspace/types.js.map +1 -0
- package/package.json +106 -11
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { findFiles } from '../walker.js';
|
|
3
|
+
import { parseFiles } from '../parsers/index.js';
|
|
4
|
+
import { aggregate } from '../stats.js';
|
|
5
|
+
import { checkScc, runScc } from '../scc.js';
|
|
6
|
+
import { documentToMarkdown } from '../markdown/convert.js';
|
|
7
|
+
import { extractFromMarkdown } from '../structure/index.js';
|
|
8
|
+
import { getExtension, METRIC_FIELDS } from '../utils.js';
|
|
9
|
+
const STRUCTURABLE_EXTS = new Set(['docx', 'pdf', 'pptx', 'odt', 'odp']);
|
|
10
|
+
function mapDocumentAggregates(results) {
|
|
11
|
+
const stats = aggregate(results, {
|
|
12
|
+
byFile: false,
|
|
13
|
+
sort: 'files',
|
|
14
|
+
showConfidence: false,
|
|
15
|
+
});
|
|
16
|
+
const rows = stats.rows.map((row) => {
|
|
17
|
+
const entry = {
|
|
18
|
+
type: row.fileType,
|
|
19
|
+
count: row.files,
|
|
20
|
+
size: row.size,
|
|
21
|
+
};
|
|
22
|
+
for (const field of METRIC_FIELDS) {
|
|
23
|
+
entry[field] = row[field] || 0;
|
|
24
|
+
}
|
|
25
|
+
return entry;
|
|
26
|
+
});
|
|
27
|
+
const totals = {
|
|
28
|
+
files: stats.totals.files,
|
|
29
|
+
size: stats.totals.size,
|
|
30
|
+
};
|
|
31
|
+
for (const field of METRIC_FIELDS) {
|
|
32
|
+
totals[field] = stats.totals[field] || 0;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
files: rows,
|
|
36
|
+
totals: totals,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function mapCodeTotals(languages) {
|
|
40
|
+
return {
|
|
41
|
+
totalFiles: languages.reduce((sum, item) => sum + item.Count, 0),
|
|
42
|
+
totalLines: languages.reduce((sum, item) => sum + item.Lines, 0),
|
|
43
|
+
totalCode: languages.reduce((sum, item) => sum + item.Code, 0),
|
|
44
|
+
totalComment: languages.reduce((sum, item) => sum + item.Comment, 0),
|
|
45
|
+
totalBlank: languages.reduce((sum, item) => sum + item.Blank, 0),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function extractStructures(rootDir, files, onProgress) {
|
|
49
|
+
const structurable = files.filter((file) => STRUCTURABLE_EXTS.has(getExtension(file.path)));
|
|
50
|
+
const structures = [];
|
|
51
|
+
const errors = [];
|
|
52
|
+
for (let i = 0; i < structurable.length; i++) {
|
|
53
|
+
const file = structurable[i];
|
|
54
|
+
try {
|
|
55
|
+
const markdown = await documentToMarkdown(file.path);
|
|
56
|
+
if (!markdown) {
|
|
57
|
+
errors.push({
|
|
58
|
+
scope: 'structure',
|
|
59
|
+
path: file.path,
|
|
60
|
+
message: 'Document conversion produced no markdown.',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const structure = extractFromMarkdown(markdown);
|
|
65
|
+
structures.push({
|
|
66
|
+
file: path.relative(rootDir, file.path).split(path.sep).join('/'),
|
|
67
|
+
totalNodes: structure.totalNodes,
|
|
68
|
+
maxDepth: structure.maxDepth,
|
|
69
|
+
nodes: structure.rootNodes,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
const error = err;
|
|
75
|
+
errors.push({
|
|
76
|
+
scope: 'structure',
|
|
77
|
+
path: file.path,
|
|
78
|
+
message: error.message,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
onProgress?.({
|
|
82
|
+
phase: 'structure',
|
|
83
|
+
total: structurable.length,
|
|
84
|
+
completed: i + 1,
|
|
85
|
+
detail: file.path,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return { structures, errors };
|
|
89
|
+
}
|
|
90
|
+
export async function analyzeWorkspace(rootDir, options = {}, onProgress) {
|
|
91
|
+
const startedAt = Date.now();
|
|
92
|
+
const resolvedRoot = path.resolve(rootDir);
|
|
93
|
+
const excludeDir = options.excludeDir ?? ['node_modules', '.git', 'dist', 'vendor', 'build', 'coverage', 'target'];
|
|
94
|
+
const includeDocuments = options.includeDocuments !== false;
|
|
95
|
+
const includeStructures = options.includeStructures !== false;
|
|
96
|
+
const includeCode = options.includeCode !== false;
|
|
97
|
+
const errors = [];
|
|
98
|
+
let skipped = [];
|
|
99
|
+
let documentResults = [];
|
|
100
|
+
let documentAggregates = null;
|
|
101
|
+
if (includeDocuments) {
|
|
102
|
+
const discovery = await findFiles([resolvedRoot], {
|
|
103
|
+
excludeDir,
|
|
104
|
+
noGitignore: options.noGitignore,
|
|
105
|
+
largeFileLimit: options.largeFileLimitMb ?? 50,
|
|
106
|
+
});
|
|
107
|
+
skipped = discovery.skipped;
|
|
108
|
+
onProgress?.({
|
|
109
|
+
phase: 'discover-documents',
|
|
110
|
+
total: discovery.files.length,
|
|
111
|
+
completed: discovery.files.length,
|
|
112
|
+
detail: 'Document discovery complete',
|
|
113
|
+
});
|
|
114
|
+
if (discovery.files.length > 0) {
|
|
115
|
+
let parsedCount = 0;
|
|
116
|
+
documentResults = await parseFiles(discovery.files, 10, (inc, detail) => {
|
|
117
|
+
parsedCount += inc;
|
|
118
|
+
onProgress?.({
|
|
119
|
+
phase: 'parse-documents',
|
|
120
|
+
total: discovery.files.length,
|
|
121
|
+
completed: Math.min(parsedCount, discovery.files.length),
|
|
122
|
+
detail,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
documentAggregates = mapDocumentAggregates(documentResults);
|
|
126
|
+
for (const result of documentResults) {
|
|
127
|
+
if (!result.success) {
|
|
128
|
+
errors.push({
|
|
129
|
+
scope: 'document',
|
|
130
|
+
path: result.filePath,
|
|
131
|
+
message: result.suggestion ?? 'Failed to parse document.',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let code = null;
|
|
138
|
+
if (includeCode) {
|
|
139
|
+
try {
|
|
140
|
+
const sccBinary = await checkScc();
|
|
141
|
+
const languages = await runScc(sccBinary, [resolvedRoot], {
|
|
142
|
+
excludeDir,
|
|
143
|
+
noGitignore: options.noGitignore,
|
|
144
|
+
});
|
|
145
|
+
code = {
|
|
146
|
+
languages,
|
|
147
|
+
totals: mapCodeTotals(languages),
|
|
148
|
+
};
|
|
149
|
+
onProgress?.({
|
|
150
|
+
phase: 'code',
|
|
151
|
+
total: 1,
|
|
152
|
+
completed: 1,
|
|
153
|
+
detail: 'Code analysis complete',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
const error = err;
|
|
158
|
+
errors.push({
|
|
159
|
+
scope: 'code',
|
|
160
|
+
path: resolvedRoot,
|
|
161
|
+
message: error.message,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let structures = [];
|
|
166
|
+
if (includeStructures && includeDocuments) {
|
|
167
|
+
const successfulFiles = documentResults
|
|
168
|
+
.filter((result) => result.success)
|
|
169
|
+
.map((result) => ({ path: result.filePath, size: result.size }));
|
|
170
|
+
const structureResult = await extractStructures(resolvedRoot, successfulFiles, onProgress);
|
|
171
|
+
structures = structureResult.structures;
|
|
172
|
+
errors.push(...structureResult.errors);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
schemaVersion: 1,
|
|
176
|
+
rootDir: resolvedRoot,
|
|
177
|
+
summary: {
|
|
178
|
+
elapsedMs: Date.now() - startedAt,
|
|
179
|
+
code: code?.totals ?? null,
|
|
180
|
+
documents: documentAggregates?.totals ?? null,
|
|
181
|
+
structures: structures.length,
|
|
182
|
+
},
|
|
183
|
+
code,
|
|
184
|
+
documents: documentAggregates ? { aggregates: documentAggregates } : null,
|
|
185
|
+
structures,
|
|
186
|
+
skipped,
|
|
187
|
+
errors,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=analyze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../../src/workspace/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,kBAAk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} from 'zod';
|
|
4
|
+
import { analyzeWorkspace } from './analyze.js';
|
|
5
|
+
import { inspectWorkspaceDocumentSet } from './documents.js';
|
|
6
|
+
import { writeStream } from '../utils.js';
|
|
7
|
+
const WorkspaceCommandOptionsSchema = z.object({
|
|
8
|
+
format: z.string().optional(),
|
|
9
|
+
output: z.string().optional(),
|
|
10
|
+
excludeDir: z.string().optional(),
|
|
11
|
+
largeFileLimit: z.string().optional(),
|
|
12
|
+
gitignore: z.boolean().optional(),
|
|
13
|
+
code: z.boolean().optional(),
|
|
14
|
+
documents: z.boolean().optional(),
|
|
15
|
+
structures: z.boolean().optional(),
|
|
16
|
+
maxFiles: z.string().optional(),
|
|
17
|
+
maxReferenceFiles: z.string().optional(),
|
|
18
|
+
includeMarkdown: z.boolean().optional(),
|
|
19
|
+
}).passthrough();
|
|
20
|
+
function getOptions(command) {
|
|
21
|
+
return WorkspaceCommandOptionsSchema.parse(command.optsWithGlobals());
|
|
22
|
+
}
|
|
23
|
+
async function emit(output, options) {
|
|
24
|
+
if (options.output) {
|
|
25
|
+
await writeFile(options.output, output);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
await writeStream(process.stdout, output);
|
|
29
|
+
}
|
|
30
|
+
function parsePositiveInt(value, fallback) {
|
|
31
|
+
const parsed = Number.parseInt(value ?? '', 10);
|
|
32
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
33
|
+
}
|
|
34
|
+
function formatWorkspaceAnalysis(result) {
|
|
35
|
+
const lines = [];
|
|
36
|
+
lines.push(`Workspace: ${result.rootDir}`);
|
|
37
|
+
lines.push(`Elapsed: ${result.summary.elapsedMs}ms`);
|
|
38
|
+
if (result.code) {
|
|
39
|
+
lines.push(`Code: ${result.summary.code?.totalFiles ?? 0} files, ${result.summary.code?.totalLines ?? 0} lines, ${result.code.languages.length} language rows`);
|
|
40
|
+
}
|
|
41
|
+
if (result.documents) {
|
|
42
|
+
lines.push(`Documents: ${result.documents.aggregates.totals.files} files, ${result.documents.aggregates.totals.words} words`);
|
|
43
|
+
}
|
|
44
|
+
lines.push(`Structures: ${result.structures.length}`);
|
|
45
|
+
if (result.skipped.length > 0)
|
|
46
|
+
lines.push(`Skipped: ${result.skipped.length}`);
|
|
47
|
+
if (result.errors.length > 0)
|
|
48
|
+
lines.push(`Errors: ${result.errors.length}`);
|
|
49
|
+
return lines.join('\n');
|
|
50
|
+
}
|
|
51
|
+
function formatWorkspaceDocumentSet(result) {
|
|
52
|
+
const lines = [];
|
|
53
|
+
lines.push(`Workspace: ${result.rootDir}`);
|
|
54
|
+
lines.push(`Documents: ${result.documents.length}`);
|
|
55
|
+
lines.push(`Cross references: ${result.crossReferences.length}`);
|
|
56
|
+
lines.push(`Unresolved mentions: ${result.unresolvedMentions.length}`);
|
|
57
|
+
if (result.skipped.length > 0)
|
|
58
|
+
lines.push(`Skipped: ${result.skipped.length}`);
|
|
59
|
+
if (result.errors.length > 0)
|
|
60
|
+
lines.push(`Errors: ${result.errors.length}`);
|
|
61
|
+
return lines.join('\n');
|
|
62
|
+
}
|
|
63
|
+
export function registerWorkspaceCommands(program) {
|
|
64
|
+
const workspace = program.command('workspace').description('Workspace-level analysis and document context helpers');
|
|
65
|
+
const analyze = workspace.command('analyze [rootDir]').description('Analyze workspace code, documents, and structures with a versioned JSON contract');
|
|
66
|
+
analyze
|
|
67
|
+
.option('--format <type>', 'output format: tabular or json', 'json')
|
|
68
|
+
.option('-o, --output <file>', 'write output to file')
|
|
69
|
+
.option('--exclude-dir <dirs>', 'directories to skip (comma-separated)', 'node_modules,.git,dist,vendor,build,coverage,target')
|
|
70
|
+
.option('--large-file-limit <mb>', 'skip files over this size in MB', '50')
|
|
71
|
+
.option('--no-gitignore', 'disable .gitignore respect')
|
|
72
|
+
.option('--no-code', 'skip code analysis')
|
|
73
|
+
.option('--no-documents', 'skip document analysis')
|
|
74
|
+
.option('--no-structures', 'skip structure extraction');
|
|
75
|
+
analyze.action(async (rootDir, _opts, command) => {
|
|
76
|
+
const options = getOptions(command);
|
|
77
|
+
const result = await analyzeWorkspace(path.resolve(rootDir ?? process.cwd()), {
|
|
78
|
+
excludeDir: options.excludeDir?.split(',').map((item) => item.trim()).filter(Boolean),
|
|
79
|
+
noGitignore: options.gitignore === false,
|
|
80
|
+
largeFileLimitMb: parsePositiveInt(options.largeFileLimit, 50),
|
|
81
|
+
includeCode: options.code !== false,
|
|
82
|
+
includeDocuments: options.documents !== false,
|
|
83
|
+
includeStructures: options.structures !== false,
|
|
84
|
+
});
|
|
85
|
+
const output = options.format === 'tabular'
|
|
86
|
+
? formatWorkspaceAnalysis(result)
|
|
87
|
+
: JSON.stringify(result, null, 2);
|
|
88
|
+
await emit(output.endsWith('\n') ? output : `${output}\n`, options);
|
|
89
|
+
});
|
|
90
|
+
const documents = workspace.command('documents [rootDir]').description('Inspect workspace document summaries and cross-document references');
|
|
91
|
+
documents
|
|
92
|
+
.option('--format <type>', 'output format: tabular or json', 'json')
|
|
93
|
+
.option('-o, --output <file>', 'write output to file')
|
|
94
|
+
.option('--exclude-dir <dirs>', 'directories to skip (comma-separated)', 'node_modules,.git,dist,vendor,build,coverage,target')
|
|
95
|
+
.option('--large-file-limit <mb>', 'skip files over this size in MB', '50')
|
|
96
|
+
.option('--no-gitignore', 'disable .gitignore respect')
|
|
97
|
+
.option('--max-files <n>', 'maximum documents to inspect', '50')
|
|
98
|
+
.option('--max-reference-files <n>', 'maximum documents to convert for cross-reference detection', '20')
|
|
99
|
+
.option('--include-markdown', 'include markdown content in per-document summaries');
|
|
100
|
+
documents.action(async (rootDir, _opts, command) => {
|
|
101
|
+
const options = getOptions(command);
|
|
102
|
+
const result = await inspectWorkspaceDocumentSet(path.resolve(rootDir ?? process.cwd()), {
|
|
103
|
+
excludeDir: options.excludeDir?.split(',').map((item) => item.trim()).filter(Boolean),
|
|
104
|
+
noGitignore: options.gitignore === false,
|
|
105
|
+
largeFileLimitMb: parsePositiveInt(options.largeFileLimit, 50),
|
|
106
|
+
maxFiles: parsePositiveInt(options.maxFiles, 50),
|
|
107
|
+
maxReferenceFiles: parsePositiveInt(options.maxReferenceFiles, 20),
|
|
108
|
+
includeMarkdown: options.includeMarkdown === true,
|
|
109
|
+
});
|
|
110
|
+
const output = options.format === 'tabular'
|
|
111
|
+
? formatWorkspaceDocumentSet(result)
|
|
112
|
+
: JSON.stringify(result, null, 2);
|
|
113
|
+
await emit(output.endsWith('\n') ? output : `${output}\n`, options);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/workspace/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC5B,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,UAAU,EAAE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MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkspaceDocumentSet } from './types.js';
|
|
2
|
+
export interface InspectWorkspaceDocumentSetOptions {
|
|
3
|
+
excludeDir?: string[];
|
|
4
|
+
noGitignore?: boolean;
|
|
5
|
+
largeFileLimitMb?: number;
|
|
6
|
+
maxFiles?: number;
|
|
7
|
+
maxReferenceFiles?: number;
|
|
8
|
+
includeMarkdown?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function inspectWorkspaceDocumentSet(rootDir: string, options?: InspectWorkspaceDocumentSetOptions): Promise<WorkspaceDocumentSet>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { findFiles } from '../walker.js';
|
|
3
|
+
import { getExtension } from '../utils.js';
|
|
4
|
+
import { documentToMarkdown } from '../markdown/convert.js';
|
|
5
|
+
import { detectCrossReferences } from '../doc/references.js';
|
|
6
|
+
import { inspectDocumentSummary } from '../doc/batch.js';
|
|
7
|
+
const DOCUMENT_FORMATS = new Set(['docx', 'pdf', 'pptx', 'xlsx', 'odt', 'ods', 'odp']);
|
|
8
|
+
export async function inspectWorkspaceDocumentSet(rootDir, options = {}) {
|
|
9
|
+
const resolvedRoot = path.resolve(rootDir);
|
|
10
|
+
const excludeDir = options.excludeDir ?? ['node_modules', '.git', 'dist', 'vendor', 'build', 'coverage', 'target'];
|
|
11
|
+
const discovery = await findFiles([resolvedRoot], {
|
|
12
|
+
excludeDir,
|
|
13
|
+
noGitignore: options.noGitignore,
|
|
14
|
+
largeFileLimit: options.largeFileLimitMb ?? 50,
|
|
15
|
+
});
|
|
16
|
+
const maxFiles = options.maxFiles ?? 50;
|
|
17
|
+
const includeMarkdown = options.includeMarkdown ?? false;
|
|
18
|
+
const maxReferenceFiles = options.maxReferenceFiles ?? 20;
|
|
19
|
+
const errors = [];
|
|
20
|
+
const documents = [];
|
|
21
|
+
const markdownByPath = new Map();
|
|
22
|
+
const discovered = discovery.files
|
|
23
|
+
.filter((file) => DOCUMENT_FORMATS.has(getExtension(file.path)))
|
|
24
|
+
.slice(0, maxFiles);
|
|
25
|
+
for (const file of discovered) {
|
|
26
|
+
const relativePath = path.relative(resolvedRoot, file.path).split(path.sep).join('/');
|
|
27
|
+
const format = getExtension(file.path);
|
|
28
|
+
const result = await inspectDocumentSummary(file.path, relativePath, format, { includeMarkdown });
|
|
29
|
+
documents.push(result.summary);
|
|
30
|
+
if (result.markdownContent) {
|
|
31
|
+
markdownByPath.set(file.path, result.markdownContent);
|
|
32
|
+
}
|
|
33
|
+
if (result.error) {
|
|
34
|
+
errors.push({
|
|
35
|
+
path: file.path,
|
|
36
|
+
message: result.error,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const docsWithContent = [];
|
|
41
|
+
for (const doc of documents.slice(0, maxReferenceFiles)) {
|
|
42
|
+
try {
|
|
43
|
+
const content = doc.markdownContent ?? markdownByPath.get(doc.filePath) ?? await documentToMarkdown(doc.filePath);
|
|
44
|
+
if (content)
|
|
45
|
+
docsWithContent.push({ filePath: doc.filePath, content });
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const error = err;
|
|
49
|
+
errors.push({
|
|
50
|
+
path: doc.filePath,
|
|
51
|
+
message: error.message,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const references = docsWithContent.length >= 2
|
|
56
|
+
? detectCrossReferences(docsWithContent)
|
|
57
|
+
: { references: [], unresolvedMentions: [] };
|
|
58
|
+
return {
|
|
59
|
+
schemaVersion: 1,
|
|
60
|
+
rootDir: resolvedRoot,
|
|
61
|
+
documents,
|
|
62
|
+
crossReferences: references.references,
|
|
63
|
+
unresolvedMentions: references.unresolvedMentions,
|
|
64
|
+
skipped: discovery.skipped,
|
|
65
|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