scai 0.1.100 → 0.1.101
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.
|
@@ -22,29 +22,27 @@ export const preserveCodeModule = {
|
|
|
22
22
|
// --- Single-line comment ---
|
|
23
23
|
for (const s of syntax.singleLine) {
|
|
24
24
|
if (trimmed.startsWith(s))
|
|
25
|
-
return
|
|
25
|
+
return "comment";
|
|
26
26
|
}
|
|
27
27
|
// --- Multi-line comment ---
|
|
28
28
|
for (const { start, end } of syntax.multiLine) {
|
|
29
29
|
if (!inBlockComment) {
|
|
30
30
|
if (trimmed.startsWith(start) && trimmed.includes(end)) {
|
|
31
|
-
return
|
|
31
|
+
return "comment"; // entire block on one line
|
|
32
32
|
}
|
|
33
33
|
if (trimmed.startsWith(start)) {
|
|
34
34
|
inBlockComment = true;
|
|
35
35
|
blockLines = [line];
|
|
36
|
-
return
|
|
36
|
+
return ""; // wait until block ends
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
blockLines.push(line);
|
|
41
41
|
if (trimmed.includes(end)) {
|
|
42
42
|
inBlockComment = false;
|
|
43
|
-
|
|
44
|
-
blockLines = [];
|
|
45
|
-
return fullBlock; // return entire multi-line block
|
|
43
|
+
return "comment"; // end of block
|
|
46
44
|
}
|
|
47
|
-
return ""; //
|
|
45
|
+
return ""; // inside block
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
return "code";
|
|
@@ -55,9 +53,9 @@ export const preserveCodeModule = {
|
|
|
55
53
|
let commentBuffer = [];
|
|
56
54
|
for (const line of lines) {
|
|
57
55
|
const type = classifyLine(line);
|
|
58
|
-
if (type
|
|
59
|
-
// Collect comment
|
|
60
|
-
commentBuffer.push(
|
|
56
|
+
if (type === "comment") {
|
|
57
|
+
// Collect full comment line
|
|
58
|
+
commentBuffer.push(line);
|
|
61
59
|
}
|
|
62
60
|
else if (type === "code") {
|
|
63
61
|
// Flush buffer when hitting code
|
|
@@ -65,8 +63,7 @@ export const preserveCodeModule = {
|
|
|
65
63
|
const key = line.trim().toLowerCase();
|
|
66
64
|
if (!map.has(key))
|
|
67
65
|
map.set(key, new Set());
|
|
68
|
-
|
|
69
|
-
const commentBlock = commentBuffer.join("\n").toLowerCase();
|
|
66
|
+
const commentBlock = commentBuffer.map(l => l.trimEnd()).join("\n").toLowerCase();
|
|
70
67
|
map.get(key).add(commentBlock);
|
|
71
68
|
commentBuffer = [];
|
|
72
69
|
}
|
|
@@ -77,7 +74,7 @@ export const preserveCodeModule = {
|
|
|
77
74
|
const key = "";
|
|
78
75
|
if (!map.has(key))
|
|
79
76
|
map.set(key, new Set());
|
|
80
|
-
const commentBlock = commentBuffer.join("\n").toLowerCase();
|
|
77
|
+
const commentBlock = commentBuffer.map(l => l.trimEnd()).join("\n").toLowerCase();
|
|
81
78
|
map.get(key).add(commentBlock);
|
|
82
79
|
}
|
|
83
80
|
return map;
|
|
@@ -120,18 +117,32 @@ export const preserveCodeModule = {
|
|
|
120
117
|
console.log(chalk.bold.blue("\n=== LINE CLASSIFICATION (original) ==="));
|
|
121
118
|
origLines.forEach((line, i) => {
|
|
122
119
|
const type = classifyLine(line);
|
|
123
|
-
const colored = type === "code"
|
|
120
|
+
const colored = type === "code"
|
|
121
|
+
? chalk.green(line)
|
|
122
|
+
: type === "comment"
|
|
123
|
+
? chalk.yellow(line)
|
|
124
|
+
: chalk.gray(line); // "" means middle of block
|
|
124
125
|
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
125
126
|
});
|
|
126
127
|
console.log(chalk.bold.blue("\n=== LINE CLASSIFICATION (model) ==="));
|
|
127
128
|
newLines.forEach((line, i) => {
|
|
128
129
|
const type = classifyLine(line);
|
|
129
|
-
const colored = type === "code"
|
|
130
|
+
const colored = type === "code"
|
|
131
|
+
? chalk.green(line)
|
|
132
|
+
: type === "comment"
|
|
133
|
+
? chalk.yellow(line)
|
|
134
|
+
: chalk.gray(line);
|
|
130
135
|
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
131
136
|
});
|
|
132
137
|
console.log(chalk.bold.blue("\n=== FIXED CONTENT ==="));
|
|
133
138
|
fixedLines.forEach((line, i) => {
|
|
134
|
-
|
|
139
|
+
// classifyLine might not be ideal here since fixedLines are final
|
|
140
|
+
// so we treat anything starting with a comment marker as "comment"
|
|
141
|
+
const trimmed = line.trimStart();
|
|
142
|
+
const type = syntax.singleLine.some(s => trimmed.startsWith(s)) ||
|
|
143
|
+
syntax.multiLine.some(({ start }) => trimmed.startsWith(start))
|
|
144
|
+
? "comment"
|
|
145
|
+
: "code";
|
|
135
146
|
const colored = type === "code" ? chalk.green(line) : chalk.yellow(line);
|
|
136
147
|
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
137
148
|
});
|