docs-coderef 0.2.0 → 0.4.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.
- package/CHANGELOG.md +30 -0
- package/README.md +27 -0
- package/dist/chunk-U3LM2QL7.mjs +268 -0
- package/dist/cli/fix.js +325 -152
- package/dist/cli/fix.mjs +108 -106
- package/dist/cli/validate.js +216 -33
- package/dist/cli/validate.mjs +20 -17
- package/package.json +8 -1
- package/dist/chunk-NTTV47AI.mjs +0 -73
package/dist/cli/fix.js
CHANGED
|
@@ -676,72 +676,244 @@ var fs3 = __toESM(require("fs"));
|
|
|
676
676
|
var path3 = __toESM(require("path"));
|
|
677
677
|
var readline = __toESM(require("readline"));
|
|
678
678
|
|
|
679
|
-
// src/utils/
|
|
680
|
-
var
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
679
|
+
// src/utils/message-formatter.ts
|
|
680
|
+
var import_chalk = __toESM(require("chalk"));
|
|
681
|
+
var COLOR_SCHEMES = {
|
|
682
|
+
error: import_chalk.default.redBright,
|
|
683
|
+
warning: import_chalk.default.yellow,
|
|
684
|
+
info: import_chalk.default.cyan,
|
|
685
|
+
success: import_chalk.default.green,
|
|
686
|
+
debug: import_chalk.default.gray,
|
|
687
|
+
neutral: import_chalk.default.white,
|
|
688
|
+
// Accent colors
|
|
689
|
+
highlight: import_chalk.default.cyan.bold,
|
|
690
|
+
dim: import_chalk.default.dim,
|
|
691
|
+
code: import_chalk.default.yellow
|
|
692
|
+
};
|
|
693
|
+
var EMOJIS = {
|
|
694
|
+
error: "\u274C",
|
|
695
|
+
warning: "\u26A0\uFE0F",
|
|
696
|
+
success: "\u2705",
|
|
697
|
+
info: "\u2139\uFE0F",
|
|
698
|
+
search: "\u{1F50D}",
|
|
699
|
+
fix: "\u{1F527}",
|
|
700
|
+
file: "\u{1F4C4}",
|
|
701
|
+
stats: "\u{1F4CA}",
|
|
702
|
+
backup: "\u{1F4BE}",
|
|
703
|
+
skip: "\u23ED\uFE0F"
|
|
704
|
+
};
|
|
705
|
+
var MessageFormatter = class {
|
|
706
|
+
/**
|
|
707
|
+
* Set verbose mode
|
|
708
|
+
* @param enabled Whether verbose mode is enabled
|
|
709
|
+
*/
|
|
710
|
+
static setVerbose(enabled) {
|
|
711
|
+
this.verboseMode = enabled;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Format error message
|
|
715
|
+
* @param text Error message text
|
|
716
|
+
* @returns Formatted error message with emoji and color
|
|
717
|
+
*/
|
|
718
|
+
static error(text) {
|
|
719
|
+
return `${COLOR_SCHEMES.error(`${EMOJIS.error} ${text}`)}`;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Format warning message
|
|
723
|
+
* @param text Warning message text
|
|
724
|
+
* @returns Formatted warning message with emoji and color
|
|
725
|
+
*/
|
|
726
|
+
static warning(text) {
|
|
727
|
+
return `${COLOR_SCHEMES.warning(`${EMOJIS.warning} ${text}`)}`;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Format info message
|
|
731
|
+
* @param text Info message text
|
|
732
|
+
* @returns Formatted info message with emoji and color
|
|
733
|
+
*/
|
|
734
|
+
static info(text) {
|
|
735
|
+
return `${COLOR_SCHEMES.info(`${EMOJIS.info} ${text}`)}`;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Format success message
|
|
739
|
+
* @param text Success message text
|
|
740
|
+
* @returns Formatted success message with emoji and color
|
|
741
|
+
*/
|
|
742
|
+
static success(text) {
|
|
743
|
+
return `${COLOR_SCHEMES.success(`${EMOJIS.success} ${text}`)}`;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Format debug message (only shown in verbose mode)
|
|
747
|
+
* @param text Debug message text
|
|
748
|
+
* @returns Formatted debug message if verbose mode is enabled, empty string otherwise
|
|
749
|
+
*/
|
|
750
|
+
static debug(text) {
|
|
751
|
+
if (!this.verboseMode) {
|
|
752
|
+
return "";
|
|
753
|
+
}
|
|
754
|
+
return COLOR_SCHEMES.debug(text);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Format neutral message (no emoji, white color)
|
|
758
|
+
* @param text Neutral message text
|
|
759
|
+
* @returns Formatted neutral message
|
|
760
|
+
*/
|
|
761
|
+
static neutral(text) {
|
|
762
|
+
return COLOR_SCHEMES.neutral(text);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Format error detail with type, message, and optional location
|
|
766
|
+
* @param type Error type (e.g., 'CODE_CONTENT_MISMATCH')
|
|
767
|
+
* @param message Error message
|
|
768
|
+
* @param location Optional file location
|
|
769
|
+
* @returns Formatted error detail
|
|
770
|
+
*/
|
|
771
|
+
static errorDetail(type, message, location) {
|
|
772
|
+
const lines = [];
|
|
773
|
+
lines.push(this.error(`${type}: ${message}`));
|
|
774
|
+
if (location) {
|
|
775
|
+
lines.push(` ${COLOR_SCHEMES.dim(`Reference: ${location}`)}`);
|
|
776
|
+
}
|
|
777
|
+
return lines.join("\n");
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Format summary section
|
|
781
|
+
* @param successful Number of successful operations
|
|
782
|
+
* @param failed Number of failed operations
|
|
783
|
+
* @param backupPaths Array of backup file paths
|
|
784
|
+
* @returns Formatted summary section
|
|
785
|
+
*/
|
|
786
|
+
static summary(successful, failed, backupPaths) {
|
|
787
|
+
const lines = [];
|
|
788
|
+
const separator = COLOR_SCHEMES.dim("\u2501".repeat(60));
|
|
789
|
+
lines.push("");
|
|
790
|
+
lines.push(separator);
|
|
791
|
+
lines.push(`${EMOJIS.stats} Fix Results Summary`);
|
|
792
|
+
lines.push("");
|
|
793
|
+
lines.push(COLOR_SCHEMES.success(`${EMOJIS.success} Successful: ${successful}`));
|
|
794
|
+
lines.push(COLOR_SCHEMES.error(`${EMOJIS.error} Failed: ${failed}`));
|
|
795
|
+
if (backupPaths.length > 0) {
|
|
796
|
+
lines.push("");
|
|
797
|
+
lines.push(`${EMOJIS.backup} Backup files: ${backupPaths.length}`);
|
|
798
|
+
backupPaths.forEach((path8) => {
|
|
799
|
+
lines.push(` ${COLOR_SCHEMES.dim(path8)}`);
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return lines.join("\n");
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Format start message for fix operation
|
|
806
|
+
* @param text Start message text
|
|
807
|
+
* @returns Formatted start message with fix emoji
|
|
808
|
+
*/
|
|
809
|
+
static startFix(text) {
|
|
810
|
+
return `${COLOR_SCHEMES.info(`${EMOJIS.fix} ${text}`)}`;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Format start message for validation operation
|
|
814
|
+
* @param text Start message text
|
|
815
|
+
* @returns Formatted start message with search emoji
|
|
816
|
+
*/
|
|
817
|
+
static startValidation(text) {
|
|
818
|
+
return `${COLOR_SCHEMES.info(`${EMOJIS.search} ${text}`)}`;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Format file reference
|
|
822
|
+
* @param text File path or reference
|
|
823
|
+
* @returns Formatted file reference with emoji
|
|
824
|
+
*/
|
|
825
|
+
static file(text) {
|
|
826
|
+
return `${EMOJIS.file} ${COLOR_SCHEMES.neutral(text)}`;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Format backup notification
|
|
830
|
+
* @param text Backup message text
|
|
831
|
+
* @returns Formatted backup message with emoji
|
|
832
|
+
*/
|
|
833
|
+
static backup(text) {
|
|
834
|
+
return `${COLOR_SCHEMES.info(`${EMOJIS.backup} ${text}`)}`;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Format skip notification
|
|
838
|
+
* @param text Skip message text
|
|
839
|
+
* @returns Formatted skip message with emoji
|
|
840
|
+
*/
|
|
841
|
+
static skip(text) {
|
|
842
|
+
return `${COLOR_SCHEMES.neutral(`${EMOJIS.skip} ${text}`)}`;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Format context line (indented with dim color)
|
|
846
|
+
* @param text Context text
|
|
847
|
+
* @returns Formatted context line with 3 spaces indentation
|
|
848
|
+
*/
|
|
849
|
+
static context(text) {
|
|
850
|
+
return ` ${COLOR_SCHEMES.dim(text)}`;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
MessageFormatter.verboseMode = false;
|
|
854
|
+
var msg = {
|
|
855
|
+
error: (text) => MessageFormatter.error(text),
|
|
856
|
+
warning: (text) => MessageFormatter.warning(text),
|
|
857
|
+
info: (text) => MessageFormatter.info(text),
|
|
858
|
+
success: (text) => MessageFormatter.success(text),
|
|
859
|
+
debug: (text) => MessageFormatter.debug(text),
|
|
860
|
+
neutral: (text) => MessageFormatter.neutral(text),
|
|
861
|
+
errorDetail: (type, message, location) => MessageFormatter.errorDetail(type, message, location),
|
|
862
|
+
summary: (successful, failed, backupPaths) => MessageFormatter.summary(successful, failed, backupPaths),
|
|
863
|
+
startFix: (text) => MessageFormatter.startFix(text),
|
|
864
|
+
startValidation: (text) => MessageFormatter.startValidation(text),
|
|
865
|
+
file: (text) => MessageFormatter.file(text),
|
|
866
|
+
backup: (text) => MessageFormatter.backup(text),
|
|
867
|
+
skip: (text) => MessageFormatter.skip(text),
|
|
868
|
+
context: (text) => MessageFormatter.context(text),
|
|
869
|
+
setVerbose: (enabled) => MessageFormatter.setVerbose(enabled)
|
|
685
870
|
};
|
|
871
|
+
|
|
872
|
+
// src/utils/diff-display.ts
|
|
686
873
|
function displayCodeDiff(expected, actual) {
|
|
687
874
|
const expectedLines = expected.split("\n");
|
|
688
875
|
const actualLines = actual.split("\n");
|
|
689
876
|
const output = [];
|
|
690
877
|
const maxLines = Math.max(expectedLines.length, actualLines.length);
|
|
691
|
-
output.push(
|
|
692
|
-
|
|
693
|
-
);
|
|
694
|
-
output.push(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
878
|
+
output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
879
|
+
output.push(COLOR_SCHEMES.error("- Expected code (in document)"));
|
|
880
|
+
output.push(COLOR_SCHEMES.success("+ Actual code (in file)"));
|
|
881
|
+
output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
882
|
+
const removedLines = [];
|
|
883
|
+
const addedLines = [];
|
|
884
|
+
const flushChanges = () => {
|
|
885
|
+
removedLines.forEach((line) => {
|
|
886
|
+
output.push(COLOR_SCHEMES.error(`- ${line}`));
|
|
887
|
+
});
|
|
888
|
+
addedLines.forEach((line) => {
|
|
889
|
+
output.push(COLOR_SCHEMES.success(`+ ${line}`));
|
|
890
|
+
});
|
|
891
|
+
removedLines.length = 0;
|
|
892
|
+
addedLines.length = 0;
|
|
893
|
+
};
|
|
699
894
|
for (let i = 0; i < maxLines; i++) {
|
|
700
895
|
const expectedLine = expectedLines[i];
|
|
701
896
|
const actualLine = actualLines[i];
|
|
702
897
|
if (expectedLine === actualLine) {
|
|
898
|
+
if (removedLines.length > 0 || addedLines.length > 0) {
|
|
899
|
+
flushChanges();
|
|
900
|
+
}
|
|
703
901
|
if (expectedLine !== void 0) {
|
|
704
902
|
output.push(` ${expectedLine}`);
|
|
705
903
|
}
|
|
706
904
|
} else {
|
|
707
905
|
if (expectedLine !== void 0) {
|
|
708
|
-
|
|
906
|
+
removedLines.push(expectedLine);
|
|
709
907
|
}
|
|
710
908
|
if (actualLine !== void 0) {
|
|
711
|
-
|
|
909
|
+
addedLines.push(actualLine);
|
|
712
910
|
}
|
|
713
911
|
}
|
|
714
912
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
function displayLineRangeDiff(code, expectedRange, actualRange) {
|
|
721
|
-
const output = [];
|
|
722
|
-
output.push(
|
|
723
|
-
`${COLORS.DIM}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${COLORS.RESET}`
|
|
724
|
-
);
|
|
725
|
-
output.push(
|
|
726
|
-
`${COLORS.RED}- Expected line range: ${expectedRange.start}-${expectedRange.end}${COLORS.RESET}`
|
|
727
|
-
);
|
|
728
|
-
output.push(
|
|
729
|
-
`${COLORS.GREEN}+ Actual line range: ${actualRange.start}-${actualRange.end}${COLORS.RESET}`
|
|
730
|
-
);
|
|
731
|
-
output.push(
|
|
732
|
-
`${COLORS.DIM}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${COLORS.RESET}`
|
|
733
|
-
);
|
|
734
|
-
const codeLines = code.split("\n");
|
|
735
|
-
codeLines.forEach((line, index) => {
|
|
736
|
-
const expectedLineNum = expectedRange.start + index;
|
|
737
|
-
const actualLineNum = actualRange.start + index;
|
|
738
|
-
output.push(
|
|
739
|
-
`${COLORS.RED}${expectedLineNum.toString().padStart(4)}${COLORS.RESET} | ${COLORS.GREEN}${actualLineNum.toString().padStart(4)}${COLORS.RESET} | ${line}`
|
|
740
|
-
);
|
|
741
|
-
});
|
|
742
|
-
output.push(
|
|
743
|
-
`${COLORS.DIM}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${COLORS.RESET}`
|
|
744
|
-
);
|
|
913
|
+
if (removedLines.length > 0 || addedLines.length > 0) {
|
|
914
|
+
flushChanges();
|
|
915
|
+
}
|
|
916
|
+
output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
745
917
|
return output.join("\n");
|
|
746
918
|
}
|
|
747
919
|
|
|
@@ -779,7 +951,22 @@ ${message}`);
|
|
|
779
951
|
if (selection >= 1 && selection <= options.length) {
|
|
780
952
|
return selection - 1;
|
|
781
953
|
}
|
|
782
|
-
console.log("
|
|
954
|
+
console.log(msg.error("Invalid selection. Please try again."));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function displayColoredCodeBlock(preview) {
|
|
958
|
+
const codeBlockMatch = /```(\w*)\n([\s\S]*?)\n```/.exec(preview);
|
|
959
|
+
if (codeBlockMatch) {
|
|
960
|
+
const language = codeBlockMatch[1] || "";
|
|
961
|
+
const code = codeBlockMatch[2];
|
|
962
|
+
console.log(COLOR_SCHEMES.dim(`\`\`\`${language}`));
|
|
963
|
+
const lines = code.split("\n");
|
|
964
|
+
lines.forEach((line) => {
|
|
965
|
+
console.log(COLOR_SCHEMES.success(`+ ${line}`));
|
|
966
|
+
});
|
|
967
|
+
console.log(COLOR_SCHEMES.dim("```"));
|
|
968
|
+
} else {
|
|
969
|
+
console.log(preview);
|
|
783
970
|
}
|
|
784
971
|
}
|
|
785
972
|
function displayFixPreview(action, projectRoot) {
|
|
@@ -787,51 +974,18 @@ function displayFixPreview(action, projectRoot) {
|
|
|
787
974
|
Changes: ${action.description}`);
|
|
788
975
|
const { error } = action;
|
|
789
976
|
const absolutePath = path3.resolve(projectRoot, error.ref.refPath);
|
|
790
|
-
switch (
|
|
791
|
-
case "CODE_LOCATION_MISMATCH": {
|
|
792
|
-
if (error.ref.codeBlock && action.newStartLine && action.newEndLine) {
|
|
793
|
-
const actualCode = extractLinesFromFile(
|
|
794
|
-
absolutePath,
|
|
795
|
-
action.newStartLine,
|
|
796
|
-
action.newEndLine
|
|
797
|
-
);
|
|
798
|
-
const diff = displayLineRangeDiff(
|
|
799
|
-
actualCode,
|
|
800
|
-
{
|
|
801
|
-
start: error.ref.startLine,
|
|
802
|
-
end: error.ref.endLine
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
start: action.newStartLine,
|
|
806
|
-
end: action.newEndLine
|
|
807
|
-
}
|
|
808
|
-
);
|
|
809
|
-
console.log(diff);
|
|
810
|
-
} else {
|
|
811
|
-
console.log(action.preview);
|
|
812
|
-
}
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
case "CODE_CONTENT_MISMATCH": {
|
|
816
|
-
if (error.expectedCode && action.newCodeBlock) {
|
|
817
|
-
const diff = displayCodeDiff(error.expectedCode, action.newCodeBlock);
|
|
818
|
-
console.log(diff);
|
|
819
|
-
} else {
|
|
820
|
-
console.log(action.preview);
|
|
821
|
-
}
|
|
822
|
-
break;
|
|
823
|
-
}
|
|
977
|
+
switch (action.type) {
|
|
824
978
|
case "INSERT_CODE_BLOCK": {
|
|
825
979
|
if (action.newCodeBlock) {
|
|
826
|
-
console.log("
|
|
827
|
-
console.log("\
|
|
980
|
+
console.log(COLOR_SCHEMES.success("+ Insert code block:"));
|
|
981
|
+
console.log(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
828
982
|
const lines = action.newCodeBlock.split("\n");
|
|
829
983
|
lines.forEach((line) => {
|
|
830
|
-
console.log(
|
|
984
|
+
console.log(COLOR_SCHEMES.success(`+ ${line}`));
|
|
831
985
|
});
|
|
832
|
-
console.log("\
|
|
986
|
+
console.log(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
833
987
|
} else {
|
|
834
|
-
|
|
988
|
+
displayColoredCodeBlock(action.preview);
|
|
835
989
|
}
|
|
836
990
|
break;
|
|
837
991
|
}
|
|
@@ -846,13 +1000,23 @@ Changes: ${action.description}`);
|
|
|
846
1000
|
}
|
|
847
1001
|
case "UPDATE_LINE_NUMBERS":
|
|
848
1002
|
case "UPDATE_END_LINE": {
|
|
1003
|
+
if (error.type === "CODE_LOCATION_MISMATCH" && !error.ref.codeBlock) {
|
|
1004
|
+
console.log(action.preview);
|
|
1005
|
+
break;
|
|
1006
|
+
}
|
|
849
1007
|
const oldComment = error.ref.fullMatch;
|
|
850
1008
|
const newComment = `<!-- CODE_REF: ${error.ref.refPath}:${action.newStartLine}-${action.newEndLine} -->`;
|
|
851
|
-
console.log("\
|
|
852
|
-
console.log(
|
|
853
|
-
console.log(
|
|
854
|
-
console.log("\
|
|
855
|
-
if (
|
|
1009
|
+
console.log(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
1010
|
+
console.log(COLOR_SCHEMES.error(`- ${oldComment}`));
|
|
1011
|
+
console.log(COLOR_SCHEMES.success(`+ ${newComment}`));
|
|
1012
|
+
console.log(COLOR_SCHEMES.dim("\u2501".repeat(64)));
|
|
1013
|
+
if (error.type === "CODE_CONTENT_MISMATCH") {
|
|
1014
|
+
console.log(
|
|
1015
|
+
COLOR_SCHEMES.warning(
|
|
1016
|
+
"\n\u26A0\uFE0F Note: Code block will remain unchanged. Please manually adjust if needed."
|
|
1017
|
+
)
|
|
1018
|
+
);
|
|
1019
|
+
} else if (action.newCodeBlock && fs3.existsSync(absolutePath)) {
|
|
856
1020
|
console.log("\nCode block content:");
|
|
857
1021
|
const lines = action.newCodeBlock.split("\n").slice(0, 10);
|
|
858
1022
|
lines.forEach((line) => {
|
|
@@ -866,7 +1030,7 @@ Changes: ${action.description}`);
|
|
|
866
1030
|
}
|
|
867
1031
|
default: {
|
|
868
1032
|
if (action.preview) {
|
|
869
|
-
|
|
1033
|
+
displayColoredCodeBlock(action.preview);
|
|
870
1034
|
}
|
|
871
1035
|
break;
|
|
872
1036
|
}
|
|
@@ -1055,7 +1219,9 @@ ${symbolCode}
|
|
|
1055
1219
|
const expandedCode = extractLinesFromFile(absolutePath, expanded.start, expanded.end);
|
|
1056
1220
|
const scopeInfo = expanded.scopeType ? ` (${expanded.scopeType})` : "";
|
|
1057
1221
|
console.log(
|
|
1058
|
-
|
|
1222
|
+
msg.debug(
|
|
1223
|
+
` Expanded ${ref.startLine}-${ref.endLine} to ${expanded.start}-${expanded.end} using AST analysis${scopeInfo}`
|
|
1224
|
+
)
|
|
1059
1225
|
);
|
|
1060
1226
|
const oldComment = ref.fullMatch;
|
|
1061
1227
|
const newComment = `<!-- CODE_REF: ${ref.refPath}:${expanded.start}-${expanded.end} -->`;
|
|
@@ -1259,7 +1425,7 @@ async function handleMultipleMatches(error, rl, config) {
|
|
|
1259
1425
|
const confidenceInfo = match.confidence === "high" && match.scopeType ? ` (${match.scopeType})` : match.confidence === "low" ? " (low confidence)" : "";
|
|
1260
1426
|
console.log(
|
|
1261
1427
|
`
|
|
1262
|
-
|
|
1428
|
+
${msg.success(`Detected single match in ${ref.refPath}: lines ${match.start}-${match.end}${confidenceInfo}`)}`
|
|
1263
1429
|
);
|
|
1264
1430
|
return {
|
|
1265
1431
|
type: "UPDATE_LINE_NUMBERS",
|
|
@@ -1281,7 +1447,7 @@ async function handleMultipleMatches(error, rl, config) {
|
|
|
1281
1447
|
const scopeInfo = bestMatch.scopeType ? ` (${bestMatch.scopeType})` : "";
|
|
1282
1448
|
console.log(
|
|
1283
1449
|
`
|
|
1284
|
-
|
|
1450
|
+
${msg.success(`Auto-selected most appropriate match in ${ref.refPath}: lines ${bestMatch.start}-${bestMatch.end}${scopeInfo}`)}`
|
|
1285
1451
|
);
|
|
1286
1452
|
return {
|
|
1287
1453
|
type: "UPDATE_LINE_NUMBERS",
|
|
@@ -1294,7 +1460,7 @@ async function handleMultipleMatches(error, rl, config) {
|
|
|
1294
1460
|
};
|
|
1295
1461
|
}
|
|
1296
1462
|
console.log(`
|
|
1297
|
-
|
|
1463
|
+
${msg.warning(`Code found in ${matches.length} locations in ${ref.refPath}:`)}`);
|
|
1298
1464
|
const options = sortedMatches.map((m) => {
|
|
1299
1465
|
const confidenceLabel = m.confidence === "high" ? "high" : m.confidence === "medium" ? "medium" : "low";
|
|
1300
1466
|
const scopeInfo = m.scopeType && m.scopeType !== "unknown" ? `, ${m.scopeType}` : "";
|
|
@@ -1303,10 +1469,10 @@ async function handleMultipleMatches(error, rl, config) {
|
|
|
1303
1469
|
const selection = await askSelectOption(rl, options, "Which position should be used?");
|
|
1304
1470
|
const selectedMatch = sortedMatches[selection];
|
|
1305
1471
|
if (selectedMatch.confidence === "low") {
|
|
1306
|
-
console.warn("
|
|
1472
|
+
console.warn(msg.warning("Scope detection confidence is low, please verify the result."));
|
|
1307
1473
|
}
|
|
1308
1474
|
if (selectedMatch.expansionType === "none") {
|
|
1309
|
-
console.warn("
|
|
1475
|
+
console.warn(msg.warning("Structural analysis failed, using simple string matching."));
|
|
1310
1476
|
}
|
|
1311
1477
|
return {
|
|
1312
1478
|
type: "UPDATE_LINE_NUMBERS",
|
|
@@ -1320,18 +1486,18 @@ async function handleMultipleMatches(error, rl, config) {
|
|
|
1320
1486
|
}
|
|
1321
1487
|
|
|
1322
1488
|
// src/utils/styles.ts
|
|
1323
|
-
var
|
|
1489
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
1324
1490
|
var colors = {
|
|
1325
|
-
//
|
|
1326
|
-
success:
|
|
1327
|
-
error:
|
|
1328
|
-
dim:
|
|
1329
|
-
//
|
|
1330
|
-
primary:
|
|
1491
|
+
// Core colors from message-formatter
|
|
1492
|
+
success: COLOR_SCHEMES.success,
|
|
1493
|
+
error: COLOR_SCHEMES.error,
|
|
1494
|
+
dim: COLOR_SCHEMES.dim,
|
|
1495
|
+
// Accent colors for fix options
|
|
1496
|
+
primary: COLOR_SCHEMES.highlight,
|
|
1331
1497
|
// Option numbers
|
|
1332
|
-
muted:
|
|
1498
|
+
muted: COLOR_SCHEMES.debug,
|
|
1333
1499
|
// Supplementary info
|
|
1334
|
-
code:
|
|
1500
|
+
code: COLOR_SCHEMES.code
|
|
1335
1501
|
// Code blocks
|
|
1336
1502
|
};
|
|
1337
1503
|
var box = {
|
|
@@ -1387,19 +1553,27 @@ function extractLineInfo(preview) {
|
|
|
1387
1553
|
return null;
|
|
1388
1554
|
}
|
|
1389
1555
|
function formatPreview(preview) {
|
|
1390
|
-
const
|
|
1556
|
+
const processedPreview = preview.replace(/\n(→\s*)/g, " $1");
|
|
1557
|
+
const lines = processedPreview.split("\n");
|
|
1391
1558
|
const output = [];
|
|
1559
|
+
const processLine = (line) => {
|
|
1560
|
+
if (line.includes("\u2192") && line.includes("<!-- CODE_REF:")) {
|
|
1561
|
+
const parts = line.split("\u2192");
|
|
1562
|
+
if (parts.length === 2) {
|
|
1563
|
+
output.push(colors.error(`- ${parts[0].trim()}`));
|
|
1564
|
+
output.push(colors.success(`+ ${parts[1].trim()}`));
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
output.push(formatCodeLine(line));
|
|
1569
|
+
};
|
|
1392
1570
|
if (lines.length > MAX_PREVIEW_LINES) {
|
|
1393
1571
|
const truncatedLines = lines.slice(0, TRUNCATE_SHOW_LINES);
|
|
1394
1572
|
const remainingCount = lines.length - TRUNCATE_SHOW_LINES;
|
|
1395
|
-
truncatedLines.forEach(
|
|
1396
|
-
output.push(formatCodeLine(line));
|
|
1397
|
-
});
|
|
1573
|
+
truncatedLines.forEach(processLine);
|
|
1398
1574
|
output.push(colors.muted(`... (${remainingCount} more lines)`));
|
|
1399
1575
|
} else {
|
|
1400
|
-
lines.forEach(
|
|
1401
|
-
output.push(formatCodeLine(line));
|
|
1402
|
-
});
|
|
1576
|
+
lines.forEach(processLine);
|
|
1403
1577
|
}
|
|
1404
1578
|
return output;
|
|
1405
1579
|
}
|
|
@@ -1407,6 +1581,9 @@ function formatCodeLine(line) {
|
|
|
1407
1581
|
if (line.trim().startsWith("```")) {
|
|
1408
1582
|
return colors.dim(line);
|
|
1409
1583
|
}
|
|
1584
|
+
if (line.includes("<!-- CODE_REF:")) {
|
|
1585
|
+
return line.replace(/<!--/g, colors.dim("<!--")).replace(/-->/g, colors.dim("-->")).replace(/(CODE_REF:)/g, import_chalk2.default.cyan.bold("$1"));
|
|
1586
|
+
}
|
|
1410
1587
|
const keywords = [
|
|
1411
1588
|
"function",
|
|
1412
1589
|
"const",
|
|
@@ -1426,7 +1603,7 @@ function formatCodeLine(line) {
|
|
|
1426
1603
|
let formattedLine = line;
|
|
1427
1604
|
keywords.forEach((keyword) => {
|
|
1428
1605
|
const regex = new RegExp(`\\b(${keyword})\\b`, "g");
|
|
1429
|
-
formattedLine = formattedLine.replace(regex,
|
|
1606
|
+
formattedLine = formattedLine.replace(regex, import_chalk2.default.cyan("$1"));
|
|
1430
1607
|
});
|
|
1431
1608
|
formattedLine = formattedLine.replace(/'[^']*'/g, (match) => colors.code(match));
|
|
1432
1609
|
formattedLine = formattedLine.replace(/"[^"]*"/g, (match) => colors.code(match));
|
|
@@ -1912,26 +2089,31 @@ async function main() {
|
|
|
1912
2089
|
backup: !options.noBackup,
|
|
1913
2090
|
verbose: options.verbose
|
|
1914
2091
|
});
|
|
1915
|
-
|
|
2092
|
+
msg.setVerbose(options.verbose);
|
|
2093
|
+
console.log(`${msg.startFix("Starting CODE_REF error fixes...")}
|
|
2094
|
+
`);
|
|
1916
2095
|
if (options.dryRun) {
|
|
1917
|
-
console.log("
|
|
2096
|
+
console.log(`${msg.warning("DRY RUN mode: No actual changes will be made")}
|
|
2097
|
+
`);
|
|
1918
2098
|
}
|
|
1919
2099
|
const errorGroups = collectErrors(config);
|
|
1920
2100
|
if (errorGroups.length === 0) {
|
|
1921
|
-
console.log("
|
|
2101
|
+
console.log(msg.success("No fixable errors found"));
|
|
1922
2102
|
process.exit(0);
|
|
1923
2103
|
}
|
|
1924
2104
|
const totalErrors = errorGroups.reduce((sum, g) => sum + g.errors.length, 0);
|
|
1925
|
-
console.log(
|
|
1926
|
-
`)
|
|
2105
|
+
console.log(
|
|
2106
|
+
`${msg.info(`Detected ${totalErrors} fixable error(s) in ${errorGroups.length} file(s)`)}
|
|
2107
|
+
`
|
|
2108
|
+
);
|
|
1927
2109
|
const rl = createPromptInterface();
|
|
1928
2110
|
const fixResults = [];
|
|
1929
2111
|
const backupFiles = /* @__PURE__ */ new Set();
|
|
1930
2112
|
try {
|
|
1931
2113
|
for (const group of errorGroups) {
|
|
1932
2114
|
console.log(`
|
|
1933
|
-
|
|
1934
|
-
console.log(
|
|
2115
|
+
${msg.file(path7.relative(config.projectRoot, group.docFile))}`);
|
|
2116
|
+
console.log(`${msg.context(`${group.errors.length} error(s)`)}
|
|
1935
2117
|
`);
|
|
1936
2118
|
const sortedErrors = group.errors.sort((a, b) => {
|
|
1937
2119
|
const lineA = a.ref.docLineNumber ?? Infinity;
|
|
@@ -1940,21 +2122,22 @@ async function main() {
|
|
|
1940
2122
|
});
|
|
1941
2123
|
let _lineOffset = 0;
|
|
1942
2124
|
for (const error of sortedErrors) {
|
|
2125
|
+
const location = `${path7.relative(config.projectRoot, error.ref.docFile)}${error.ref.docLineNumber ? `:${error.ref.docLineNumber}` : ""}`;
|
|
1943
2126
|
console.log(`
|
|
1944
|
-
|
|
1945
|
-
console.log(
|
|
1946
|
-
` Reference: ${path7.relative(config.projectRoot, error.ref.docFile)}${error.ref.docLineNumber ? `:${error.ref.docLineNumber}` : ""}`
|
|
1947
|
-
);
|
|
2127
|
+
${msg.errorDetail(error.type, error.message, location)}`);
|
|
1948
2128
|
let action;
|
|
1949
2129
|
if (error.type === "CODE_LOCATION_MISMATCH") {
|
|
1950
2130
|
action = await handleMultipleMatches(error, rl, config);
|
|
1951
2131
|
} else {
|
|
1952
2132
|
const fixActionResult = await createFixAction(error, config, rl);
|
|
1953
2133
|
if (Array.isArray(fixActionResult)) {
|
|
1954
|
-
console.log(
|
|
2134
|
+
console.log(`
|
|
2135
|
+
${msg.info("Please select a fix method:")}
|
|
2136
|
+
`);
|
|
1955
2137
|
console.log(formatFixOptions(fixActionResult));
|
|
1956
2138
|
if (options.auto) {
|
|
1957
|
-
console.log("
|
|
2139
|
+
console.log(`${msg.context("Auto-selecting option 1 in auto mode")}
|
|
2140
|
+
`);
|
|
1958
2141
|
action = fixActionResult[0];
|
|
1959
2142
|
} else {
|
|
1960
2143
|
const selection = await new Promise((resolve5) => {
|
|
@@ -1963,13 +2146,13 @@ async function main() {
|
|
|
1963
2146
|
if (num >= 1 && num <= fixActionResult.length) {
|
|
1964
2147
|
resolve5(num - 1);
|
|
1965
2148
|
} else {
|
|
1966
|
-
console.log("
|
|
2149
|
+
console.log(msg.context("Invalid selection. Skipping."));
|
|
1967
2150
|
resolve5(-1);
|
|
1968
2151
|
}
|
|
1969
2152
|
});
|
|
1970
2153
|
});
|
|
1971
2154
|
if (selection === -1) {
|
|
1972
|
-
console.log("
|
|
2155
|
+
console.log(msg.context("Skipped"));
|
|
1973
2156
|
continue;
|
|
1974
2157
|
}
|
|
1975
2158
|
action = fixActionResult[selection];
|
|
@@ -1979,7 +2162,7 @@ async function main() {
|
|
|
1979
2162
|
}
|
|
1980
2163
|
}
|
|
1981
2164
|
if (!action) {
|
|
1982
|
-
console.log("
|
|
2165
|
+
console.log(msg.context("This error cannot be fixed"));
|
|
1983
2166
|
continue;
|
|
1984
2167
|
}
|
|
1985
2168
|
if (!Array.isArray(action)) {
|
|
@@ -1990,11 +2173,11 @@ async function main() {
|
|
|
1990
2173
|
shouldFix = await askYesNo(rl, "\nApply this fix?", false);
|
|
1991
2174
|
}
|
|
1992
2175
|
if (!shouldFix) {
|
|
1993
|
-
console.log("
|
|
2176
|
+
console.log(msg.context("Skipped"));
|
|
1994
2177
|
continue;
|
|
1995
2178
|
}
|
|
1996
2179
|
if (options.dryRun) {
|
|
1997
|
-
console.log("
|
|
2180
|
+
console.log(msg.context("[DRY RUN] Simulated fix"));
|
|
1998
2181
|
fixResults.push({ success: true, action });
|
|
1999
2182
|
continue;
|
|
2000
2183
|
}
|
|
@@ -2002,19 +2185,19 @@ async function main() {
|
|
|
2002
2185
|
if (!options.noBackup && !backupFiles.has(group.docFile)) {
|
|
2003
2186
|
backupPath = createBackup(group.docFile);
|
|
2004
2187
|
backupFiles.add(group.docFile);
|
|
2005
|
-
console.log(`
|
|
2188
|
+
console.log(msg.context(`Backup created: ${path7.basename(backupPath)}`));
|
|
2006
2189
|
}
|
|
2007
2190
|
try {
|
|
2008
2191
|
const lineDelta = applyFix(action);
|
|
2009
2192
|
_lineOffset += lineDelta;
|
|
2010
|
-
if (lineDelta !== 0) {
|
|
2011
|
-
console.log(`
|
|
2193
|
+
if (lineDelta !== 0 && options.verbose) {
|
|
2194
|
+
console.log(msg.debug(` Line delta: ${lineDelta > 0 ? "+" : ""}${lineDelta}`));
|
|
2012
2195
|
}
|
|
2013
|
-
console.log("
|
|
2196
|
+
console.log(msg.context("Fix applied"));
|
|
2014
2197
|
fixResults.push({ success: true, action, backupPath });
|
|
2015
2198
|
} catch (err) {
|
|
2016
2199
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
2017
|
-
console.log(`
|
|
2200
|
+
console.log(msg.context(`Fix failed: ${errorMsg}`));
|
|
2018
2201
|
fixResults.push({ success: false, action, error: errorMsg, backupPath });
|
|
2019
2202
|
}
|
|
2020
2203
|
}
|
|
@@ -2022,26 +2205,16 @@ async function main() {
|
|
|
2022
2205
|
} finally {
|
|
2023
2206
|
rl.close();
|
|
2024
2207
|
}
|
|
2025
|
-
console.log(`
|
|
2026
|
-
${"=".repeat(60)}`);
|
|
2027
|
-
console.log("\u{1F4CA} Fix Results Summary\n");
|
|
2028
2208
|
const successful = fixResults.filter((r) => r.success).length;
|
|
2029
2209
|
const failed = fixResults.filter((r) => !r.success).length;
|
|
2030
|
-
|
|
2031
|
-
console.log(
|
|
2032
|
-
if (backupFiles.size > 0 && !options.noBackup) {
|
|
2033
|
-
console.log(`
|
|
2034
|
-
\u{1F4BE} Backup files: ${backupFiles.size}`);
|
|
2035
|
-
for (const file of backupFiles) {
|
|
2036
|
-
const backupPath = `${file}.backup`;
|
|
2037
|
-
console.log(` ${path7.relative(config.projectRoot, backupPath)}`);
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2210
|
+
const backupPaths = !options.noBackup && backupFiles.size > 0 ? Array.from(backupFiles).map((file) => path7.relative(config.projectRoot, `${file}.backup`)) : [];
|
|
2211
|
+
console.log(msg.summary(successful, failed, backupPaths));
|
|
2040
2212
|
process.exit(failed > 0 ? 1 : 0);
|
|
2041
2213
|
}
|
|
2042
2214
|
if (require.main === module) {
|
|
2043
2215
|
main().catch((error) => {
|
|
2044
|
-
console.error(
|
|
2216
|
+
console.error(`
|
|
2217
|
+
${msg.error(`An error occurred: ${error}`)}`);
|
|
2045
2218
|
process.exit(1);
|
|
2046
2219
|
});
|
|
2047
2220
|
}
|