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; // return actual 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 a single line
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 line; // start of multi-line block
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; // return entire multi-line block
46
+ return fullBlock; // emit entire block
46
47
  }
47
- return ""; // middle lines, wait until block ends
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 type = classifyLine(line);
58
- if (type && type !== "code") {
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
- // Join consecutive comments into one block
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
- // Flush remaining comments at EOF
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
- const commentBlock = commentBuffer.join("\n").toLowerCase();
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, commentSet] of modelComments.entries()) {
90
- if (origComments.has(key)) {
91
- commentSet.forEach(c => {
92
- origComments.get(key).delete(c.trim().toLowerCase());
93
- });
94
- if (origComments.get(key).size === 0)
95
- origComments.delete(key);
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 with model comments inserted above original ---
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).forEach(block => {
105
- const lines = block.split("\n");
106
- for (const line of lines) {
107
- if (!fixedLines.includes(line)) {
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 comment:"), line.trim());
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 for debugging ---
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 type = classifyLine(line);
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.100",
3
+ "version": "0.1.102",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"