@equinor/fusion-framework-cli-plugin-ai-index 3.0.6 → 3.0.7
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/CHANGELOG.md +32 -0
- package/dist/esm/bin/apply-metadata.js +13 -5
- package/dist/esm/bin/apply-metadata.js.map +1 -1
- package/dist/esm/bin/apply-schema.js +7 -1
- package/dist/esm/bin/apply-schema.js.map +1 -1
- package/dist/esm/bin/apply-schema.test.js +2 -1
- package/dist/esm/bin/apply-schema.test.js.map +1 -1
- package/dist/esm/bin/{delete-removed-files.js → create-delete-removed-files-stream.js} +12 -1
- package/dist/esm/bin/create-delete-removed-files-stream.js.map +1 -0
- package/dist/esm/bin/embed.js +260 -97
- package/dist/esm/bin/embed.js.map +1 -1
- package/dist/esm/bin/execute-pipeline.js +5 -0
- package/dist/esm/bin/execute-pipeline.js.map +1 -1
- package/dist/esm/bin/get-diff.js +6 -0
- package/dist/esm/bin/get-diff.js.map +1 -1
- package/dist/esm/{embeddings-command.options.js → command-options-schema.js} +1 -1
- package/dist/esm/command-options-schema.js.map +1 -0
- package/dist/esm/{embeddings-command.js → command.js} +4 -2
- package/dist/esm/command.js.map +1 -0
- package/dist/esm/{create-command.js → create-index-command.js} +13 -5
- package/dist/esm/create-index-command.js.map +1 -0
- package/dist/esm/{schema.js → define-index-schema.js} +1 -1
- package/dist/esm/define-index-schema.js.map +1 -0
- package/dist/esm/delete-command.js +11 -2
- package/dist/esm/delete-command.js.map +1 -1
- package/dist/esm/delete-index-command.js +4 -0
- package/dist/esm/delete-index-command.js.map +1 -1
- package/dist/esm/{delete-command.options.js → delete-options-schema.js} +1 -1
- package/dist/esm/delete-options-schema.js.map +1 -0
- package/dist/esm/embed-command.js +3 -4
- package/dist/esm/embed-command.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/search-command.js +20 -0
- package/dist/esm/search-command.js.map +1 -1
- package/dist/esm/utils/git/{metadata.js → extract-git-metadata.js} +4 -2
- package/dist/esm/utils/git/extract-git-metadata.js.map +1 -0
- package/dist/esm/utils/git/get-changed-files.js +87 -0
- package/dist/esm/utils/git/get-changed-files.js.map +1 -0
- package/dist/esm/utils/git/{file-changes.js → get-file-status.js} +9 -95
- package/dist/esm/utils/git/get-file-status.js.map +1 -0
- package/dist/esm/utils/git/{status.js → get-git-status.js} +5 -2
- package/dist/esm/utils/git/get-git-status.js.map +1 -0
- package/dist/esm/utils/git/get-git.js +30 -0
- package/dist/esm/utils/git/get-git.js.map +1 -0
- package/dist/esm/utils/git/index.js +7 -4
- package/dist/esm/utils/git/index.js.map +1 -1
- package/dist/esm/utils/git/is-file-changed.js +19 -0
- package/dist/esm/utils/git/is-file-changed.js.map +1 -0
- package/dist/esm/utils/git/resolve-project-root.js +22 -0
- package/dist/esm/utils/git/resolve-project-root.js.map +1 -0
- package/dist/esm/utils/markdown/index.js +3 -1
- package/dist/esm/utils/markdown/index.js.map +1 -1
- package/dist/esm/utils/markdown/is-markdown-file.js +10 -0
- package/dist/esm/utils/markdown/is-markdown-file.js.map +1 -0
- package/dist/esm/utils/markdown/parse-markdown-file.js +29 -0
- package/dist/esm/utils/markdown/parse-markdown-file.js.map +1 -0
- package/dist/esm/utils/markdown/{parser.js → parse-markdown.js} +8 -37
- package/dist/esm/utils/markdown/parse-markdown.js.map +1 -0
- package/dist/esm/utils/{embedding-dimensions.js → resolve-embedding-dimensions.js} +3 -1
- package/dist/esm/utils/resolve-embedding-dimensions.js.map +1 -0
- package/dist/esm/utils/{package-resolver.js → resolve-package.js} +4 -1
- package/dist/esm/utils/resolve-package.js.map +1 -0
- package/dist/esm/utils/ts-doc/create-typescript-document.js +27 -0
- package/dist/esm/utils/ts-doc/create-typescript-document.js.map +1 -0
- package/dist/esm/utils/ts-doc/extract-document-from-class-node.js +86 -0
- package/dist/esm/utils/ts-doc/extract-document-from-class-node.js.map +1 -0
- package/dist/esm/utils/ts-doc/extract-document-from-node.js +82 -0
- package/dist/esm/utils/ts-doc/extract-document-from-node.js.map +1 -0
- package/dist/esm/utils/ts-doc/index.js +3 -1
- package/dist/esm/utils/ts-doc/index.js.map +1 -1
- package/dist/esm/utils/ts-doc/is-typescript-file.js +10 -0
- package/dist/esm/utils/ts-doc/is-typescript-file.js.map +1 -0
- package/dist/esm/utils/ts-doc/{constants.js → node-kinds.js} +1 -1
- package/dist/esm/utils/ts-doc/node-kinds.js.map +1 -0
- package/dist/esm/utils/ts-doc/parse-ts-doc-from-file-sync.js +23 -0
- package/dist/esm/utils/ts-doc/parse-ts-doc-from-file-sync.js.map +1 -0
- package/dist/esm/utils/ts-doc/parse-ts-doc-sync.js +18 -0
- package/dist/esm/utils/ts-doc/parse-ts-doc-sync.js.map +1 -0
- package/dist/esm/utils/ts-doc/process-source-file.js +22 -0
- package/dist/esm/utils/ts-doc/process-source-file.js.map +1 -0
- package/dist/esm/utils/zod-to-azure-fields.js +7 -0
- package/dist/esm/utils/zod-to-azure-fields.js.map +1 -1
- package/dist/esm/utils/zod-to-azure-fields.test.js +8 -7
- package/dist/esm/utils/zod-to-azure-fields.test.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/bin/apply-schema.d.ts +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils/git/get-changed-files.d.ts +13 -0
- package/dist/types/utils/git/get-file-status.d.ts +13 -0
- package/dist/types/utils/git/{git-client.d.ts → get-git.d.ts} +0 -10
- package/dist/types/utils/git/index.d.ts +7 -4
- package/dist/types/utils/git/is-file-changed.d.ts +12 -0
- package/dist/types/utils/git/resolve-project-root.d.ts +10 -0
- package/dist/types/utils/markdown/index.d.ts +3 -1
- package/dist/types/utils/markdown/is-markdown-file.d.ts +7 -0
- package/dist/types/utils/markdown/parse-markdown-file.d.ts +14 -0
- package/dist/types/utils/markdown/parse-markdown.d.ts +14 -0
- package/dist/types/utils/ts-doc/create-typescript-document.d.ts +12 -0
- package/dist/types/utils/ts-doc/extract-document-from-class-node.d.ts +15 -0
- package/dist/types/utils/ts-doc/extract-document-from-node.d.ts +20 -0
- package/dist/types/utils/ts-doc/index.d.ts +3 -1
- package/dist/types/utils/ts-doc/is-typescript-file.d.ts +7 -0
- package/dist/types/utils/ts-doc/parse-ts-doc-from-file-sync.d.ts +14 -0
- package/dist/types/utils/ts-doc/parse-ts-doc-sync.d.ts +12 -0
- package/dist/types/utils/ts-doc/process-source-file.d.ts +11 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -8
- package/src/bin/apply-metadata.ts +69 -57
- package/src/bin/apply-schema.test.ts +2 -1
- package/src/bin/apply-schema.ts +6 -1
- package/src/bin/{delete-removed-files.ts → create-delete-removed-files-stream.ts} +12 -1
- package/src/bin/embed.ts +389 -145
- package/src/bin/execute-pipeline.ts +5 -0
- package/src/bin/get-diff.ts +7 -1
- package/src/bin/types.ts +1 -1
- package/src/{embeddings-command.ts → command.ts} +3 -1
- package/src/config.ts +1 -1
- package/src/{create-command.ts → create-index-command.ts} +15 -5
- package/src/delete-command.ts +11 -2
- package/src/delete-index-command.ts +4 -0
- package/src/embed-command.ts +3 -6
- package/src/index.ts +3 -3
- package/src/search-command.ts +20 -0
- package/src/utils/git/{metadata.ts → extract-git-metadata.ts} +3 -1
- package/src/utils/git/get-changed-files.ts +93 -0
- package/src/utils/git/{file-changes.ts → get-file-status.ts} +9 -103
- package/src/utils/git/{status.ts → get-git-status.ts} +4 -1
- package/src/utils/git/{git-client.ts → get-git.ts} +4 -22
- package/src/utils/git/index.ts +7 -4
- package/src/utils/git/is-file-changed.ts +21 -0
- package/src/utils/git/resolve-project-root.ts +22 -0
- package/src/utils/markdown/index.ts +3 -1
- package/src/utils/markdown/is-markdown-file.ts +9 -0
- package/src/utils/markdown/parse-markdown-file.ts +36 -0
- package/src/utils/markdown/{parser.ts → parse-markdown.ts} +16 -51
- package/src/utils/{embedding-dimensions.ts → resolve-embedding-dimensions.ts} +2 -0
- package/src/utils/{package-resolver.ts → resolve-package.ts} +3 -0
- package/src/utils/ts-doc/create-typescript-document.ts +36 -0
- package/src/utils/ts-doc/extract-document-from-class-node.ts +106 -0
- package/src/utils/ts-doc/extract-document-from-node.ts +120 -0
- package/src/utils/ts-doc/index.ts +3 -1
- package/src/utils/ts-doc/is-typescript-file.ts +9 -0
- package/src/utils/ts-doc/parse-ts-doc-from-file-sync.ts +32 -0
- package/src/utils/ts-doc/parse-ts-doc-sync.ts +23 -0
- package/src/utils/ts-doc/process-source-file.ts +30 -0
- package/src/utils/zod-to-azure-fields.test.ts +10 -7
- package/src/utils/zod-to-azure-fields.ts +7 -0
- package/src/version.ts +1 -1
- package/dist/esm/bin/delete-removed-files.js.map +0 -1
- package/dist/esm/bin/file-stream.js +0 -22
- package/dist/esm/bin/file-stream.js.map +0 -1
- package/dist/esm/create-command.js.map +0 -1
- package/dist/esm/delete-command.options.js.map +0 -1
- package/dist/esm/embeddings-command.js.map +0 -1
- package/dist/esm/embeddings-command.options.js.map +0 -1
- package/dist/esm/schema.js.map +0 -1
- package/dist/esm/utils/embedding-dimensions.js.map +0 -1
- package/dist/esm/utils/git/file-changes.js.map +0 -1
- package/dist/esm/utils/git/git-client.js +0 -48
- package/dist/esm/utils/git/git-client.js.map +0 -1
- package/dist/esm/utils/git/metadata.js.map +0 -1
- package/dist/esm/utils/git/status.js.map +0 -1
- package/dist/esm/utils/markdown/parser.js.map +0 -1
- package/dist/esm/utils/package-resolver.js.map +0 -1
- package/dist/esm/utils/ts-doc/constants.js.map +0 -1
- package/dist/esm/utils/ts-doc/extractors.js +0 -189
- package/dist/esm/utils/ts-doc/extractors.js.map +0 -1
- package/dist/esm/utils/ts-doc/parser.js +0 -46
- package/dist/esm/utils/ts-doc/parser.js.map +0 -1
- package/dist/types/bin/file-stream.d.ts +0 -1
- package/dist/types/utils/git/file-changes.d.ts +0 -36
- package/dist/types/utils/markdown/parser.d.ts +0 -34
- package/dist/types/utils/ts-doc/extractors.d.ts +0 -42
- package/dist/types/utils/ts-doc/parser.d.ts +0 -32
- package/src/bin/file-stream.ts +0 -34
- package/src/utils/ts-doc/extractors.ts +0 -260
- package/src/utils/ts-doc/parser.ts +0 -60
- /package/dist/types/bin/{delete-removed-files.d.ts → create-delete-removed-files-stream.d.ts} +0 -0
- /package/dist/types/{embeddings-command.options.d.ts → command-options-schema.d.ts} +0 -0
- /package/dist/types/{embeddings-command.d.ts → command.d.ts} +0 -0
- /package/dist/types/{create-command.d.ts → create-index-command.d.ts} +0 -0
- /package/dist/types/{schema.d.ts → define-index-schema.d.ts} +0 -0
- /package/dist/types/{delete-command.options.d.ts → delete-options-schema.d.ts} +0 -0
- /package/dist/types/utils/git/{metadata.d.ts → extract-git-metadata.d.ts} +0 -0
- /package/dist/types/utils/git/{status.d.ts → get-git-status.d.ts} +0 -0
- /package/dist/types/utils/{embedding-dimensions.d.ts → resolve-embedding-dimensions.d.ts} +0 -0
- /package/dist/types/utils/{package-resolver.d.ts → resolve-package.d.ts} +0 -0
- /package/dist/types/utils/ts-doc/{constants.d.ts → node-kinds.d.ts} +0 -0
- /package/src/{embeddings-command.options.ts → command-options-schema.ts} +0 -0
- /package/src/{schema.ts → define-index-schema.ts} +0 -0
- /package/src/{delete-command.options.ts → delete-options-schema.ts} +0 -0
- /package/src/utils/ts-doc/{constants.ts → node-kinds.ts} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { resolveProjectRoot } from './resolve-project-root.js';
|
|
2
|
+
import { getGit } from './get-git.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a list of files changed between `baseRef` and HEAD.
|
|
5
|
+
*
|
|
6
|
+
* Parses the output of `git diff --name-status` to classify each file as
|
|
7
|
+
* `'new'`, `'modified'`, or `'removed'`. Renames are expanded into a
|
|
8
|
+
* `'removed'` entry for the old path and a `'new'` entry for the new path.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Configuration controlling the diff reference and working directory.
|
|
11
|
+
* @returns Array of changed files with their status.
|
|
12
|
+
* @throws {Error} If the working directory is not inside a git repository.
|
|
13
|
+
*/
|
|
14
|
+
export const getChangedFiles = async (options) => {
|
|
15
|
+
const { diff, baseRef = 'HEAD~1', cwd = process.cwd() } = options;
|
|
16
|
+
// Skip git entirely when diff mode wasn't requested
|
|
17
|
+
if (!diff) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const projectRoot = resolveProjectRoot(cwd);
|
|
21
|
+
// Diff mode requires a git repository to resolve the project root against
|
|
22
|
+
if (!projectRoot) {
|
|
23
|
+
throw new Error('Not in a git repository. Cannot use --diff option.');
|
|
24
|
+
}
|
|
25
|
+
const { git } = getGit(cwd) ?? {};
|
|
26
|
+
// Cannot proceed without a working git client
|
|
27
|
+
if (!git) {
|
|
28
|
+
throw new Error('Failed to initialize git client');
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
// Get changes since baseRef with status (A=added, M=modified, D=deleted)
|
|
32
|
+
try {
|
|
33
|
+
const diffResult = await git.diff([`${baseRef}`, '--name-status']);
|
|
34
|
+
// Drop blank lines left by the trailing newline in git's output
|
|
35
|
+
const lines = diffResult.split('\n').filter((line) => line.trim() !== '');
|
|
36
|
+
const changedFiles = [];
|
|
37
|
+
// Classify each changed line by its git status code
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
// Match status and file path
|
|
40
|
+
// Format: "A\tfile.ts" or "M\tfile.ts" or "D\tfile.ts"
|
|
41
|
+
// Also handle renames: "R100\told.ts\tnew.ts"
|
|
42
|
+
const renameMatch = line.match(/^R\d*\s+(.+?)\s+(.+)$/);
|
|
43
|
+
// Expand a detected rename into a removed old-path entry and a new-path entry
|
|
44
|
+
if (renameMatch) {
|
|
45
|
+
const [, oldFile, newFile] = renameMatch;
|
|
46
|
+
// Add both the removed old file and the new file
|
|
47
|
+
changedFiles.push({ filepath: `${projectRoot}/${oldFile}`, status: 'removed' });
|
|
48
|
+
changedFiles.push({ filepath: `${projectRoot}/${newFile}`, status: 'new' });
|
|
49
|
+
// Rename already handled above; skip the add/modify/delete matching below
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const match = line.match(/^([AMD])\s+(.+)$/);
|
|
53
|
+
// Only lines matching the single-letter add/modify/delete status format are actionable
|
|
54
|
+
if (match) {
|
|
55
|
+
const [, gitStatus, file] = match;
|
|
56
|
+
const fullPath = `${projectRoot}/${file}`;
|
|
57
|
+
let status;
|
|
58
|
+
// Map git's single-letter status codes to our ChangedFile status values
|
|
59
|
+
if (gitStatus === 'A') {
|
|
60
|
+
status = 'new';
|
|
61
|
+
}
|
|
62
|
+
else if (gitStatus === 'M') {
|
|
63
|
+
status = 'modified';
|
|
64
|
+
}
|
|
65
|
+
else if (gitStatus === 'D') {
|
|
66
|
+
status = 'removed';
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Skip unknown statuses (C=copied, etc.)
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
changedFiles.push({ filepath: fullPath, status });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return changedFiles;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Handle case where baseRef doesn't exist (e.g., first commit)
|
|
79
|
+
console.warn(`⚠️ Warning: Git reference '${baseRef}' not found. Processing all files.`);
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error(`Git diff failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=get-changed-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-changed-files.js","sourceRoot":"","sources":["../../../../src/utils/git/get-changed-files.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;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;YACzF,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,80 +1,5 @@
|
|
|
1
1
|
import { join, relative } from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
4
|
-
* Returns a list of files changed between `baseRef` and HEAD.
|
|
5
|
-
*
|
|
6
|
-
* Parses the output of `git diff --name-status` to classify each file as
|
|
7
|
-
* `'new'`, `'modified'`, or `'removed'`. Renames are expanded into a
|
|
8
|
-
* `'removed'` entry for the old path and a `'new'` entry for the new path.
|
|
9
|
-
*
|
|
10
|
-
* @param options - Configuration controlling the diff reference and working directory.
|
|
11
|
-
* @returns Array of changed files with their status.
|
|
12
|
-
* @throws {Error} If the working directory is not inside a git repository.
|
|
13
|
-
*/
|
|
14
|
-
export const getChangedFiles = async (options) => {
|
|
15
|
-
const { diff, baseRef = 'HEAD~1', cwd = process.cwd() } = options;
|
|
16
|
-
if (!diff) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
const projectRoot = resolveProjectRoot(cwd);
|
|
20
|
-
if (!projectRoot) {
|
|
21
|
-
throw new Error('Not in a git repository. Cannot use --diff option.');
|
|
22
|
-
}
|
|
23
|
-
const { git } = getGit(cwd) ?? {};
|
|
24
|
-
if (!git) {
|
|
25
|
-
throw new Error('Failed to initialize git client');
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
// Get changes since baseRef with status (A=added, M=modified, D=deleted)
|
|
29
|
-
try {
|
|
30
|
-
const diffResult = await git.diff([`${baseRef}`, '--name-status']);
|
|
31
|
-
const lines = diffResult.split('\n').filter((line) => line.trim() !== '');
|
|
32
|
-
const changedFiles = [];
|
|
33
|
-
for (const line of lines) {
|
|
34
|
-
// Match status and file path
|
|
35
|
-
// Format: "A\tfile.ts" or "M\tfile.ts" or "D\tfile.ts"
|
|
36
|
-
// Also handle renames: "R100\told.ts\tnew.ts"
|
|
37
|
-
const renameMatch = line.match(/^R\d*\s+(.+?)\s+(.+)$/);
|
|
38
|
-
if (renameMatch) {
|
|
39
|
-
const [, oldFile, newFile] = renameMatch;
|
|
40
|
-
// Add both the removed old file and the new file
|
|
41
|
-
changedFiles.push({ filepath: `${projectRoot}/${oldFile}`, status: 'removed' });
|
|
42
|
-
changedFiles.push({ filepath: `${projectRoot}/${newFile}`, status: 'new' });
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const match = line.match(/^([AMD])\s+(.+)$/);
|
|
46
|
-
if (match) {
|
|
47
|
-
const [, gitStatus, file] = match;
|
|
48
|
-
const fullPath = `${projectRoot}/${file}`;
|
|
49
|
-
let status;
|
|
50
|
-
if (gitStatus === 'A') {
|
|
51
|
-
status = 'new';
|
|
52
|
-
}
|
|
53
|
-
else if (gitStatus === 'M') {
|
|
54
|
-
status = 'modified';
|
|
55
|
-
}
|
|
56
|
-
else if (gitStatus === 'D') {
|
|
57
|
-
status = 'removed';
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
// Skip unknown statuses (C=copied, etc.)
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
changedFiles.push({ filepath: fullPath, status });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return changedFiles;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
// Handle case where baseRef doesn't exist (e.g., first commit)
|
|
70
|
-
console.warn(`⚠️ Warning: Git reference '${baseRef}' not found. Processing all files.`);
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
throw new Error(`Git diff failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
2
|
+
import { getGit } from './get-git.js';
|
|
78
3
|
/**
|
|
79
4
|
* Determines the git change status of a single file.
|
|
80
5
|
*
|
|
@@ -88,8 +13,8 @@ export const getChangedFiles = async (options) => {
|
|
|
88
13
|
*/
|
|
89
14
|
export const getFileStatus = async (filePath) => {
|
|
90
15
|
const { git, gitRepoPath } = getGit(filePath) ?? {};
|
|
16
|
+
// Not in a git repository, assume new
|
|
91
17
|
if (!git || !gitRepoPath) {
|
|
92
|
-
// Not in a git repository, assume new
|
|
93
18
|
return [{ filepath: filePath, status: 'new' }];
|
|
94
19
|
}
|
|
95
20
|
const gitFilePath = relative(gitRepoPath, filePath);
|
|
@@ -101,8 +26,8 @@ export const getFileStatus = async (filePath) => {
|
|
|
101
26
|
.raw(['ls-files', '--error-unmatch', normalizedGitFilePath])
|
|
102
27
|
.then(() => true)
|
|
103
28
|
.catch(() => false);
|
|
29
|
+
// File is tracked at this path, it's modified
|
|
104
30
|
if (isTracked) {
|
|
105
|
-
// File is tracked at this path, it's modified
|
|
106
31
|
return [{ filepath: filePath, status: 'modified' }];
|
|
107
32
|
}
|
|
108
33
|
// File is not tracked - quickly check if it's explicitly untracked
|
|
@@ -115,6 +40,7 @@ export const getFileStatus = async (filePath) => {
|
|
|
115
40
|
normalizedGitFilePath,
|
|
116
41
|
]);
|
|
117
42
|
const trimmed = fileStatusOutput.trim();
|
|
43
|
+
// Only inspect porcelain output when git actually reported something for this path
|
|
118
44
|
if (trimmed.length > 0) {
|
|
119
45
|
// If status shows ??, it's untracked (truly new)
|
|
120
46
|
if (/^\?\?/.test(trimmed)) {
|
|
@@ -130,10 +56,13 @@ export const getFileStatus = async (filePath) => {
|
|
|
130
56
|
try {
|
|
131
57
|
// Get full git status to check for renames (only if needed)
|
|
132
58
|
const statusOutput = await git.raw(['status', '--porcelain']);
|
|
59
|
+
// Drop blank lines left by the trailing newline in git's output
|
|
133
60
|
const lines = statusOutput.split('\n').filter((line) => line.trim() !== '');
|
|
61
|
+
// Scan every status line for a rename or copy that produced this file
|
|
134
62
|
for (const line of lines) {
|
|
135
63
|
// Check for rename format: "R100\told.ts\tnew.ts"
|
|
136
64
|
const renameMatch = line.match(/^R\d+\s+(.+?)\s+(.+)$/);
|
|
65
|
+
// A rename line resolves this file only if it matches the new path
|
|
137
66
|
if (renameMatch) {
|
|
138
67
|
const [, oldPath, newPath] = renameMatch;
|
|
139
68
|
const oldFullPath = join(gitRepoPath, oldPath);
|
|
@@ -148,6 +77,7 @@ export const getFileStatus = async (filePath) => {
|
|
|
148
77
|
}
|
|
149
78
|
// Check for copy format: "C100\told.ts\tnew.ts" (similar to rename)
|
|
150
79
|
const copyMatch = line.match(/^C\d+\s+(.+?)\s+(.+)$/);
|
|
80
|
+
// A copy line resolves this file only if it matches the new path
|
|
151
81
|
if (copyMatch) {
|
|
152
82
|
const [, , newPath] = copyMatch;
|
|
153
83
|
const newFullPath = join(gitRepoPath, newPath);
|
|
@@ -192,20 +122,4 @@ export const getFileStatus = async (filePath) => {
|
|
|
192
122
|
return [{ filepath: filePath, status: 'new' }];
|
|
193
123
|
}
|
|
194
124
|
};
|
|
195
|
-
|
|
196
|
-
* Checks whether a file path appears in a list of changed files.
|
|
197
|
-
*
|
|
198
|
-
* When the changed-files list is empty (no diff filtering active), every
|
|
199
|
-
* file is considered changed so that all files are processed.
|
|
200
|
-
*
|
|
201
|
-
* @param filePath - Absolute file path to look up.
|
|
202
|
-
* @param changedFiles - Array of {@link ChangedFile} entries to search.
|
|
203
|
-
* @returns `true` if the file has changed or if diff filtering is disabled.
|
|
204
|
-
*/
|
|
205
|
-
export const isFileChanged = (filePath, changedFiles) => {
|
|
206
|
-
if (changedFiles.length === 0) {
|
|
207
|
-
return true; // If no diff filtering, process all files
|
|
208
|
-
}
|
|
209
|
-
return changedFiles.some((file) => file.filepath === filePath);
|
|
210
|
-
};
|
|
211
|
-
//# sourceMappingURL=file-changes.js.map
|
|
125
|
+
//# sourceMappingURL=get-file-status.js.map
|
|
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QAC3E,CAAC;QAAC,MAAM,CAAC;YACP,0CAA0C;YAC1C,OAAO,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,iDAAiD;QACjD,OAAO,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { resolveProjectRoot
|
|
1
|
+
import { resolveProjectRoot } from './resolve-project-root.js';
|
|
2
|
+
import { getGit } from './get-git.js';
|
|
2
3
|
/**
|
|
3
4
|
* Retrieves a summary of the current git working-tree status.
|
|
4
5
|
*
|
|
@@ -12,10 +13,12 @@ import { resolveProjectRoot, getGit } from './git-client.js';
|
|
|
12
13
|
*/
|
|
13
14
|
export const getGitStatus = async (cwd = process.cwd()) => {
|
|
14
15
|
const projectRoot = resolveProjectRoot(cwd);
|
|
16
|
+
// Status can only be reported when cwd is inside a git repository
|
|
15
17
|
if (!projectRoot) {
|
|
16
18
|
throw new Error('Not in a git repository');
|
|
17
19
|
}
|
|
18
20
|
const { git } = getGit(cwd) ?? {};
|
|
21
|
+
// Fail fast if the git client could not be created for this repository
|
|
19
22
|
if (!git) {
|
|
20
23
|
throw new Error('Failed to initialize git client');
|
|
21
24
|
}
|
|
@@ -37,4 +40,4 @@ export const getGitStatus = async (cwd = process.cwd()) => {
|
|
|
37
40
|
throw new Error(`Failed to get git status: ${error instanceof Error ? error.message : String(error)}`);
|
|
38
41
|
}
|
|
39
42
|
};
|
|
40
|
-
//# sourceMappingURL=status.js.map
|
|
43
|
+
//# sourceMappingURL=get-git-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-git-status.js","sourceRoot":"","sources":["../../../../src/utils/git/get-git-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACtF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { simpleGit } from 'simple-git';
|
|
2
|
+
import { resolveProjectRoot } from './resolve-project-root.js';
|
|
3
|
+
const gitCache = new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Returns a cached `SimpleGit` instance scoped to the repository that
|
|
6
|
+
* contains `filePath`.
|
|
7
|
+
*
|
|
8
|
+
* Instances are cached by repository root to avoid repeatedly spawning
|
|
9
|
+
* new git processes for the same repo.
|
|
10
|
+
*
|
|
11
|
+
* @param filePath - Absolute file path to locate the repository for.
|
|
12
|
+
* @returns An object containing the git client and the repository root path,
|
|
13
|
+
* or `undefined` when `filePath` is not inside a git repository.
|
|
14
|
+
*/
|
|
15
|
+
export const getGit = (filePath) => {
|
|
16
|
+
const gitRepoPath = resolveProjectRoot(filePath);
|
|
17
|
+
// Only build/cache a client when the file is inside a git repository
|
|
18
|
+
if (gitRepoPath) {
|
|
19
|
+
// Reuse an existing client for this repo root instead of spawning a new one
|
|
20
|
+
if (!gitCache.has(gitRepoPath)) {
|
|
21
|
+
gitCache.set(gitRepoPath, simpleGit(gitRepoPath));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
git: gitCache.get(gitRepoPath),
|
|
25
|
+
gitRepoPath,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=get-git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-git.js","sourceRoot":"","sources":["../../../../src/utils/git/get-git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,QAAgB,EACiD,EAAE;IACnE,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACjD,qEAAqE;IACrE,IAAI,WAAW,EAAE,CAAC;QAChB,4EAA4E;QAC5E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO;YACL,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC;YAC9B,WAAW;SACZ,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// Re-export git client utilities
|
|
2
|
-
export { resolveProjectRoot
|
|
2
|
+
export { resolveProjectRoot } from './resolve-project-root.js';
|
|
3
|
+
export { getGit } from './get-git.js';
|
|
3
4
|
// Re-export metadata functions
|
|
4
|
-
export { extractGitMetadata } from './metadata.js';
|
|
5
|
+
export { extractGitMetadata } from './extract-git-metadata.js';
|
|
5
6
|
// Re-export file change functions
|
|
6
|
-
export { getChangedFiles
|
|
7
|
+
export { getChangedFiles } from './get-changed-files.js';
|
|
8
|
+
export { getFileStatus } from './get-file-status.js';
|
|
9
|
+
export { isFileChanged } from './is-file-changed.js';
|
|
7
10
|
// Re-export status functions
|
|
8
|
-
export { getGitStatus } from './status.js';
|
|
11
|
+
export { getGitStatus } from './get-git-status.js';
|
|
9
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/git/index.ts"],"names":[],"mappings":"AAQA,iCAAiC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/git/index.ts"],"names":[],"mappings":"AAQA,iCAAiC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,+BAA+B;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,kCAAkC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,6BAA6B;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a file path appears in a list of changed files.
|
|
3
|
+
*
|
|
4
|
+
* When the changed-files list is empty (no diff filtering active), every
|
|
5
|
+
* file is considered changed so that all files are processed.
|
|
6
|
+
*
|
|
7
|
+
* @param filePath - Absolute file path to look up.
|
|
8
|
+
* @param changedFiles - Array of {@link ChangedFile} entries to search.
|
|
9
|
+
* @returns `true` if the file has changed or if diff filtering is disabled.
|
|
10
|
+
*/
|
|
11
|
+
export const isFileChanged = (filePath, changedFiles) => {
|
|
12
|
+
// If no diff filtering, process all files
|
|
13
|
+
if (changedFiles.length === 0) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
// A file is considered changed when its path matches any entry in the list
|
|
17
|
+
return changedFiles.some((file) => file.filepath === filePath);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=is-file-changed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-file-changed.js","sourceRoot":"","sources":["../../../../src/utils/git/is-file-changed.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,YAA2B,EAAW,EAAE;IACtF,0CAA0C;IAC1C,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2EAA2E;IAC3E,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { findUpSync } from 'find-up';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the git repository root for a given file path.
|
|
6
|
+
*
|
|
7
|
+
* Walks up the directory tree looking for a `.git` directory or file
|
|
8
|
+
* (to support worktrees) and returns the enclosing directory.
|
|
9
|
+
*
|
|
10
|
+
* @param filePath - Absolute file or directory path to resolve from.
|
|
11
|
+
* @returns Absolute path to the repository root, or `undefined` if not inside a git repo.
|
|
12
|
+
*/
|
|
13
|
+
export const resolveProjectRoot = (filePath) => {
|
|
14
|
+
// if we are in the root of the git repository, return the root
|
|
15
|
+
if (existsSync(join(filePath, '.git'))) {
|
|
16
|
+
return filePath;
|
|
17
|
+
}
|
|
18
|
+
const gitRepoPath = findUpSync('.git', { cwd: dirname(filePath), type: 'both' });
|
|
19
|
+
const projectRoot = gitRepoPath?.replace(/\.git$/, '');
|
|
20
|
+
return projectRoot;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=resolve-project-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-project-root.js","sourceRoot":"","sources":["../../../../src/utils/git/resolve-project-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAsB,EAAE;IACzE,+DAA+D;IAC/D,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACjF,MAAM,WAAW,GAAG,WAAW,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
// Re-export parser functions
|
|
2
|
-
export { isMarkdownFile
|
|
2
|
+
export { isMarkdownFile } from './is-markdown-file.js';
|
|
3
|
+
export { parseMarkdown } from './parse-markdown.js';
|
|
4
|
+
export { parseMarkdownFile } from './parse-markdown-file.js';
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/markdown/index.ts"],"names":[],"mappings":"AAGA,6BAA6B;AAC7B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/markdown/index.ts"],"names":[],"mappings":"AAGA,6BAA6B;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a file path has a Markdown (`.md`) or MDX (`.mdx`) extension.
|
|
3
|
+
*
|
|
4
|
+
* @param filePath - Absolute or relative file path.
|
|
5
|
+
* @returns `true` when the extension is `.md` or `.mdx`.
|
|
6
|
+
*/
|
|
7
|
+
export const isMarkdownFile = (filePath) => {
|
|
8
|
+
return filePath.endsWith('.md') || filePath.endsWith('.mdx');
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=is-markdown-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-markdown-file.js","sourceRoot":"","sources":["../../../../src/utils/markdown/is-markdown-file.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAW,EAAE;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC/D,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { assert } from 'node:console';
|
|
3
|
+
import { isMarkdownFile } from './is-markdown-file.js';
|
|
4
|
+
import { parseMarkdown } from './parse-markdown.js';
|
|
5
|
+
/**
|
|
6
|
+
* Reads a Markdown or MDX file from disk and parses it into chunked documents.
|
|
7
|
+
*
|
|
8
|
+
* Delegates to {@link parseMarkdown} after reading the file content, then
|
|
9
|
+
* enriches each resulting document with the `rootPath` from the source file.
|
|
10
|
+
*
|
|
11
|
+
* @template T - Additional frontmatter attributes.
|
|
12
|
+
* @param file - Source file descriptor with path and optional project root.
|
|
13
|
+
* @returns Array of Markdown documents with root-path metadata.
|
|
14
|
+
* @throws {AssertionError} If the file does not have a `.md` or `.mdx` extension.
|
|
15
|
+
*/
|
|
16
|
+
export const parseMarkdownFile = async (file) => {
|
|
17
|
+
assert(isMarkdownFile(file.path), `File ${file.path} is not a markdown or MDX file`);
|
|
18
|
+
const content = readFileSync(file.path, 'utf8');
|
|
19
|
+
const result = await parseMarkdown(content, file.relativePath ?? file.path);
|
|
20
|
+
// Enrich each parsed chunk with the file's project root for downstream path resolution
|
|
21
|
+
return result.map((document) => ({
|
|
22
|
+
...document,
|
|
23
|
+
metadata: {
|
|
24
|
+
...document.metadata,
|
|
25
|
+
rootPath: file.projectRoot,
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=parse-markdown-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-markdown-file.js","sourceRoot":"","sources":["../../../../src/utils/markdown/parse-markdown-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAGpC,IAAgB,EACgB,EAAE;IAClC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,IAAI,CAAC,IAAI,gCAAgC,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,aAAa,CAAI,OAAO,EAAE,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/E,uFAAuF;IACvF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC/B,GAAG,QAAQ;QACX,QAAQ,EAAE;YACR,GAAG,QAAQ,CAAC,QAAQ;YACpB,QAAQ,EAAE,IAAI,CAAC,WAAW;SAC3B;KACF,CAAC,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { assert } from 'node:console';
|
|
3
1
|
import { default as grayMatter } from 'gray-matter';
|
|
4
2
|
import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';
|
|
5
3
|
import { generateChunkId } from '../generate-chunk-id.js';
|
|
@@ -21,15 +19,6 @@ const markdownConfig = {
|
|
|
21
19
|
],
|
|
22
20
|
keepSeparator: true,
|
|
23
21
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Checks whether a file path has a Markdown (`.md`) or MDX (`.mdx`) extension.
|
|
26
|
-
*
|
|
27
|
-
* @param filePath - Absolute or relative file path.
|
|
28
|
-
* @returns `true` when the extension is `.md` or `.mdx`.
|
|
29
|
-
*/
|
|
30
|
-
export const isMarkdownFile = (filePath) => {
|
|
31
|
-
return filePath.endsWith('.md') || filePath.endsWith('.mdx');
|
|
32
|
-
};
|
|
33
22
|
/**
|
|
34
23
|
* Validates that a text chunk contains meaningful content.
|
|
35
24
|
*
|
|
@@ -41,6 +30,7 @@ export const isMarkdownFile = (filePath) => {
|
|
|
41
30
|
*/
|
|
42
31
|
const isValidChunk = (chunk) => {
|
|
43
32
|
const trimmed = chunk.trim();
|
|
33
|
+
// Skip empty or whitespace-only chunks
|
|
44
34
|
if (!trimmed)
|
|
45
35
|
return false;
|
|
46
36
|
// Skip chunks that are only code fence markers
|
|
@@ -62,6 +52,7 @@ const isValidChunk = (chunk) => {
|
|
|
62
52
|
*/
|
|
63
53
|
export const parseMarkdown = async (content, source) => {
|
|
64
54
|
const { content: markdownContent, data } = grayMatter(content);
|
|
55
|
+
// Prefix each frontmatter key with `md_` to namespace it in the document metadata
|
|
65
56
|
const markdownAttributes = Object.entries(data).reduce((acc, [key, value]) => {
|
|
66
57
|
acc[`md_${key}`] = value;
|
|
67
58
|
return acc;
|
|
@@ -72,41 +63,21 @@ export const parseMarkdown = async (content, source) => {
|
|
|
72
63
|
const chunks = await textSplitter.splitText(markdownContent);
|
|
73
64
|
// Filter out empty chunks and chunks that are just code fence markers
|
|
74
65
|
const validChunks = chunks.filter((chunk) => {
|
|
66
|
+
// Discard invalid chunks; keep everything else
|
|
75
67
|
if (!isValidChunk(chunk)) {
|
|
76
68
|
return false;
|
|
77
69
|
}
|
|
78
70
|
return true;
|
|
79
71
|
});
|
|
80
|
-
return validChunks
|
|
72
|
+
return (validChunks
|
|
73
|
+
// Wrap each valid chunk into a vector-store-ready document
|
|
74
|
+
.map((chunk, _index) => ({
|
|
81
75
|
id: generateChunkId(source, _index),
|
|
82
76
|
pageContent: chunk,
|
|
83
77
|
metadata: {
|
|
84
78
|
source,
|
|
85
79
|
attributes: markdownAttributes,
|
|
86
80
|
},
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Reads a Markdown or MDX file from disk and parses it into chunked documents.
|
|
91
|
-
*
|
|
92
|
-
* Delegates to {@link parseMarkdown} after reading the file content, then
|
|
93
|
-
* enriches each resulting document with the `rootPath` from the source file.
|
|
94
|
-
*
|
|
95
|
-
* @template T - Additional frontmatter attributes.
|
|
96
|
-
* @param file - Source file descriptor with path and optional project root.
|
|
97
|
-
* @returns Array of Markdown documents with root-path metadata.
|
|
98
|
-
* @throws {AssertionError} If the file does not have a `.md` or `.mdx` extension.
|
|
99
|
-
*/
|
|
100
|
-
export const parseMarkdownFile = async (file) => {
|
|
101
|
-
assert(isMarkdownFile(file.path), `File ${file.path} is not a markdown or MDX file`);
|
|
102
|
-
const content = readFileSync(file.path, 'utf8');
|
|
103
|
-
const result = await parseMarkdown(content, file.relativePath ?? file.path);
|
|
104
|
-
return result.map((document) => ({
|
|
105
|
-
...document,
|
|
106
|
-
metadata: {
|
|
107
|
-
...document.metadata,
|
|
108
|
-
rootPath: file.projectRoot,
|
|
109
|
-
},
|
|
110
|
-
}));
|
|
81
|
+
})));
|
|
111
82
|
};
|
|
112
|
-
//# sourceMappingURL=
|
|
83
|
+
//# sourceMappingURL=parse-markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-markdown.js","sourceRoot":"","sources":["../../../../src/utils/markdown/parse-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,cAAc,GAAG;IACrB,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,GAAG;IACjB,UAAU,EAAE;QACV,MAAM;QACN,OAAO;QACP,QAAQ;QACR,SAAS;QACT,UAAU;QACV,WAAW;QACX,OAAO;QACP,SAAS;QACT,SAAS;QACT,MAAM;QACN,IAAI;KACL;IACD,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,YAAY,GAAG,CAAC,KAAa,EAAW,EAAE;IAC9C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,uCAAuC;IACvC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,+CAA+C;IAC/C,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,OAAe,EACf,MAAc,EACkB,EAAE;IAClC,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAC/D,kFAAkF;IAClF,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACpD,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACpB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC,EACD;QACE,IAAI,EAAE,UAAU;KACU,CAC7B,CAAC;IACF,MAAM,YAAY,GAAG,IAAI,8BAA8B,CAAC,cAAc,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAE7D,sEAAsE;IACtE,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1C,+CAA+C;QAC/C,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,WAAW;QACT,2DAA2D;SAC1D,GAAG,CACF,CAAC,KAAK,EAAE,MAAM,EAAuB,EAAE,CAAC,CAAC;QACvC,EAAE,EAAE,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC;QACnC,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE;YACR,MAAM;YACN,UAAU,EAAE,kBAAuD;SACpE;KACF,CAAC,CACH,CACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -25,8 +25,10 @@ const KNOWN_MODEL_DIMENSIONS = new Map([
|
|
|
25
25
|
*/
|
|
26
26
|
export function resolveEmbeddingDimensions(model, configDimensions) {
|
|
27
27
|
const known = KNOWN_MODEL_DIMENSIONS.get(model);
|
|
28
|
+
// Known models resolve directly from the lookup map.
|
|
28
29
|
if (known !== undefined)
|
|
29
30
|
return known;
|
|
31
|
+
// Unknown models fall back to an explicit dimensions override from config.
|
|
30
32
|
if (configDimensions !== undefined)
|
|
31
33
|
return configDimensions;
|
|
32
34
|
const knownModels = [...KNOWN_MODEL_DIMENSIONS.keys()].join(', ');
|
|
@@ -34,4 +36,4 @@ export function resolveEmbeddingDimensions(model, configDimensions) {
|
|
|
34
36
|
`Known models: ${knownModels}. ` +
|
|
35
37
|
'For custom models, set `index.embedding.dimensions` in the config.');
|
|
36
38
|
}
|
|
37
|
-
//# sourceMappingURL=embedding-dimensions.js.map
|
|
39
|
+
//# sourceMappingURL=resolve-embedding-dimensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-embedding-dimensions.js","sourceRoot":"","sources":["../../../src/utils/resolve-embedding-dimensions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAgC,IAAI,GAAG,CAAC;IAClE,CAAC,wBAAwB,EAAE,IAAI,CAAC;IAChC,CAAC,wBAAwB,EAAE,IAAI,CAAC;IAChC,CAAC,wBAAwB,EAAE,IAAI,CAAC;CACjC,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAa,EAAE,gBAAyB;IACjF,MAAM,KAAK,GAAG,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChD,qDAAqD;IACrD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAEtC,2EAA2E;IAC3E,IAAI,gBAAgB,KAAK,SAAS;QAAE,OAAO,gBAAgB,CAAC;IAE5D,MAAM,WAAW,GAAG,CAAC,GAAG,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,MAAM,IAAI,KAAK,CACb,4BAA4B,KAAK,KAAK;QACpC,iBAAiB,WAAW,IAAI;QAChC,oEAAoE,CACvE,CAAC;AACJ,CAAC"}
|
|
@@ -23,8 +23,10 @@ const packageMap = new Map();
|
|
|
23
23
|
export async function resolvePackage(filePath) {
|
|
24
24
|
// Check cache: iterate through known package directories
|
|
25
25
|
for (const packageRoot of packageMap.keys()) {
|
|
26
|
+
// A cached package root that is a prefix of filePath is the closest known package.
|
|
26
27
|
if (filePath.startsWith(packageRoot)) {
|
|
27
28
|
const packageJson = packageMap.get(packageRoot);
|
|
29
|
+
// Guard: satisfies TypeScript's strict Map#get return type despite the key check above.
|
|
28
30
|
if (packageJson) {
|
|
29
31
|
return packageJson;
|
|
30
32
|
}
|
|
@@ -34,6 +36,7 @@ export async function resolvePackage(filePath) {
|
|
|
34
36
|
// readPackageUp expects a directory path, not a file path
|
|
35
37
|
const dirPath = dirname(filePath);
|
|
36
38
|
const result = await readPackageUp({ cwd: dirPath, normalize: false });
|
|
39
|
+
// Cache the resolved package.json so future lookups under the same root are free.
|
|
37
40
|
if (result) {
|
|
38
41
|
// Cache using the package directory (where package.json is located)
|
|
39
42
|
const packageDir = dirname(result.path);
|
|
@@ -41,4 +44,4 @@ export async function resolvePackage(filePath) {
|
|
|
41
44
|
}
|
|
42
45
|
return result?.packageJson;
|
|
43
46
|
}
|
|
44
|
-
//# sourceMappingURL=package
|
|
47
|
+
//# sourceMappingURL=resolve-package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-package.js","sourceRoot":"","sources":["../../../src/utils/resolve-package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAoB,MAAM,iBAAiB,CAAC;AAElE;;;GAGG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,yDAAyD;IACzD,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5C,mFAAmF;QACnF,IAAI,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAChD,wFAAwF;YACxF,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,8CAA8C;IAC9C,0DAA0D;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAEvE,kFAAkF;IAClF,IAAI,MAAM,EAAE,CAAC;QACX,oEAAoE;QACpE,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,EAAE,WAAW,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { generateChunkId } from '../generate-chunk-id.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a TypescriptDocument from the given parameters.
|
|
4
|
+
* @param sourceFile - The source file containing the node.
|
|
5
|
+
* @param pageContent - The content of the document.
|
|
6
|
+
* @param tsKind - The TypeScript node kind name.
|
|
7
|
+
* @param tsName - The name of the TypeScript node.
|
|
8
|
+
* @param options - Optional parsing configuration.
|
|
9
|
+
* @returns A TypeScript document with metadata.
|
|
10
|
+
*/
|
|
11
|
+
export const createTypescriptDocument = (sourceFile, pageContent, tsKind, tsName, options) => {
|
|
12
|
+
const source = sourceFile.getFilePath().replace(/^\/+/, '');
|
|
13
|
+
return {
|
|
14
|
+
id: generateChunkId(source),
|
|
15
|
+
pageContent,
|
|
16
|
+
metadata: {
|
|
17
|
+
source,
|
|
18
|
+
...(options?.projectRoot && { rootPath: options.projectRoot }),
|
|
19
|
+
attributes: {
|
|
20
|
+
type: 'tsdoc',
|
|
21
|
+
ts_kind: tsKind,
|
|
22
|
+
ts_name: tsName,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=create-typescript-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-typescript-document.js","sourceRoot":"","sources":["../../../../src/utils/ts-doc/create-typescript-document.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,UAA6B,EAC7B,WAAmB,EACnB,MAAc,EACd,MAAc,EACd,OAA2B,EACP,EAAE;IACtB,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5D,OAAO;QACL,EAAE,EAAE,eAAe,CAAC,MAAM,CAAC;QAC3B,WAAW;QACX,QAAQ,EAAE;YACR,MAAM;YACN,GAAG,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;YAC9D,UAAU,EAAE;gBACV,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,MAAM;aAChB;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|