scaffolding for checkpoints

This commit is contained in:
Andrew Pareles 2025-03-30 21:30:01 -07:00
parent 878a439acd
commit 7c0ba71314
2 changed files with 39 additions and 7 deletions

View file

@ -76,18 +76,19 @@ type ThreadType = {
createdAt: string; // ISO string
lastModified: string; // ISO string
messages: ChatMessage[];
currentHistoryIdx: number | null; // index in messages, ALWAYS points to a LLMHistoryEntry or UserHistoryEntry, or -1 if no changes. current code is inclusive of the current index's change
// this doesn't need to go in a state object, but feels right
state: {
stagingSelections: StagingSelectionItem[];
focusedMessageIdx: number | undefined; // index of the message that is being edited (undefined if none)
focusedMessageIdx: number | undefined; // index of the user message that is being edited (undefined if none)
linksOfMessageIdx: { // eg. link = linksOfMessageIdx[4]['RangeFunction']
[messageIdx: number]: {
[codespanName: string]: CodespanLocationLink
}
}
isCheckedOfSelectionId: { [selectionId: string]: boolean }; // TODO
}
};
}
type ChatThreads = {
@ -97,7 +98,6 @@ type ChatThreads = {
export const defaultThreadState: ThreadType['state'] = {
stagingSelections: [],
focusedMessageIdx: undefined,
isCheckedOfSelectionId: {},
linksOfMessageIdx: {},
}
@ -130,7 +130,8 @@ const newThreadObject = () => {
lastModified: now,
messages: [],
state: defaultThreadState,
} satisfies ChatThreads[string]
currentHistoryIdx: null,
} satisfies ThreadType
}
@ -943,6 +944,9 @@ class ChatThreadService extends Disposable implements IChatThreadService {
}
async callWhenJumpBackToIdx(toIdx: number) {
// TODO!!!
}
@ -1251,7 +1255,20 @@ class ChatThreadService extends Disposable implements IChatThreadService {
// add the current file as a staging selection
const model = this._codeEditorService.getActiveCodeEditor()?.getModel()
if (model) {
this._setCurrentThreadState({ ...defaultThreadState, stagingSelections: [{ type: 'File', fileURI: model.uri, language: model.getLanguageId(), selectionStr: null, range: null, state: { isOpened: false, wasAddedAsCurrentFile: true } }] })
this._setCurrentThreadState({
...defaultThreadState,
stagingSelections: [{
type: 'File',
fileURI: model.uri,
language: model.getLanguageId(),
selectionStr: null,
range: null,
state: {
isOpened: false,
wasAddedAsCurrentFile: true
}
}]
})
}
return;
}

View file

@ -24,6 +24,18 @@ export type ToolRequestApproval<T extends ToolName> = {
id: string; // proposed tool's id
}
// checkpoints
export type LLMHistoryEntry = { // ALWAYS comes right after a {role:'tool', name:'edit'} message
role: 'LLM_changes';
afterStrOfURI: { [fsPath: string]: string };
}
export type UserHistoryEntry = { // ALWAYS comes right before a {role:'user'} message, or if it's the last message (w/o a user message yet)
role: 'user_changes';
afterStrOfURI: { [fsPath: string]: string };
}
// WARNING: changing this format is a big deal!!!!!! need to migrate old format to new format on users' computers so people don't get errors.
export type ChatMessage =
| {
@ -44,6 +56,8 @@ export type ChatMessage =
}
| ToolMessage<ToolName>
| ToolRequestApproval<ToolName>
| LLMHistoryEntry // invisible
| UserHistoryEntry // invisible
// one of the square items that indicates a selection in a chat bubble (NOT a file, a Selection of text)
@ -75,6 +89,7 @@ export type StagingSelectionItem = CodeSelection | FileSelection
// a link to a symbol (an underlined link to a piece of code)
export type CodespanLocationLink = {
uri: URI, // we handle serialization for this
displayText: string,