Add datetimestamp to exported session filename
This commit is contained in:
parent
10b4701272
commit
e44ea2b391
1 changed files with 26 additions and 4 deletions
|
|
@ -3,11 +3,30 @@ import { homedir } from "os";
|
|||
import { SlashCommand } from "../..";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
|
||||
// If useful elsewhere, helper funcs should move to core/util/index.ts or similar
|
||||
function getOffsetDatetime(date: Date): Date {
|
||||
const offset = date.getTimezoneOffset();
|
||||
const offsetHours = Math.floor(offset / 60);
|
||||
const offsetMinutes = offset % 60;
|
||||
date.setHours(date.getHours() - offsetHours);
|
||||
date.setMinutes(date.getMinutes() - offsetMinutes);
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
function asBasicISOString(date: Date): string {
|
||||
const isoString = date.toISOString();
|
||||
|
||||
return isoString.replace(/[-:]/g, "").replace(/\.\d+Z/, "");
|
||||
}
|
||||
|
||||
const ShareSlashCommand: SlashCommand = {
|
||||
name: "share",
|
||||
description: "Export the current chat session to markdown",
|
||||
run: async function* ({ ide, history, params }) {
|
||||
let content = `This is a session transcript from [Continue](https://continue.dev) on ${new Date().toLocaleString()}.`;
|
||||
const now = new Date();
|
||||
|
||||
let content = `This is a session transcript from [Continue](https://continue.dev) on ${now.toLocaleString()}.`;
|
||||
|
||||
for (const msg of history) {
|
||||
content += `\n\n## ${
|
||||
|
|
@ -22,8 +41,10 @@ const ShareSlashCommand: SlashCommand = {
|
|||
if (outputDir.startsWith("~")) {
|
||||
outputDir = outputDir.replace(/~/, homedir);
|
||||
}
|
||||
//TODO: error handling, create path if it doesn't exist?
|
||||
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
|
||||
|
||||
// Although the most common situation is to have one directory open in a
|
||||
// workspace it's also possible to have just a file open without an
|
||||
// associated directory or to use multi-root workspaces in which multiple
|
||||
|
|
@ -31,8 +52,9 @@ const ShareSlashCommand: SlashCommand = {
|
|||
// it exists.
|
||||
const workspaceDirectory = workspaceDirs?.[0] || "";
|
||||
outputDir = outputDir.replace(/CURRENT_WORKSPACE/, workspaceDirectory);
|
||||
const outPath = path.join(outputDir, `session.md`); //TODO: more flexible naming
|
||||
|
||||
const dtString = asBasicISOString(getOffsetDatetime(now));
|
||||
const outPath = path.join(outputDir, `${dtString}_session.md`); //TODO: more flexible naming
|
||||
//TODO: more flexible naming
|
||||
|
||||
await ide.writeFile(outPath, content);
|
||||
await ide.openFile(outPath);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue