From 9ece2fc982dd046998b71daffa4fa8e0b21eff84 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 5 Aug 2024 20:51:33 +0000 Subject: [PATCH 1/4] chore: Add comments functionality to extension.ts and activate it --- packages/vscode/src/comments.ts | 14 ++++++++++++++ packages/vscode/src/extension.ts | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 packages/vscode/src/comments.ts diff --git a/packages/vscode/src/comments.ts b/packages/vscode/src/comments.ts new file mode 100644 index 0000000000..38ac5b3f19 --- /dev/null +++ b/packages/vscode/src/comments.ts @@ -0,0 +1,14 @@ +import * as vscode from "vscode" +import { ExtensionState } from "./state" +import { TOOL_ID, TOOL_NAME } from "../../core/src/constants" + +export function activateComments(state: ExtensionState) { + const { context } = state + const { subscriptions } = context + + const controller = vscode.comments.createCommentController( + TOOL_ID, + `${TOOL_NAME} comments` + ) + subscriptions.push(controller) +} diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 52f5651cd8..584bf2e1df 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -15,6 +15,7 @@ import { registerCommand } from "./commands" import { EXTENSION_ID, TOOL_NAME } from "../../core/src/constants" import type MarkdownIt from "markdown-it" import MarkdownItGitHubAlerts from "markdown-it-github-alerts" +import { activateComments } from "./comments" export async function activate(context: ExtensionContext) { const state = new ExtensionState(context) @@ -27,6 +28,7 @@ export async function activate(context: ExtensionContext) { activateTraceTreeDataProvider(state) activateStatusBar(state) activateDocsNotebook(state) + activateComments(state) context.subscriptions.push( registerCommand("genaiscript.request.abort", async () => { From ef57e1b64760ad1b0f2f8cb701b6e589f3f2f456 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Thu, 29 Aug 2024 14:02:02 -0700 Subject: [PATCH 2/4] serialize comments to cache --- docs/genaisrc/genaiscript.d.ts | 54 +++++++++++++++++++ genaisrc/genaiscript.d.ts | 54 +++++++++++++++++++ packages/core/src/constants.ts | 1 + packages/core/src/genaisrc/genaiscript.d.ts | 54 +++++++++++++++++++ packages/core/src/types/prompt_template.d.ts | 54 +++++++++++++++++++ packages/sample/genaisrc/genaiscript.d.ts | 54 +++++++++++++++++++ .../sample/genaisrc/node/genaiscript.d.ts | 54 +++++++++++++++++++ .../sample/genaisrc/python/genaiscript.d.ts | 54 +++++++++++++++++++ .../sample/genaisrc/style/genaiscript.d.ts | 54 +++++++++++++++++++ packages/sample/src/aici/genaiscript.d.ts | 54 +++++++++++++++++++ packages/sample/src/errors/genaiscript.d.ts | 54 +++++++++++++++++++ packages/sample/src/makecode/genaiscript.d.ts | 54 +++++++++++++++++++ packages/sample/src/tla/genaiscript.d.ts | 54 +++++++++++++++++++ packages/sample/src/vision/genaiscript.d.ts | 54 +++++++++++++++++++ packages/vscode/src/comments.ts | 43 ++++++++++++++- slides/genaisrc/genaiscript.d.ts | 54 +++++++++++++++++++ 16 files changed, 799 insertions(+), 1 deletion(-) diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 0de7375531..146df84ce7 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -212,6 +212,7 @@ export const AI_REQUESTS_CACHE = "airequests" export const CHAT_CACHE = "chat" export const GITHUB_PULL_REQUEST_REVIEWS_CACHE = "prr" export const GITHUB_PULLREQUEST_REVIEW_COMMENT_LINE_DISTANCE = 5 +export const COMMENTS_CACHE = "comments" export const PLACEHOLDER_API_BASE = "" export const PLACEHOLDER_API_KEY = "" diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index ad664ed5c7..4a7d5df957 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -614,6 +614,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -647,6 +696,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit diff --git a/packages/vscode/src/comments.ts b/packages/vscode/src/comments.ts index 38ac5b3f19..9366ebdb30 100644 --- a/packages/vscode/src/comments.ts +++ b/packages/vscode/src/comments.ts @@ -1,6 +1,29 @@ import * as vscode from "vscode" import { ExtensionState } from "./state" -import { TOOL_ID, TOOL_NAME } from "../../core/src/constants" +import { COMMENTS_CACHE, TOOL_ID, TOOL_NAME } from "../../core/src/constants" +import { JSONLineCache } from "../../core/src/cache" +import { toRange } from "./edit" + +export interface CommentKey {} + +export interface CommentValue { + uri: string + source: string + range: [number, number] + comments: Comment[] + label?: string + resolved?: boolean +} + +function commentToVSCodeComment(comment: Comment): vscode.Comment { + const { reactions, timestamp, ...rest } = comment + return { + ...rest, + timestamp: new Date(timestamp), + reactions: reactions.map((r) => ({ ...r, iconPath: "" })), + mode: vscode.CommentMode.Preview, + } +} export function activateComments(state: ExtensionState) { const { context } = state @@ -11,4 +34,22 @@ export function activateComments(state: ExtensionState) { `${TOOL_NAME} comments` ) subscriptions.push(controller) + const cache = JSONLineCache.byName(COMMENTS_CACHE) + + vscode.workspace.onDidChangeWorkspaceFolders(async () => { + const entries = await cache.entries() + for (const { val } of entries) { + const { uri, range, comments, label, resolved } = val + const thread = controller.createCommentThread( + vscode.Uri.parse(uri), + toRange(range), + comments.map(commentToVSCodeComment) + ) + thread.label = val.label + thread.canReply = true + thread.state = resolved + ? vscode.CommentThreadState.Resolved + : vscode.CommentThreadState.Unresolved + } + }) } diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index c27bcf06db..9f20910cad 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -640,6 +640,55 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment + */ +interface Comment { + /** + * The human-readable comment body + */ + body: string + + /** + * The author of the comment + */ + author: { name: string } + + /** + * Optional reactions of the comment + */ + reactions?: CommentReaction[] + + /** + * Optional label describing the comment + * Label will be rendered next to authorName if exists. + */ + label?: string + + /** + * Optional timestamp that will be displayed in comments. + * The date will be formatted according to the user's locale and settings. + */ + timestamp?: string +} + +interface CommentReaction { + /** + * The human-readable label for the reaction + */ + label: string + + /** + * The number of users who have reacted to this reaction + */ + count: number + + /** + * Whether the author of the comment has reacted to this reaction + */ + authorHasReacted: boolean +} + /** * A set of text extracted from the context of the prompt execution */ @@ -673,6 +722,11 @@ interface ExpansionVariables { * Root prompt generation context */ generator: ChatGenerationContext + + /** + * Comments generated in the context of this prompt + */ + comments: Comment[] } type MakeOptional = Partial> & Omit From c0b3997d4880629f45b3ecad26a23823181387a8 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Thu, 29 Aug 2024 14:15:25 -0700 Subject: [PATCH 3/4] load comments from env --- docs/genaisrc/genaiscript.d.ts | 16 ++++++++++++-- genaisrc/genaiscript.d.ts | 16 ++++++++++++-- packages/core/src/comments.ts | 21 +++++++++++++++++++ packages/core/src/genaisrc/genaiscript.d.ts | 16 ++++++++++++-- packages/core/src/promptrunner.ts | 3 +++ packages/core/src/types/prompt_template.d.ts | 16 ++++++++++++-- packages/sample/genaisrc/genaiscript.d.ts | 16 ++++++++++++-- .../sample/genaisrc/node/genaiscript.d.ts | 16 ++++++++++++-- .../sample/genaisrc/python/genaiscript.d.ts | 16 ++++++++++++-- .../sample/genaisrc/style/genaiscript.d.ts | 16 ++++++++++++-- packages/sample/src/aici/genaiscript.d.ts | 16 ++++++++++++-- packages/sample/src/errors/genaiscript.d.ts | 16 ++++++++++++-- packages/sample/src/makecode/genaiscript.d.ts | 16 ++++++++++++-- packages/sample/src/tla/genaiscript.d.ts | 16 ++++++++++++-- packages/sample/src/vision/genaiscript.d.ts | 16 ++++++++++++-- packages/vscode/src/comments.ts | 14 ++++++------- slides/genaisrc/genaiscript.d.ts | 16 ++++++++++++-- 17 files changed, 227 insertions(+), 35 deletions(-) create mode 100644 packages/core/src/comments.ts diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/comments.ts b/packages/core/src/comments.ts new file mode 100644 index 0000000000..2116890a33 --- /dev/null +++ b/packages/core/src/comments.ts @@ -0,0 +1,21 @@ +import { JSONLineCache } from "./cache" +import { COMMENTS_CACHE } from "./constants" + +export interface CommentKey { + uri: string + line: number + source: string +} + +export function commentsCache() { + const cache = JSONLineCache.byName( + COMMENTS_CACHE + ) + return cache +} + +export async function commentsForSource(source: string) { + const cache = commentsCache() + const entries = await cache.entries() + return entries.map(({ val }) => val).filter((c) => c.source === source) +} diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/core/src/promptrunner.ts b/packages/core/src/promptrunner.ts index db4c2482b2..6e3e40781e 100644 --- a/packages/core/src/promptrunner.ts +++ b/packages/core/src/promptrunner.ts @@ -22,6 +22,7 @@ import { validateJSONWithSchema } from "./schema" import { YAMLParse } from "./yaml" import { expandTemplate } from "./expander" import { resolveLanguageModel } from "./lm" +import { commentsCache, commentsForSource } from "./comments" async function resolveExpansionVars( project: Project, @@ -57,6 +58,7 @@ async function resolveExpansionVars( secrets[secret] = value } else trace.error(`secret \`${secret}\` not found`) } + const comments = await commentsForSource(template.id) const res: Partial = { dir: ".", files, @@ -67,6 +69,7 @@ async function resolveExpansionVars( }, vars: attrs, secrets, + comments, } return res } diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 4a7d5df957..577815b044 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -614,6 +614,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -698,9 +710,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit diff --git a/packages/vscode/src/comments.ts b/packages/vscode/src/comments.ts index 9366ebdb30..461e95c6dd 100644 --- a/packages/vscode/src/comments.ts +++ b/packages/vscode/src/comments.ts @@ -1,8 +1,8 @@ import * as vscode from "vscode" import { ExtensionState } from "./state" -import { COMMENTS_CACHE, TOOL_ID, TOOL_NAME } from "../../core/src/constants" -import { JSONLineCache } from "../../core/src/cache" +import { TOOL_ID, TOOL_NAME } from "../../core/src/constants" import { toRange } from "./edit" +import { commentsCache } from "../../core/src/comments" export interface CommentKey {} @@ -34,18 +34,18 @@ export function activateComments(state: ExtensionState) { `${TOOL_NAME} comments` ) subscriptions.push(controller) - const cache = JSONLineCache.byName(COMMENTS_CACHE) + const cache = commentsCache() vscode.workspace.onDidChangeWorkspaceFolders(async () => { const entries = await cache.entries() for (const { val } of entries) { - const { uri, range, comments, label, resolved } = val + const { filename, line, comments, label, resolved } = val const thread = controller.createCommentThread( - vscode.Uri.parse(uri), - toRange(range), + state.host.toUri(filename), + toRange([line, line]), comments.map(commentToVSCodeComment) ) - thread.label = val.label + thread.label = label thread.canReply = true thread.state = resolved ? vscode.CommentThreadState.Resolved diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index 9f20910cad..f59e60a5ca 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -640,6 +640,18 @@ interface ChatParticipant { options: ChatParticipantOptions } +/** + * A comment thread + */ +interface CommentThread { + filename: string + source: string + line: number + comments: Comment[] + label?: string + resolved?: boolean +} + /** * A comment */ @@ -724,9 +736,9 @@ interface ExpansionVariables { generator: ChatGenerationContext /** - * Comments generated in the context of this prompt + * Comment threads generated in the context of this prompt */ - comments: Comment[] + comments: CommentThread[] } type MakeOptional = Partial> & Omit From 9317599228a15cbe951e4552e89c7a867f61c140 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Thu, 29 Aug 2024 18:50:50 -0700 Subject: [PATCH 4/4] Add snapshot option to comments cache for thread state preservation during workspace changes --- packages/core/src/cache.ts | 10 +++++++--- packages/core/src/comments.ts | 5 +++-- packages/vscode/src/comments.ts | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core/src/cache.ts b/packages/core/src/cache.ts index 4589b00903..3de2147d92 100644 --- a/packages/core/src/cache.ts +++ b/packages/core/src/cache.ts @@ -13,12 +13,16 @@ export class JSONLineCache extends EventTarget { super() } - static byName(name: string): JSONLineCache { + static byName( + name: string, + options?: { snapshot?: boolean } + ): JSONLineCache { + const { snapshot } = options || {} name = name.replace(/[^a-z0-9_]/gi, "_") const key = "cacheKV." + name - if (host.userState[key]) return host.userState[key] + if (!snapshot && host.userState[key]) return host.userState[key] const r = new JSONLineCache(name) - host.userState[key] = r + if (!snapshot) host.userState[key] = r return r } diff --git a/packages/core/src/comments.ts b/packages/core/src/comments.ts index 2116890a33..38af1b4631 100644 --- a/packages/core/src/comments.ts +++ b/packages/core/src/comments.ts @@ -7,9 +7,10 @@ export interface CommentKey { source: string } -export function commentsCache() { +export function commentsCache(options?: { snapshot?: boolean }) { const cache = JSONLineCache.byName( - COMMENTS_CACHE + COMMENTS_CACHE, + options ) return cache } diff --git a/packages/vscode/src/comments.ts b/packages/vscode/src/comments.ts index 461e95c6dd..f9bb853035 100644 --- a/packages/vscode/src/comments.ts +++ b/packages/vscode/src/comments.ts @@ -34,9 +34,10 @@ export function activateComments(state: ExtensionState) { `${TOOL_NAME} comments` ) subscriptions.push(controller) - const cache = commentsCache() + const threads: vscode.CommentThread[] = [] vscode.workspace.onDidChangeWorkspaceFolders(async () => { + const cache = commentsCache({ snapshot: true }) const entries = await cache.entries() for (const { val } of entries) { const { filename, line, comments, label, resolved } = val @@ -45,6 +46,8 @@ export function activateComments(state: ExtensionState) { toRange([line, line]), comments.map(commentToVSCodeComment) ) + subscriptions.push(thread) + threads.push(thread) thread.label = label thread.canReply = true thread.state = resolved