scai 0.1.100 → 0.1.102
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.
|
@@ -17,23 +17,24 @@ export const preserveCodeModule = {
|
|
|
17
17
|
// --- Classify line ---
|
|
18
18
|
let inBlockComment = false;
|
|
19
19
|
let blockLines = [];
|
|
20
|
+
// returns: "code" | comment string | null
|
|
20
21
|
const classifyLine = (line) => {
|
|
21
22
|
const trimmed = line.trimStart();
|
|
22
23
|
// --- Single-line comment ---
|
|
23
24
|
for (const s of syntax.singleLine) {
|
|
24
25
|
if (trimmed.startsWith(s))
|
|
25
|
-
return line;
|
|
26
|
+
return line;
|
|
26
27
|
}
|
|
27
28
|
// --- Multi-line comment ---
|
|
28
29
|
for (const { start, end } of syntax.multiLine) {
|
|
29
30
|
if (!inBlockComment) {
|
|
30
31
|
if (trimmed.startsWith(start) && trimmed.includes(end)) {
|
|
31
|
-
return line; // entire block on
|
|
32
|
+
return line; // entire block on one line
|
|
32
33
|
}
|
|
33
34
|
if (trimmed.startsWith(start)) {
|
|
34
35
|
inBlockComment = true;
|
|
35
36
|
blockLines = [line];
|
|
36
|
-
return
|
|
37
|
+
return null; // wait until block ends
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
else {
|
|
@@ -42,9 +43,9 @@ export const preserveCodeModule = {
|
|
|
42
43
|
inBlockComment = false;
|
|
43
44
|
const fullBlock = blockLines.join("\n");
|
|
44
45
|
blockLines = [];
|
|
45
|
-
return fullBlock; //
|
|
46
|
+
return fullBlock; // emit entire block
|
|
46
47
|
}
|
|
47
|
-
return
|
|
48
|
+
return null; // still inside block
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
return "code";
|
|
@@ -54,84 +55,78 @@ export const preserveCodeModule = {
|
|
|
54
55
|
const map = new Map();
|
|
55
56
|
let commentBuffer = [];
|
|
56
57
|
for (const line of lines) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
// Collect comment lines
|
|
60
|
-
commentBuffer.push(type.trim());
|
|
61
|
-
}
|
|
62
|
-
else if (type === "code") {
|
|
63
|
-
// Flush buffer when hitting code
|
|
58
|
+
const result = classifyLine(line);
|
|
59
|
+
if (result === "code") {
|
|
64
60
|
if (commentBuffer.length > 0) {
|
|
65
61
|
const key = line.trim().toLowerCase();
|
|
62
|
+
const block = commentBuffer.join("\n").trim().toLowerCase();
|
|
66
63
|
if (!map.has(key))
|
|
67
64
|
map.set(key, new Set());
|
|
68
|
-
|
|
69
|
-
const commentBlock = commentBuffer.join("\n").toLowerCase();
|
|
70
|
-
map.get(key).add(commentBlock);
|
|
65
|
+
map.get(key).add(block);
|
|
71
66
|
commentBuffer = [];
|
|
72
67
|
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (typeof result === "string") {
|
|
71
|
+
// comment line or block
|
|
72
|
+
commentBuffer.push(result);
|
|
73
73
|
}
|
|
74
|
+
// result === null => inside multi-line block, do nothing
|
|
74
75
|
}
|
|
75
|
-
//
|
|
76
|
+
// flush at EOF
|
|
76
77
|
if (commentBuffer.length > 0) {
|
|
77
78
|
const key = "";
|
|
79
|
+
const block = commentBuffer.join("\n").trim().toLowerCase();
|
|
78
80
|
if (!map.has(key))
|
|
79
81
|
map.set(key, new Set());
|
|
80
|
-
|
|
81
|
-
map.get(key).add(commentBlock);
|
|
82
|
+
map.get(key).add(block);
|
|
82
83
|
}
|
|
83
84
|
return map;
|
|
84
85
|
}
|
|
85
86
|
// --- Step 1: Collect comments ---
|
|
86
87
|
const modelComments = collectCommentsMap(newLines); // model first
|
|
87
88
|
const origComments = collectCommentsMap(origLines); // original
|
|
88
|
-
// --- Step 2: Remove duplicates ---
|
|
89
|
-
for (const [key,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
89
|
+
// --- Step 2: Remove duplicates from model (since we insert model) ---
|
|
90
|
+
for (const [key, modelSet] of modelComments.entries()) {
|
|
91
|
+
const origSet = origComments.get(key);
|
|
92
|
+
if (!origSet)
|
|
93
|
+
continue;
|
|
94
|
+
for (const c of Array.from(modelSet)) {
|
|
95
|
+
if (origSet.has(c))
|
|
96
|
+
modelSet.delete(c);
|
|
96
97
|
}
|
|
98
|
+
if (modelSet.size === 0)
|
|
99
|
+
modelComments.delete(key);
|
|
97
100
|
}
|
|
98
|
-
// --- Step 3: Build fixed lines
|
|
101
|
+
// --- Step 3: Build fixed lines ---
|
|
99
102
|
const fixedLines = [];
|
|
100
103
|
for (const origLine of origLines) {
|
|
101
104
|
const key = origLine.trim().toLowerCase();
|
|
102
|
-
// Insert model comment blocks if any
|
|
103
105
|
if (modelComments.has(key)) {
|
|
104
|
-
modelComments.get(key)
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
for (const block of modelComments.get(key)) {
|
|
107
|
+
for (const line of block.split("\n")) {
|
|
108
|
+
const norm = line.trim().toLowerCase();
|
|
109
|
+
const already = fixedLines.some(l => l.trim().toLowerCase() === norm);
|
|
110
|
+
if (!already) {
|
|
108
111
|
fixedLines.push(line);
|
|
109
112
|
console.log(chalk.blue("Inserted comment:"), line.trim());
|
|
110
113
|
}
|
|
111
114
|
else {
|
|
112
|
-
console.log(chalk.gray("Skipped duplicate
|
|
115
|
+
console.log(chalk.gray("Skipped duplicate:"), line.trim());
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
}
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
|
-
fixedLines.push(origLine);
|
|
120
|
+
fixedLines.push(origLine); // always keep original
|
|
118
121
|
}
|
|
119
|
-
// --- Logging
|
|
120
|
-
console.log(chalk.bold.blue("\n=== LINE CLASSIFICATION (original) ==="));
|
|
121
|
-
origLines.forEach((line, i) => {
|
|
122
|
-
const type = classifyLine(line);
|
|
123
|
-
const colored = type === "code" ? chalk.green(line) : chalk.yellow(line);
|
|
124
|
-
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
125
|
-
});
|
|
126
|
-
console.log(chalk.bold.blue("\n=== LINE CLASSIFICATION (model) ==="));
|
|
127
|
-
newLines.forEach((line, i) => {
|
|
128
|
-
const type = classifyLine(line);
|
|
129
|
-
const colored = type === "code" ? chalk.green(line) : chalk.yellow(line);
|
|
130
|
-
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
131
|
-
});
|
|
122
|
+
// --- Logging ---
|
|
132
123
|
console.log(chalk.bold.blue("\n=== FIXED CONTENT ==="));
|
|
133
124
|
fixedLines.forEach((line, i) => {
|
|
134
|
-
const
|
|
125
|
+
const trimmed = line.trimStart();
|
|
126
|
+
const type = syntax.singleLine.some(s => trimmed.startsWith(s)) ||
|
|
127
|
+
syntax.multiLine.some(({ start }) => trimmed.startsWith(start))
|
|
128
|
+
? "comment"
|
|
129
|
+
: "code";
|
|
135
130
|
const colored = type === "code" ? chalk.green(line) : chalk.yellow(line);
|
|
136
131
|
console.log(`${i + 1}: ${colored} ${chalk.gray(`[${type}]`)}`);
|
|
137
132
|
});
|