Skip to content

Conversation

@avi-alpert
Copy link
Contributor

@avi-alpert avi-alpert commented Mar 31, 2025

Problem

Users lose all chats when they close VSCode, and there's no way to browse through chat history. Users also cant export their conversations to an easily shareable format.

Solution

Automatically persist conversations to JSON files in ~/.aws/amazonq/history, one for each workspace where Amazon Q chats occur. Add chat history and chat export buttons to top of Amazon Q toolbar. Clicking on the chat history button allows users to browse and search through chat history. Users click on an old conversation to open it back up (currently open conversations are in bold). Clicking on chat export button allows users to save chat transcript as a markdown or html.

Note: persistence + history is only for Q Chat Tabs (not /dev, /doc, /transform, etc.)

Screenshot 2025-03-31 at 2 49 27 PM


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@avi-alpert avi-alpert force-pushed the aalpert/coversation-history branch from 259581d to e2f0a2d Compare March 31, 2025 18:28
@avi-alpert
Copy link
Contributor Author

/runIntegrationTests

if (e.key === 'Escape') {
this.closeList()
} else if (e.key === 'Enter') {
// todo: call onItemSelect on Enter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for mynah-ui to provide TargetElementId, should be included in prod release tomorrow

"js-yaml": "^4.1.0",
"jsonc-parser": "^3.2.0",
"lodash": "^4.17.21",
"lokijs": "^1.5.12",
Copy link
Contributor

@justinmk3 justinmk3 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required? what alternatives were considered? are you confidence this package will be actively maintained?

is https://github.com/techfort/LokiJS/pulse the correct repo for it? no activity for 3 years.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats the correct repo, and based on my research its stable and widely used. its a pretty lightweight library with 500k+ weekly downloads https://www.npmjs.com/package/lokijs

LokiJS includes helpful functionality out of the box like autoload, autosave, finding elements, and updating elements, and was easy to use. Alternatives considered were better-sqlite3 and sqlite3 but those are not web-compatible

initialized: boolean = false

constructor() {
this.dbDirectory = path.join(fs.getUserHomeDir(), '.aws', 'amazonq', 'history')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is never required to join() string literals. Not on Windows, nor anywhere else. "/" slashes work fine.

Suggested change
this.dbDirectory = path.join(fs.getUserHomeDir(), '.aws', 'amazonq', 'history')
this.dbDirectory = path.join(fs.getUserHomeDir(), '.aws/amazonq/history')

// Case 1: .code-workspace file (saved workspace)
const workspace = vscode.workspace.workspaceFile
if (workspace) {
crypto.createHash('md5').update(workspace.fsPath).digest('hex')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just return at L62

await this.ensureDirectory()
const filename = path.join(this.directory, dbname)

await fs.writeFile(filename, dbstring, 'utf8')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the history is corrupted or has partial writes, or multiple vscode instances try to save the file simultaneously? on Windows, this will have problems.

if you are ok with the current limitations, the limitations should be cleary called-out in the docstring for FileSystemAdapter (which currently has no docstring).

@avi-alpert
Copy link
Contributor Author

/runIntegrationTests

@avi-alpert avi-alpert marked this pull request as ready for review April 1, 2025 15:20
@avi-alpert avi-alpert requested review from a team as code owners April 1, 2025 15:20
"@aws-sdk/smithy-client": "<3.731.0",
"@aws-sdk/util-arn-parser": "<3.731.0",
"@aws/mynah-ui": "^4.26.1",
"@aws/mynah-ui": "^4.27.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be done by #6901

@avi-alpert avi-alpert requested a review from leigaol April 1, 2025 16:33
@avi-alpert avi-alpert force-pushed the aalpert/coversation-history branch from 161f730 to e5b017b Compare April 1, 2025 18:01
@avi-alpert
Copy link
Contributor Author

/runIntegrationTests

@avi-alpert avi-alpert force-pushed the aalpert/coversation-history branch from e5b017b to a1ef003 Compare April 1, 2025 20:16
@avi-alpert
Copy link
Contributor Author

Rebased with master

@avi-alpert avi-alpert requested a review from justinmk3 April 1, 2025 20:57
@justinmk3 justinmk3 merged commit 2da999c into aws:master Apr 2, 2025
29 of 31 checks passed
export enum ClientType {
VSCode = 'IDE-VSCode',
JetBrains = 'IDE_JetBrains',
CLI = 'CLI',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI does not use mynah-ui, does it? What is the plan to make CLI work with the history, given native mynah-ui types, like ChatItem, are stored in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just added in here as a placeholder in case we ever had a shared history store in the future

import path from 'path'

import { TabType } from '../../../amazonq/webview/ui/storages/tabsStorage'
import { ChatItem, ChatItemButton, DetailedListItem, DetailedListItemGroup, MynahIconsType } from '@aws/mynah-ui'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you store native mynah-ui types into history. It can be not straightforward to migrate this to language-servers while preserving history. There's protocol abstracting UI from chat server business logic, meaning types in chat language server are non-UI specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could create a new type in flare, in history we are storing an object for each message that has body, type, codeReference, and relatedContent. so as long as we keep those four properties we can be backwards compatible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants