newo 2.0.4 → 2.0.5

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.
@@ -110,57 +110,59 @@ export async function askForOverwrite(skillIdn, existingContent, newContent, fil
110
110
  // Show a GitHub-style colored diff with line numbers and context
111
111
  const localLines = existingContent.trim().split('\n');
112
112
  const remoteLines = newContent.trim().split('\n');
113
- // Find differences and show with 2 lines context before/after
114
- const diffs = [];
115
- // Simple diff algorithm to find changes
116
- let localIdx = 0;
117
- let remoteIdx = 0;
118
- while (localIdx < localLines.length || remoteIdx < remoteLines.length) {
119
- const localLine = localLines[localIdx];
120
- const remoteLine = remoteLines[remoteIdx];
121
- if (localLine !== remoteLine) {
122
- if (localLine !== undefined && remoteLine !== undefined) {
123
- diffs.push({ localIndex: localIdx, remoteIndex: remoteIdx, type: 'change' });
124
- }
125
- else if (localLine !== undefined) {
126
- diffs.push({ localIndex: localIdx, remoteIndex: -1, type: 'remove' });
127
- }
128
- else if (remoteLine !== undefined) {
129
- diffs.push({ localIndex: -1, remoteIndex: remoteIdx, type: 'add' });
130
- }
113
+ // Find the first differing section and show it with context
114
+ let diffStart = -1;
115
+ let diffEnd = -1;
116
+ // Find first difference
117
+ for (let i = 0; i < Math.max(localLines.length, remoteLines.length); i++) {
118
+ if (localLines[i] !== remoteLines[i]) {
119
+ diffStart = i;
120
+ break;
131
121
  }
132
- if (localLine !== undefined)
133
- localIdx++;
134
- if (remoteLine !== undefined)
135
- remoteIdx++;
136
- }
137
- // Show diffs with context (2 lines before/after each change)
138
- let shown = 0;
139
- const maxDiffGroups = 3;
140
- for (const diff of diffs.slice(0, maxDiffGroups)) {
141
- if (shown > 0)
142
- console.log(''); // Separator between diff groups
143
- // Show context before
144
- const contextStart = Math.max(0, diff.localIndex - 2);
145
- for (let i = contextStart; i < diff.localIndex && i < localLines.length; i++) {
122
+ }
123
+ if (diffStart === -1) {
124
+ // No differences found (shouldn't happen, but handle gracefully)
125
+ console.log(`${gray} No differences found${reset}`);
126
+ return 'no';
127
+ }
128
+ // Find end of difference section
129
+ diffEnd = diffStart;
130
+ while (diffEnd < Math.max(localLines.length, remoteLines.length) &&
131
+ (localLines[diffEnd] !== remoteLines[diffEnd] ||
132
+ localLines[diffEnd] === undefined ||
133
+ remoteLines[diffEnd] === undefined)) {
134
+ diffEnd++;
135
+ }
136
+ // Show context before (2 lines)
137
+ const contextStart = Math.max(0, diffStart - 2);
138
+ for (let i = contextStart; i < diffStart; i++) {
139
+ if (localLines[i] !== undefined) {
146
140
  console.log(` ${String(i + 1).padStart(3)} ${localLines[i]}`);
147
141
  }
148
- // Show the actual diff
149
- if (diff.type === 'change' || diff.type === 'remove') {
150
- console.log(`${redBg} - ${String(diff.localIndex + 1).padStart(3)} ${localLines[diff.localIndex]} ${reset}`);
142
+ }
143
+ // Show the differences
144
+ const maxDiffLine = Math.min(diffEnd, Math.max(localLines.length, remoteLines.length));
145
+ for (let i = diffStart; i < maxDiffLine; i++) {
146
+ const localLine = localLines[i];
147
+ const remoteLine = remoteLines[i];
148
+ if (localLine !== undefined && (remoteLine === undefined || localLine !== remoteLine)) {
149
+ console.log(`${redBg} - ${String(i + 1).padStart(3)} ${localLine} ${reset}`);
151
150
  }
152
- if (diff.type === 'change' || diff.type === 'add') {
153
- console.log(`${greenBg} + ${String(diff.remoteIndex + 1).padStart(3)} ${remoteLines[diff.remoteIndex]} ${reset}`);
151
+ if (remoteLine !== undefined && (localLine === undefined || localLine !== remoteLine)) {
152
+ console.log(`${greenBg} + ${String(i + 1).padStart(3)} ${remoteLine} ${reset}`);
154
153
  }
155
- // Show context after
156
- const contextEnd = Math.min(localLines.length, diff.localIndex + 3);
157
- for (let i = diff.localIndex + 1; i < contextEnd; i++) {
154
+ }
155
+ // Show context after (2 lines)
156
+ const contextEnd = Math.min(localLines.length, diffEnd + 2);
157
+ for (let i = diffEnd; i < contextEnd; i++) {
158
+ if (localLines[i] !== undefined) {
158
159
  console.log(` ${String(i + 1).padStart(3)} ${localLines[i]}`);
159
160
  }
160
- shown++;
161
161
  }
162
- if (diffs.length > maxDiffGroups) {
163
- console.log(`${gray}... (${diffs.length - maxDiffGroups} more diff groups)${reset}`);
162
+ // Show if there are more differences
163
+ const totalDiffs = Math.abs(localLines.length - remoteLines.length) + (diffEnd - diffStart);
164
+ if (totalDiffs > (diffEnd - diffStart)) {
165
+ console.log(`${gray}... (${totalDiffs - (diffEnd - diffStart)} more differences)${reset}`);
164
166
  }
165
167
  const answer = await new Promise((resolve) => {
166
168
  rl.question(`\nReplace local with remote? (y)es/(n)o/(a)ll/(q)uit: `, resolve);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newo",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "NEWO CLI: Professional command-line tool with modular architecture for NEWO AI Agent development. Features IDN-based file management, real-time progress tracking, intelligent sync operations, and comprehensive multi-customer support.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -166,63 +166,67 @@ export async function askForOverwrite(skillIdn: string, existingContent: string,
166
166
  const localLines = existingContent.trim().split('\n');
167
167
  const remoteLines = newContent.trim().split('\n');
168
168
 
169
- // Find differences and show with 2 lines context before/after
170
- const diffs: Array<{localIndex: number, remoteIndex: number, type: 'change' | 'add' | 'remove'}> = [];
171
-
172
- // Simple diff algorithm to find changes
173
- let localIdx = 0;
174
- let remoteIdx = 0;
175
-
176
- while (localIdx < localLines.length || remoteIdx < remoteLines.length) {
177
- const localLine = localLines[localIdx];
178
- const remoteLine = remoteLines[remoteIdx];
179
-
180
- if (localLine !== remoteLine) {
181
- if (localLine !== undefined && remoteLine !== undefined) {
182
- diffs.push({localIndex: localIdx, remoteIndex: remoteIdx, type: 'change'});
183
- } else if (localLine !== undefined) {
184
- diffs.push({localIndex: localIdx, remoteIndex: -1, type: 'remove'});
185
- } else if (remoteLine !== undefined) {
186
- diffs.push({localIndex: -1, remoteIndex: remoteIdx, type: 'add'});
187
- }
169
+ // Find the first differing section and show it with context
170
+ let diffStart = -1;
171
+ let diffEnd = -1;
172
+
173
+ // Find first difference
174
+ for (let i = 0; i < Math.max(localLines.length, remoteLines.length); i++) {
175
+ if (localLines[i] !== remoteLines[i]) {
176
+ diffStart = i;
177
+ break;
188
178
  }
189
-
190
- if (localLine !== undefined) localIdx++;
191
- if (remoteLine !== undefined) remoteIdx++;
192
179
  }
193
180
 
194
- // Show diffs with context (2 lines before/after each change)
195
- let shown = 0;
196
- const maxDiffGroups = 3;
181
+ if (diffStart === -1) {
182
+ // No differences found (shouldn't happen, but handle gracefully)
183
+ console.log(`${gray} No differences found${reset}`);
184
+ return 'no';
185
+ }
197
186
 
198
- for (const diff of diffs.slice(0, maxDiffGroups)) {
199
- if (shown > 0) console.log(''); // Separator between diff groups
187
+ // Find end of difference section
188
+ diffEnd = diffStart;
189
+ while (diffEnd < Math.max(localLines.length, remoteLines.length) &&
190
+ (localLines[diffEnd] !== remoteLines[diffEnd] ||
191
+ localLines[diffEnd] === undefined ||
192
+ remoteLines[diffEnd] === undefined)) {
193
+ diffEnd++;
194
+ }
200
195
 
201
- // Show context before
202
- const contextStart = Math.max(0, diff.localIndex - 2);
203
- for (let i = contextStart; i < diff.localIndex && i < localLines.length; i++) {
196
+ // Show context before (2 lines)
197
+ const contextStart = Math.max(0, diffStart - 2);
198
+ for (let i = contextStart; i < diffStart; i++) {
199
+ if (localLines[i] !== undefined) {
204
200
  console.log(` ${String(i + 1).padStart(3)} ${localLines[i]}`);
205
201
  }
202
+ }
203
+
204
+ // Show the differences
205
+ const maxDiffLine = Math.min(diffEnd, Math.max(localLines.length, remoteLines.length));
206
+ for (let i = diffStart; i < maxDiffLine; i++) {
207
+ const localLine = localLines[i];
208
+ const remoteLine = remoteLines[i];
206
209
 
207
- // Show the actual diff
208
- if (diff.type === 'change' || diff.type === 'remove') {
209
- console.log(`${redBg} - ${String(diff.localIndex + 1).padStart(3)} ${localLines[diff.localIndex]} ${reset}`);
210
+ if (localLine !== undefined && (remoteLine === undefined || localLine !== remoteLine)) {
211
+ console.log(`${redBg} - ${String(i + 1).padStart(3)} ${localLine} ${reset}`);
210
212
  }
211
- if (diff.type === 'change' || diff.type === 'add') {
212
- console.log(`${greenBg} + ${String(diff.remoteIndex + 1).padStart(3)} ${remoteLines[diff.remoteIndex]} ${reset}`);
213
+ if (remoteLine !== undefined && (localLine === undefined || localLine !== remoteLine)) {
214
+ console.log(`${greenBg} + ${String(i + 1).padStart(3)} ${remoteLine} ${reset}`);
213
215
  }
216
+ }
214
217
 
215
- // Show context after
216
- const contextEnd = Math.min(localLines.length, diff.localIndex + 3);
217
- for (let i = diff.localIndex + 1; i < contextEnd; i++) {
218
+ // Show context after (2 lines)
219
+ const contextEnd = Math.min(localLines.length, diffEnd + 2);
220
+ for (let i = diffEnd; i < contextEnd; i++) {
221
+ if (localLines[i] !== undefined) {
218
222
  console.log(` ${String(i + 1).padStart(3)} ${localLines[i]}`);
219
223
  }
220
-
221
- shown++;
222
224
  }
223
225
 
224
- if (diffs.length > maxDiffGroups) {
225
- console.log(`${gray}... (${diffs.length - maxDiffGroups} more diff groups)${reset}`);
226
+ // Show if there are more differences
227
+ const totalDiffs = Math.abs(localLines.length - remoteLines.length) + (diffEnd - diffStart);
228
+ if (totalDiffs > (diffEnd - diffStart)) {
229
+ console.log(`${gray}... (${totalDiffs - (diffEnd - diffStart)} more differences)${reset}`);
226
230
  }
227
231
 
228
232
  const answer = await new Promise<string>((resolve) => {