From 523b718bafd578d7ae81e325c69f09d9cb1c4bd1 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 15 Jul 2025 11:54:44 +0530 Subject: [PATCH 1/4] show current session data in editor - add a protocol in core to get session data - add gui in help section --- core/core.ts | 4 +++ core/protocol/core.ts | 1 + core/protocol/passThrough.ts | 1 + core/util/history.ts | 13 ++++++++ .../constants/MessageTypes.kt | 1 + gui/src/pages/config/HelpCenterSection.tsx | 31 ++++++++++++++++++- 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/core/core.ts b/core/core.ts index 915099a3e..ef1c8fd29 100644 --- a/core/core.ts +++ b/core/core.ts @@ -292,6 +292,10 @@ export class Core { historyManager.clearAll(); }); + on("history/getSessionData", (msg) => { + return historyManager.getSessionData(msg.data.id); + }); + on("devdata/log", async (msg) => { void DataLogger.getInstance().logDevData(msg.data); }); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index f06d1db04..7ee0b84cc 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -67,6 +67,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { "history/load": [{ id: string }, Session]; "history/save": [Session, void]; "history/clear": [undefined, void]; + "history/getSessionData": [{ id: string }, string]; "devdata/log": [DevDataLogEvent, void]; "config/addOpenAiKey": [string, void]; "config/addModel": [ diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 6b29ce472..deffb3319 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -15,6 +15,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "history/load", "history/save", "history/clear", + "history/getSessionData", "devdata/log", "config/addModel", "config/newPromptFile", diff --git a/core/util/history.ts b/core/util/history.ts index ab332a11b..3446e7941 100644 --- a/core/util/history.ts +++ b/core/util/history.ts @@ -95,6 +95,19 @@ class HistoryManager { } } + getSessionData(sessionId: string): string { + try { + const sessionFile = getSessionFilePath(sessionId); + if (!fs.existsSync(sessionFile)) { + throw new Error(`Session file ${sessionFile} does not exist`); + } + const fileContent = fs.readFileSync(sessionFile, "utf8"); + return JSON.stringify(JSON.parse(fileContent), null, 2); + } catch (e) { + throw new Error(`Error reading session data: ${e}`); + } + } + save(session: Session) { // Save the main session json file // Explicitely rewriting here to influence the written key order in the file! diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index c53b4bc6e..246141d6f 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -81,6 +81,7 @@ class MessageTypes { "history/load", "history/save", "history/clear", + "history/getSessionData", "devdata/log", "config/addModel", "config/newPromptFile", diff --git a/gui/src/pages/config/HelpCenterSection.tsx b/gui/src/pages/config/HelpCenterSection.tsx index 004e5b78a..dc9e0a879 100644 --- a/gui/src/pages/config/HelpCenterSection.tsx +++ b/gui/src/pages/config/HelpCenterSection.tsx @@ -1,13 +1,14 @@ import { ArrowTopRightOnSquareIcon, DocumentArrowUpIcon, + NumberedListIcon, PaintBrushIcon, TableCellsIcon, } from "@heroicons/react/24/outline"; import { useContext } from "react"; import { useNavigate } from "react-router-dom"; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppDispatch } from "../../redux/hooks"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { setOnboardingCard } from "../../redux/slices/uiSlice"; import { saveCurrentSession } from "../../redux/thunks/session"; import { ROUTES } from "../../util/navigation"; @@ -18,6 +19,25 @@ export function HelpCenterSection() { const navigate = useNavigate(); const dispatch = useAppDispatch(); + const currentSession = useAppSelector((state) => state.session); + + const handleViewSessionData = async () => { + try { + const sessionData = await ideMessenger.request("history/getSessionData", { + id: currentSession.id, + }); + + if (sessionData.status === "success") { + await ideMessenger.request("showVirtualFile", { + name: "currentSessionData.json", + content: sessionData.content, + }); + } + } catch (error) { + console.error("Error viewing session data:", error); + } + }; + return (

Help center

@@ -68,6 +88,15 @@ export function HelpCenterSection() { onClick={() => navigate("/stats")} /> + {currentSession.history.length > 0 && !currentSession.isStreaming && ( + + )} + Date: Tue, 15 Jul 2025 11:56:00 +0530 Subject: [PATCH 2/4] add tests --- core/util/history.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/util/history.test.ts b/core/util/history.test.ts index dbcf69619..4e3b447ad 100644 --- a/core/util/history.test.ts +++ b/core/util/history.test.ts @@ -37,6 +37,12 @@ describe("No sessions have been created", () => { sessionId: testSessionId, }); }); + + test("Getting session data for non-existent session throws error", () => { + expect(() => { + historyManager.getSessionData(testSessionId); + }).toThrow(); + }); }); describe("Full session lifecycle", () => { @@ -55,6 +61,14 @@ describe("Full session lifecycle", () => { expect(retrievedSession).toEqual(testSession); }); + test("Getting session data returns formatted JSON string", () => { + const sessionData = historyManager.getSessionData(testSession.sessionId); + const parsed = JSON.parse(sessionData); + expect(parsed.sessionId).toBe(testSession.sessionId); + expect(parsed.title).toBe(testSession.title); + expect(parsed.workspaceDirectory).toBe(testSession.workspaceDirectory); + }); + test("Saving session with new title updates session", () => { const modifiedSession = { ...testSession }; modifiedSession.title = `Edited: ${testSession.title}`; From 601eb1f6608b6c0c57e95a7a8b756d8ab63d013c Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 15 Jul 2025 12:56:34 +0530 Subject: [PATCH 3/4] use history.load --- core/core.ts | 4 ---- core/protocol/core.ts | 1 - core/protocol/passThrough.ts | 1 - core/util/history.test.ts | 14 -------------- core/util/history.ts | 13 ------------- .../constants/MessageTypes.kt | 1 - gui/src/pages/config/HelpCenterSection.tsx | 6 +++--- 7 files changed, 3 insertions(+), 37 deletions(-) diff --git a/core/core.ts b/core/core.ts index ef1c8fd29..915099a3e 100644 --- a/core/core.ts +++ b/core/core.ts @@ -292,10 +292,6 @@ export class Core { historyManager.clearAll(); }); - on("history/getSessionData", (msg) => { - return historyManager.getSessionData(msg.data.id); - }); - on("devdata/log", async (msg) => { void DataLogger.getInstance().logDevData(msg.data); }); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 7ee0b84cc..f06d1db04 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -67,7 +67,6 @@ export type ToCoreFromIdeOrWebviewProtocol = { "history/load": [{ id: string }, Session]; "history/save": [Session, void]; "history/clear": [undefined, void]; - "history/getSessionData": [{ id: string }, string]; "devdata/log": [DevDataLogEvent, void]; "config/addOpenAiKey": [string, void]; "config/addModel": [ diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index deffb3319..6b29ce472 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -15,7 +15,6 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "history/load", "history/save", "history/clear", - "history/getSessionData", "devdata/log", "config/addModel", "config/newPromptFile", diff --git a/core/util/history.test.ts b/core/util/history.test.ts index 4e3b447ad..dbcf69619 100644 --- a/core/util/history.test.ts +++ b/core/util/history.test.ts @@ -37,12 +37,6 @@ describe("No sessions have been created", () => { sessionId: testSessionId, }); }); - - test("Getting session data for non-existent session throws error", () => { - expect(() => { - historyManager.getSessionData(testSessionId); - }).toThrow(); - }); }); describe("Full session lifecycle", () => { @@ -61,14 +55,6 @@ describe("Full session lifecycle", () => { expect(retrievedSession).toEqual(testSession); }); - test("Getting session data returns formatted JSON string", () => { - const sessionData = historyManager.getSessionData(testSession.sessionId); - const parsed = JSON.parse(sessionData); - expect(parsed.sessionId).toBe(testSession.sessionId); - expect(parsed.title).toBe(testSession.title); - expect(parsed.workspaceDirectory).toBe(testSession.workspaceDirectory); - }); - test("Saving session with new title updates session", () => { const modifiedSession = { ...testSession }; modifiedSession.title = `Edited: ${testSession.title}`; diff --git a/core/util/history.ts b/core/util/history.ts index 3446e7941..ab332a11b 100644 --- a/core/util/history.ts +++ b/core/util/history.ts @@ -95,19 +95,6 @@ class HistoryManager { } } - getSessionData(sessionId: string): string { - try { - const sessionFile = getSessionFilePath(sessionId); - if (!fs.existsSync(sessionFile)) { - throw new Error(`Session file ${sessionFile} does not exist`); - } - const fileContent = fs.readFileSync(sessionFile, "utf8"); - return JSON.stringify(JSON.parse(fileContent), null, 2); - } catch (e) { - throw new Error(`Error reading session data: ${e}`); - } - } - save(session: Session) { // Save the main session json file // Explicitely rewriting here to influence the written key order in the file! diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index 246141d6f..c53b4bc6e 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -81,7 +81,6 @@ class MessageTypes { "history/load", "history/save", "history/clear", - "history/getSessionData", "devdata/log", "config/addModel", "config/newPromptFile", diff --git a/gui/src/pages/config/HelpCenterSection.tsx b/gui/src/pages/config/HelpCenterSection.tsx index dc9e0a879..df53a4212 100644 --- a/gui/src/pages/config/HelpCenterSection.tsx +++ b/gui/src/pages/config/HelpCenterSection.tsx @@ -23,14 +23,14 @@ export function HelpCenterSection() { const handleViewSessionData = async () => { try { - const sessionData = await ideMessenger.request("history/getSessionData", { + const sessionData = await ideMessenger.request("history/load", { id: currentSession.id, }); if (sessionData.status === "success") { await ideMessenger.request("showVirtualFile", { - name: "currentSessionData.json", - content: sessionData.content, + name: `${sessionData.content.title}.json`, + content: JSON.stringify(sessionData.content, null, 2), }); } } catch (error) { From d8666f47a4394072901834eef522039d9b456c18 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 15 Jul 2025 12:57:56 +0530 Subject: [PATCH 4/4] remove try catch --- gui/src/pages/config/HelpCenterSection.tsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gui/src/pages/config/HelpCenterSection.tsx b/gui/src/pages/config/HelpCenterSection.tsx index df53a4212..7a711068c 100644 --- a/gui/src/pages/config/HelpCenterSection.tsx +++ b/gui/src/pages/config/HelpCenterSection.tsx @@ -22,19 +22,15 @@ export function HelpCenterSection() { const currentSession = useAppSelector((state) => state.session); const handleViewSessionData = async () => { - try { - const sessionData = await ideMessenger.request("history/load", { - id: currentSession.id, - }); + const sessionData = await ideMessenger.request("history/load", { + id: currentSession.id, + }); - if (sessionData.status === "success") { - await ideMessenger.request("showVirtualFile", { - name: `${sessionData.content.title}.json`, - content: JSON.stringify(sessionData.content, null, 2), - }); - } - } catch (error) { - console.error("Error viewing session data:", error); + if (sessionData.status === "success") { + await ideMessenger.request("showVirtualFile", { + name: `${sessionData.content.title}.json`, + content: JSON.stringify(sessionData.content, null, 2), + }); } };