attocode 0.1.5 → 0.1.7
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.
- package/CHANGELOG.md +27 -2
- package/README.md +47 -0
- package/dist/src/adapters.d.ts +21 -1
- package/dist/src/adapters.d.ts.map +1 -1
- package/dist/src/adapters.js +29 -1
- package/dist/src/adapters.js.map +1 -1
- package/dist/src/agent.d.ts +69 -3
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +692 -42
- package/dist/src/agent.js.map +1 -1
- package/dist/src/commands/agents-commands.d.ts.map +1 -1
- package/dist/src/commands/agents-commands.js +18 -4
- package/dist/src/commands/agents-commands.js.map +1 -1
- package/dist/src/commands/handler.d.ts.map +1 -1
- package/dist/src/commands/handler.js +120 -5
- package/dist/src/commands/handler.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -6
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +4 -7
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/defaults.d.ts +31 -1
- package/dist/src/defaults.d.ts.map +1 -1
- package/dist/src/defaults.js +52 -2
- package/dist/src/defaults.js.map +1 -1
- package/dist/src/integrations/agent-registry.d.ts.map +1 -1
- package/dist/src/integrations/agent-registry.js +12 -5
- package/dist/src/integrations/agent-registry.js.map +1 -1
- package/dist/src/integrations/codebase-context.d.ts +163 -0
- package/dist/src/integrations/codebase-context.d.ts.map +1 -1
- package/dist/src/integrations/codebase-context.js +462 -0
- package/dist/src/integrations/codebase-context.js.map +1 -1
- package/dist/src/integrations/economics.js +2 -2
- package/dist/src/integrations/economics.js.map +1 -1
- package/dist/src/integrations/file-change-tracker.d.ts +1 -0
- package/dist/src/integrations/file-change-tracker.d.ts.map +1 -1
- package/dist/src/integrations/file-change-tracker.js +30 -12
- package/dist/src/integrations/file-change-tracker.js.map +1 -1
- package/dist/src/integrations/graph-visualization.d.ts +72 -0
- package/dist/src/integrations/graph-visualization.d.ts.map +1 -0
- package/dist/src/integrations/graph-visualization.js +383 -0
- package/dist/src/integrations/graph-visualization.js.map +1 -0
- package/dist/src/integrations/index.d.ts +3 -1
- package/dist/src/integrations/index.d.ts.map +1 -1
- package/dist/src/integrations/index.js +4 -0
- package/dist/src/integrations/index.js.map +1 -1
- package/dist/src/integrations/memory.d.ts +8 -0
- package/dist/src/integrations/memory.d.ts.map +1 -1
- package/dist/src/integrations/memory.js +23 -0
- package/dist/src/integrations/memory.js.map +1 -1
- package/dist/src/integrations/pending-plan.d.ts +26 -1
- package/dist/src/integrations/pending-plan.d.ts.map +1 -1
- package/dist/src/integrations/pending-plan.js +131 -3
- package/dist/src/integrations/pending-plan.js.map +1 -1
- package/dist/src/integrations/planning.d.ts +19 -0
- package/dist/src/integrations/planning.d.ts.map +1 -1
- package/dist/src/integrations/planning.js +78 -4
- package/dist/src/integrations/planning.js.map +1 -1
- package/dist/src/integrations/safety.d.ts +4 -0
- package/dist/src/integrations/safety.d.ts.map +1 -1
- package/dist/src/integrations/safety.js +46 -7
- package/dist/src/integrations/safety.js.map +1 -1
- package/dist/src/integrations/sqlite-store.d.ts.map +1 -1
- package/dist/src/integrations/sqlite-store.js +24 -2
- package/dist/src/integrations/sqlite-store.js.map +1 -1
- package/dist/src/integrations/task-manager.d.ts +132 -0
- package/dist/src/integrations/task-manager.d.ts.map +1 -0
- package/dist/src/integrations/task-manager.js +309 -0
- package/dist/src/integrations/task-manager.js.map +1 -0
- package/dist/src/modes/tui.d.ts.map +1 -1
- package/dist/src/modes/tui.js +9 -0
- package/dist/src/modes/tui.js.map +1 -1
- package/dist/src/modes.d.ts +30 -0
- package/dist/src/modes.d.ts.map +1 -1
- package/dist/src/modes.js +130 -2
- package/dist/src/modes.js.map +1 -1
- package/dist/src/providers/adapters/openai.d.ts +46 -2
- package/dist/src/providers/adapters/openai.d.ts.map +1 -1
- package/dist/src/providers/adapters/openai.js +221 -21
- package/dist/src/providers/adapters/openai.js.map +1 -1
- package/dist/src/providers/llm-resilience.d.ts +8 -0
- package/dist/src/providers/llm-resilience.d.ts.map +1 -1
- package/dist/src/providers/llm-resilience.js +36 -0
- package/dist/src/providers/llm-resilience.js.map +1 -1
- package/dist/src/tools/agent.d.ts +38 -1
- package/dist/src/tools/agent.d.ts.map +1 -1
- package/dist/src/tools/agent.js +152 -2
- package/dist/src/tools/agent.js.map +1 -1
- package/dist/src/tools/file.d.ts.map +1 -1
- package/dist/src/tools/file.js +17 -3
- package/dist/src/tools/file.js.map +1 -1
- package/dist/src/tools/tasks.d.ts +32 -0
- package/dist/src/tools/tasks.d.ts.map +1 -0
- package/dist/src/tools/tasks.js +334 -0
- package/dist/src/tools/tasks.js.map +1 -0
- package/dist/src/tracing/trace-collector.d.ts +81 -0
- package/dist/src/tracing/trace-collector.d.ts.map +1 -1
- package/dist/src/tracing/trace-collector.js +216 -4
- package/dist/src/tracing/trace-collector.js.map +1 -1
- package/dist/src/tracing/types.d.ts +8 -0
- package/dist/src/tracing/types.d.ts.map +1 -1
- package/dist/src/tracing/types.js.map +1 -1
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +503 -90
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/components/ActiveAgentsPanel.d.ts +45 -0
- package/dist/src/tui/components/ActiveAgentsPanel.d.ts.map +1 -0
- package/dist/src/tui/components/ActiveAgentsPanel.js +121 -0
- package/dist/src/tui/components/ActiveAgentsPanel.js.map +1 -0
- package/dist/src/tui/components/CollapsibleDiffView.d.ts +49 -0
- package/dist/src/tui/components/CollapsibleDiffView.d.ts.map +1 -0
- package/dist/src/tui/components/CollapsibleDiffView.js +302 -0
- package/dist/src/tui/components/CollapsibleDiffView.js.map +1 -0
- package/dist/src/tui/components/DiffView.d.ts +55 -0
- package/dist/src/tui/components/DiffView.d.ts.map +1 -0
- package/dist/src/tui/components/DiffView.js +356 -0
- package/dist/src/tui/components/DiffView.js.map +1 -0
- package/dist/src/tui/components/ErrorBoundary.d.ts +63 -0
- package/dist/src/tui/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/src/tui/components/ErrorBoundary.js +88 -0
- package/dist/src/tui/components/ErrorBoundary.js.map +1 -0
- package/dist/src/tui/components/FileChangeSummary.d.ts +48 -0
- package/dist/src/tui/components/FileChangeSummary.d.ts.map +1 -0
- package/dist/src/tui/components/FileChangeSummary.js +152 -0
- package/dist/src/tui/components/FileChangeSummary.js.map +1 -0
- package/dist/src/tui/components/SideBySideDiff.d.ts +62 -0
- package/dist/src/tui/components/SideBySideDiff.d.ts.map +1 -0
- package/dist/src/tui/components/SideBySideDiff.js +320 -0
- package/dist/src/tui/components/SideBySideDiff.js.map +1 -0
- package/dist/src/tui/components/SyntaxText.d.ts +47 -0
- package/dist/src/tui/components/SyntaxText.d.ts.map +1 -0
- package/dist/src/tui/components/SyntaxText.js +43 -0
- package/dist/src/tui/components/SyntaxText.js.map +1 -0
- package/dist/src/tui/components/TasksPanel.d.ts +25 -0
- package/dist/src/tui/components/TasksPanel.d.ts.map +1 -0
- package/dist/src/tui/components/TasksPanel.js +101 -0
- package/dist/src/tui/components/TasksPanel.js.map +1 -0
- package/dist/src/tui/components/index.d.ts +8 -0
- package/dist/src/tui/components/index.d.ts.map +1 -1
- package/dist/src/tui/components/index.js +13 -0
- package/dist/src/tui/components/index.js.map +1 -1
- package/dist/src/tui/hooks/index.d.ts +7 -0
- package/dist/src/tui/hooks/index.d.ts.map +1 -0
- package/dist/src/tui/hooks/index.js +7 -0
- package/dist/src/tui/hooks/index.js.map +1 -0
- package/dist/src/tui/hooks/useMessagePruning.d.ts +114 -0
- package/dist/src/tui/hooks/useMessagePruning.d.ts.map +1 -0
- package/dist/src/tui/hooks/useMessagePruning.js +127 -0
- package/dist/src/tui/hooks/useMessagePruning.js.map +1 -0
- package/dist/src/tui/index.d.ts +3 -0
- package/dist/src/tui/index.d.ts.map +1 -1
- package/dist/src/tui/index.js +9 -0
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/syntax/index.d.ts +12 -0
- package/dist/src/tui/syntax/index.d.ts.map +1 -0
- package/dist/src/tui/syntax/index.js +14 -0
- package/dist/src/tui/syntax/index.js.map +1 -0
- package/dist/src/tui/syntax/languages/bash.d.ts +8 -0
- package/dist/src/tui/syntax/languages/bash.d.ts.map +1 -0
- package/dist/src/tui/syntax/languages/bash.js +296 -0
- package/dist/src/tui/syntax/languages/bash.js.map +1 -0
- package/dist/src/tui/syntax/languages/javascript.d.ts +8 -0
- package/dist/src/tui/syntax/languages/javascript.d.ts.map +1 -0
- package/dist/src/tui/syntax/languages/javascript.js +253 -0
- package/dist/src/tui/syntax/languages/javascript.js.map +1 -0
- package/dist/src/tui/syntax/languages/json.d.ts +8 -0
- package/dist/src/tui/syntax/languages/json.d.ts.map +1 -0
- package/dist/src/tui/syntax/languages/json.js +112 -0
- package/dist/src/tui/syntax/languages/json.js.map +1 -0
- package/dist/src/tui/syntax/languages/python.d.ts +8 -0
- package/dist/src/tui/syntax/languages/python.d.ts.map +1 -0
- package/dist/src/tui/syntax/languages/python.js +232 -0
- package/dist/src/tui/syntax/languages/python.js.map +1 -0
- package/dist/src/tui/syntax/lexer.d.ts +51 -0
- package/dist/src/tui/syntax/lexer.d.ts.map +1 -0
- package/dist/src/tui/syntax/lexer.js +131 -0
- package/dist/src/tui/syntax/lexer.js.map +1 -0
- package/dist/src/tui/utils/index.d.ts +7 -0
- package/dist/src/tui/utils/index.d.ts.map +1 -0
- package/dist/src/tui/utils/index.js +7 -0
- package/dist/src/tui/utils/index.js.map +1 -0
- package/dist/src/tui/utils/keyboard.d.ts +123 -0
- package/dist/src/tui/utils/keyboard.d.ts.map +1 -0
- package/dist/src/tui/utils/keyboard.js +185 -0
- package/dist/src/tui/utils/keyboard.js.map +1 -0
- package/dist/src/types.d.ts +73 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* DiffView Component
|
|
4
|
+
*
|
|
5
|
+
* Displays unified diff with color coding for additions/deletions.
|
|
6
|
+
* Supports:
|
|
7
|
+
* - Collapsed summary (+N/-M) or expanded full diff
|
|
8
|
+
* - Line numbers (optional)
|
|
9
|
+
* - Word-level diff highlighting within modified lines
|
|
10
|
+
* - Parsed UnifiedDiff format for structured rendering
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // Simple string diff
|
|
15
|
+
* <DiffView diff={diffString} expanded={true} />
|
|
16
|
+
*
|
|
17
|
+
* // With line numbers
|
|
18
|
+
* <DiffView diff={diffString} expanded={true} showLineNumbers={true} />
|
|
19
|
+
*
|
|
20
|
+
* // With word-level highlighting (shows exactly what changed within lines)
|
|
21
|
+
* <DiffView parsedDiff={parsed} expanded={true} showWordDiff={true} />
|
|
22
|
+
*
|
|
23
|
+
* // Full featured: line numbers + word diff
|
|
24
|
+
* const parsed = parseUnifiedDiff(diffString);
|
|
25
|
+
* <DiffView parsedDiff={parsed[0]} expanded={true} showLineNumbers={true} showWordDiff={true} />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { memo, useMemo } from 'react';
|
|
29
|
+
import { Box, Text } from 'ink';
|
|
30
|
+
import { diffWords } from 'diff';
|
|
31
|
+
import { tokenize, detectLanguage, getTokenColor } from '../syntax/index.js';
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// COLORS
|
|
34
|
+
// =============================================================================
|
|
35
|
+
const COLORS = {
|
|
36
|
+
addition: '#98FB98', // Green for additions
|
|
37
|
+
deletion: '#FF6B6B', // Red for deletions
|
|
38
|
+
context: '#666666', // Gray for context
|
|
39
|
+
hunkHeader: '#87CEEB', // Cyan for @@ lines
|
|
40
|
+
fileHeader: '#DDA0DD', // Purple for --- +++ lines
|
|
41
|
+
lineNumber: '#555555', // Dim for line numbers
|
|
42
|
+
};
|
|
43
|
+
// =============================================================================
|
|
44
|
+
// HELPER FUNCTIONS
|
|
45
|
+
// =============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Parse diff statistics from a unified diff string.
|
|
48
|
+
*/
|
|
49
|
+
function parseDiffStats(diff) {
|
|
50
|
+
const lines = diff.split('\n');
|
|
51
|
+
let additions = 0;
|
|
52
|
+
let deletions = 0;
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
55
|
+
additions++;
|
|
56
|
+
}
|
|
57
|
+
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
58
|
+
deletions++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { additions, deletions };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get stats from a parsed diff.
|
|
65
|
+
*/
|
|
66
|
+
function getParsedDiffStats(diff) {
|
|
67
|
+
let additions = 0;
|
|
68
|
+
let deletions = 0;
|
|
69
|
+
for (const hunk of diff.hunks) {
|
|
70
|
+
for (const line of hunk.lines) {
|
|
71
|
+
if (line.type === 'add')
|
|
72
|
+
additions++;
|
|
73
|
+
else if (line.type === 'remove')
|
|
74
|
+
deletions++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { additions, deletions };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get color for a diff line based on its prefix.
|
|
81
|
+
*/
|
|
82
|
+
function getDiffLineColor(line) {
|
|
83
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
84
|
+
return COLORS.addition;
|
|
85
|
+
}
|
|
86
|
+
if (line.startsWith('-') && !line.startsWith('---')) {
|
|
87
|
+
return COLORS.deletion;
|
|
88
|
+
}
|
|
89
|
+
if (line.startsWith('@@')) {
|
|
90
|
+
return COLORS.hunkHeader;
|
|
91
|
+
}
|
|
92
|
+
if (line.startsWith('---') || line.startsWith('+++')) {
|
|
93
|
+
return COLORS.fileHeader;
|
|
94
|
+
}
|
|
95
|
+
return COLORS.context;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get color for a DiffLine type.
|
|
99
|
+
*/
|
|
100
|
+
function getLineTypeColor(type) {
|
|
101
|
+
switch (type) {
|
|
102
|
+
case 'add': return COLORS.addition;
|
|
103
|
+
case 'remove': return COLORS.deletion;
|
|
104
|
+
default: return COLORS.context;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get prefix character for a DiffLine type.
|
|
109
|
+
*/
|
|
110
|
+
function getLinePrefix(type) {
|
|
111
|
+
switch (type) {
|
|
112
|
+
case 'add': return '+';
|
|
113
|
+
case 'remove': return '-';
|
|
114
|
+
default: return ' ';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Pair up adjacent removed and added lines for word-level diffing.
|
|
119
|
+
* Returns Map<lineIndex, pairedLineContent> for lines that should show word diffs.
|
|
120
|
+
*/
|
|
121
|
+
function findLinePairs(lines) {
|
|
122
|
+
const pairs = new Map();
|
|
123
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
124
|
+
const current = lines[i];
|
|
125
|
+
const next = lines[i + 1];
|
|
126
|
+
// If we have a remove followed by an add, they're likely a modification
|
|
127
|
+
if (current.type === 'remove' && next.type === 'add') {
|
|
128
|
+
pairs.set(i, next.content); // removed line paired with added content
|
|
129
|
+
pairs.set(i + 1, current.content); // added line paired with removed content
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return pairs;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Render word-level diff between old and new content.
|
|
136
|
+
*/
|
|
137
|
+
function renderWordDiff(oldContent, newContent, lineType) {
|
|
138
|
+
const changes = diffWords(oldContent, newContent);
|
|
139
|
+
return changes.map((change, i) => {
|
|
140
|
+
// For a removed line, highlight what was removed
|
|
141
|
+
// For an added line, highlight what was added
|
|
142
|
+
if (lineType === 'remove') {
|
|
143
|
+
if (change.removed) {
|
|
144
|
+
// This part was removed - highlight it strongly
|
|
145
|
+
return (_jsx(Text, { color: COLORS.deletion, bold: true, inverse: true, children: change.value }, i));
|
|
146
|
+
}
|
|
147
|
+
else if (change.added) {
|
|
148
|
+
// This part was added in the new version - don't show on removed line
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
// Unchanged part
|
|
152
|
+
return _jsx(Text, { color: COLORS.deletion, children: change.value }, i);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// lineType === 'add'
|
|
156
|
+
if (change.added) {
|
|
157
|
+
// This part was added - highlight it strongly
|
|
158
|
+
return (_jsx(Text, { color: COLORS.addition, bold: true, inverse: true, children: change.value }, i));
|
|
159
|
+
}
|
|
160
|
+
else if (change.removed) {
|
|
161
|
+
// This part was in the old version - don't show on added line
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
// Unchanged part
|
|
165
|
+
return _jsx(Text, { color: COLORS.addition, children: change.value }, i);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Render content with syntax highlighting.
|
|
171
|
+
*/
|
|
172
|
+
function renderSyntaxHighlight(content, theme, language, baseColor) {
|
|
173
|
+
if (!language) {
|
|
174
|
+
return _jsx(Text, { color: baseColor, children: content });
|
|
175
|
+
}
|
|
176
|
+
const tokens = tokenize(content, language);
|
|
177
|
+
return tokens.map((token, i) => (_jsx(Text, { color: getTokenColor(token.type, theme), children: token.content }, i)));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Render word-level diff with syntax highlighting.
|
|
181
|
+
* Combines word-diff highlighting with syntax colors.
|
|
182
|
+
*/
|
|
183
|
+
function renderWordDiffWithSyntax(oldContent, newContent, lineType, theme, language) {
|
|
184
|
+
const changes = diffWords(oldContent, newContent);
|
|
185
|
+
const elements = [];
|
|
186
|
+
let keyIndex = 0;
|
|
187
|
+
for (const change of changes) {
|
|
188
|
+
if (lineType === 'remove') {
|
|
189
|
+
if (change.removed) {
|
|
190
|
+
// Removed content - use inverse highlighting
|
|
191
|
+
elements.push(_jsx(Text, { color: COLORS.deletion, bold: true, inverse: true, children: change.value }, keyIndex++));
|
|
192
|
+
}
|
|
193
|
+
else if (change.added) {
|
|
194
|
+
// Skip added content on removed line
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Unchanged - apply syntax highlighting
|
|
199
|
+
if (language) {
|
|
200
|
+
const tokens = tokenize(change.value, language);
|
|
201
|
+
for (const token of tokens) {
|
|
202
|
+
elements.push(_jsx(Text, { color: getTokenColor(token.type, theme), children: token.content }, keyIndex++));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
elements.push(_jsx(Text, { color: COLORS.deletion, children: change.value }, keyIndex++));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// lineType === 'add'
|
|
212
|
+
if (change.added) {
|
|
213
|
+
// Added content - use inverse highlighting
|
|
214
|
+
elements.push(_jsx(Text, { color: COLORS.addition, bold: true, inverse: true, children: change.value }, keyIndex++));
|
|
215
|
+
}
|
|
216
|
+
else if (change.removed) {
|
|
217
|
+
// Skip removed content on added line
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// Unchanged - apply syntax highlighting
|
|
222
|
+
if (language) {
|
|
223
|
+
const tokens = tokenize(change.value, language);
|
|
224
|
+
for (const token of tokens) {
|
|
225
|
+
elements.push(_jsx(Text, { color: getTokenColor(token.type, theme), children: token.content }, keyIndex++));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
elements.push(_jsx(Text, { color: COLORS.addition, children: change.value }, keyIndex++));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return _jsx(_Fragment, { children: elements });
|
|
235
|
+
}
|
|
236
|
+
// =============================================================================
|
|
237
|
+
// SUB-COMPONENTS
|
|
238
|
+
// =============================================================================
|
|
239
|
+
/**
|
|
240
|
+
* Render diff summary (collapsed view).
|
|
241
|
+
*/
|
|
242
|
+
const DiffSummary = memo(function DiffSummary({ additions, deletions, }) {
|
|
243
|
+
return (_jsxs(Text, { children: [_jsxs(Text, { color: COLORS.addition, children: ["+", additions] }), _jsx(Text, { color: COLORS.context, children: "/" }), _jsxs(Text, { color: COLORS.deletion, children: ["-", deletions] })] }));
|
|
244
|
+
});
|
|
245
|
+
/**
|
|
246
|
+
* Render a single diff line with optional line numbers and word-level highlighting.
|
|
247
|
+
*/
|
|
248
|
+
const DiffLineView = memo(function DiffLineView({ line, showLineNumbers, lineNumberWidth = 4, pairedContent, showWordDiff, syntaxHighlight, theme, language, }) {
|
|
249
|
+
const color = getLineTypeColor(line.type);
|
|
250
|
+
const prefix = getLinePrefix(line.type);
|
|
251
|
+
// Determine if we should render word-level diff
|
|
252
|
+
const useWordDiff = showWordDiff && pairedContent !== undefined &&
|
|
253
|
+
(line.type === 'add' || line.type === 'remove');
|
|
254
|
+
// Determine if we should use syntax highlighting
|
|
255
|
+
const useSyntax = syntaxHighlight && theme && language;
|
|
256
|
+
// Render the content
|
|
257
|
+
let contentNode;
|
|
258
|
+
if (useWordDiff && useSyntax) {
|
|
259
|
+
// Word diff with syntax highlighting
|
|
260
|
+
contentNode = (_jsxs(Text, { children: [_jsx(Text, { color: color, children: prefix }), renderWordDiffWithSyntax(line.type === 'remove' ? line.content : pairedContent, line.type === 'add' ? line.content : pairedContent, line.type, theme, language)] }));
|
|
261
|
+
}
|
|
262
|
+
else if (useWordDiff) {
|
|
263
|
+
// Word diff without syntax
|
|
264
|
+
contentNode = (_jsxs(Text, { children: [_jsx(Text, { color: color, children: prefix }), renderWordDiff(line.type === 'remove' ? line.content : pairedContent, line.type === 'add' ? line.content : pairedContent, line.type)] }));
|
|
265
|
+
}
|
|
266
|
+
else if (useSyntax) {
|
|
267
|
+
// Syntax highlighting without word diff
|
|
268
|
+
contentNode = (_jsxs(Text, { children: [_jsx(Text, { color: color, children: prefix }), renderSyntaxHighlight(line.content, theme, language, color)] }));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
// Plain text
|
|
272
|
+
contentNode = _jsxs(Text, { color: color, children: [prefix, line.content] });
|
|
273
|
+
}
|
|
274
|
+
if (showLineNumbers) {
|
|
275
|
+
const oldNum = line.oldLineNumber?.toString().padStart(lineNumberWidth) ?? ' '.repeat(lineNumberWidth);
|
|
276
|
+
const newNum = line.newLineNumber?.toString().padStart(lineNumberWidth) ?? ' '.repeat(lineNumberWidth);
|
|
277
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: COLORS.lineNumber, dimColor: true, children: oldNum }), _jsx(Text, { children: " " }), _jsx(Text, { color: COLORS.lineNumber, dimColor: true, children: newNum }), _jsx(Text, { children: " " }), contentNode] }));
|
|
278
|
+
}
|
|
279
|
+
return contentNode;
|
|
280
|
+
});
|
|
281
|
+
/**
|
|
282
|
+
* Render a hunk header (@@...@@).
|
|
283
|
+
*/
|
|
284
|
+
const HunkHeaderView = memo(function HunkHeaderView({ hunk, showLineNumbers, lineNumberWidth = 4, }) {
|
|
285
|
+
const header = `@@ -${hunk.oldStart},${hunk.oldCount} +${hunk.newStart},${hunk.newCount} @@`;
|
|
286
|
+
const gutterWidth = showLineNumbers ? (lineNumberWidth * 2 + 2) : 0;
|
|
287
|
+
return (_jsxs(Box, { children: [showLineNumbers && _jsx(Text, { color: COLORS.lineNumber, children: ' '.repeat(gutterWidth) }), _jsx(Text, { color: COLORS.hunkHeader, children: header })] }));
|
|
288
|
+
});
|
|
289
|
+
/**
|
|
290
|
+
* Render a single hunk.
|
|
291
|
+
*/
|
|
292
|
+
const HunkView = memo(function HunkView({ hunk, showLineNumbers, lineNumberWidth, maxLines, showWordDiff, syntaxHighlight, theme, language, }) {
|
|
293
|
+
const linesToShow = maxLines ? hunk.lines.slice(0, maxLines) : hunk.lines;
|
|
294
|
+
const hasMore = maxLines && hunk.lines.length > maxLines;
|
|
295
|
+
// Pre-compute line pairs for word-level diffing
|
|
296
|
+
const linePairs = useMemo(() => {
|
|
297
|
+
if (!showWordDiff)
|
|
298
|
+
return new Map();
|
|
299
|
+
return findLinePairs(linesToShow);
|
|
300
|
+
}, [showWordDiff, linesToShow]);
|
|
301
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(HunkHeaderView, { hunk: hunk, showLineNumbers: showLineNumbers, lineNumberWidth: lineNumberWidth }), linesToShow.map((line, i) => (_jsx(DiffLineView, { line: line, showLineNumbers: showLineNumbers, lineNumberWidth: lineNumberWidth, pairedContent: linePairs.get(i), showWordDiff: showWordDiff, syntaxHighlight: syntaxHighlight, theme: theme, language: language }, i))), hasMore && (_jsxs(Text, { color: COLORS.context, dimColor: true, children: ["... (", hunk.lines.length - (maxLines ?? 0), " more lines in hunk)"] }))] }));
|
|
302
|
+
});
|
|
303
|
+
// =============================================================================
|
|
304
|
+
// MAIN COMPONENT
|
|
305
|
+
// =============================================================================
|
|
306
|
+
export const DiffView = memo(function DiffView({ diff, parsedDiff, expanded, maxLines = 50, showLineNumbers = false, lineNumberWidth = 4, showWordDiff = false, syntaxHighlight = false, theme, filePath, }) {
|
|
307
|
+
// Use parsed diff if provided, otherwise fall back to string diff
|
|
308
|
+
const hasParsedDiff = parsedDiff !== undefined;
|
|
309
|
+
const hasStringDiff = diff !== undefined && diff.trim().length > 0;
|
|
310
|
+
// Detect language for syntax highlighting
|
|
311
|
+
const detectedLanguage = useMemo(() => {
|
|
312
|
+
if (!syntaxHighlight)
|
|
313
|
+
return null;
|
|
314
|
+
// Try to detect from filePath prop first
|
|
315
|
+
if (filePath) {
|
|
316
|
+
return detectLanguage(filePath);
|
|
317
|
+
}
|
|
318
|
+
// Fall back to parsed diff paths
|
|
319
|
+
if (hasParsedDiff) {
|
|
320
|
+
const path = parsedDiff.newPath || parsedDiff.oldPath;
|
|
321
|
+
if (path)
|
|
322
|
+
return detectLanguage(path);
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
}, [syntaxHighlight, filePath, hasParsedDiff, parsedDiff]);
|
|
326
|
+
// Compute stats
|
|
327
|
+
const stats = useMemo(() => {
|
|
328
|
+
if (hasParsedDiff) {
|
|
329
|
+
return getParsedDiffStats(parsedDiff);
|
|
330
|
+
}
|
|
331
|
+
if (hasStringDiff) {
|
|
332
|
+
return parseDiffStats(diff);
|
|
333
|
+
}
|
|
334
|
+
return { additions: 0, deletions: 0 };
|
|
335
|
+
}, [diff, parsedDiff, hasParsedDiff, hasStringDiff]);
|
|
336
|
+
// No content
|
|
337
|
+
if (!hasParsedDiff && !hasStringDiff) {
|
|
338
|
+
return _jsx(Text, { color: COLORS.context, dimColor: true, children: "No changes" });
|
|
339
|
+
}
|
|
340
|
+
// Collapsed view: just show +N/-M summary
|
|
341
|
+
if (!expanded) {
|
|
342
|
+
return _jsx(DiffSummary, { additions: stats.additions, deletions: stats.deletions });
|
|
343
|
+
}
|
|
344
|
+
// Expanded view with parsed diff (structured rendering)
|
|
345
|
+
if (hasParsedDiff) {
|
|
346
|
+
const linesPerHunk = maxLines ? Math.ceil(maxLines / Math.max(parsedDiff.hunks.length, 1)) : undefined;
|
|
347
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Box, { gap: 1, children: [_jsxs(Text, { color: COLORS.fileHeader, bold: true, children: [parsedDiff.isNewFile ? 'New: ' : parsedDiff.isDeletedFile ? 'Deleted: ' : 'Modified: ', parsedDiff.newPath] }), _jsx(DiffSummary, { additions: stats.additions, deletions: stats.deletions })] }), _jsx(Box, { flexDirection: "column", marginLeft: 1, marginTop: 1, children: parsedDiff.hunks.map((hunk, i) => (_jsx(HunkView, { hunk: hunk, showLineNumbers: showLineNumbers, lineNumberWidth: lineNumberWidth, maxLines: linesPerHunk, showWordDiff: showWordDiff, syntaxHighlight: syntaxHighlight, theme: theme, language: detectedLanguage }, i))) })] }));
|
|
348
|
+
}
|
|
349
|
+
// Expanded view with string diff (legacy rendering)
|
|
350
|
+
const lines = diff.split('\n');
|
|
351
|
+
const displayLines = lines.slice(0, maxLines);
|
|
352
|
+
const hasMore = lines.length > maxLines;
|
|
353
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Box, { gap: 1, children: [_jsx(Text, { color: COLORS.fileHeader, bold: true, children: "Diff:" }), _jsx(DiffSummary, { additions: stats.additions, deletions: stats.deletions })] }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, marginTop: 1, children: [displayLines.map((line, i) => (_jsx(Text, { color: getDiffLineColor(line), children: line || ' ' }, i))), hasMore && (_jsxs(Text, { color: COLORS.context, dimColor: true, children: ["... (", lines.length - maxLines, " more lines)"] }))] })] }));
|
|
354
|
+
});
|
|
355
|
+
export default DiffView;
|
|
356
|
+
//# sourceMappingURL=DiffView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiffView.js","sourceRoot":"","sources":["../../../../src/tui/components/DiffView.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAc,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,SAAS,EAAe,MAAM,MAAM,CAAC;AAG9C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;AAyBzF,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,MAAM,MAAM,GAAG;IACb,QAAQ,EAAE,SAAS,EAAO,sBAAsB;IAChD,QAAQ,EAAE,SAAS,EAAO,oBAAoB;IAC9C,OAAO,EAAE,SAAS,EAAQ,mBAAmB;IAC7C,UAAU,EAAE,SAAS,EAAK,oBAAoB;IAC9C,UAAU,EAAE,SAAS,EAAK,2BAA2B;IACrD,UAAU,EAAE,SAAS,EAAK,uBAAuB;CAClD,CA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AAE,QAAQ,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;IAExC,OAAO,CACL,MAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,EAAC,SAAS,EAAE,CAAC,aAEtC,MAAC,GAAG,IAAC,GAAG,EAAE,CAAC,aACT,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,4BAAa,EACjD,KAAC,WAAW,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,IACnE,EAGN,MAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,EAAC,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,aACpD,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAC7B,KAAC,IAAI,IAAS,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,YACxC,IAAI,IAAI,GAAG,IADH,CAAC,CAEL,CACR,CAAC,EACD,OAAO,IAAI,CACV,MAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,4BAC7B,KAAK,CAAC,MAAM,GAAG,QAAQ,oBACxB,CACR,IACG,IACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TUI Error Boundary Component
|
|
3
|
+
*
|
|
4
|
+
* Catches JavaScript errors in child components and displays a fallback UI
|
|
5
|
+
* instead of crashing the entire TUI. This is critical for stability in
|
|
6
|
+
* long-running terminal sessions.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <TUIErrorBoundary name="MessageList">
|
|
11
|
+
* <MessageList messages={messages} />
|
|
12
|
+
* </TUIErrorBoundary>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import React, { Component, type ReactNode, type ErrorInfo } from 'react';
|
|
16
|
+
interface ErrorBoundaryProps {
|
|
17
|
+
/** Name for logging/display purposes */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Child components to wrap */
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
/** Custom fallback UI (optional) */
|
|
22
|
+
fallback?: ReactNode;
|
|
23
|
+
/** Callback when an error is caught */
|
|
24
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
25
|
+
/** Whether to show detailed error info (default: false in production) */
|
|
26
|
+
showDetails?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface ErrorBoundaryState {
|
|
29
|
+
hasError: boolean;
|
|
30
|
+
error: Error | null;
|
|
31
|
+
errorInfo: ErrorInfo | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error boundary component for TUI sections.
|
|
35
|
+
*
|
|
36
|
+
* Wraps critical TUI sections to prevent a single component error
|
|
37
|
+
* from crashing the entire interface. Shows a clean fallback UI
|
|
38
|
+
* and logs error details for debugging.
|
|
39
|
+
*/
|
|
40
|
+
export declare class TUIErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
41
|
+
constructor(props: ErrorBoundaryProps);
|
|
42
|
+
static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
|
|
43
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
44
|
+
/**
|
|
45
|
+
* Reset the error boundary state.
|
|
46
|
+
* Can be called programmatically to retry rendering.
|
|
47
|
+
*/
|
|
48
|
+
reset: () => void;
|
|
49
|
+
render(): ReactNode;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Simple error fallback component for minimal display.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ErrorFallback({ message, compact, }: {
|
|
55
|
+
message?: string;
|
|
56
|
+
compact?: boolean;
|
|
57
|
+
}): JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* HOC to wrap a component with error boundary.
|
|
60
|
+
*/
|
|
61
|
+
export declare function withErrorBoundary<P extends object>(WrappedComponent: React.ComponentType<P>, boundaryName: string, options?: Omit<ErrorBoundaryProps, 'name' | 'children'>): React.FC<P>;
|
|
62
|
+
export default TUIErrorBoundary;
|
|
63
|
+
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../../src/tui/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzE,UAAU,kBAAkB;IAC1B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,QAAQ,EAAE,SAAS,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uCAAuC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IACvD,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACzE,KAAK,EAAE,kBAAkB;IASrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI1E,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAW3D;;;OAGG;IACH,KAAK,QAAO,IAAI,CAMd;IAEF,MAAM,IAAI,SAAS;CA0CpB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAC5B,OAA2B,EAC3B,OAAe,GAChB,EAAE;IACD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,GAAG,CAAC,OAAO,CAcd;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,UAAU,CAAC,GACtD,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAUb;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* TUI Error Boundary Component
|
|
4
|
+
*
|
|
5
|
+
* Catches JavaScript errors in child components and displays a fallback UI
|
|
6
|
+
* instead of crashing the entire TUI. This is critical for stability in
|
|
7
|
+
* long-running terminal sessions.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <TUIErrorBoundary name="MessageList">
|
|
12
|
+
* <MessageList messages={messages} />
|
|
13
|
+
* </TUIErrorBoundary>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { Component } from 'react';
|
|
17
|
+
import { Box, Text } from 'ink';
|
|
18
|
+
/**
|
|
19
|
+
* Error boundary component for TUI sections.
|
|
20
|
+
*
|
|
21
|
+
* Wraps critical TUI sections to prevent a single component error
|
|
22
|
+
* from crashing the entire interface. Shows a clean fallback UI
|
|
23
|
+
* and logs error details for debugging.
|
|
24
|
+
*/
|
|
25
|
+
export class TUIErrorBoundary extends Component {
|
|
26
|
+
constructor(props) {
|
|
27
|
+
super(props);
|
|
28
|
+
this.state = {
|
|
29
|
+
hasError: false,
|
|
30
|
+
error: null,
|
|
31
|
+
errorInfo: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
static getDerivedStateFromError(error) {
|
|
35
|
+
return { hasError: true, error };
|
|
36
|
+
}
|
|
37
|
+
componentDidCatch(error, errorInfo) {
|
|
38
|
+
this.setState({ errorInfo });
|
|
39
|
+
// Log error for debugging
|
|
40
|
+
console.error(`[TUIErrorBoundary:${this.props.name}] Component error:`, error);
|
|
41
|
+
console.error(`[TUIErrorBoundary:${this.props.name}] Component stack:`, errorInfo.componentStack);
|
|
42
|
+
// Call optional error handler
|
|
43
|
+
this.props.onError?.(error, errorInfo);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reset the error boundary state.
|
|
47
|
+
* Can be called programmatically to retry rendering.
|
|
48
|
+
*/
|
|
49
|
+
reset = () => {
|
|
50
|
+
this.setState({
|
|
51
|
+
hasError: false,
|
|
52
|
+
error: null,
|
|
53
|
+
errorInfo: null,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
render() {
|
|
57
|
+
const { hasError, error } = this.state;
|
|
58
|
+
const { children, name, fallback, showDetails = false } = this.props;
|
|
59
|
+
if (hasError) {
|
|
60
|
+
// Return custom fallback if provided
|
|
61
|
+
if (fallback) {
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
// Default fallback UI
|
|
65
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "single", borderColor: "#FF6B6B", paddingX: 1, marginY: 1, children: [_jsxs(Box, { gap: 1, children: [_jsx(Text, { color: "#FF6B6B", bold: true, children: "[X]" }), _jsxs(Text, { color: "#FF6B6B", bold: true, children: [name, " encountered an error"] })] }), showDetails && error && (_jsx(Box, { marginTop: 1, flexDirection: "column", children: _jsxs(Text, { color: "#FFD700", dimColor: true, children: [error.name, ": ", error.message.slice(0, 100), error.message.length > 100 ? '...' : ''] }) })), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "#666", dimColor: true, children: "This section has been disabled to prevent TUI crash." }) })] }));
|
|
66
|
+
}
|
|
67
|
+
return children;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Simple error fallback component for minimal display.
|
|
72
|
+
*/
|
|
73
|
+
export function ErrorFallback({ message = 'Component error', compact = false, }) {
|
|
74
|
+
if (compact) {
|
|
75
|
+
return (_jsx(Box, { children: _jsxs(Text, { color: "#FF6B6B", children: ["[!] ", message] }) }));
|
|
76
|
+
}
|
|
77
|
+
return (_jsx(Box, { borderStyle: "round", borderColor: "#FF6B6B", paddingX: 1, children: _jsxs(Text, { color: "#FF6B6B", children: ["[X] ", message] }) }));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* HOC to wrap a component with error boundary.
|
|
81
|
+
*/
|
|
82
|
+
export function withErrorBoundary(WrappedComponent, boundaryName, options) {
|
|
83
|
+
const WithErrorBoundary = (props) => (_jsx(TUIErrorBoundary, { name: boundaryName, ...options, children: _jsx(WrappedComponent, { ...props }) }));
|
|
84
|
+
WithErrorBoundary.displayName = `withErrorBoundary(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
85
|
+
return WithErrorBoundary;
|
|
86
|
+
}
|
|
87
|
+
export default TUIErrorBoundary;
|
|
88
|
+
//# sourceMappingURL=ErrorBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../../src/tui/components/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAc,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAqBhC;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAiD;IACrF,YAAY,KAAyB;Q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AAS,qBAAM,OAAO,IAAQ,GACtC,CACP,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAAwC,EACxC,YAAoB,EACpB,OAAuD;IAEvD,MAAM,iBAAiB,GAAgB,CAAC,KAAQ,EAAE,EAAE,CAAC,CACnD,KAAC,gBAAgB,IAAC,IAAI,EAAE,YAAY,KAAM,OAAO,YAC/C,KAAC,gBAAgB,OAAK,KAAK,GAAI,GACd,CACpB,CAAC;IAEF,iBAAiB,CAAC,WAAW,GAAG,qBAAqB,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,GAAG,CAAC;IAE7H,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileChangeSummary Component
|
|
3
|
+
*
|
|
4
|
+
* Displays a summary of all files changed during a session.
|
|
5
|
+
* Shows total additions/deletions and per-file breakdown.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Collapsed mode: Just totals
|
|
9
|
+
* - Expanded mode: Full file list with stats
|
|
10
|
+
* - Visual indicators for new vs modified files
|
|
11
|
+
* - Sortable by various criteria
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <FileChangeSummary
|
|
16
|
+
* changes={[
|
|
17
|
+
* { path: 'src/index.ts', additions: 10, deletions: 5, type: 'modify' },
|
|
18
|
+
* { path: 'src/new.ts', additions: 50, deletions: 0, type: 'create' },
|
|
19
|
+
* ]}
|
|
20
|
+
* expanded={true}
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface FileChange {
|
|
25
|
+
/** File path (relative to project root) */
|
|
26
|
+
path: string;
|
|
27
|
+
/** Number of lines added */
|
|
28
|
+
additions: number;
|
|
29
|
+
/** Number of lines deleted */
|
|
30
|
+
deletions: number;
|
|
31
|
+
/** Type of change */
|
|
32
|
+
type: 'create' | 'modify' | 'delete' | 'rename';
|
|
33
|
+
/** For renames, the original path */
|
|
34
|
+
oldPath?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface FileChangeSummaryProps {
|
|
37
|
+
/** List of file changes */
|
|
38
|
+
changes: FileChange[];
|
|
39
|
+
/** Whether to show expanded view with per-file details */
|
|
40
|
+
expanded?: boolean;
|
|
41
|
+
/** Sort order for file list */
|
|
42
|
+
sortBy?: 'path' | 'additions' | 'deletions' | 'total';
|
|
43
|
+
/** Maximum files to show in expanded view */
|
|
44
|
+
maxFiles?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const FileChangeSummary: import("react").NamedExoticComponent<FileChangeSummaryProps>;
|
|
47
|
+
export default FileChangeSummary;
|
|
48
|
+
//# sourceMappingURL=FileChangeSummary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileChangeSummary.d.ts","sourceRoot":"","sources":["../../../../src/tui/components/FileChangeSummary.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AASH,MAAM,WAAW,UAAU;IACzB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAChD,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,2BAA2B;IAC3B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC;IACtD,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAoJD,eAAO,MAAM,iBAAiB,8DA6G5B,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|