intentumdiff-python 0.0.1__py3-none-macosx_11_0_arm64.whl

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.
Files changed (165) hide show
  1. intentumdiff/__init__.py +134 -0
  2. intentumdiff/_differ_gate.py +210 -0
  3. intentumdiff/_differ_presentation.py +786 -0
  4. intentumdiff/_differ_runtime.py +320 -0
  5. intentumdiff/analysis/__init__.py +1 -0
  6. intentumdiff/analysis/compile_commands.py +151 -0
  7. intentumdiff/analysis/cross_file.py +71 -0
  8. intentumdiff/analysis/diagnostics.py +309 -0
  9. intentumdiff/analysis/guardrail_reports.py +254 -0
  10. intentumdiff/analysis/guardrails.py +318 -0
  11. intentumdiff/analysis/invariances.py +1207 -0
  12. intentumdiff/analysis/keyed_profiles.py +25 -0
  13. intentumdiff/analysis/resource_profiles.py +14 -0
  14. intentumdiff/analysis/schema_resolver.py +816 -0
  15. intentumdiff/analysis/text_review.py +46 -0
  16. intentumdiff/analysis/user_schemas.py +430 -0
  17. intentumdiff/assets.py +45 -0
  18. intentumdiff/cache/__init__.py +37 -0
  19. intentumdiff/cache/duckdb_store.py +98 -0
  20. intentumdiff/cache/sqlite_store.py +149 -0
  21. intentumdiff/cache/store.py +190 -0
  22. intentumdiff/cli/__init__.py +199 -0
  23. intentumdiff/cli/_commands.py +2141 -0
  24. intentumdiff/cli/_parser.py +1061 -0
  25. intentumdiff/cli/_shared.py +644 -0
  26. intentumdiff/content_type.py +59 -0
  27. intentumdiff/core/__init__.py +1 -0
  28. intentumdiff/core/commit_differ.py +599 -0
  29. intentumdiff/core/config.py +51 -0
  30. intentumdiff/core/cst_serializer.py +101 -0
  31. intentumdiff/core/diffignore.py +87 -0
  32. intentumdiff/core/index.py +189 -0
  33. intentumdiff/core/indexer.py +792 -0
  34. intentumdiff/core/models.py +837 -0
  35. intentumdiff/differ.py +2195 -0
  36. intentumdiff/github_app.py +287 -0
  37. intentumdiff/intentumdiff_rust_core/__init__.py +7 -0
  38. intentumdiff/intentumdiff_rust_core/ffi.py +8 -0
  39. intentumdiff/intentumdiff_rust_core/libintentumdiff_rust_core.dylib +0 -0
  40. intentumdiff/invariances/__init__.py +2 -0
  41. intentumdiff/invariances/rules.schema.json +283 -0
  42. intentumdiff/invariances/rules.yaml +349 -0
  43. intentumdiff/live_server.py +1314 -0
  44. intentumdiff/lsp/__init__.py +67 -0
  45. intentumdiff/lsp/client.py +544 -0
  46. intentumdiff/lsp/config.py +96 -0
  47. intentumdiff/lsp/enricher.py +227 -0
  48. intentumdiff/lsp/exceptions.py +27 -0
  49. intentumdiff/lsp/launcher.py +273 -0
  50. intentumdiff/lsp/servers.py +356 -0
  51. intentumdiff/lsp_server/__init__.py +14 -0
  52. intentumdiff/lsp_server/_codelens.py +67 -0
  53. intentumdiff/lsp_server/_diagnostics.py +62 -0
  54. intentumdiff/lsp_server/_handlers.py +175 -0
  55. intentumdiff/lsp_server/server.py +205 -0
  56. intentumdiff/plugins/__init__.py +1 -0
  57. intentumdiff/plugins/adapter.py +397 -0
  58. intentumdiff/plugins/builtins.py +323 -0
  59. intentumdiff/plugins/exceptions.py +93 -0
  60. intentumdiff/plugins/hub.py +1155 -0
  61. intentumdiff/plugins/language_metadata.py +250 -0
  62. intentumdiff/plugins/loader.py +1252 -0
  63. intentumdiff/plugins/registry.py +1079 -0
  64. intentumdiff/plugins/registry.schema.json +99 -0
  65. intentumdiff/plugins/registry_schema.py +280 -0
  66. intentumdiff/plugins/wit/plugin.wit +351 -0
  67. intentumdiff/rust_core.py +2370 -0
  68. intentumdiff/serve/__init__.py +19 -0
  69. intentumdiff/serve/_app.py +485 -0
  70. intentumdiff/serve/_static/index.html +326 -0
  71. intentumdiff/serve/_static/playground.js +567 -0
  72. intentumdiff/sources/__init__.py +1 -0
  73. intentumdiff/sources/base.py +28 -0
  74. intentumdiff/sources/file_source.py +48 -0
  75. intentumdiff/sources/git_source.py +375 -0
  76. intentumdiff/sources/live_buffer_source.py +113 -0
  77. intentumdiff/sources/patch_source.py +126 -0
  78. intentumdiff/sources/string_source.py +44 -0
  79. intentumdiff/testing.py +165 -0
  80. intentumdiff/vcs/__init__.py +37 -0
  81. intentumdiff/vcs/_safe_path.py +50 -0
  82. intentumdiff/vcs/base.py +136 -0
  83. intentumdiff/vcs/git_backend.py +97 -0
  84. intentumdiff/vcs/git_cli.py +100 -0
  85. intentumdiff/vcs/hg_backend.py +94 -0
  86. intentumdiff/vcs/perforce_backend.py +109 -0
  87. intentumdiff/vcs/svn_backend.py +105 -0
  88. intentumdiff/wasm/.gitkeep +2 -0
  89. intentumdiff/wasm/abap_parser.wasm +0 -0
  90. intentumdiff/wasm/adf_parser.wasm +0 -0
  91. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  92. intentumdiff/wasm/asm_parser.wasm +0 -0
  93. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  94. intentumdiff/wasm/astro_parser.wasm +0 -0
  95. intentumdiff/wasm/bash_parser.wasm +0 -0
  96. intentumdiff/wasm/clojure_parser.wasm +0 -0
  97. intentumdiff/wasm/cmake_parser.wasm +0 -0
  98. intentumdiff/wasm/cpp_parser.wasm +0 -0
  99. intentumdiff/wasm/csharp_parser.wasm +0 -0
  100. intentumdiff/wasm/css_parser.wasm +0 -0
  101. intentumdiff/wasm/dart_parser.wasm +0 -0
  102. intentumdiff/wasm/databricks_parser.wasm +0 -0
  103. intentumdiff/wasm/dax_parser.wasm +0 -0
  104. intentumdiff/wasm/delphi_parser.wasm +0 -0
  105. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  106. intentumdiff/wasm/elixir_parser.wasm +0 -0
  107. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  108. intentumdiff/wasm/generic_parser.wasm +0 -0
  109. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  110. intentumdiff/wasm/go_parser.wasm +0 -0
  111. intentumdiff/wasm/gomod_parser.wasm +0 -0
  112. intentumdiff/wasm/graphql_parser.wasm +0 -0
  113. intentumdiff/wasm/groovy_parser.wasm +0 -0
  114. intentumdiff/wasm/haskell_parser.wasm +0 -0
  115. intentumdiff/wasm/html_parser.wasm +0 -0
  116. intentumdiff/wasm/ini_parser.wasm +0 -0
  117. intentumdiff/wasm/java_parser.wasm +0 -0
  118. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  119. intentumdiff/wasm/json_parser.wasm +0 -0
  120. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  121. intentumdiff/wasm/latex_parser.wasm +0 -0
  122. intentumdiff/wasm/lua_parser.wasm +0 -0
  123. intentumdiff/wasm/make_parser.wasm +0 -0
  124. intentumdiff/wasm/markdown_parser.wasm +0 -0
  125. intentumdiff/wasm/mdx_parser.wasm +0 -0
  126. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  127. intentumdiff/wasm/odin_parser.wasm +0 -0
  128. intentumdiff/wasm/parser_manifest.json +590 -0
  129. intentumdiff/wasm/perl_parser.wasm +0 -0
  130. intentumdiff/wasm/php_parser.wasm +0 -0
  131. intentumdiff/wasm/plsql_parser.wasm +0 -0
  132. intentumdiff/wasm/po_parser.wasm +0 -0
  133. intentumdiff/wasm/postscript_parser.wasm +0 -0
  134. intentumdiff/wasm/powershell_parser.wasm +0 -0
  135. intentumdiff/wasm/proto_parser.wasm +0 -0
  136. intentumdiff/wasm/puppet_parser.wasm +0 -0
  137. intentumdiff/wasm/python_parser.wasm +0 -0
  138. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  139. intentumdiff/wasm/r_parser.wasm +0 -0
  140. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  141. intentumdiff/wasm/ruby_parser.wasm +0 -0
  142. intentumdiff/wasm/rust_parser.wasm +0 -0
  143. intentumdiff/wasm/sas_parser.wasm +0 -0
  144. intentumdiff/wasm/scala_parser.wasm +0 -0
  145. intentumdiff/wasm/scss_parser.wasm +0 -0
  146. intentumdiff/wasm/sql_parser.wasm +0 -0
  147. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  148. intentumdiff/wasm/svelte_parser.wasm +0 -0
  149. intentumdiff/wasm/swift_parser.wasm +0 -0
  150. intentumdiff/wasm/terraform_parser.wasm +0 -0
  151. intentumdiff/wasm/toml_parser.wasm +0 -0
  152. intentumdiff/wasm/tsql_parser.wasm +0 -0
  153. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  154. intentumdiff/wasm/vue_parser.wasm +0 -0
  155. intentumdiff/wasm/wat_parser.wasm +0 -0
  156. intentumdiff/wasm/xml_parser.wasm +0 -0
  157. intentumdiff/wasm/yaml_parser.wasm +0 -0
  158. intentumdiff/wasm/zig_parser.wasm +0 -0
  159. intentumdiff/watcher.py +259 -0
  160. intentumdiff_python-0.0.1.dist-info/METADATA +112 -0
  161. intentumdiff_python-0.0.1.dist-info/RECORD +165 -0
  162. intentumdiff_python-0.0.1.dist-info/WHEEL +4 -0
  163. intentumdiff_python-0.0.1.dist-info/entry_points.txt +80 -0
  164. intentumdiff_python-0.0.1.dist-info/licenses/LICENSE +21 -0
  165. intentumdiff_python-0.0.1.dist-info/sboms/intentumdiff-rust-core.cyclonedx.json +10968 -0
