Add files using upload-large-folder tool
Browse files- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/IDEContextDetailDisplay.test.tsx.snap +24 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ModelStatsDisplay.test.tsx.snap +121 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/SessionSummaryDisplay.test.tsx.snap +30 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ShellConfirmationDialog.test.tsx.snap +21 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/StatsDisplay.test.tsx.snap +264 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ToolStatsDisplay.test.tsx.snap +91 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/CompressionMessage.tsx +49 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx +365 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/DiffRenderer.tsx +358 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/ErrorMessage.tsx +31 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/GeminiMessage.tsx +43 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/GeminiMessageContent.tsx +43 -0
- projects/ui/qwen-code/packages/cli/src/ui/components/messages/InfoMessage.tsx +32 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/markdownUtilities.test.ts +50 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/markdownUtilities.ts +125 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/platformConstants.ts +52 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/terminalSetup.ts +342 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/textUtils.ts +40 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/updateCheck.test.ts +163 -0
- projects/ui/qwen-code/packages/cli/src/ui/utils/updateCheck.ts +100 -0
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/IDEContextDetailDisplay.test.tsx.snap
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`IDEContextDetailDisplay > handles duplicate basenames by showing path hints 1`] = `
|
| 4 |
+
"
|
| 5 |
+
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 6 |
+
โ VS Code Context (ctrl+g to toggle) โ
|
| 7 |
+
โ โ
|
| 8 |
+
โ Open files: โ
|
| 9 |
+
โ - bar.txt (/foo) (active) โ
|
| 10 |
+
โ - bar.txt (/qux) โ
|
| 11 |
+
โ - unique.txt โ
|
| 12 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 13 |
+
`;
|
| 14 |
+
|
| 15 |
+
exports[`IDEContextDetailDisplay > renders a list of open files with active status 1`] = `
|
| 16 |
+
"
|
| 17 |
+
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 18 |
+
โ VS Code Context (ctrl+g to toggle) โ
|
| 19 |
+
โ โ
|
| 20 |
+
โ Open files: โ
|
| 21 |
+
โ - bar.txt (active) โ
|
| 22 |
+
โ - baz.txt โ
|
| 23 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 24 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ModelStatsDisplay.test.tsx.snap
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`<ModelStatsDisplay /> > should display a single model correctly 1`] = `
|
| 4 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 5 |
+
โ โ
|
| 6 |
+
โ Model Stats For Nerds โ
|
| 7 |
+
โ โ
|
| 8 |
+
โ Metric gemini-2.5-pro โ
|
| 9 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 10 |
+
โ API โ
|
| 11 |
+
โ Requests 1 โ
|
| 12 |
+
โ Errors 0 (0.0%) โ
|
| 13 |
+
โ Avg Latency 100ms โ
|
| 14 |
+
โ โ
|
| 15 |
+
โ Tokens โ
|
| 16 |
+
โ Total 30 โ
|
| 17 |
+
โ โณ Prompt 10 โ
|
| 18 |
+
โ โณ Cached 5 (50.0%) โ
|
| 19 |
+
โ โณ Thoughts 2 โ
|
| 20 |
+
โ โณ Tool 1 โ
|
| 21 |
+
โ โณ Output 20 โ
|
| 22 |
+
โ โ
|
| 23 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 24 |
+
`;
|
| 25 |
+
|
| 26 |
+
exports[`<ModelStatsDisplay /> > should display conditional rows if at least one model has data 1`] = `
|
| 27 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 28 |
+
โ โ
|
| 29 |
+
โ Model Stats For Nerds โ
|
| 30 |
+
โ โ
|
| 31 |
+
โ Metric gemini-2.5-pro gemini-2.5-flash โ
|
| 32 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 33 |
+
โ API โ
|
| 34 |
+
โ Requests 1 1 โ
|
| 35 |
+
โ Errors 0 (0.0%) 0 (0.0%) โ
|
| 36 |
+
โ Avg Latency 100ms 50ms โ
|
| 37 |
+
โ โ
|
| 38 |
+
โ Tokens โ
|
| 39 |
+
โ Total 30 15 โ
|
| 40 |
+
โ โณ Prompt 10 5 โ
|
| 41 |
+
โ โณ Cached 5 (50.0%) 0 (0.0%) โ
|
| 42 |
+
โ โณ Thoughts 2 0 โ
|
| 43 |
+
โ โณ Tool 0 3 โ
|
| 44 |
+
โ โณ Output 20 10 โ
|
| 45 |
+
โ โ
|
| 46 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 47 |
+
`;
|
| 48 |
+
|
| 49 |
+
exports[`<ModelStatsDisplay /> > should display stats for multiple models correctly 1`] = `
|
| 50 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 51 |
+
โ โ
|
| 52 |
+
โ Model Stats For Nerds โ
|
| 53 |
+
โ โ
|
| 54 |
+
โ Metric gemini-2.5-pro gemini-2.5-flash โ
|
| 55 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 56 |
+
โ API โ
|
| 57 |
+
โ Requests 10 20 โ
|
| 58 |
+
โ Errors 1 (10.0%) 2 (10.0%) โ
|
| 59 |
+
โ Avg Latency 100ms 25ms โ
|
| 60 |
+
โ โ
|
| 61 |
+
โ Tokens โ
|
| 62 |
+
โ Total 300 600 โ
|
| 63 |
+
โ โณ Prompt 100 200 โ
|
| 64 |
+
โ โณ Cached 50 (50.0%) 100 (50.0%) โ
|
| 65 |
+
โ โณ Thoughts 10 20 โ
|
| 66 |
+
โ โณ Tool 5 10 โ
|
| 67 |
+
โ โณ Output 200 400 โ
|
| 68 |
+
โ โ
|
| 69 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 70 |
+
`;
|
| 71 |
+
|
| 72 |
+
exports[`<ModelStatsDisplay /> > should handle large values without wrapping or overlapping 1`] = `
|
| 73 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 74 |
+
โ โ
|
| 75 |
+
โ Model Stats For Nerds โ
|
| 76 |
+
โ โ
|
| 77 |
+
โ Metric gemini-2.5-pro โ
|
| 78 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 79 |
+
โ API โ
|
| 80 |
+
โ Requests 999,999,999 โ
|
| 81 |
+
โ Errors 123,456,789 (12.3%) โ
|
| 82 |
+
โ Avg Latency 0ms โ
|
| 83 |
+
โ โ
|
| 84 |
+
โ Tokens โ
|
| 85 |
+
โ Total 999,999,999 โ
|
| 86 |
+
โ โณ Prompt 987,654,321 โ
|
| 87 |
+
โ โณ Cached 123,456,789 (12.5%) โ
|
| 88 |
+
โ โณ Thoughts 111,111,111 โ
|
| 89 |
+
โ โณ Tool 222,222,222 โ
|
| 90 |
+
โ โณ Output 123,456,789 โ
|
| 91 |
+
โ โ
|
| 92 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 93 |
+
`;
|
| 94 |
+
|
| 95 |
+
exports[`<ModelStatsDisplay /> > should not display conditional rows if no model has data for them 1`] = `
|
| 96 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 97 |
+
โ โ
|
| 98 |
+
โ Model Stats For Nerds โ
|
| 99 |
+
โ โ
|
| 100 |
+
โ Metric gemini-2.5-pro โ
|
| 101 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 102 |
+
โ API โ
|
| 103 |
+
โ Requests 1 โ
|
| 104 |
+
โ Errors 0 (0.0%) โ
|
| 105 |
+
โ Avg Latency 100ms โ
|
| 106 |
+
โ โ
|
| 107 |
+
โ Tokens โ
|
| 108 |
+
โ Total 30 โ
|
| 109 |
+
โ โณ Prompt 10 โ
|
| 110 |
+
โ โณ Output 20 โ
|
| 111 |
+
โ โ
|
| 112 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 113 |
+
`;
|
| 114 |
+
|
| 115 |
+
exports[`<ModelStatsDisplay /> > should render "no API calls" message when there are no active models 1`] = `
|
| 116 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 117 |
+
โ โ
|
| 118 |
+
โ No API calls have been made in this session. โ
|
| 119 |
+
โ โ
|
| 120 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 121 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/SessionSummaryDisplay.test.tsx.snap
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`<SessionSummaryDisplay /> > renders the summary display with a title 1`] = `
|
| 4 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 5 |
+
โ โ
|
| 6 |
+
โ Agent powering down. Goodbye! โ
|
| 7 |
+
โ โ
|
| 8 |
+
โ Interaction Summary โ
|
| 9 |
+
โ Session ID: โ
|
| 10 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 11 |
+
โ Success Rate: 0.0% โ
|
| 12 |
+
โ Code Changes: +42 -15 โ
|
| 13 |
+
โ โ
|
| 14 |
+
โ Performance โ
|
| 15 |
+
โ Wall Time: 1h 23m 45s โ
|
| 16 |
+
โ Agent Active: 50.2s โ
|
| 17 |
+
โ ยป API Time: 50.2s (100.0%) โ
|
| 18 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 19 |
+
โ โ
|
| 20 |
+
โ โ
|
| 21 |
+
โ Model Usage Reqs Input Tokens Output Tokens โ
|
| 22 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 23 |
+
โ gemini-2.5-pro 10 1,000 2,000 โ
|
| 24 |
+
โ โ
|
| 25 |
+
โ Savings Highlight: 500 (50.0%) of input tokens were served from the cache, reducing costs. โ
|
| 26 |
+
โ โ
|
| 27 |
+
โ ยป Tip: For a full token breakdown, run \`/stats model\`. โ
|
| 28 |
+
โ โ
|
| 29 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 30 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ShellConfirmationDialog.test.tsx.snap
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`ShellConfirmationDialog > renders correctly 1`] = `
|
| 4 |
+
" โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 5 |
+
โ โ
|
| 6 |
+
โ Shell Command Execution โ
|
| 7 |
+
โ A custom command wants to run the following shell commands: โ
|
| 8 |
+
โ โ
|
| 9 |
+
โ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ
|
| 10 |
+
โ โ ls -la โ โ
|
| 11 |
+
โ โ echo "hello" โ โ
|
| 12 |
+
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ โ
|
| 13 |
+
โ โ
|
| 14 |
+
โ Do you want to proceed? โ
|
| 15 |
+
โ โ
|
| 16 |
+
โ โ 1. Yes, allow once โ
|
| 17 |
+
โ 2. Yes, allow always for this session โ
|
| 18 |
+
โ 3. No (esc) โ
|
| 19 |
+
โ โ
|
| 20 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 21 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/StatsDisplay.test.tsx.snap
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`<StatsDisplay /> > Code Changes Display > displays Code Changes when line counts are present 1`] = `
|
| 4 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 5 |
+
โ โ
|
| 6 |
+
โ Session Stats โ
|
| 7 |
+
โ โ
|
| 8 |
+
โ Interaction Summary โ
|
| 9 |
+
โ Session ID: test-session-id โ
|
| 10 |
+
โ Tool Calls: 1 ( โ 1 โ 0 ) โ
|
| 11 |
+
โ Success Rate: 100.0% โ
|
| 12 |
+
โ Code Changes: +42 -18 โ
|
| 13 |
+
โ โ
|
| 14 |
+
โ Performance โ
|
| 15 |
+
โ Wall Time: 1s โ
|
| 16 |
+
โ Agent Active: 100ms โ
|
| 17 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 18 |
+
โ ยป Tool Time: 100ms (100.0%) โ
|
| 19 |
+
โ โ
|
| 20 |
+
โ โ
|
| 21 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 22 |
+
`;
|
| 23 |
+
|
| 24 |
+
exports[`<StatsDisplay /> > Code Changes Display > hides Code Changes when no lines are added or removed 1`] = `
|
| 25 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 26 |
+
โ โ
|
| 27 |
+
โ Session Stats โ
|
| 28 |
+
โ โ
|
| 29 |
+
โ Interaction Summary โ
|
| 30 |
+
โ Session ID: test-session-id โ
|
| 31 |
+
โ Tool Calls: 1 ( โ 1 โ 0 ) โ
|
| 32 |
+
โ Success Rate: 100.0% โ
|
| 33 |
+
โ โ
|
| 34 |
+
โ Performance โ
|
| 35 |
+
โ Wall Time: 1s โ
|
| 36 |
+
โ Agent Active: 100ms โ
|
| 37 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 38 |
+
โ ยป Tool Time: 100ms (100.0%) โ
|
| 39 |
+
โ โ
|
| 40 |
+
โ โ
|
| 41 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 42 |
+
`;
|
| 43 |
+
|
| 44 |
+
exports[`<StatsDisplay /> > Conditional Color Tests > renders success rate in green for high values 1`] = `
|
| 45 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 46 |
+
โ โ
|
| 47 |
+
โ Session Stats โ
|
| 48 |
+
โ โ
|
| 49 |
+
โ Interaction Summary โ
|
| 50 |
+
โ Session ID: test-session-id โ
|
| 51 |
+
โ Tool Calls: 10 ( โ 10 โ 0 ) โ
|
| 52 |
+
โ Success Rate: 100.0% โ
|
| 53 |
+
โ โ
|
| 54 |
+
โ Performance โ
|
| 55 |
+
โ Wall Time: 1s โ
|
| 56 |
+
โ Agent Active: 0s โ
|
| 57 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 58 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 59 |
+
โ โ
|
| 60 |
+
โ โ
|
| 61 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 62 |
+
`;
|
| 63 |
+
|
| 64 |
+
exports[`<StatsDisplay /> > Conditional Color Tests > renders success rate in red for low values 1`] = `
|
| 65 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 66 |
+
โ โ
|
| 67 |
+
โ Session Stats โ
|
| 68 |
+
โ โ
|
| 69 |
+
โ Interaction Summary โ
|
| 70 |
+
โ Session ID: test-session-id โ
|
| 71 |
+
โ Tool Calls: 10 ( โ 5 โ 5 ) โ
|
| 72 |
+
โ Success Rate: 50.0% โ
|
| 73 |
+
โ โ
|
| 74 |
+
โ Performance โ
|
| 75 |
+
โ Wall Time: 1s โ
|
| 76 |
+
โ Agent Active: 0s โ
|
| 77 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 78 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 79 |
+
โ โ
|
| 80 |
+
โ โ
|
| 81 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 82 |
+
`;
|
| 83 |
+
|
| 84 |
+
exports[`<StatsDisplay /> > Conditional Color Tests > renders success rate in yellow for medium values 1`] = `
|
| 85 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 86 |
+
โ โ
|
| 87 |
+
โ Session Stats โ
|
| 88 |
+
โ โ
|
| 89 |
+
โ Interaction Summary โ
|
| 90 |
+
โ Session ID: test-session-id โ
|
| 91 |
+
โ Tool Calls: 10 ( โ 9 โ 1 ) โ
|
| 92 |
+
โ Success Rate: 90.0% โ
|
| 93 |
+
โ โ
|
| 94 |
+
โ Performance โ
|
| 95 |
+
โ Wall Time: 1s โ
|
| 96 |
+
โ Agent Active: 0s โ
|
| 97 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 98 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 99 |
+
โ โ
|
| 100 |
+
โ โ
|
| 101 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 102 |
+
`;
|
| 103 |
+
|
| 104 |
+
exports[`<StatsDisplay /> > Conditional Rendering Tests > hides Efficiency section when cache is not used 1`] = `
|
| 105 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 106 |
+
โ โ
|
| 107 |
+
โ Session Stats โ
|
| 108 |
+
โ โ
|
| 109 |
+
โ Interaction Summary โ
|
| 110 |
+
โ Session ID: test-session-id โ
|
| 111 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 112 |
+
โ Success Rate: 0.0% โ
|
| 113 |
+
โ โ
|
| 114 |
+
โ Performance โ
|
| 115 |
+
โ Wall Time: 1s โ
|
| 116 |
+
โ Agent Active: 100ms โ
|
| 117 |
+
โ ยป API Time: 100ms (100.0%) โ
|
| 118 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 119 |
+
โ โ
|
| 120 |
+
โ โ
|
| 121 |
+
โ Model Usage Reqs Input Tokens Output Tokens โ
|
| 122 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 123 |
+
โ gemini-2.5-pro 1 100 100 โ
|
| 124 |
+
โ โ
|
| 125 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 126 |
+
`;
|
| 127 |
+
|
| 128 |
+
exports[`<StatsDisplay /> > Conditional Rendering Tests > hides User Agreement when no decisions are made 1`] = `
|
| 129 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 130 |
+
โ โ
|
| 131 |
+
โ Session Stats โ
|
| 132 |
+
โ โ
|
| 133 |
+
โ Interaction Summary โ
|
| 134 |
+
โ Session ID: test-session-id โ
|
| 135 |
+
โ Tool Calls: 2 ( โ 1 โ 1 ) โ
|
| 136 |
+
โ Success Rate: 50.0% โ
|
| 137 |
+
โ โ
|
| 138 |
+
โ Performance โ
|
| 139 |
+
โ Wall Time: 1s โ
|
| 140 |
+
โ Agent Active: 123ms โ
|
| 141 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 142 |
+
โ ยป Tool Time: 123ms (100.0%) โ
|
| 143 |
+
โ โ
|
| 144 |
+
โ โ
|
| 145 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 146 |
+
`;
|
| 147 |
+
|
| 148 |
+
exports[`<StatsDisplay /> > Title Rendering > renders the custom title when a title prop is provided 1`] = `
|
| 149 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 150 |
+
โ โ
|
| 151 |
+
โ Agent powering down. Goodbye! โ
|
| 152 |
+
โ โ
|
| 153 |
+
โ Interaction Summary โ
|
| 154 |
+
โ Session ID: test-session-id โ
|
| 155 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 156 |
+
โ Success Rate: 0.0% โ
|
| 157 |
+
โ โ
|
| 158 |
+
โ Performance โ
|
| 159 |
+
โ Wall Time: 1s โ
|
| 160 |
+
โ Agent Active: 0s โ
|
| 161 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 162 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 163 |
+
โ โ
|
| 164 |
+
โ โ
|
| 165 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 166 |
+
`;
|
| 167 |
+
|
| 168 |
+
exports[`<StatsDisplay /> > Title Rendering > renders the default title when no title prop is provided 1`] = `
|
| 169 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 170 |
+
โ โ
|
| 171 |
+
โ Session Stats โ
|
| 172 |
+
โ โ
|
| 173 |
+
โ Interaction Summary โ
|
| 174 |
+
โ Session ID: test-session-id โ
|
| 175 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 176 |
+
โ Success Rate: 0.0% โ
|
| 177 |
+
โ โ
|
| 178 |
+
โ Performance โ
|
| 179 |
+
โ Wall Time: 1s โ
|
| 180 |
+
โ Agent Active: 0s โ
|
| 181 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 182 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 183 |
+
โ โ
|
| 184 |
+
โ โ
|
| 185 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 186 |
+
`;
|
| 187 |
+
|
| 188 |
+
exports[`<StatsDisplay /> > renders a table with two models correctly 1`] = `
|
| 189 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 190 |
+
โ โ
|
| 191 |
+
โ Session Stats โ
|
| 192 |
+
โ โ
|
| 193 |
+
โ Interaction Summary โ
|
| 194 |
+
โ Session ID: test-session-id โ
|
| 195 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 196 |
+
โ Success Rate: 0.0% โ
|
| 197 |
+
โ โ
|
| 198 |
+
โ Performance โ
|
| 199 |
+
โ Wall Time: 1s โ
|
| 200 |
+
โ Agent Active: 19.5s โ
|
| 201 |
+
โ ยป API Time: 19.5s (100.0%) โ
|
| 202 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 203 |
+
โ โ
|
| 204 |
+
โ โ
|
| 205 |
+
โ Model Usage Reqs Input Tokens Output Tokens โ
|
| 206 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 207 |
+
โ gemini-2.5-pro 3 1,000 2,000 โ
|
| 208 |
+
โ gemini-2.5-flash 5 25,000 15,000 โ
|
| 209 |
+
โ โ
|
| 210 |
+
โ Savings Highlight: 10,500 (40.4%) of input tokens were served from the cache, reducing costs. โ
|
| 211 |
+
โ โ
|
| 212 |
+
โ ยป Tip: For a full token breakdown, run \`/stats model\`. โ
|
| 213 |
+
โ โ
|
| 214 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 215 |
+
`;
|
| 216 |
+
|
| 217 |
+
exports[`<StatsDisplay /> > renders all sections when all data is present 1`] = `
|
| 218 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 219 |
+
โ โ
|
| 220 |
+
โ Session Stats โ
|
| 221 |
+
โ โ
|
| 222 |
+
โ Interaction Summary โ
|
| 223 |
+
โ Session ID: test-session-id โ
|
| 224 |
+
โ Tool Calls: 2 ( โ 1 โ 1 ) โ
|
| 225 |
+
โ Success Rate: 50.0% โ
|
| 226 |
+
โ User Agreement: 100.0% (1 reviewed) โ
|
| 227 |
+
โ โ
|
| 228 |
+
โ Performance โ
|
| 229 |
+
โ Wall Time: 1s โ
|
| 230 |
+
โ Agent Active: 223ms โ
|
| 231 |
+
โ ยป API Time: 100ms (44.8%) โ
|
| 232 |
+
โ ยป Tool Time: 123ms (55.2%) โ
|
| 233 |
+
โ โ
|
| 234 |
+
โ โ
|
| 235 |
+
โ Model Usage Reqs Input Tokens Output Tokens โ
|
| 236 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 237 |
+
โ gemini-2.5-pro 1 100 100 โ
|
| 238 |
+
โ โ
|
| 239 |
+
โ Savings Highlight: 50 (50.0%) of input tokens were served from the cache, reducing costs. โ
|
| 240 |
+
โ โ
|
| 241 |
+
โ ยป Tip: For a full token breakdown, run \`/stats model\`. โ
|
| 242 |
+
โ โ
|
| 243 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 244 |
+
`;
|
| 245 |
+
|
| 246 |
+
exports[`<StatsDisplay /> > renders only the Performance section in its zero state 1`] = `
|
| 247 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 248 |
+
โ โ
|
| 249 |
+
โ Session Stats โ
|
| 250 |
+
โ โ
|
| 251 |
+
โ Interaction Summary โ
|
| 252 |
+
โ Session ID: test-session-id โ
|
| 253 |
+
โ Tool Calls: 0 ( โ 0 โ 0 ) โ
|
| 254 |
+
โ Success Rate: 0.0% โ
|
| 255 |
+
โ โ
|
| 256 |
+
โ Performance โ
|
| 257 |
+
โ Wall Time: 1s โ
|
| 258 |
+
โ Agent Active: 0s โ
|
| 259 |
+
โ ยป API Time: 0s (0.0%) โ
|
| 260 |
+
โ ยป Tool Time: 0s (0.0%) โ
|
| 261 |
+
โ โ
|
| 262 |
+
โ โ
|
| 263 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 264 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/__snapshots__/ToolStatsDisplay.test.tsx.snap
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
| 2 |
+
|
| 3 |
+
exports[`<ToolStatsDisplay /> > should display stats for a single tool correctly 1`] = `
|
| 4 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 5 |
+
โ โ
|
| 6 |
+
โ Tool Stats For Nerds โ
|
| 7 |
+
โ โ
|
| 8 |
+
โ Tool Name Calls Success Rate Avg Duration โ
|
| 9 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 10 |
+
โ test-tool 1 100.0% 100ms โ
|
| 11 |
+
โ โ
|
| 12 |
+
โ User Decision Summary โ
|
| 13 |
+
โ Total Reviewed Suggestions: 1 โ
|
| 14 |
+
โ ยป Accepted: 1 โ
|
| 15 |
+
โ ยป Rejected: 0 โ
|
| 16 |
+
โ ยป Modified: 0 โ
|
| 17 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 18 |
+
โ Overall Agreement Rate: 100.0% โ
|
| 19 |
+
โ โ
|
| 20 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 21 |
+
`;
|
| 22 |
+
|
| 23 |
+
exports[`<ToolStatsDisplay /> > should display stats for multiple tools correctly 1`] = `
|
| 24 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 25 |
+
โ โ
|
| 26 |
+
โ Tool Stats For Nerds โ
|
| 27 |
+
โ โ
|
| 28 |
+
โ Tool Name Calls Success Rate Avg Duration โ
|
| 29 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 30 |
+
โ tool-a 2 50.0% 100ms โ
|
| 31 |
+
โ tool-b 1 100.0% 100ms โ
|
| 32 |
+
โ โ
|
| 33 |
+
โ User Decision Summary โ
|
| 34 |
+
โ Total Reviewed Suggestions: 3 โ
|
| 35 |
+
โ ยป Accepted: 1 โ
|
| 36 |
+
โ ยป Rejected: 1 โ
|
| 37 |
+
โ ยป Modified: 1 โ
|
| 38 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 39 |
+
โ Overall Agreement Rate: 33.3% โ
|
| 40 |
+
โ โ
|
| 41 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 42 |
+
`;
|
| 43 |
+
|
| 44 |
+
exports[`<ToolStatsDisplay /> > should handle large values without wrapping or overlapping 1`] = `
|
| 45 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 46 |
+
โ โ
|
| 47 |
+
โ Tool Stats For Nerds โ
|
| 48 |
+
โ โ
|
| 49 |
+
โ Tool Name Calls Success Rate Avg Duration โ
|
| 50 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 51 |
+
โ long-named-tool-for-testi99999999 88.9% 1ms โ
|
| 52 |
+
โ ng-wrapping-and-such 9 โ
|
| 53 |
+
โ โ
|
| 54 |
+
โ User Decision Summary โ
|
| 55 |
+
โ Total Reviewed Suggestions: 222234566 โ
|
| 56 |
+
โ ยป Accepted: 123456789 โ
|
| 57 |
+
โ ยป Rejected: 98765432 โ
|
| 58 |
+
โ ยป Modified: 12345 โ
|
| 59 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 60 |
+
โ Overall Agreement Rate: 55.6% โ
|
| 61 |
+
โ โ
|
| 62 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 63 |
+
`;
|
| 64 |
+
|
| 65 |
+
exports[`<ToolStatsDisplay /> > should handle zero decisions gracefully 1`] = `
|
| 66 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 67 |
+
โ โ
|
| 68 |
+
โ Tool Stats For Nerds โ
|
| 69 |
+
โ โ
|
| 70 |
+
โ Tool Name Calls Success Rate Avg Duration โ
|
| 71 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 72 |
+
โ test-tool 1 100.0% 100ms โ
|
| 73 |
+
โ โ
|
| 74 |
+
โ User Decision Summary โ
|
| 75 |
+
โ Total Reviewed Suggestions: 0 โ
|
| 76 |
+
โ ยป Accepted: 0 โ
|
| 77 |
+
โ ยป Rejected: 0 โ
|
| 78 |
+
โ ยป Modified: 0 โ
|
| 79 |
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
| 80 |
+
โ Overall Agreement Rate: -- โ
|
| 81 |
+
โ โ
|
| 82 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 83 |
+
`;
|
| 84 |
+
|
| 85 |
+
exports[`<ToolStatsDisplay /> > should render "no tool calls" message when there are no active tools 1`] = `
|
| 86 |
+
"โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
|
| 87 |
+
โ โ
|
| 88 |
+
โ No tool calls have been made in this session. โ
|
| 89 |
+
โ โ
|
| 90 |
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ"
|
| 91 |
+
`;
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/CompressionMessage.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Box, Text } from 'ink';
|
| 9 |
+
import { CompressionProps } from '../../types.js';
|
| 10 |
+
import Spinner from 'ink-spinner';
|
| 11 |
+
import { Colors } from '../../colors.js';
|
| 12 |
+
|
| 13 |
+
export interface CompressionDisplayProps {
|
| 14 |
+
compression: CompressionProps;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/*
|
| 18 |
+
* Compression messages appear when the /compress command is run, and show a loading spinner
|
| 19 |
+
* while compression is in progress, followed up by some compression stats.
|
| 20 |
+
*/
|
| 21 |
+
export const CompressionMessage: React.FC<CompressionDisplayProps> = ({
|
| 22 |
+
compression,
|
| 23 |
+
}) => {
|
| 24 |
+
const text = compression.isPending
|
| 25 |
+
? 'Compressing chat history'
|
| 26 |
+
: `Chat history compressed from ${compression.originalTokenCount ?? 'unknown'}` +
|
| 27 |
+
` to ${compression.newTokenCount ?? 'unknown'} tokens.`;
|
| 28 |
+
|
| 29 |
+
return (
|
| 30 |
+
<Box flexDirection="row">
|
| 31 |
+
<Box marginRight={1}>
|
| 32 |
+
{compression.isPending ? (
|
| 33 |
+
<Spinner type="dots" />
|
| 34 |
+
) : (
|
| 35 |
+
<Text color={Colors.AccentPurple}>โฆ</Text>
|
| 36 |
+
)}
|
| 37 |
+
</Box>
|
| 38 |
+
<Box>
|
| 39 |
+
<Text
|
| 40 |
+
color={
|
| 41 |
+
compression.isPending ? Colors.AccentPurple : Colors.AccentGreen
|
| 42 |
+
}
|
| 43 |
+
>
|
| 44 |
+
{text}
|
| 45 |
+
</Text>
|
| 46 |
+
</Box>
|
| 47 |
+
</Box>
|
| 48 |
+
);
|
| 49 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import { OverflowProvider } from '../../contexts/OverflowContext.js';
|
| 8 |
+
import { render } from 'ink-testing-library';
|
| 9 |
+
import { DiffRenderer } from './DiffRenderer.js';
|
| 10 |
+
import * as CodeColorizer from '../../utils/CodeColorizer.js';
|
| 11 |
+
import { vi } from 'vitest';
|
| 12 |
+
|
| 13 |
+
describe('<OverflowProvider><DiffRenderer /></OverflowProvider>', () => {
|
| 14 |
+
const mockColorizeCode = vi.spyOn(CodeColorizer, 'colorizeCode');
|
| 15 |
+
|
| 16 |
+
beforeEach(() => {
|
| 17 |
+
mockColorizeCode.mockClear();
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
const sanitizeOutput = (output: string | undefined, terminalWidth: number) =>
|
| 21 |
+
output?.replace(/GAP_INDICATOR/g, 'โ'.repeat(terminalWidth));
|
| 22 |
+
|
| 23 |
+
it('should call colorizeCode with correct language for new file with known extension', () => {
|
| 24 |
+
const newFileDiffContent = `
|
| 25 |
+
diff --git a/test.py b/test.py
|
| 26 |
+
new file mode 100644
|
| 27 |
+
index 0000000..e69de29
|
| 28 |
+
--- /dev/null
|
| 29 |
+
+++ b/test.py
|
| 30 |
+
@@ -0,0 +1 @@
|
| 31 |
+
+print("hello world")
|
| 32 |
+
`;
|
| 33 |
+
render(
|
| 34 |
+
<OverflowProvider>
|
| 35 |
+
<DiffRenderer
|
| 36 |
+
diffContent={newFileDiffContent}
|
| 37 |
+
filename="test.py"
|
| 38 |
+
terminalWidth={80}
|
| 39 |
+
/>
|
| 40 |
+
</OverflowProvider>,
|
| 41 |
+
);
|
| 42 |
+
expect(mockColorizeCode).toHaveBeenCalledWith(
|
| 43 |
+
'print("hello world")',
|
| 44 |
+
'python',
|
| 45 |
+
undefined,
|
| 46 |
+
80,
|
| 47 |
+
undefined,
|
| 48 |
+
);
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
it('should call colorizeCode with null language for new file with unknown extension', () => {
|
| 52 |
+
const newFileDiffContent = `
|
| 53 |
+
diff --git a/test.unknown b/test.unknown
|
| 54 |
+
new file mode 100644
|
| 55 |
+
index 0000000..e69de29
|
| 56 |
+
--- /dev/null
|
| 57 |
+
+++ b/test.unknown
|
| 58 |
+
@@ -0,0 +1 @@
|
| 59 |
+
+some content
|
| 60 |
+
`;
|
| 61 |
+
render(
|
| 62 |
+
<OverflowProvider>
|
| 63 |
+
<DiffRenderer
|
| 64 |
+
diffContent={newFileDiffContent}
|
| 65 |
+
filename="test.unknown"
|
| 66 |
+
terminalWidth={80}
|
| 67 |
+
/>
|
| 68 |
+
</OverflowProvider>,
|
| 69 |
+
);
|
| 70 |
+
expect(mockColorizeCode).toHaveBeenCalledWith(
|
| 71 |
+
'some content',
|
| 72 |
+
null,
|
| 73 |
+
undefined,
|
| 74 |
+
80,
|
| 75 |
+
undefined,
|
| 76 |
+
);
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
it('should call colorizeCode with null language for new file if no filename is provided', () => {
|
| 80 |
+
const newFileDiffContent = `
|
| 81 |
+
diff --git a/test.txt b/test.txt
|
| 82 |
+
new file mode 100644
|
| 83 |
+
index 0000000..e69de29
|
| 84 |
+
--- /dev/null
|
| 85 |
+
+++ b/test.txt
|
| 86 |
+
@@ -0,0 +1 @@
|
| 87 |
+
+some text content
|
| 88 |
+
`;
|
| 89 |
+
render(
|
| 90 |
+
<OverflowProvider>
|
| 91 |
+
<DiffRenderer diffContent={newFileDiffContent} terminalWidth={80} />
|
| 92 |
+
</OverflowProvider>,
|
| 93 |
+
);
|
| 94 |
+
expect(mockColorizeCode).toHaveBeenCalledWith(
|
| 95 |
+
'some text content',
|
| 96 |
+
null,
|
| 97 |
+
undefined,
|
| 98 |
+
80,
|
| 99 |
+
undefined,
|
| 100 |
+
);
|
| 101 |
+
});
|
| 102 |
+
|
| 103 |
+
it('should render diff content for existing file (not calling colorizeCode directly for the whole block)', () => {
|
| 104 |
+
const existingFileDiffContent = `
|
| 105 |
+
diff --git a/test.txt b/test.txt
|
| 106 |
+
index 0000001..0000002 100644
|
| 107 |
+
--- a/test.txt
|
| 108 |
+
+++ b/test.txt
|
| 109 |
+
@@ -1 +1 @@
|
| 110 |
+
-old line
|
| 111 |
+
+new line
|
| 112 |
+
`;
|
| 113 |
+
const { lastFrame } = render(
|
| 114 |
+
<OverflowProvider>
|
| 115 |
+
<DiffRenderer
|
| 116 |
+
diffContent={existingFileDiffContent}
|
| 117 |
+
filename="test.txt"
|
| 118 |
+
terminalWidth={80}
|
| 119 |
+
/>
|
| 120 |
+
</OverflowProvider>,
|
| 121 |
+
);
|
| 122 |
+
// colorizeCode is used internally by the line-by-line rendering, not for the whole block
|
| 123 |
+
expect(mockColorizeCode).not.toHaveBeenCalledWith(
|
| 124 |
+
expect.stringContaining('old line'),
|
| 125 |
+
expect.anything(),
|
| 126 |
+
);
|
| 127 |
+
expect(mockColorizeCode).not.toHaveBeenCalledWith(
|
| 128 |
+
expect.stringContaining('new line'),
|
| 129 |
+
expect.anything(),
|
| 130 |
+
);
|
| 131 |
+
const output = lastFrame();
|
| 132 |
+
const lines = output!.split('\n');
|
| 133 |
+
expect(lines[0]).toBe('1 - old line');
|
| 134 |
+
expect(lines[1]).toBe('1 + new line');
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
it('should handle diff with only header and no changes', () => {
|
| 138 |
+
const noChangeDiff = `diff --git a/file.txt b/file.txt
|
| 139 |
+
index 1234567..1234567 100644
|
| 140 |
+
--- a/file.txt
|
| 141 |
+
+++ b/file.txt
|
| 142 |
+
`;
|
| 143 |
+
const { lastFrame } = render(
|
| 144 |
+
<OverflowProvider>
|
| 145 |
+
<DiffRenderer
|
| 146 |
+
diffContent={noChangeDiff}
|
| 147 |
+
filename="file.txt"
|
| 148 |
+
terminalWidth={80}
|
| 149 |
+
/>
|
| 150 |
+
</OverflowProvider>,
|
| 151 |
+
);
|
| 152 |
+
expect(lastFrame()).toContain('No changes detected');
|
| 153 |
+
expect(mockColorizeCode).not.toHaveBeenCalled();
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
+
it('should handle empty diff content', () => {
|
| 157 |
+
const { lastFrame } = render(
|
| 158 |
+
<OverflowProvider>
|
| 159 |
+
<DiffRenderer diffContent="" terminalWidth={80} />
|
| 160 |
+
</OverflowProvider>,
|
| 161 |
+
);
|
| 162 |
+
expect(lastFrame()).toContain('No diff content');
|
| 163 |
+
expect(mockColorizeCode).not.toHaveBeenCalled();
|
| 164 |
+
});
|
| 165 |
+
|
| 166 |
+
it('should render a gap indicator for skipped lines', () => {
|
| 167 |
+
const diffWithGap = `
|
| 168 |
+
diff --git a/file.txt b/file.txt
|
| 169 |
+
index 123..456 100644
|
| 170 |
+
--- a/file.txt
|
| 171 |
+
+++ b/file.txt
|
| 172 |
+
@@ -1,2 +1,2 @@
|
| 173 |
+
context line 1
|
| 174 |
+
-deleted line
|
| 175 |
+
+added line
|
| 176 |
+
@@ -10,2 +10,2 @@
|
| 177 |
+
context line 10
|
| 178 |
+
context line 11
|
| 179 |
+
`;
|
| 180 |
+
const { lastFrame } = render(
|
| 181 |
+
<OverflowProvider>
|
| 182 |
+
<DiffRenderer
|
| 183 |
+
diffContent={diffWithGap}
|
| 184 |
+
filename="file.txt"
|
| 185 |
+
terminalWidth={80}
|
| 186 |
+
/>
|
| 187 |
+
</OverflowProvider>,
|
| 188 |
+
);
|
| 189 |
+
const output = lastFrame();
|
| 190 |
+
expect(output).toContain('โ'); // Check for the border character used in the gap
|
| 191 |
+
|
| 192 |
+
// Verify that lines before and after the gap are rendered
|
| 193 |
+
expect(output).toContain('context line 1');
|
| 194 |
+
expect(output).toContain('added line');
|
| 195 |
+
expect(output).toContain('context line 10');
|
| 196 |
+
});
|
| 197 |
+
|
| 198 |
+
it('should not render a gap indicator for small gaps (<= MAX_CONTEXT_LINES_WITHOUT_GAP)', () => {
|
| 199 |
+
const diffWithSmallGap = `
|
| 200 |
+
diff --git a/file.txt b/file.txt
|
| 201 |
+
index abc..def 100644
|
| 202 |
+
--- a/file.txt
|
| 203 |
+
+++ b/file.txt
|
| 204 |
+
@@ -1,5 +1,5 @@
|
| 205 |
+
context line 1
|
| 206 |
+
context line 2
|
| 207 |
+
context line 3
|
| 208 |
+
context line 4
|
| 209 |
+
context line 5
|
| 210 |
+
@@ -11,5 +11,5 @@
|
| 211 |
+
context line 11
|
| 212 |
+
context line 12
|
| 213 |
+
context line 13
|
| 214 |
+
context line 14
|
| 215 |
+
context line 15
|
| 216 |
+
`;
|
| 217 |
+
const { lastFrame } = render(
|
| 218 |
+
<OverflowProvider>
|
| 219 |
+
<DiffRenderer
|
| 220 |
+
diffContent={diffWithSmallGap}
|
| 221 |
+
filename="file.txt"
|
| 222 |
+
terminalWidth={80}
|
| 223 |
+
/>
|
| 224 |
+
</OverflowProvider>,
|
| 225 |
+
);
|
| 226 |
+
const output = lastFrame();
|
| 227 |
+
expect(output).not.toContain('โ'); // Ensure no separator is rendered
|
| 228 |
+
|
| 229 |
+
// Verify that lines before and after the gap are rendered
|
| 230 |
+
expect(output).toContain('context line 5');
|
| 231 |
+
expect(output).toContain('context line 11');
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
+
describe('should correctly render a diff with multiple hunks and a gap indicator', () => {
|
| 235 |
+
const diffWithMultipleHunks = `
|
| 236 |
+
diff --git a/multi.js b/multi.js
|
| 237 |
+
index 123..789 100644
|
| 238 |
+
--- a/multi.js
|
| 239 |
+
+++ b/multi.js
|
| 240 |
+
@@ -1,3 +1,3 @@
|
| 241 |
+
console.log('first hunk');
|
| 242 |
+
-const oldVar = 1;
|
| 243 |
+
+const newVar = 1;
|
| 244 |
+
console.log('end of first hunk');
|
| 245 |
+
@@ -20,3 +20,3 @@
|
| 246 |
+
console.log('second hunk');
|
| 247 |
+
-const anotherOld = 'test';
|
| 248 |
+
+const anotherNew = 'test';
|
| 249 |
+
console.log('end of second hunk');
|
| 250 |
+
`;
|
| 251 |
+
|
| 252 |
+
it.each([
|
| 253 |
+
{
|
| 254 |
+
terminalWidth: 80,
|
| 255 |
+
height: undefined,
|
| 256 |
+
expected: ` 1 console.log('first hunk');
|
| 257 |
+
2 - const oldVar = 1;
|
| 258 |
+
2 + const newVar = 1;
|
| 259 |
+
3 console.log('end of first hunk');
|
| 260 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 261 |
+
20 console.log('second hunk');
|
| 262 |
+
21 - const anotherOld = 'test';
|
| 263 |
+
21 + const anotherNew = 'test';
|
| 264 |
+
22 console.log('end of second hunk');`,
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
terminalWidth: 80,
|
| 268 |
+
height: 6,
|
| 269 |
+
expected: `... first 4 lines hidden ...
|
| 270 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 271 |
+
20 console.log('second hunk');
|
| 272 |
+
21 - const anotherOld = 'test';
|
| 273 |
+
21 + const anotherNew = 'test';
|
| 274 |
+
22 console.log('end of second hunk');`,
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
terminalWidth: 30,
|
| 278 |
+
height: 6,
|
| 279 |
+
expected: `... first 10 lines hidden ...
|
| 280 |
+
;
|
| 281 |
+
21 + const anotherNew = 'test'
|
| 282 |
+
;
|
| 283 |
+
22 console.log('end of
|
| 284 |
+
second hunk');`,
|
| 285 |
+
},
|
| 286 |
+
])(
|
| 287 |
+
'with terminalWidth $terminalWidth and height $height',
|
| 288 |
+
({ terminalWidth, height, expected }) => {
|
| 289 |
+
const { lastFrame } = render(
|
| 290 |
+
<OverflowProvider>
|
| 291 |
+
<DiffRenderer
|
| 292 |
+
diffContent={diffWithMultipleHunks}
|
| 293 |
+
filename="multi.js"
|
| 294 |
+
terminalWidth={terminalWidth}
|
| 295 |
+
availableTerminalHeight={height}
|
| 296 |
+
/>
|
| 297 |
+
</OverflowProvider>,
|
| 298 |
+
);
|
| 299 |
+
const output = lastFrame();
|
| 300 |
+
expect(sanitizeOutput(output, terminalWidth)).toEqual(expected);
|
| 301 |
+
},
|
| 302 |
+
);
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
+
it('should correctly render a diff with a SVN diff format', () => {
|
| 306 |
+
const newFileDiff = `
|
| 307 |
+
fileDiff Index: file.txt
|
| 308 |
+
===================================================================
|
| 309 |
+
--- a/file.txt Current
|
| 310 |
+
+++ b/file.txt Proposed
|
| 311 |
+
--- a/multi.js
|
| 312 |
+
+++ b/multi.js
|
| 313 |
+
@@ -1,1 +1,1 @@
|
| 314 |
+
-const oldVar = 1;
|
| 315 |
+
+const newVar = 1;
|
| 316 |
+
@@ -20,1 +20,1 @@
|
| 317 |
+
-const anotherOld = 'test';
|
| 318 |
+
+const anotherNew = 'test';
|
| 319 |
+
\
|
| 320 |
+
`;
|
| 321 |
+
const { lastFrame } = render(
|
| 322 |
+
<OverflowProvider>
|
| 323 |
+
<DiffRenderer
|
| 324 |
+
diffContent={newFileDiff}
|
| 325 |
+
filename="TEST"
|
| 326 |
+
terminalWidth={80}
|
| 327 |
+
/>
|
| 328 |
+
</OverflowProvider>,
|
| 329 |
+
);
|
| 330 |
+
const output = lastFrame();
|
| 331 |
+
|
| 332 |
+
expect(output).toEqual(` 1 - const oldVar = 1;
|
| 333 |
+
1 + const newVar = 1;
|
| 334 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 335 |
+
20 - const anotherOld = 'test';
|
| 336 |
+
20 + const anotherNew = 'test';`);
|
| 337 |
+
});
|
| 338 |
+
|
| 339 |
+
it('should correctly render a new file with no file extension correctly', () => {
|
| 340 |
+
const newFileDiff = `
|
| 341 |
+
fileDiff Index: Dockerfile
|
| 342 |
+
===================================================================
|
| 343 |
+
--- Dockerfile Current
|
| 344 |
+
+++ Dockerfile Proposed
|
| 345 |
+
@@ -0,0 +1,3 @@
|
| 346 |
+
+FROM node:14
|
| 347 |
+
+RUN npm install
|
| 348 |
+
+RUN npm run build
|
| 349 |
+
\
|
| 350 |
+
`;
|
| 351 |
+
const { lastFrame } = render(
|
| 352 |
+
<OverflowProvider>
|
| 353 |
+
<DiffRenderer
|
| 354 |
+
diffContent={newFileDiff}
|
| 355 |
+
filename="Dockerfile"
|
| 356 |
+
terminalWidth={80}
|
| 357 |
+
/>
|
| 358 |
+
</OverflowProvider>,
|
| 359 |
+
);
|
| 360 |
+
const output = lastFrame();
|
| 361 |
+
expect(output).toEqual(`1 FROM node:14
|
| 362 |
+
2 RUN npm install
|
| 363 |
+
3 RUN npm run build`);
|
| 364 |
+
});
|
| 365 |
+
});
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/DiffRenderer.tsx
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Box, Text } from 'ink';
|
| 9 |
+
import { Colors } from '../../colors.js';
|
| 10 |
+
import crypto from 'crypto';
|
| 11 |
+
import { colorizeCode, colorizeLine } from '../../utils/CodeColorizer.js';
|
| 12 |
+
import { MaxSizedBox } from '../shared/MaxSizedBox.js';
|
| 13 |
+
import { theme } from '../../semantic-colors.js';
|
| 14 |
+
|
| 15 |
+
interface DiffLine {
|
| 16 |
+
type: 'add' | 'del' | 'context' | 'hunk' | 'other';
|
| 17 |
+
oldLine?: number;
|
| 18 |
+
newLine?: number;
|
| 19 |
+
content: string;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function parseDiffWithLineNumbers(diffContent: string): DiffLine[] {
|
| 23 |
+
const lines = diffContent.split('\n');
|
| 24 |
+
const result: DiffLine[] = [];
|
| 25 |
+
let currentOldLine = 0;
|
| 26 |
+
let currentNewLine = 0;
|
| 27 |
+
let inHunk = false;
|
| 28 |
+
const hunkHeaderRegex = /^@@ -(\d+),?\d* \+(\d+),?\d* @@/;
|
| 29 |
+
|
| 30 |
+
for (const line of lines) {
|
| 31 |
+
const hunkMatch = line.match(hunkHeaderRegex);
|
| 32 |
+
if (hunkMatch) {
|
| 33 |
+
currentOldLine = parseInt(hunkMatch[1], 10);
|
| 34 |
+
currentNewLine = parseInt(hunkMatch[2], 10);
|
| 35 |
+
inHunk = true;
|
| 36 |
+
result.push({ type: 'hunk', content: line });
|
| 37 |
+
// We need to adjust the starting point because the first line number applies to the *first* actual line change/context,
|
| 38 |
+
// but we increment *before* pushing that line. So decrement here.
|
| 39 |
+
currentOldLine--;
|
| 40 |
+
currentNewLine--;
|
| 41 |
+
continue;
|
| 42 |
+
}
|
| 43 |
+
if (!inHunk) {
|
| 44 |
+
// Skip standard Git header lines more robustly
|
| 45 |
+
if (
|
| 46 |
+
line.startsWith('--- ') ||
|
| 47 |
+
line.startsWith('+++ ') ||
|
| 48 |
+
line.startsWith('diff --git') ||
|
| 49 |
+
line.startsWith('index ') ||
|
| 50 |
+
line.startsWith('similarity index') ||
|
| 51 |
+
line.startsWith('rename from') ||
|
| 52 |
+
line.startsWith('rename to') ||
|
| 53 |
+
line.startsWith('new file mode') ||
|
| 54 |
+
line.startsWith('deleted file mode')
|
| 55 |
+
)
|
| 56 |
+
continue;
|
| 57 |
+
// If it's not a hunk or header, skip (or handle as 'other' if needed)
|
| 58 |
+
continue;
|
| 59 |
+
}
|
| 60 |
+
if (line.startsWith('+')) {
|
| 61 |
+
currentNewLine++; // Increment before pushing
|
| 62 |
+
result.push({
|
| 63 |
+
type: 'add',
|
| 64 |
+
newLine: currentNewLine,
|
| 65 |
+
content: line.substring(1),
|
| 66 |
+
});
|
| 67 |
+
} else if (line.startsWith('-')) {
|
| 68 |
+
currentOldLine++; // Increment before pushing
|
| 69 |
+
result.push({
|
| 70 |
+
type: 'del',
|
| 71 |
+
oldLine: currentOldLine,
|
| 72 |
+
content: line.substring(1),
|
| 73 |
+
});
|
| 74 |
+
} else if (line.startsWith(' ')) {
|
| 75 |
+
currentOldLine++; // Increment before pushing
|
| 76 |
+
currentNewLine++;
|
| 77 |
+
result.push({
|
| 78 |
+
type: 'context',
|
| 79 |
+
oldLine: currentOldLine,
|
| 80 |
+
newLine: currentNewLine,
|
| 81 |
+
content: line.substring(1),
|
| 82 |
+
});
|
| 83 |
+
} else if (line.startsWith('\\')) {
|
| 84 |
+
// Handle ""
|
| 85 |
+
result.push({ type: 'other', content: line });
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
return result;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
interface DiffRendererProps {
|
| 92 |
+
diffContent: string;
|
| 93 |
+
filename?: string;
|
| 94 |
+
tabWidth?: number;
|
| 95 |
+
availableTerminalHeight?: number;
|
| 96 |
+
terminalWidth: number;
|
| 97 |
+
theme?: import('../../themes/theme.js').Theme;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
const DEFAULT_TAB_WIDTH = 4; // Spaces per tab for normalization
|
| 101 |
+
|
| 102 |
+
export const DiffRenderer: React.FC<DiffRendererProps> = ({
|
| 103 |
+
diffContent,
|
| 104 |
+
filename,
|
| 105 |
+
tabWidth = DEFAULT_TAB_WIDTH,
|
| 106 |
+
availableTerminalHeight,
|
| 107 |
+
terminalWidth,
|
| 108 |
+
theme,
|
| 109 |
+
}) => {
|
| 110 |
+
if (!diffContent || typeof diffContent !== 'string') {
|
| 111 |
+
return <Text color={Colors.AccentYellow}>No diff content.</Text>;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
const parsedLines = parseDiffWithLineNumbers(diffContent);
|
| 115 |
+
|
| 116 |
+
if (parsedLines.length === 0) {
|
| 117 |
+
return (
|
| 118 |
+
<Box borderStyle="round" borderColor={Colors.Gray} padding={1}>
|
| 119 |
+
<Text dimColor>No changes detected.</Text>
|
| 120 |
+
</Box>
|
| 121 |
+
);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// Check if the diff represents a new file (only additions and header lines)
|
| 125 |
+
const isNewFile = parsedLines.every(
|
| 126 |
+
(line) =>
|
| 127 |
+
line.type === 'add' ||
|
| 128 |
+
line.type === 'hunk' ||
|
| 129 |
+
line.type === 'other' ||
|
| 130 |
+
line.content.startsWith('diff --git') ||
|
| 131 |
+
line.content.startsWith('new file mode'),
|
| 132 |
+
);
|
| 133 |
+
|
| 134 |
+
let renderedOutput;
|
| 135 |
+
|
| 136 |
+
if (isNewFile) {
|
| 137 |
+
// Extract only the added lines' content
|
| 138 |
+
const addedContent = parsedLines
|
| 139 |
+
.filter((line) => line.type === 'add')
|
| 140 |
+
.map((line) => line.content)
|
| 141 |
+
.join('\n');
|
| 142 |
+
// Attempt to infer language from filename, default to plain text if no filename
|
| 143 |
+
const fileExtension = filename?.split('.').pop() || null;
|
| 144 |
+
const language = fileExtension
|
| 145 |
+
? getLanguageFromExtension(fileExtension)
|
| 146 |
+
: null;
|
| 147 |
+
renderedOutput = colorizeCode(
|
| 148 |
+
addedContent,
|
| 149 |
+
language,
|
| 150 |
+
availableTerminalHeight,
|
| 151 |
+
terminalWidth,
|
| 152 |
+
theme,
|
| 153 |
+
);
|
| 154 |
+
} else {
|
| 155 |
+
renderedOutput = renderDiffContent(
|
| 156 |
+
parsedLines,
|
| 157 |
+
filename,
|
| 158 |
+
tabWidth,
|
| 159 |
+
availableTerminalHeight,
|
| 160 |
+
terminalWidth,
|
| 161 |
+
);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
return renderedOutput;
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
const renderDiffContent = (
|
| 168 |
+
parsedLines: DiffLine[],
|
| 169 |
+
filename: string | undefined,
|
| 170 |
+
tabWidth = DEFAULT_TAB_WIDTH,
|
| 171 |
+
availableTerminalHeight: number | undefined,
|
| 172 |
+
terminalWidth: number,
|
| 173 |
+
) => {
|
| 174 |
+
// 1. Normalize whitespace (replace tabs with spaces) *before* further processing
|
| 175 |
+
const normalizedLines = parsedLines.map((line) => ({
|
| 176 |
+
...line,
|
| 177 |
+
content: line.content.replace(/\t/g, ' '.repeat(tabWidth)),
|
| 178 |
+
}));
|
| 179 |
+
|
| 180 |
+
// Filter out non-displayable lines (hunks, potentially 'other') using the normalized list
|
| 181 |
+
const displayableLines = normalizedLines.filter(
|
| 182 |
+
(l) => l.type !== 'hunk' && l.type !== 'other',
|
| 183 |
+
);
|
| 184 |
+
|
| 185 |
+
if (displayableLines.length === 0) {
|
| 186 |
+
return (
|
| 187 |
+
<Box borderStyle="round" borderColor={Colors.Gray} padding={1}>
|
| 188 |
+
<Text dimColor>No changes detected.</Text>
|
| 189 |
+
</Box>
|
| 190 |
+
);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
const maxLineNumber = Math.max(
|
| 194 |
+
0,
|
| 195 |
+
...displayableLines.map((l) => l.oldLine ?? 0),
|
| 196 |
+
...displayableLines.map((l) => l.newLine ?? 0),
|
| 197 |
+
);
|
| 198 |
+
const gutterWidth = Math.max(1, maxLineNumber.toString().length);
|
| 199 |
+
|
| 200 |
+
const fileExtension = filename?.split('.').pop() || null;
|
| 201 |
+
const language = fileExtension
|
| 202 |
+
? getLanguageFromExtension(fileExtension)
|
| 203 |
+
: null;
|
| 204 |
+
|
| 205 |
+
// Calculate the minimum indentation across all displayable lines
|
| 206 |
+
let baseIndentation = Infinity; // Start high to find the minimum
|
| 207 |
+
for (const line of displayableLines) {
|
| 208 |
+
// Only consider lines with actual content for indentation calculation
|
| 209 |
+
if (line.content.trim() === '') continue;
|
| 210 |
+
|
| 211 |
+
const firstCharIndex = line.content.search(/\S/); // Find index of first non-whitespace char
|
| 212 |
+
const currentIndent = firstCharIndex === -1 ? 0 : firstCharIndex; // Indent is 0 if no non-whitespace found
|
| 213 |
+
baseIndentation = Math.min(baseIndentation, currentIndent);
|
| 214 |
+
}
|
| 215 |
+
// If baseIndentation remained Infinity (e.g., no displayable lines with content), default to 0
|
| 216 |
+
if (!isFinite(baseIndentation)) {
|
| 217 |
+
baseIndentation = 0;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
const key = filename
|
| 221 |
+
? `diff-box-${filename}`
|
| 222 |
+
: `diff-box-${crypto.createHash('sha1').update(JSON.stringify(parsedLines)).digest('hex')}`;
|
| 223 |
+
|
| 224 |
+
let lastLineNumber: number | null = null;
|
| 225 |
+
const MAX_CONTEXT_LINES_WITHOUT_GAP = 5;
|
| 226 |
+
|
| 227 |
+
return (
|
| 228 |
+
<MaxSizedBox
|
| 229 |
+
maxHeight={availableTerminalHeight}
|
| 230 |
+
maxWidth={terminalWidth}
|
| 231 |
+
key={key}
|
| 232 |
+
>
|
| 233 |
+
{displayableLines.reduce<React.ReactNode[]>((acc, line, index) => {
|
| 234 |
+
// Determine the relevant line number for gap calculation based on type
|
| 235 |
+
let relevantLineNumberForGapCalc: number | null = null;
|
| 236 |
+
if (line.type === 'add' || line.type === 'context') {
|
| 237 |
+
relevantLineNumberForGapCalc = line.newLine ?? null;
|
| 238 |
+
} else if (line.type === 'del') {
|
| 239 |
+
// For deletions, the gap is typically in relation to the original file's line numbering
|
| 240 |
+
relevantLineNumberForGapCalc = line.oldLine ?? null;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
if (
|
| 244 |
+
lastLineNumber !== null &&
|
| 245 |
+
relevantLineNumberForGapCalc !== null &&
|
| 246 |
+
relevantLineNumberForGapCalc >
|
| 247 |
+
lastLineNumber + MAX_CONTEXT_LINES_WITHOUT_GAP + 1
|
| 248 |
+
) {
|
| 249 |
+
acc.push(
|
| 250 |
+
<Box key={`gap-${index}`}>
|
| 251 |
+
<Text wrap="truncate" color={Colors.Gray}>
|
| 252 |
+
{'โ'.repeat(terminalWidth)}
|
| 253 |
+
</Text>
|
| 254 |
+
</Box>,
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
const lineKey = `diff-line-${index}`;
|
| 259 |
+
let gutterNumStr = '';
|
| 260 |
+
let prefixSymbol = ' ';
|
| 261 |
+
|
| 262 |
+
switch (line.type) {
|
| 263 |
+
case 'add':
|
| 264 |
+
gutterNumStr = (line.newLine ?? '').toString();
|
| 265 |
+
prefixSymbol = '+';
|
| 266 |
+
lastLineNumber = line.newLine ?? null;
|
| 267 |
+
break;
|
| 268 |
+
case 'del':
|
| 269 |
+
gutterNumStr = (line.oldLine ?? '').toString();
|
| 270 |
+
prefixSymbol = '-';
|
| 271 |
+
// For deletions, update lastLineNumber based on oldLine if it's advancing.
|
| 272 |
+
// This helps manage gaps correctly if there are multiple consecutive deletions
|
| 273 |
+
// or if a deletion is followed by a context line far away in the original file.
|
| 274 |
+
if (line.oldLine !== undefined) {
|
| 275 |
+
lastLineNumber = line.oldLine;
|
| 276 |
+
}
|
| 277 |
+
break;
|
| 278 |
+
case 'context':
|
| 279 |
+
gutterNumStr = (line.newLine ?? '').toString();
|
| 280 |
+
prefixSymbol = ' ';
|
| 281 |
+
lastLineNumber = line.newLine ?? null;
|
| 282 |
+
break;
|
| 283 |
+
default:
|
| 284 |
+
return acc;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
const displayContent = line.content.substring(baseIndentation);
|
| 288 |
+
|
| 289 |
+
acc.push(
|
| 290 |
+
<Box key={lineKey} flexDirection="row">
|
| 291 |
+
<Text
|
| 292 |
+
color={theme.text.secondary}
|
| 293 |
+
backgroundColor={
|
| 294 |
+
line.type === 'add'
|
| 295 |
+
? theme.background.diff.added
|
| 296 |
+
: line.type === 'del'
|
| 297 |
+
? theme.background.diff.removed
|
| 298 |
+
: undefined
|
| 299 |
+
}
|
| 300 |
+
>
|
| 301 |
+
{gutterNumStr.padStart(gutterWidth)}{' '}
|
| 302 |
+
</Text>
|
| 303 |
+
{line.type === 'context' ? (
|
| 304 |
+
<>
|
| 305 |
+
<Text>{prefixSymbol} </Text>
|
| 306 |
+
<Text wrap="wrap">
|
| 307 |
+
{colorizeLine(displayContent, language)}
|
| 308 |
+
</Text>
|
| 309 |
+
</>
|
| 310 |
+
) : (
|
| 311 |
+
<Text
|
| 312 |
+
backgroundColor={
|
| 313 |
+
line.type === 'add'
|
| 314 |
+
? theme.background.diff.added
|
| 315 |
+
: theme.background.diff.removed
|
| 316 |
+
}
|
| 317 |
+
wrap="wrap"
|
| 318 |
+
>
|
| 319 |
+
<Text
|
| 320 |
+
color={
|
| 321 |
+
line.type === 'add'
|
| 322 |
+
? theme.status.success
|
| 323 |
+
: theme.status.error
|
| 324 |
+
}
|
| 325 |
+
>
|
| 326 |
+
{prefixSymbol}
|
| 327 |
+
</Text>{' '}
|
| 328 |
+
{colorizeLine(displayContent, language)}
|
| 329 |
+
</Text>
|
| 330 |
+
)}
|
| 331 |
+
</Box>,
|
| 332 |
+
);
|
| 333 |
+
return acc;
|
| 334 |
+
}, [])}
|
| 335 |
+
</MaxSizedBox>
|
| 336 |
+
);
|
| 337 |
+
};
|
| 338 |
+
|
| 339 |
+
const getLanguageFromExtension = (extension: string): string | null => {
|
| 340 |
+
const languageMap: { [key: string]: string } = {
|
| 341 |
+
js: 'javascript',
|
| 342 |
+
ts: 'typescript',
|
| 343 |
+
py: 'python',
|
| 344 |
+
json: 'json',
|
| 345 |
+
css: 'css',
|
| 346 |
+
html: 'html',
|
| 347 |
+
sh: 'bash',
|
| 348 |
+
md: 'markdown',
|
| 349 |
+
yaml: 'yaml',
|
| 350 |
+
yml: 'yaml',
|
| 351 |
+
txt: 'plaintext',
|
| 352 |
+
java: 'java',
|
| 353 |
+
c: 'c',
|
| 354 |
+
cpp: 'cpp',
|
| 355 |
+
rb: 'ruby',
|
| 356 |
+
};
|
| 357 |
+
return languageMap[extension] || null; // Return null if extension not found
|
| 358 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/ErrorMessage.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Text, Box } from 'ink';
|
| 9 |
+
import { Colors } from '../../colors.js';
|
| 10 |
+
|
| 11 |
+
interface ErrorMessageProps {
|
| 12 |
+
text: string;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export const ErrorMessage: React.FC<ErrorMessageProps> = ({ text }) => {
|
| 16 |
+
const prefix = 'โ ';
|
| 17 |
+
const prefixWidth = prefix.length;
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
<Box flexDirection="row" marginBottom={1}>
|
| 21 |
+
<Box width={prefixWidth}>
|
| 22 |
+
<Text color={Colors.AccentRed}>{prefix}</Text>
|
| 23 |
+
</Box>
|
| 24 |
+
<Box flexGrow={1}>
|
| 25 |
+
<Text wrap="wrap" color={Colors.AccentRed}>
|
| 26 |
+
{text}
|
| 27 |
+
</Text>
|
| 28 |
+
</Box>
|
| 29 |
+
</Box>
|
| 30 |
+
);
|
| 31 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/GeminiMessage.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Text, Box } from 'ink';
|
| 9 |
+
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
|
| 10 |
+
import { Colors } from '../../colors.js';
|
| 11 |
+
|
| 12 |
+
interface GeminiMessageProps {
|
| 13 |
+
text: string;
|
| 14 |
+
isPending: boolean;
|
| 15 |
+
availableTerminalHeight?: number;
|
| 16 |
+
terminalWidth: number;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export const GeminiMessage: React.FC<GeminiMessageProps> = ({
|
| 20 |
+
text,
|
| 21 |
+
isPending,
|
| 22 |
+
availableTerminalHeight,
|
| 23 |
+
terminalWidth,
|
| 24 |
+
}) => {
|
| 25 |
+
const prefix = 'โฆ ';
|
| 26 |
+
const prefixWidth = prefix.length;
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<Box flexDirection="row">
|
| 30 |
+
<Box width={prefixWidth}>
|
| 31 |
+
<Text color={Colors.AccentPurple}>{prefix}</Text>
|
| 32 |
+
</Box>
|
| 33 |
+
<Box flexGrow={1} flexDirection="column">
|
| 34 |
+
<MarkdownDisplay
|
| 35 |
+
text={text}
|
| 36 |
+
isPending={isPending}
|
| 37 |
+
availableTerminalHeight={availableTerminalHeight}
|
| 38 |
+
terminalWidth={terminalWidth}
|
| 39 |
+
/>
|
| 40 |
+
</Box>
|
| 41 |
+
</Box>
|
| 42 |
+
);
|
| 43 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/GeminiMessageContent.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Box } from 'ink';
|
| 9 |
+
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
|
| 10 |
+
|
| 11 |
+
interface GeminiMessageContentProps {
|
| 12 |
+
text: string;
|
| 13 |
+
isPending: boolean;
|
| 14 |
+
availableTerminalHeight?: number;
|
| 15 |
+
terminalWidth: number;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/*
|
| 19 |
+
* Gemini message content is a semi-hacked component. The intention is to represent a partial
|
| 20 |
+
* of GeminiMessage and is only used when a response gets too long. In that instance messages
|
| 21 |
+
* are split into multiple GeminiMessageContent's to enable the root <Static> component in
|
| 22 |
+
* App.tsx to be as performant as humanly possible.
|
| 23 |
+
*/
|
| 24 |
+
export const GeminiMessageContent: React.FC<GeminiMessageContentProps> = ({
|
| 25 |
+
text,
|
| 26 |
+
isPending,
|
| 27 |
+
availableTerminalHeight,
|
| 28 |
+
terminalWidth,
|
| 29 |
+
}) => {
|
| 30 |
+
const originalPrefix = 'โฆ ';
|
| 31 |
+
const prefixWidth = originalPrefix.length;
|
| 32 |
+
|
| 33 |
+
return (
|
| 34 |
+
<Box flexDirection="column" paddingLeft={prefixWidth}>
|
| 35 |
+
<MarkdownDisplay
|
| 36 |
+
text={text}
|
| 37 |
+
isPending={isPending}
|
| 38 |
+
availableTerminalHeight={availableTerminalHeight}
|
| 39 |
+
terminalWidth={terminalWidth}
|
| 40 |
+
/>
|
| 41 |
+
</Box>
|
| 42 |
+
);
|
| 43 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/components/messages/InfoMessage.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import React from 'react';
|
| 8 |
+
import { Text, Box } from 'ink';
|
| 9 |
+
import { Colors } from '../../colors.js';
|
| 10 |
+
import { RenderInline } from '../../utils/InlineMarkdownRenderer.js';
|
| 11 |
+
|
| 12 |
+
interface InfoMessageProps {
|
| 13 |
+
text: string;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const InfoMessage: React.FC<InfoMessageProps> = ({ text }) => {
|
| 17 |
+
const prefix = 'โน ';
|
| 18 |
+
const prefixWidth = prefix.length;
|
| 19 |
+
|
| 20 |
+
return (
|
| 21 |
+
<Box flexDirection="row" marginTop={1}>
|
| 22 |
+
<Box width={prefixWidth}>
|
| 23 |
+
<Text color={Colors.AccentYellow}>{prefix}</Text>
|
| 24 |
+
</Box>
|
| 25 |
+
<Box flexGrow={1}>
|
| 26 |
+
<Text wrap="wrap" color={Colors.AccentYellow}>
|
| 27 |
+
<RenderInline text={text} />
|
| 28 |
+
</Text>
|
| 29 |
+
</Box>
|
| 30 |
+
</Box>
|
| 31 |
+
);
|
| 32 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/utils/markdownUtilities.test.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import { describe, it, expect } from 'vitest';
|
| 8 |
+
import { findLastSafeSplitPoint } from './markdownUtilities.js';
|
| 9 |
+
|
| 10 |
+
describe('markdownUtilities', () => {
|
| 11 |
+
describe('findLastSafeSplitPoint', () => {
|
| 12 |
+
it('should split at the last double newline if not in a code block', () => {
|
| 13 |
+
const content = 'paragraph1\n\nparagraph2\n\nparagraph3';
|
| 14 |
+
expect(findLastSafeSplitPoint(content)).toBe(24); // After the second \n\n
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
it('should return content.length if no safe split point is found', () => {
|
| 18 |
+
const content = 'longstringwithoutanysafesplitpoint';
|
| 19 |
+
expect(findLastSafeSplitPoint(content)).toBe(content.length);
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
it('should prioritize splitting at \n\n over being at the very end of the string if the end is not in a code block', () => {
|
| 23 |
+
const content = 'Some text here.\n\nAnd more text here.';
|
| 24 |
+
expect(findLastSafeSplitPoint(content)).toBe(17); // after the \n\n
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
it('should return content.length if the only \n\n is inside a code block and the end of content is not', () => {
|
| 28 |
+
const content = '```\nignore this\n\nnewline\n```KeepThis';
|
| 29 |
+
expect(findLastSafeSplitPoint(content)).toBe(content.length);
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
it('should correctly identify the last \n\n even if it is followed by text not in a code block', () => {
|
| 33 |
+
const content =
|
| 34 |
+
'First part.\n\nSecond part.\n\nThird part, then some more text.';
|
| 35 |
+
// Split should be after "Second part.\n\n"
|
| 36 |
+
// "First part.\n\n" is 13 chars. "Second part.\n\n" is 14 chars. Total 27.
|
| 37 |
+
expect(findLastSafeSplitPoint(content)).toBe(27);
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
it('should return content.length if content is empty', () => {
|
| 41 |
+
const content = '';
|
| 42 |
+
expect(findLastSafeSplitPoint(content)).toBe(0);
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
it('should return content.length if content has no newlines and no code blocks', () => {
|
| 46 |
+
const content = 'Single line of text';
|
| 47 |
+
expect(findLastSafeSplitPoint(content)).toBe(content.length);
|
| 48 |
+
});
|
| 49 |
+
});
|
| 50 |
+
});
|
projects/ui/qwen-code/packages/cli/src/ui/utils/markdownUtilities.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
**Background & Purpose:**
|
| 9 |
+
|
| 10 |
+
The `findSafeSplitPoint` function is designed to address the challenge of displaying or processing large, potentially streaming, pieces of Markdown text. When content (e.g., from an LLM like Gemini) arrives in chunks or grows too large for a single display unit (like a message bubble), it needs to be split. A naive split (e.g., just at a character limit) can break Markdown formatting, especially critical for multi-line elements like code blocks, lists, or blockquotes, leading to incorrect rendering.
|
| 11 |
+
|
| 12 |
+
This function aims to find an *intelligent* or "safe" index within the provided `content` string at which to make such a split, prioritizing the preservation of Markdown integrity.
|
| 13 |
+
|
| 14 |
+
**Key Expectations & Behavior (Prioritized):**
|
| 15 |
+
|
| 16 |
+
1. **No Split if Short Enough:**
|
| 17 |
+
* If `content.length` is less than or equal to `idealMaxLength`, the function should return `content.length` (indicating no split is necessary for length reasons).
|
| 18 |
+
|
| 19 |
+
2. **Code Block Integrity (Highest Priority for Safety):**
|
| 20 |
+
* The function must try to avoid splitting *inside* a fenced code block (i.e., between ` ``` ` and ` ``` `).
|
| 21 |
+
* If `idealMaxLength` falls within a code block:
|
| 22 |
+
* The function will attempt to return an index that splits the content *before* the start of that code block.
|
| 23 |
+
* If a code block starts at the very beginning of the `content` and `idealMaxLength` falls within it (meaning the block itself is too long for the first chunk), the function might return `0`. This effectively makes the first chunk empty, pushing the entire oversized code block to the second part of the split.
|
| 24 |
+
* When considering splits near code blocks, the function prefers to keep the entire code block intact in one of the resulting chunks.
|
| 25 |
+
|
| 26 |
+
3. **Markdown-Aware Newline Splitting (If Not Governed by Code Block Logic):**
|
| 27 |
+
* If `idealMaxLength` does not fall within a code block (or after code block considerations have been made), the function will look for natural break points by scanning backwards from `idealMaxLength`:
|
| 28 |
+
* **Paragraph Breaks:** It prioritizes splitting after a double newline (`\n\n`), as this typically signifies the end of a paragraph or a block-level element.
|
| 29 |
+
* **Single Line Breaks:** If no double newline is found in a suitable range, it will look for a single newline (`\n`).
|
| 30 |
+
* Any newline chosen as a split point must also not be inside a code block.
|
| 31 |
+
|
| 32 |
+
4. **Fall back to `idealMaxLength`:**
|
| 33 |
+
* If no "safer" split point (respecting code blocks or finding suitable newlines) is identified before or at `idealMaxLength`, and `idealMaxLength` itself is not determined to be an unsafe split point (e.g., inside a code block), the function may return a length larger than `idealMaxLength`, again it CANNOT break markdown formatting. This could happen with very long lines of text without Markdown block structures or newlines.
|
| 34 |
+
|
| 35 |
+
**In essence, `findSafeSplitPoint` tries to be a good Markdown citizen when forced to divide content, preferring structural boundaries over arbitrary character limits, with a strong emphasis on not corrupting code blocks.**
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Checks if a given character index within a string is inside a fenced (```) code block.
|
| 40 |
+
* @param content The full string content.
|
| 41 |
+
* @param indexToTest The character index to test.
|
| 42 |
+
* @returns True if the index is inside a code block's content, false otherwise.
|
| 43 |
+
*/
|
| 44 |
+
const isIndexInsideCodeBlock = (
|
| 45 |
+
content: string,
|
| 46 |
+
indexToTest: number,
|
| 47 |
+
): boolean => {
|
| 48 |
+
let fenceCount = 0;
|
| 49 |
+
let searchPos = 0;
|
| 50 |
+
while (searchPos < content.length) {
|
| 51 |
+
const nextFence = content.indexOf('```', searchPos);
|
| 52 |
+
if (nextFence === -1 || nextFence >= indexToTest) {
|
| 53 |
+
break;
|
| 54 |
+
}
|
| 55 |
+
fenceCount++;
|
| 56 |
+
searchPos = nextFence + 3;
|
| 57 |
+
}
|
| 58 |
+
return fenceCount % 2 === 1;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Finds the starting index of the code block that encloses the given index.
|
| 63 |
+
* Returns -1 if the index is not inside a code block.
|
| 64 |
+
* @param content The markdown content.
|
| 65 |
+
* @param index The index to check.
|
| 66 |
+
* @returns Start index of the enclosing code block or -1.
|
| 67 |
+
*/
|
| 68 |
+
const findEnclosingCodeBlockStart = (
|
| 69 |
+
content: string,
|
| 70 |
+
index: number,
|
| 71 |
+
): number => {
|
| 72 |
+
if (!isIndexInsideCodeBlock(content, index)) {
|
| 73 |
+
return -1;
|
| 74 |
+
}
|
| 75 |
+
let currentSearchPos = 0;
|
| 76 |
+
while (currentSearchPos < index) {
|
| 77 |
+
const blockStartIndex = content.indexOf('```', currentSearchPos);
|
| 78 |
+
if (blockStartIndex === -1 || blockStartIndex >= index) {
|
| 79 |
+
break;
|
| 80 |
+
}
|
| 81 |
+
const blockEndIndex = content.indexOf('```', blockStartIndex + 3);
|
| 82 |
+
if (blockStartIndex < index) {
|
| 83 |
+
if (blockEndIndex === -1 || index < blockEndIndex + 3) {
|
| 84 |
+
return blockStartIndex;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
if (blockEndIndex === -1) break;
|
| 88 |
+
currentSearchPos = blockEndIndex + 3;
|
| 89 |
+
}
|
| 90 |
+
return -1;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
export const findLastSafeSplitPoint = (content: string) => {
|
| 94 |
+
const enclosingBlockStart = findEnclosingCodeBlockStart(
|
| 95 |
+
content,
|
| 96 |
+
content.length,
|
| 97 |
+
);
|
| 98 |
+
if (enclosingBlockStart !== -1) {
|
| 99 |
+
// The end of the content is contained in a code block. Split right before.
|
| 100 |
+
return enclosingBlockStart;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Search for the last double newline (\n\n) not in a code block.
|
| 104 |
+
let searchStartIndex = content.length;
|
| 105 |
+
while (searchStartIndex >= 0) {
|
| 106 |
+
const dnlIndex = content.lastIndexOf('\n\n', searchStartIndex);
|
| 107 |
+
if (dnlIndex === -1) {
|
| 108 |
+
// No more double newlines found.
|
| 109 |
+
break;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
const potentialSplitPoint = dnlIndex + 2;
|
| 113 |
+
if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) {
|
| 114 |
+
return potentialSplitPoint;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// If potentialSplitPoint was inside a code block,
|
| 118 |
+
// the next search should start *before* the \n\n we just found to ensure progress.
|
| 119 |
+
searchStartIndex = dnlIndex - 1;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// If no safe double newline is found, return content.length
|
| 123 |
+
// to keep the entire content as one piece.
|
| 124 |
+
return content.length;
|
| 125 |
+
};
|
projects/ui/qwen-code/packages/cli/src/ui/utils/platformConstants.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Terminal Platform Constants
|
| 9 |
+
*
|
| 10 |
+
* This file contains terminal-related constants used throughout the application,
|
| 11 |
+
* specifically for handling keyboard inputs and terminal protocols.
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Kitty keyboard protocol sequences for enhanced keyboard input.
|
| 16 |
+
* @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
| 17 |
+
*/
|
| 18 |
+
export const KITTY_CTRL_C = '[99;5u';
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Kitty keyboard protocol keycodes
|
| 22 |
+
*/
|
| 23 |
+
export const KITTY_KEYCODE_ENTER = 13;
|
| 24 |
+
export const KITTY_KEYCODE_NUMPAD_ENTER = 57414;
|
| 25 |
+
export const KITTY_KEYCODE_TAB = 9;
|
| 26 |
+
export const KITTY_KEYCODE_BACKSPACE = 127;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Timing constants for terminal interactions
|
| 30 |
+
*/
|
| 31 |
+
export const CTRL_EXIT_PROMPT_DURATION_MS = 1000;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* VS Code terminal integration constants
|
| 35 |
+
*/
|
| 36 |
+
export const VSCODE_SHIFT_ENTER_SEQUENCE = '\\\r\n';
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Backslash + Enter detection window in milliseconds.
|
| 40 |
+
* Used to detect Shift+Enter pattern where backslash
|
| 41 |
+
* is followed by Enter within this timeframe.
|
| 42 |
+
*/
|
| 43 |
+
export const BACKSLASH_ENTER_DETECTION_WINDOW_MS = 5;
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Maximum expected length of a Kitty keyboard protocol sequence.
|
| 47 |
+
* Format: ESC [ <keycode> ; <modifiers> u/~
|
| 48 |
+
* Example: \x1b[13;2u (Shift+Enter) = 8 chars
|
| 49 |
+
* Longest reasonable: \x1b[127;15~ = 11 chars (Del with all modifiers)
|
| 50 |
+
* We use 12 to provide a small buffer.
|
| 51 |
+
*/
|
| 52 |
+
export const MAX_KITTY_SEQUENCE_LENGTH = 12;
|
projects/ui/qwen-code/packages/cli/src/ui/utils/terminalSetup.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Terminal setup utility for configuring Shift+Enter and Ctrl+Enter support.
|
| 9 |
+
*
|
| 10 |
+
* This module provides automatic detection and configuration of various terminal
|
| 11 |
+
* emulators to support multiline input through modified Enter keys.
|
| 12 |
+
*
|
| 13 |
+
* Supported terminals:
|
| 14 |
+
* - VS Code: Configures keybindings.json to send \\\r\n
|
| 15 |
+
* - Cursor: Configures keybindings.json to send \\\r\n (VS Code fork)
|
| 16 |
+
* - Windsurf: Configures keybindings.json to send \\\r\n (VS Code fork)
|
| 17 |
+
*
|
| 18 |
+
* For VS Code and its forks:
|
| 19 |
+
* - Shift+Enter: Sends \\\r\n (backslash followed by CRLF)
|
| 20 |
+
* - Ctrl+Enter: Sends \\\r\n (backslash followed by CRLF)
|
| 21 |
+
*
|
| 22 |
+
* The module will not modify existing shift+enter or ctrl+enter keybindings
|
| 23 |
+
* to avoid conflicts with user customizations.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
import { promises as fs } from 'fs';
|
| 27 |
+
import * as os from 'os';
|
| 28 |
+
import * as path from 'path';
|
| 29 |
+
import { exec } from 'child_process';
|
| 30 |
+
import { promisify } from 'util';
|
| 31 |
+
import { isKittyProtocolEnabled } from './kittyProtocolDetector.js';
|
| 32 |
+
import { VSCODE_SHIFT_ENTER_SEQUENCE } from './platformConstants.js';
|
| 33 |
+
|
| 34 |
+
const execAsync = promisify(exec);
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Removes single-line JSON comments (// ...) from a string to allow parsing
|
| 38 |
+
* VS Code style JSON files that may contain comments.
|
| 39 |
+
*/
|
| 40 |
+
function stripJsonComments(content: string): string {
|
| 41 |
+
// Remove single-line comments (// ...)
|
| 42 |
+
return content.replace(/^\s*\/\/.*$/gm, '');
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
export interface TerminalSetupResult {
|
| 46 |
+
success: boolean;
|
| 47 |
+
message: string;
|
| 48 |
+
requiresRestart?: boolean;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
type SupportedTerminal = 'vscode' | 'cursor' | 'windsurf';
|
| 52 |
+
|
| 53 |
+
// Terminal detection
|
| 54 |
+
async function detectTerminal(): Promise<SupportedTerminal | null> {
|
| 55 |
+
const termProgram = process.env['TERM_PROGRAM'];
|
| 56 |
+
|
| 57 |
+
// Check VS Code and its forks - check forks first to avoid false positives
|
| 58 |
+
// Check for Cursor-specific indicators
|
| 59 |
+
if (
|
| 60 |
+
process.env['CURSOR_TRACE_ID'] ||
|
| 61 |
+
process.env['VSCODE_GIT_ASKPASS_MAIN']?.toLowerCase().includes('cursor')
|
| 62 |
+
) {
|
| 63 |
+
return 'cursor';
|
| 64 |
+
}
|
| 65 |
+
// Check for Windsurf-specific indicators
|
| 66 |
+
if (
|
| 67 |
+
process.env['VSCODE_GIT_ASKPASS_MAIN']?.toLowerCase().includes('windsurf')
|
| 68 |
+
) {
|
| 69 |
+
return 'windsurf';
|
| 70 |
+
}
|
| 71 |
+
// Check VS Code last since forks may also set VSCODE env vars
|
| 72 |
+
if (termProgram === 'vscode' || process.env['VSCODE_GIT_IPC_HANDLE']) {
|
| 73 |
+
return 'vscode';
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// Check parent process name
|
| 77 |
+
if (os.platform() !== 'win32') {
|
| 78 |
+
try {
|
| 79 |
+
const { stdout } = await execAsync('ps -o comm= -p $PPID');
|
| 80 |
+
const parentName = stdout.trim();
|
| 81 |
+
|
| 82 |
+
// Check forks before VS Code to avoid false positives
|
| 83 |
+
if (parentName.includes('windsurf') || parentName.includes('Windsurf'))
|
| 84 |
+
return 'windsurf';
|
| 85 |
+
if (parentName.includes('cursor') || parentName.includes('Cursor'))
|
| 86 |
+
return 'cursor';
|
| 87 |
+
if (parentName.includes('code') || parentName.includes('Code'))
|
| 88 |
+
return 'vscode';
|
| 89 |
+
} catch (error) {
|
| 90 |
+
// Continue detection even if process check fails
|
| 91 |
+
console.debug('Parent process detection failed:', error);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return null;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// Backup file helper
|
| 99 |
+
async function backupFile(filePath: string): Promise<void> {
|
| 100 |
+
try {
|
| 101 |
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
| 102 |
+
const backupPath = `${filePath}.backup.${timestamp}`;
|
| 103 |
+
await fs.copyFile(filePath, backupPath);
|
| 104 |
+
} catch (error) {
|
| 105 |
+
// Log backup errors but continue with operation
|
| 106 |
+
console.warn(`Failed to create backup of ${filePath}:`, error);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// Helper function to get VS Code-style config directory
|
| 111 |
+
function getVSCodeStyleConfigDir(appName: string): string | null {
|
| 112 |
+
const platform = os.platform();
|
| 113 |
+
|
| 114 |
+
if (platform === 'darwin') {
|
| 115 |
+
return path.join(
|
| 116 |
+
os.homedir(),
|
| 117 |
+
'Library',
|
| 118 |
+
'Application Support',
|
| 119 |
+
appName,
|
| 120 |
+
'User',
|
| 121 |
+
);
|
| 122 |
+
} else if (platform === 'win32') {
|
| 123 |
+
if (!process.env['APPDATA']) {
|
| 124 |
+
return null;
|
| 125 |
+
}
|
| 126 |
+
return path.join(process.env['APPDATA'], appName, 'User');
|
| 127 |
+
} else {
|
| 128 |
+
return path.join(os.homedir(), '.config', appName, 'User');
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
// Generic VS Code-style terminal configuration
|
| 133 |
+
async function configureVSCodeStyle(
|
| 134 |
+
terminalName: string,
|
| 135 |
+
appName: string,
|
| 136 |
+
): Promise<TerminalSetupResult> {
|
| 137 |
+
const configDir = getVSCodeStyleConfigDir(appName);
|
| 138 |
+
|
| 139 |
+
if (!configDir) {
|
| 140 |
+
return {
|
| 141 |
+
success: false,
|
| 142 |
+
message: `Could not determine ${terminalName} config path on Windows: APPDATA environment variable is not set.`,
|
| 143 |
+
};
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
const keybindingsFile = path.join(configDir, 'keybindings.json');
|
| 147 |
+
|
| 148 |
+
try {
|
| 149 |
+
await fs.mkdir(configDir, { recursive: true });
|
| 150 |
+
|
| 151 |
+
let keybindings: unknown[] = [];
|
| 152 |
+
try {
|
| 153 |
+
const content = await fs.readFile(keybindingsFile, 'utf8');
|
| 154 |
+
await backupFile(keybindingsFile);
|
| 155 |
+
try {
|
| 156 |
+
const cleanContent = stripJsonComments(content);
|
| 157 |
+
const parsedContent = JSON.parse(cleanContent);
|
| 158 |
+
if (!Array.isArray(parsedContent)) {
|
| 159 |
+
return {
|
| 160 |
+
success: false,
|
| 161 |
+
message:
|
| 162 |
+
`${terminalName} keybindings.json exists but is not a valid JSON array. ` +
|
| 163 |
+
`Please fix the file manually or delete it to allow automatic configuration.\n` +
|
| 164 |
+
`File: ${keybindingsFile}`,
|
| 165 |
+
};
|
| 166 |
+
}
|
| 167 |
+
keybindings = parsedContent;
|
| 168 |
+
} catch (parseError) {
|
| 169 |
+
return {
|
| 170 |
+
success: false,
|
| 171 |
+
message:
|
| 172 |
+
`Failed to parse ${terminalName} keybindings.json. The file contains invalid JSON.\n` +
|
| 173 |
+
`Please fix the file manually or delete it to allow automatic configuration.\n` +
|
| 174 |
+
`File: ${keybindingsFile}\n` +
|
| 175 |
+
`Error: ${parseError}`,
|
| 176 |
+
};
|
| 177 |
+
}
|
| 178 |
+
} catch {
|
| 179 |
+
// File doesn't exist, will create new one
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
const shiftEnterBinding = {
|
| 183 |
+
key: 'shift+enter',
|
| 184 |
+
command: 'workbench.action.terminal.sendSequence',
|
| 185 |
+
when: 'terminalFocus',
|
| 186 |
+
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
const ctrlEnterBinding = {
|
| 190 |
+
key: 'ctrl+enter',
|
| 191 |
+
command: 'workbench.action.terminal.sendSequence',
|
| 192 |
+
when: 'terminalFocus',
|
| 193 |
+
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
|
| 194 |
+
};
|
| 195 |
+
|
| 196 |
+
// Check if ANY shift+enter or ctrl+enter bindings already exist
|
| 197 |
+
const existingShiftEnter = keybindings.find((kb) => {
|
| 198 |
+
const binding = kb as { key?: string };
|
| 199 |
+
return binding.key === 'shift+enter';
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
const existingCtrlEnter = keybindings.find((kb) => {
|
| 203 |
+
const binding = kb as { key?: string };
|
| 204 |
+
return binding.key === 'ctrl+enter';
|
| 205 |
+
});
|
| 206 |
+
|
| 207 |
+
if (existingShiftEnter || existingCtrlEnter) {
|
| 208 |
+
const messages: string[] = [];
|
| 209 |
+
if (existingShiftEnter) {
|
| 210 |
+
messages.push(`- Shift+Enter binding already exists`);
|
| 211 |
+
}
|
| 212 |
+
if (existingCtrlEnter) {
|
| 213 |
+
messages.push(`- Ctrl+Enter binding already exists`);
|
| 214 |
+
}
|
| 215 |
+
return {
|
| 216 |
+
success: false,
|
| 217 |
+
message:
|
| 218 |
+
`Existing keybindings detected. Will not modify to avoid conflicts.\n` +
|
| 219 |
+
messages.join('\n') +
|
| 220 |
+
'\n' +
|
| 221 |
+
`Please check and modify manually if needed: ${keybindingsFile}`,
|
| 222 |
+
};
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Check if our specific bindings already exist
|
| 226 |
+
const hasOurShiftEnter = keybindings.some((kb) => {
|
| 227 |
+
const binding = kb as {
|
| 228 |
+
command?: string;
|
| 229 |
+
args?: { text?: string };
|
| 230 |
+
key?: string;
|
| 231 |
+
};
|
| 232 |
+
return (
|
| 233 |
+
binding.key === 'shift+enter' &&
|
| 234 |
+
binding.command === 'workbench.action.terminal.sendSequence' &&
|
| 235 |
+
binding.args?.text === '\\\r\n'
|
| 236 |
+
);
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
const hasOurCtrlEnter = keybindings.some((kb) => {
|
| 240 |
+
const binding = kb as {
|
| 241 |
+
command?: string;
|
| 242 |
+
args?: { text?: string };
|
| 243 |
+
key?: string;
|
| 244 |
+
};
|
| 245 |
+
return (
|
| 246 |
+
binding.key === 'ctrl+enter' &&
|
| 247 |
+
binding.command === 'workbench.action.terminal.sendSequence' &&
|
| 248 |
+
binding.args?.text === '\\\r\n'
|
| 249 |
+
);
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
if (!hasOurShiftEnter || !hasOurCtrlEnter) {
|
| 253 |
+
if (!hasOurShiftEnter) keybindings.unshift(shiftEnterBinding);
|
| 254 |
+
if (!hasOurCtrlEnter) keybindings.unshift(ctrlEnterBinding);
|
| 255 |
+
|
| 256 |
+
await fs.writeFile(keybindingsFile, JSON.stringify(keybindings, null, 4));
|
| 257 |
+
return {
|
| 258 |
+
success: true,
|
| 259 |
+
message: `Added Shift+Enter and Ctrl+Enter keybindings to ${terminalName}.\nModified: ${keybindingsFile}`,
|
| 260 |
+
requiresRestart: true,
|
| 261 |
+
};
|
| 262 |
+
} else {
|
| 263 |
+
return {
|
| 264 |
+
success: true,
|
| 265 |
+
message: `${terminalName} keybindings already configured.`,
|
| 266 |
+
};
|
| 267 |
+
}
|
| 268 |
+
} catch (error) {
|
| 269 |
+
return {
|
| 270 |
+
success: false,
|
| 271 |
+
message: `Failed to configure ${terminalName}.\nFile: ${keybindingsFile}\nError: ${error}`,
|
| 272 |
+
};
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// Terminal-specific configuration functions
|
| 277 |
+
|
| 278 |
+
async function configureVSCode(): Promise<TerminalSetupResult> {
|
| 279 |
+
return configureVSCodeStyle('VS Code', 'Code');
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
async function configureCursor(): Promise<TerminalSetupResult> {
|
| 283 |
+
return configureVSCodeStyle('Cursor', 'Cursor');
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
async function configureWindsurf(): Promise<TerminalSetupResult> {
|
| 287 |
+
return configureVSCodeStyle('Windsurf', 'Windsurf');
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
/**
|
| 291 |
+
* Main terminal setup function that detects and configures the current terminal.
|
| 292 |
+
*
|
| 293 |
+
* This function:
|
| 294 |
+
* 1. Detects the current terminal emulator
|
| 295 |
+
* 2. Applies appropriate configuration for Shift+Enter and Ctrl+Enter support
|
| 296 |
+
* 3. Creates backups of configuration files before modifying them
|
| 297 |
+
*
|
| 298 |
+
* @returns Promise<TerminalSetupResult> Result object with success status and message
|
| 299 |
+
*
|
| 300 |
+
* @example
|
| 301 |
+
* const result = await terminalSetup();
|
| 302 |
+
* if (result.success) {
|
| 303 |
+
* console.log(result.message);
|
| 304 |
+
* if (result.requiresRestart) {
|
| 305 |
+
* console.log('Please restart your terminal');
|
| 306 |
+
* }
|
| 307 |
+
* }
|
| 308 |
+
*/
|
| 309 |
+
export async function terminalSetup(): Promise<TerminalSetupResult> {
|
| 310 |
+
// Check if terminal already has optimal keyboard support
|
| 311 |
+
if (isKittyProtocolEnabled()) {
|
| 312 |
+
return {
|
| 313 |
+
success: true,
|
| 314 |
+
message:
|
| 315 |
+
'Your terminal is already configured for an optimal experience with multiline input (Shift+Enter and Ctrl+Enter).',
|
| 316 |
+
};
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
const terminal = await detectTerminal();
|
| 320 |
+
|
| 321 |
+
if (!terminal) {
|
| 322 |
+
return {
|
| 323 |
+
success: false,
|
| 324 |
+
message:
|
| 325 |
+
'Could not detect terminal type. Supported terminals: VS Code, Cursor, and Windsurf.',
|
| 326 |
+
};
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
switch (terminal) {
|
| 330 |
+
case 'vscode':
|
| 331 |
+
return configureVSCode();
|
| 332 |
+
case 'cursor':
|
| 333 |
+
return configureCursor();
|
| 334 |
+
case 'windsurf':
|
| 335 |
+
return configureWindsurf();
|
| 336 |
+
default:
|
| 337 |
+
return {
|
| 338 |
+
success: false,
|
| 339 |
+
message: `Terminal "${terminal}" is not supported yet.`,
|
| 340 |
+
};
|
| 341 |
+
}
|
| 342 |
+
}
|
projects/ui/qwen-code/packages/cli/src/ui/utils/textUtils.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Calculates the maximum width of a multi-line ASCII art string.
|
| 9 |
+
* @param asciiArt The ASCII art string.
|
| 10 |
+
* @returns The length of the longest line in the ASCII art.
|
| 11 |
+
*/
|
| 12 |
+
export const getAsciiArtWidth = (asciiArt: string): number => {
|
| 13 |
+
if (!asciiArt) {
|
| 14 |
+
return 0;
|
| 15 |
+
}
|
| 16 |
+
const lines = asciiArt.split('\n');
|
| 17 |
+
return Math.max(...lines.map((line) => line.length));
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
/*
|
| 21 |
+
* -------------------------------------------------------------------------
|
| 22 |
+
* Unicodeโaware helpers (work at the codeโpoint level rather than UTFโ16
|
| 23 |
+
* code units so that surrogateโpair emoji count as one "column".)
|
| 24 |
+
* ---------------------------------------------------------------------- */
|
| 25 |
+
|
| 26 |
+
export function toCodePoints(str: string): string[] {
|
| 27 |
+
// [...str] or Array.from both iterate by UTFโ32 code point, handling
|
| 28 |
+
// surrogate pairs correctly.
|
| 29 |
+
return Array.from(str);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
export function cpLen(str: string): number {
|
| 33 |
+
return toCodePoints(str).length;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export function cpSlice(str: string, start: number, end?: number): string {
|
| 37 |
+
// Slice by codeโpoint indices and reโjoin.
|
| 38 |
+
const arr = toCodePoints(str).slice(start, end);
|
| 39 |
+
return arr.join('');
|
| 40 |
+
}
|
projects/ui/qwen-code/packages/cli/src/ui/utils/updateCheck.test.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
| 8 |
+
import { checkForUpdates } from './updateCheck.js';
|
| 9 |
+
|
| 10 |
+
const getPackageJson = vi.hoisted(() => vi.fn());
|
| 11 |
+
vi.mock('../../utils/package.js', () => ({
|
| 12 |
+
getPackageJson,
|
| 13 |
+
}));
|
| 14 |
+
|
| 15 |
+
const updateNotifier = vi.hoisted(() => vi.fn());
|
| 16 |
+
vi.mock('update-notifier', () => ({
|
| 17 |
+
default: updateNotifier,
|
| 18 |
+
}));
|
| 19 |
+
|
| 20 |
+
describe('checkForUpdates', () => {
|
| 21 |
+
beforeEach(() => {
|
| 22 |
+
vi.useFakeTimers();
|
| 23 |
+
vi.resetAllMocks();
|
| 24 |
+
// Clear DEV environment variable before each test
|
| 25 |
+
delete process.env['DEV'];
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
afterEach(() => {
|
| 29 |
+
vi.useRealTimers();
|
| 30 |
+
vi.restoreAllMocks();
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
it('should return null when running from source (DEV=true)', async () => {
|
| 34 |
+
process.env['DEV'] = 'true';
|
| 35 |
+
getPackageJson.mockResolvedValue({
|
| 36 |
+
name: 'test-package',
|
| 37 |
+
version: '1.0.0',
|
| 38 |
+
});
|
| 39 |
+
updateNotifier.mockReturnValue({
|
| 40 |
+
fetchInfo: vi
|
| 41 |
+
.fn()
|
| 42 |
+
.mockResolvedValue({ current: '1.0.0', latest: '1.1.0' }),
|
| 43 |
+
});
|
| 44 |
+
const result = await checkForUpdates();
|
| 45 |
+
expect(result).toBeNull();
|
| 46 |
+
expect(getPackageJson).not.toHaveBeenCalled();
|
| 47 |
+
expect(updateNotifier).not.toHaveBeenCalled();
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
it('should return null if package.json is missing', async () => {
|
| 51 |
+
getPackageJson.mockResolvedValue(null);
|
| 52 |
+
const result = await checkForUpdates();
|
| 53 |
+
expect(result).toBeNull();
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
it('should return null if there is no update', async () => {
|
| 57 |
+
getPackageJson.mockResolvedValue({
|
| 58 |
+
name: 'test-package',
|
| 59 |
+
version: '1.0.0',
|
| 60 |
+
});
|
| 61 |
+
updateNotifier.mockReturnValue({
|
| 62 |
+
fetchInfo: vi.fn().mockResolvedValue(null),
|
| 63 |
+
});
|
| 64 |
+
const result = await checkForUpdates();
|
| 65 |
+
expect(result).toBeNull();
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
it('should return a message if a newer version is available', async () => {
|
| 69 |
+
getPackageJson.mockResolvedValue({
|
| 70 |
+
name: 'test-package',
|
| 71 |
+
version: '1.0.0',
|
| 72 |
+
});
|
| 73 |
+
updateNotifier.mockReturnValue({
|
| 74 |
+
fetchInfo: vi
|
| 75 |
+
.fn()
|
| 76 |
+
.mockResolvedValue({ current: '1.0.0', latest: '1.1.0' }),
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
const result = await checkForUpdates();
|
| 80 |
+
expect(result?.message).toContain('1.0.0 โ 1.1.0');
|
| 81 |
+
expect(result?.update).toEqual({ current: '1.0.0', latest: '1.1.0' });
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
it('should return null if the latest version is the same as the current version', async () => {
|
| 85 |
+
getPackageJson.mockResolvedValue({
|
| 86 |
+
name: 'test-package',
|
| 87 |
+
version: '1.0.0',
|
| 88 |
+
});
|
| 89 |
+
updateNotifier.mockReturnValue({
|
| 90 |
+
fetchInfo: vi
|
| 91 |
+
.fn()
|
| 92 |
+
.mockResolvedValue({ current: '1.0.0', latest: '1.0.0' }),
|
| 93 |
+
});
|
| 94 |
+
const result = await checkForUpdates();
|
| 95 |
+
expect(result).toBeNull();
|
| 96 |
+
});
|
| 97 |
+
|
| 98 |
+
it('should return null if the latest version is older than the current version', async () => {
|
| 99 |
+
getPackageJson.mockResolvedValue({
|
| 100 |
+
name: 'test-package',
|
| 101 |
+
version: '1.1.0',
|
| 102 |
+
});
|
| 103 |
+
updateNotifier.mockReturnValue({
|
| 104 |
+
fetchInfo: vi
|
| 105 |
+
.fn()
|
| 106 |
+
.mockResolvedValue({ current: '1.1.0', latest: '1.0.0' }),
|
| 107 |
+
});
|
| 108 |
+
const result = await checkForUpdates();
|
| 109 |
+
expect(result).toBeNull();
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
it('should return null if fetchInfo rejects', async () => {
|
| 113 |
+
getPackageJson.mockResolvedValue({
|
| 114 |
+
name: 'test-package',
|
| 115 |
+
version: '1.0.0',
|
| 116 |
+
});
|
| 117 |
+
updateNotifier.mockReturnValue({
|
| 118 |
+
fetchInfo: vi.fn().mockRejectedValue(new Error('Timeout')),
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
const result = await checkForUpdates();
|
| 122 |
+
expect(result).toBeNull();
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
it('should handle errors gracefully', async () => {
|
| 126 |
+
getPackageJson.mockRejectedValue(new Error('test error'));
|
| 127 |
+
const result = await checkForUpdates();
|
| 128 |
+
expect(result).toBeNull();
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
describe('nightly updates', () => {
|
| 132 |
+
it('should notify for a newer nightly version when current is nightly', async () => {
|
| 133 |
+
getPackageJson.mockResolvedValue({
|
| 134 |
+
name: 'test-package',
|
| 135 |
+
version: '1.2.3-nightly.1',
|
| 136 |
+
});
|
| 137 |
+
|
| 138 |
+
const fetchInfoMock = vi.fn().mockImplementation(({ distTag }) => {
|
| 139 |
+
if (distTag === 'nightly') {
|
| 140 |
+
return Promise.resolve({
|
| 141 |
+
latest: '1.2.3-nightly.2',
|
| 142 |
+
current: '1.2.3-nightly.1',
|
| 143 |
+
});
|
| 144 |
+
}
|
| 145 |
+
if (distTag === 'latest') {
|
| 146 |
+
return Promise.resolve({
|
| 147 |
+
latest: '1.2.3',
|
| 148 |
+
current: '1.2.3-nightly.1',
|
| 149 |
+
});
|
| 150 |
+
}
|
| 151 |
+
return Promise.resolve(null);
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
updateNotifier.mockImplementation(({ pkg, distTag }) => ({
|
| 155 |
+
fetchInfo: () => fetchInfoMock({ pkg, distTag }),
|
| 156 |
+
}));
|
| 157 |
+
|
| 158 |
+
const result = await checkForUpdates();
|
| 159 |
+
expect(result?.message).toContain('1.2.3-nightly.1 โ 1.2.3-nightly.2');
|
| 160 |
+
expect(result?.update.latest).toBe('1.2.3-nightly.2');
|
| 161 |
+
});
|
| 162 |
+
});
|
| 163 |
+
});
|
projects/ui/qwen-code/packages/cli/src/ui/utils/updateCheck.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license
|
| 3 |
+
* Copyright 2025 Google LLC
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import updateNotifier, { UpdateInfo } from 'update-notifier';
|
| 8 |
+
import semver from 'semver';
|
| 9 |
+
import { getPackageJson } from '../../utils/package.js';
|
| 10 |
+
|
| 11 |
+
export const FETCH_TIMEOUT_MS = 2000;
|
| 12 |
+
|
| 13 |
+
export interface UpdateObject {
|
| 14 |
+
message: string;
|
| 15 |
+
update: UpdateInfo;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* From a nightly and stable update, determines which is the "best" one to offer.
|
| 20 |
+
* The rule is to always prefer nightly if the base versions are the same.
|
| 21 |
+
*/
|
| 22 |
+
function getBestAvailableUpdate(
|
| 23 |
+
nightly?: UpdateInfo,
|
| 24 |
+
stable?: UpdateInfo,
|
| 25 |
+
): UpdateInfo | null {
|
| 26 |
+
if (!nightly) return stable || null;
|
| 27 |
+
if (!stable) return nightly || null;
|
| 28 |
+
|
| 29 |
+
const nightlyVer = nightly.latest;
|
| 30 |
+
const stableVer = stable.latest;
|
| 31 |
+
|
| 32 |
+
if (
|
| 33 |
+
semver.coerce(stableVer)?.version === semver.coerce(nightlyVer)?.version
|
| 34 |
+
) {
|
| 35 |
+
return nightly;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return semver.gt(stableVer, nightlyVer) ? stable : nightly;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
export async function checkForUpdates(): Promise<UpdateObject | null> {
|
| 42 |
+
try {
|
| 43 |
+
// Skip update check when running from source (development mode)
|
| 44 |
+
if (process.env['DEV'] === 'true') {
|
| 45 |
+
return null;
|
| 46 |
+
}
|
| 47 |
+
const packageJson = await getPackageJson();
|
| 48 |
+
if (!packageJson || !packageJson.name || !packageJson.version) {
|
| 49 |
+
return null;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
const { name, version: currentVersion } = packageJson;
|
| 53 |
+
const isNightly = currentVersion.includes('nightly');
|
| 54 |
+
const createNotifier = (distTag: 'latest' | 'nightly') =>
|
| 55 |
+
updateNotifier({
|
| 56 |
+
pkg: {
|
| 57 |
+
name,
|
| 58 |
+
version: currentVersion,
|
| 59 |
+
},
|
| 60 |
+
updateCheckInterval: 0,
|
| 61 |
+
shouldNotifyInNpmScript: true,
|
| 62 |
+
distTag,
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
if (isNightly) {
|
| 66 |
+
const [nightlyUpdateInfo, latestUpdateInfo] = await Promise.all([
|
| 67 |
+
createNotifier('nightly').fetchInfo(),
|
| 68 |
+
createNotifier('latest').fetchInfo(),
|
| 69 |
+
]);
|
| 70 |
+
|
| 71 |
+
const bestUpdate = getBestAvailableUpdate(
|
| 72 |
+
nightlyUpdateInfo,
|
| 73 |
+
latestUpdateInfo,
|
| 74 |
+
);
|
| 75 |
+
|
| 76 |
+
if (bestUpdate && semver.gt(bestUpdate.latest, currentVersion)) {
|
| 77 |
+
const message = `A new version of Qwen Code is available! ${currentVersion} โ ${bestUpdate.latest}`;
|
| 78 |
+
return {
|
| 79 |
+
message,
|
| 80 |
+
update: { ...bestUpdate, current: currentVersion },
|
| 81 |
+
};
|
| 82 |
+
}
|
| 83 |
+
} else {
|
| 84 |
+
const updateInfo = await createNotifier('latest').fetchInfo();
|
| 85 |
+
|
| 86 |
+
if (updateInfo && semver.gt(updateInfo.latest, currentVersion)) {
|
| 87 |
+
const message = `Qwen Code update available! ${currentVersion} โ ${updateInfo.latest}`;
|
| 88 |
+
return {
|
| 89 |
+
message,
|
| 90 |
+
update: { ...updateInfo, current: currentVersion },
|
| 91 |
+
};
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return null;
|
| 96 |
+
} catch (e) {
|
| 97 |
+
console.warn('Failed to check for updates: ' + e);
|
| 98 |
+
return null;
|
| 99 |
+
}
|
| 100 |
+
}
|