Skip to content

Commit 1e1bda1

Browse files
committed
Implement the ability to copy checkpoint logs to the clipboard via a new quick pick button
1 parent 8396498 commit 1e1bda1

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const dictionary = {
1515
CLIPBOARD_CONTENT_APPLIED_SUCCESSFULLY:
1616
'Clipboard content applied successfully.',
1717
COPIED_TO_CLIPBOARD: 'Message copied to the clipboard.',
18+
CHECKPOINTS_COPIED_TO_CLIPBOARD:
19+
'Checkpoints copied to clipboard as logs.',
1820
NO_SAVED_CONTEXTS_IN_WORKSPACE_STATE:
1921
'No saved contexts remaining in the Workspace State.',
2022
NO_SAVED_CONTEXTS_IN_JSON_FILE:

‎packages/vscode/src/commands/checkpoints-command/checkpoints-command.ts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { PanelProvider } from '@/views/panel/backend/panel-provider'
1818
import { get_checkpoint_path } from './utils'
1919
import { WebsitesProvider } from '@/context/providers/websites-provider'
20+
import { dictionary } from '@shared/constants/dictionary'
2021

2122
dayjs.extend(relativeTime)
2223

@@ -84,6 +85,11 @@ export const checkpoints_command = (params: {
8485
tooltip: 'Delete all checkpoints'
8586
}
8687

88+
const copy_button: vscode.QuickInputButton = {
89+
iconPath: new vscode.ThemeIcon('copy'),
90+
tooltip: 'Copy checkpoints as logs'
91+
}
92+
8793
let notification_count = 0
8894
let checkpoints: Checkpoint[] = []
8995
let temp_checkpoint_is_valid = false
@@ -103,7 +109,7 @@ export const checkpoints_command = (params: {
103109
const visible_checkpoints = checkpoints.filter((c) => !c.is_temporary)
104110

105111
if (visible_checkpoints.length > 0) {
106-
quick_pick.buttons = [clear_all_button]
112+
quick_pick.buttons = [copy_button, clear_all_button]
107113
} else {
108114
quick_pick.buttons = []
109115
}
@@ -260,6 +266,53 @@ export const checkpoints_command = (params: {
260266
})
261267

262268
quick_pick.onDidTriggerButton(async (button) => {
269+
if (button === copy_button) {
270+
const visible_checkpoints = checkpoints
271+
.filter((c) => !c.is_temporary)
272+
.sort((a, b) => b.timestamp - a.timestamp)
273+
274+
if (visible_checkpoints.length == 0) {
275+
return
276+
}
277+
278+
const longest_title_length = Math.max(
279+
...visible_checkpoints.map((c) => c.title.length)
280+
)
281+
282+
const time_zone = Intl.DateTimeFormat().resolvedOptions().timeZone
283+
284+
const log_lines: string[] = []
285+
let last_full_hour: string | null = null
286+
287+
for (const c of visible_checkpoints) {
288+
const date_obj = dayjs(c.timestamp)
289+
const current_full_hour = date_obj.format('YYYY-MM-DD HH')
290+
291+
if (
292+
last_full_hour !== null &&
293+
last_full_hour !== current_full_hour
294+
) {
295+
log_lines.push('')
296+
}
297+
298+
const date = date_obj.format('YYYY-MM-DD HH:mm')
299+
const padded_title = c.title.padEnd(longest_title_length, ' ')
300+
log_lines.push(
301+
`[${date} ${time_zone}] | ${padded_title} | ${
302+
c.description ? c.description : ''
303+
}`
304+
)
305+
last_full_hour = current_full_hour
306+
}
307+
308+
const log_string = log_lines.join('\n')
309+
await vscode.env.clipboard.writeText(log_string)
310+
vscode.window.showInformationMessage(
311+
dictionary.information_message.CHECKPOINTS_COPIED_TO_CLIPBOARD
312+
)
313+
return
314+
}
315+
263316
if (button === clear_all_button) {
264317
quick_pick.hide()
265318
const confirmation = await vscode.window.showWarningMessage(

0 commit comments

Comments
 (0)