@@ -0,0 +1,567 @@
1
+ 'use strict';
2
+
3
+ const PREF_KEY = 'intentumdiff.preferredPlugins.v1';
4
+
5
+ let languageGroups = [];
6
+ let languageById = {};
7
+ let preferredPlugins = readPreferredPlugins();
8
+ let oldEditor, newEditor;
9
+ let oldTextArea, newTextArea;
10
+ let oldDecColl = null, newDecColl = null;
11
+ let currentChanges = [];
12
+ let detectRequestId = 0;
13
+
14
+ const exampleCache = {};
15
+
16
+ const BADGE_COLORS = {
17
+ ADDITION: '#3fb950',
18
+ DELETION: '#f85149',
19
+ MODIFICATION: '#e3b341',
20
+ MOVE: '#58a6ff',
21
+ STYLE_ONLY: '#484f58',
22
+ REFACTORING: '#bc8cff',
23
+ MOVE_TO_MODULE: '#39d353',
24
+ CROSS_FILE_RENAME: '#ffa657',
25
+ REORDER: '#388bfd',
26
+ };
27
+
28
+ function readPreferredPlugins() {
29
+ try {
30
+ const raw = localStorage.getItem(PREF_KEY);
31
+ const parsed = raw ? JSON.parse(raw) : {};
32
+ return parsed && typeof parsed === 'object' ? parsed : {};
33
+ } catch {
34
+ return {};
35
+ }
36
+ }
37
+
38
+ function writePreferredPlugins() {
39
+ try {
40
+ localStorage.setItem(PREF_KEY, JSON.stringify(preferredPlugins));
41
+ } catch {
42
+ /* localStorage can be unavailable in private or embedded contexts */
43
+ }
44
+ }
45
+
46
+ function selectedLanguage() {
47
+ return document.getElementById('lang-select')?.value || '';
48
+ }
49
+
50
+ function groupFor(lang) {
51
+ return lang ? languageById[lang] || null : null;
52
+ }
53
+
54
+ function selectedPluginFor(lang) {
55
+ const group = groupFor(lang);
56
+ if (!group || !Array.isArray(group.plugins) || group.plugins.length === 0) return null;
57
+ const preferred = preferredPlugins[lang];
58
+ return (
59
+ group.plugins.find(p => p.pluginId === preferred) ||
60
+ group.plugins.find(p => p.pluginId === group.selectedPluginId) ||
61
+ group.plugins[0]
62
+ );
63
+ }
64
+
65
+ function preferredPluginPayload() {
66
+ const payload = {};
67
+ Object.entries(preferredPlugins).forEach(([lang, pluginId]) => {
68
+ const group = groupFor(lang);
69
+ if (group && group.plugins.some(p => p.pluginId === pluginId)) {
70
+ payload[lang] = pluginId;
71
+ }
72
+ });
73
+ return payload;
74
+ }
75
+
76
+ function pluginQuery(plugin) {
77
+ return plugin ? `?plugin_id=${encodeURIComponent(plugin.pluginId)}` : '';
78
+ }
79
+
80
+ function filenameFor(lang) {
81
+ return selectedPluginFor(lang)?.defaultFilename || (lang ? `code.${lang}` : 'code.txt');
82
+ }
83
+
84
+ function monacoLanguageFor(lang) {
85
+ return selectedPluginFor(lang)?.monacoLanguage || 'plaintext';
86
+ }
87
+
88
+ async function fetchLanguageInfo() {
89
+ const r = await fetch('/language-info');
90
+ if (!r.ok) throw new Error('language-info failed');
91
+ const data = await r.json();
92
+ if (!Array.isArray(data.languages)) throw new Error('language-info malformed');
93
+ return data.languages;
94
+ }
95
+
96
+ async function fetchLegacyLanguages() {
97
+ const r = await fetch('/languages');
98
+ if (!r.ok) return [];
99
+ const data = await r.json();
100
+ if (!Array.isArray(data.languages)) return [];
101
+ return data.languages.map(lang => ({
102
+ language: lang,
103
+ selectedPluginId: lang,
104
+ plugins: [{
105
+ languageId: lang,
106
+ languageName: lang,
107
+ languageShortName: lang,
108
+ monacoLanguage: 'plaintext',
109
+ defaultFilename: `code.${lang}`,
110
+ languageFileExtensions: [],
111
+ author: '',
112
+ pluginVersion: '',
113
+ lastUpdated: '',
114
+ pluginId: lang,
115
+ grammarId: lang,
116
+ priority: 0,
117
+ isTrusted: false,
118
+ provenance: '',
119
+ }],
120
+ }));
121
+ }
122
+
123
+ async function populateLanguageSelector() {
124
+ try {
125
+ languageGroups = await fetchLanguageInfo();
126
+ } catch {
127
+ languageGroups = await fetchLegacyLanguages();
128
+ }
129
+ languageById = Object.fromEntries(languageGroups.map(group => [group.language, group]));
130
+
131
+ const sel = document.getElementById('lang-select');
132
+ if (!sel) return;
133
+ const current = sel.value;
134
+ while (sel.options.length > 1) sel.remove(1);
135
+ languageGroups.forEach(group => {
136
+ const plugin = selectedPluginFor(group.language) || group.plugins[0] || {};
137
+ const opt = document.createElement('option');
138
+ opt.value = group.language;
139
+ opt.textContent = plugin.languageName || group.language;
140
+ sel.appendChild(opt);
141
+ });
142
+ const languages = languageGroups.map(group => group.language);
143
+ sel.value = current && languages.includes(current)
144
+ ? current
145
+ : (languages.includes('python') ? 'python' : '');
146
+ updatePluginSelector();
147
+ }
148
+
149
+ function updatePluginSelector() {
150
+ const label = document.getElementById('plugin-label');
151
+ const sel = document.getElementById('plugin-select');
152
+ if (!sel) return;
153
+
154
+ const lang = selectedLanguage();
155
+ const group = groupFor(lang);
156
+ const plugins = group?.plugins || [];
157
+ sel.innerHTML = '';
158
+
159
+ if (!lang || plugins.length <= 1) {
160
+ sel.style.display = 'none';
161
+ if (label) label.style.display = 'none';
162
+ return;
163
+ }
164
+
165
+ plugins.forEach(plugin => {
166
+ const opt = document.createElement('option');
167
+ opt.value = plugin.pluginId;
168
+ opt.textContent = plugin.provenance
169
+ ? `${plugin.languageShortName || lang} - ${plugin.provenance}`
170
+ : `${plugin.languageShortName || lang} - ${plugin.pluginId}`;
171
+ sel.appendChild(opt);
172
+ });
173
+ sel.value = selectedPluginFor(lang)?.pluginId || plugins[0].pluginId;
174
+ sel.style.display = '';
175
+ if (label) label.style.display = '';
176
+ }
177
+
178
+ async function fetchExample(lang) {
179
+ if (!lang) return null;
180
+ const plugin = selectedPluginFor(lang);
181
+ const cacheKey = `${lang}:${plugin?.pluginId || ''}`;
182
+ if (exampleCache[cacheKey]) return exampleCache[cacheKey];
183
+ try {
184
+ const r = await fetch(`/example/${encodeURIComponent(lang)}${pluginQuery(plugin)}`);
185
+ if (!r.ok) return null;
186
+ const ex = await r.json();
187
+ if (ex.old == null && ex.new == null) return null;
188
+ exampleCache[cacheKey] = ex;
189
+ return ex;
190
+ } catch {
191
+ return null;
192
+ }
193
+ }
194
+
195
+ function getOldValue() {
196
+ return oldEditor ? oldEditor.getValue() : (oldTextArea?.value || '');
197
+ }
198
+
199
+ function getNewValue() {
200
+ return newEditor ? newEditor.getValue() : (newTextArea?.value || '');
201
+ }
202
+
203
+ function setOldValue(value) {
204
+ if (oldEditor) oldEditor.setValue(value);
205
+ if (oldTextArea) oldTextArea.value = value;
206
+ }
207
+
208
+ function setNewValue(value) {
209
+ if (newEditor) newEditor.setValue(value);
210
+ if (newTextArea) newTextArea.value = value;
211
+ }
212
+
213
+ function setEditorLanguage(lang) {
214
+ if (!oldEditor || !newEditor || typeof monaco === 'undefined') return;
215
+ const monacoLang = monacoLanguageFor(lang);
216
+ monaco.editor.setModelLanguage(oldEditor.getModel(), monacoLang);
217
+ monaco.editor.setModelLanguage(newEditor.getModel(), monacoLang);
218
+ }
219
+
220
+ function triggerDetectIfAuto() {
221
+ if (selectedLanguage() !== '') return;
222
+ clearTimeout(triggerDetectIfAuto.timer);
223
+ triggerDetectIfAuto.timer = setTimeout(() => {
224
+ serverDetect(`${getNewValue()}\n${getOldValue()}`);
225
+ }, 500);
226
+ }
227
+
228
+ function createFallbackEditor(id, label) {
229
+ const wrap = document.getElementById(id);
230
+ if (!wrap) return null;
231
+ wrap.innerHTML = '';
232
+ const textarea = document.createElement('textarea');
233
+ textarea.className = 'fallback-editor';
234
+ textarea.setAttribute('aria-label', label);
235
+ textarea.spellcheck = false;
236
+ textarea.addEventListener('input', triggerDetectIfAuto);
237
+ wrap.appendChild(textarea);
238
+ return textarea;
239
+ }
240
+
241
+ function initFallbackEditors() {
242
+ oldTextArea = createFallbackEditor('old-wrap', 'Old code');
243
+ newTextArea = createFallbackEditor('new-wrap', 'New code');
244
+ loadExample(selectedLanguage() || 'python');
245
+ }
246
+
247
+ function initEditors() {
248
+ const initialLanguage = monacoLanguageFor(selectedLanguage() || 'python');
249
+ const common = {
250
+ theme: 'vs-dark',
251
+ fontSize: 13,
252
+ minimap: { enabled: false },
253
+ scrollBeyondLastLine: false,
254
+ wordWrap: 'on',
255
+ automaticLayout: true,
256
+ language: initialLanguage,
257
+ glyphMargin: true,
258
+ overviewRulerLanes: 3,
259
+ };
260
+ oldEditor = monaco.editor.create(
261
+ document.getElementById('old-wrap'),
262
+ { ...common, value: '' }
263
+ );
264
+ newEditor = monaco.editor.create(
265
+ document.getElementById('new-wrap'),
266
+ { ...common, value: '' }
267
+ );
268
+ oldEditor.onDidChangeModelContent(triggerDetectIfAuto);
269
+ newEditor.onDidChangeModelContent(triggerDetectIfAuto);
270
+ loadExample(selectedLanguage() || 'python');
271
+ }
272
+
273
+ function startEditors() {
274
+ if (typeof require === 'function' && typeof require.config === 'function') {
275
+ require.config({ paths: { vs: '/static/vendor/min/vs' } });
276
+ require(['vs/editor/editor.main'], initEditors);
277
+ } else {
278
+ console.warn('Monaco loader unavailable; using textarea editors.');
279
+ initFallbackEditors();
280
+ }
281
+ }
282
+
283
+ async function loadExample(lang) {
284
+ const ex = await fetchExample(lang);
285
+ if (!ex) return;
286
+ setOldValue(ex.old);
287
+ setNewValue(ex.new);
288
+ }
289
+
290
+ function showDetected(lang) {
291
+ const span = document.getElementById('detected-lang');
292
+ const name = document.getElementById('detected-lang-name');
293
+ if (lang) {
294
+ name.textContent = lang;
295
+ span.style.display = 'inline';
296
+ setEditorLanguage(lang);
297
+ } else {
298
+ span.style.display = 'none';
299
+ }
300
+ }
301
+
302
+ async function detectOnServer(code) {
303
+ if (!code || code.trim().length < 10) return null;
304
+ try {
305
+ const preferred = preferredPluginPayload();
306
+ const body = { content: code.slice(0, 8192) };
307
+ if (Object.keys(preferred).length) body.preferred_plugins = preferred;
308
+ const r = await fetch('/detect', {
309
+ method: 'POST',
310
+ headers: { 'Content-Type': 'application/json' },
311
+ body: JSON.stringify(body),
312
+ });
313
+ if (!r.ok) return null;
314
+ const { language } = await r.json();
315
+ return language || null;
316
+ } catch {
317
+ return null;
318
+ }
319
+ }
320
+
321
+ async function serverDetect(code) {
322
+ const requestId = ++detectRequestId;
323
+ const language = await detectOnServer(code);
324
+ if (requestId !== detectRequestId) return;
325
+ showDetected(language);
326
+ }
327
+
328
+ function clearDecorations() {
329
+ oldDecColl?.clear(); newDecColl?.clear();
330
+ oldDecColl = newDecColl = null;
331
+ }
332
+
333
+ function applyDecorations(changes) {
334
+ if (!oldEditor || !newEditor) return;
335
+ const oldDecs = [], newDecs = [];
336
+ changes.forEach(c => {
337
+ const ct = c.change_type;
338
+ const color = BADGE_COLORS[ct] || '#888';
339
+ const makeOpts = label => ({
340
+ isWholeLine: false,
341
+ className: 'dec-' + ct,
342
+ glyphMarginClassName: 'dec-' + ct + '-glyph',
343
+ hoverMessage: {
344
+ value: '**' + ct + '**' + (label ? ': ' + label : ''),
345
+ isTrusted: false,
346
+ },
347
+ overviewRuler: { color, position: monaco.editor.OverviewRulerLane.Right },
348
+ stickiness: monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
349
+ });
350
+ if (c.old_node?.position) {
351
+ const p = c.old_node.position;
352
+ oldDecs.push({
353
+ range: new monaco.Range(p.start_line + 1, p.start_col + 1, p.end_line + 1, p.end_col + 1),
354
+ options: makeOpts(c.old_node.label),
355
+ });
356
+ }
357
+ if (c.new_node?.position) {
358
+ const p = c.new_node.position;
359
+ newDecs.push({
360
+ range: new monaco.Range(p.start_line + 1, p.start_col + 1, p.end_line + 1, p.end_col + 1),
361
+ options: makeOpts(c.new_node.label),
362
+ });
363
+ }
364
+ });
365
+ oldDecColl = oldEditor.createDecorationsCollection(oldDecs);
366
+ newDecColl = newEditor.createDecorationsCollection(newDecs);
367
+ }
368
+
369
+ document.getElementById('lang-select').addEventListener('change', e => {
370
+ const lang = e.target.value;
371
+ updatePluginSelector();
372
+ setEditorLanguage(lang);
373
+ if (lang) {
374
+ loadExample(lang);
375
+ showDetected(null);
376
+ }
377
+ });
378
+
379
+ document.getElementById('plugin-select')?.addEventListener('change', e => {
380
+ const lang = selectedLanguage();
381
+ if (!lang) return;
382
+ preferredPlugins[lang] = e.target.value;
383
+ writePreferredPlugins();
384
+ setEditorLanguage(lang);
385
+ loadExample(lang);
386
+ });
387
+
388
+ document.getElementById('results-toggle').addEventListener('click', () => {
389
+ const panel = document.getElementById('results');
390
+ const btn = document.getElementById('results-toggle');
391
+ btn.textContent = panel.classList.toggle('collapsed') ? 'Changes >' : 'Changes v';
392
+ });
393
+
394
+ document.getElementById('results').addEventListener('click', e => {
395
+ const li = e.target.closest('[data-idx]');
396
+ if (!li) return;
397
+ const c = currentChanges[+li.dataset.idx];
398
+ if (!c) return;
399
+ if (c.old_node?.position && oldEditor) {
400
+ oldEditor.revealLineInCenter(c.old_node.position.start_line + 1);
401
+ }
402
+ if (c.new_node?.position && newEditor) {
403
+ newEditor.revealLineInCenter(c.new_node.position.start_line + 1);
404
+ }
405
+ });
406
+
407
+ document.getElementById('compare-btn').addEventListener('click', async () => {
408
+ const btn = document.getElementById('compare-btn');
409
+ const spinner = document.getElementById('spinner');
410
+ const results = document.getElementById('results');
411
+
412
+ btn.disabled = true;
413
+ spinner.style.display = 'inline';
414
+ results.innerHTML = '';
415
+ clearDecorations();
416
+
417
+ let lang = selectedLanguage();
418
+ if (!lang) {
419
+ lang = await detectOnServer(`${getNewValue()}\n${getOldValue()}`) || '';
420
+ if (lang) showDetected(lang);
421
+ }
422
+
423
+ const plugin = selectedPluginFor(lang);
424
+ try {
425
+ const res = await fetch('/diff', {
426
+ method: 'POST',
427
+ headers: { 'Content-Type': 'application/json' },
428
+ body: JSON.stringify({
429
+ old: getOldValue(),
430
+ new: getNewValue(),
431
+ filename: filenameFor(lang),
432
+ language: lang || null,
433
+ plugin_id: plugin?.pluginId || null,
434
+ }),
435
+ });
436
+
437
+ if (!res.ok) {
438
+ const err = await res.json().catch(() => ({ detail: res.statusText }));
439
+ const detail = typeof err.detail === 'string' ? err.detail : JSON.stringify(err.detail);
440
+ results.innerHTML = '<div class="error-msg">Error ' + res.status + ': ' + escHtml(detail) + '</div>';
441
+ return;
442
+ }
443
+
444
+ const diff = await res.json();
445
+ renderResults(diff);
446
+ if (results.classList.contains('collapsed')) {
447
+ results.classList.remove('collapsed');
448
+ document.getElementById('results-toggle').textContent = 'Changes v';
449
+ }
450
+ } catch (ex) {
451
+ results.innerHTML = '<div class="error-msg">Network error: ' + escHtml(ex.message) + '</div>';
452
+ } finally {
453
+ btn.disabled = false;
454
+ spinner.style.display = 'none';
455
+ }
456
+ });
457
+
458
+ function renderResults(diff) {
459
+ const results = document.getElementById('results');
460
+ const frag = document.createDocumentFragment();
461
+
462
+ currentChanges = diff.changes || [];
463
+ applyDecorations(currentChanges);
464
+
465
+ (diff.parse_errors || []).forEach(msg => {
466
+ const div = document.createElement('div');
467
+ div.className = 'parse-error';
468
+ div.textContent = '! ' + msg;
469
+ frag.appendChild(div);
470
+ });
471
+
472
+ const changes = diff.changes || [];
473
+ const summary = document.createElement('p');
474
+ summary.className = 'summary';
475
+ if (!diff.has_semantic_changes && !diff.is_style_only) {
476
+ summary.innerHTML = '<strong>No changes</strong> detected.';
477
+ } else if (diff.is_style_only) {
478
+ summary.innerHTML = '<strong>Style-only</strong> - no semantic differences.';
479
+ } else {
480
+ const counts = {};
481
+ changes.forEach(c => { counts[c.change_type] = (counts[c.change_type] || 0) + 1; });
482
+ const parts = Object.entries(counts).map(
483
+ ([k, v]) => v + ' ' + escHtml(k.toLowerCase().replace(/_/g, ' '))
484
+ );
485
+ const n = changes.length;
486
+ summary.innerHTML =
487
+ '<strong>' + n + ' change' + (n !== 1 ? 's' : '') + '</strong> - ' + parts.join(', ') + '.';
488
+ }
489
+ frag.appendChild(summary);
490
+
491
+ if (changes.length > 0) {
492
+ const ul = document.createElement('ul');
493
+ ul.className = 'change-list';
494
+ changes.forEach((c, idx) => {
495
+ const li = document.createElement('li');
496
+ const ct = c.change_type;
497
+ li.className = 'change-item ci-' + ct;
498
+ li.dataset.idx = idx;
499
+ const node = c.new_node || c.old_node;
500
+ const label = node ? node.label : '-';
501
+ const desc = normaliseDescription(c);
502
+ const metaParts = [
503
+ node ? node.node_type : null,
504
+ formatNodePosition(node),
505
+ ].filter(Boolean);
506
+ li.innerHTML =
507
+ '<span class="badge badge-' + escHtml(ct) + '">' + escHtml(formatChangeType(ct)) + '</span>' +
508
+ '<div class="change-detail">' +
509
+ '<span class="change-label">' + escHtml(label) + '</span>' +
510
+ (desc
511
+ ? '<span class="change-desc">' + escHtml(desc) + '</span>'
512
+ : '') +
513
+ (metaParts.length
514
+ ? '<span class="change-meta">' + escHtml(metaParts.join(' · ')) + '</span>'
515
+ : '') +
516
+ '</div>';
517
+ ul.appendChild(li);
518
+ });
519
+ frag.appendChild(ul);
520
+ }
521
+
522
+ const details = document.createElement('details');
523
+ details.className = 'json-toggle';
524
+ const summary2 = document.createElement('summary');
525
+ summary2.textContent = 'Raw JSON';
526
+ const pre = document.createElement('pre');
527
+ pre.textContent = JSON.stringify(diff, null, 2);
528
+ details.appendChild(summary2);
529
+ details.appendChild(pre);
530
+ frag.appendChild(details);
531
+
532
+ results.appendChild(frag);
533
+ }
534
+
535
+ function formatChangeType(value) {
536
+ return String(value || '')
537
+ .toLowerCase()
538
+ .split('_')
539
+ .map(part => part ? part[0].toUpperCase() + part.slice(1) : part)
540
+ .join(' ');
541
+ }
542
+
543
+ function normaliseDescription(change) {
544
+ const parts = [];
545
+ if (change.description) parts.push(change.description);
546
+ if (change.refactoring_kind) {
547
+ const kind = change.refactoring_kind.replace(/_/g, ' ').toLowerCase();
548
+ if (!parts.some(part => part.toLowerCase().includes(kind))) parts.push(kind);
549
+ }
550
+ return parts.join(' · ');
551
+ }
552
+
553
+ function formatNodePosition(node) {
554
+ const pos = node?.position;
555
+ if (!pos || typeof pos.start_line !== 'number') return null;
556
+ return 'line ' + (pos.start_line + 1);
557
+ }
558
+
559
+ function escHtml(s) {
560
+ return String(s)
561
+ .replace(/&/g, '&amp;')
562
+ .replace(/</g, '&lt;')
563
+ .replace(/>/g, '&gt;')
564
+ .replace(/"/g, '&quot;');
565
+ }
566
+
567
+ populateLanguageSelector().then(startEditors);
@@ -0,0 +1 @@
1
+ # intentumdiff/sources
@@ -0,0 +1,28 @@
1
+ """
2
+ intentumdiff.sources.base
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Abstract base class for all input sources.
6
+
7
+ Every Source produces a 4-tuple:
8
+ (old_content: str, new_content: str, filename: str, language_hint: str | None)
9
+
10
+ ``language_hint`` may be None — the plugin registry will detect the language.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from abc import ABC, abstractmethod
16
+
17
+
18
+ class Source(ABC):
19
+ """Abstract input source. Subclasses must implement ``get_content``."""
20
+
21
+ @abstractmethod
22
+ def get_content(self) -> tuple[str, str, str, str | None]:
23
+ """
24
+ Return ``(old_content, new_content, filename, language_hint)``.
25
+
26
+ ``language_hint`` — e.g. "python", "sql". Pass None to auto-detect.
27
+ """
28
+ ...
@@ -0,0 +1,48 @@
1
+ """
2
+ intentumdiff.sources.file_source
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Compare two files on the local filesystem.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ from pathlib import Path
12
+
13
+ from intentumdiff.sources.base import Source
14
+
15
+
16
+ class FileSource(Source):
17
+ """
18
+ Compare two local files.
19
+
20
+ Parameters
21
+ ----------
22
+ old_path:
23
+ Path to the old (before) version of the file.
24
+ new_path:
25
+ Path to the new (after) version of the file.
26
+ language_hint:
27
+ Optional language override.
28
+ filename:
29
+ Display filename used in diff output. Defaults to the basename of
30
+ ``new_path``.
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ old_path: str | os.PathLike[str],
36
+ new_path: str | os.PathLike[str],
37
+ language_hint: str | None = None,
38
+ filename: str | None = None,
39
+ ) -> None:
40
+ self._old_path = Path(old_path)
41
+ self._new_path = Path(new_path)
42
+ self._language_hint = language_hint
43
+ self._filename = filename or self._new_path.name
44
+
45
+ def get_content(self) -> tuple[str, str, str, str | None]:
46
+ old_content = self._old_path.read_text(encoding="utf-8", errors="replace")
47
+ new_content = self._new_path.read_text(encoding="utf-8", errors="replace")
48
+ return old_content, new_content, self._filename, self._language_hint