-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(kilo-vscode): migrate legacy sessions into new extension #7924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
d01d373
feat(vscode): detect sessions in old extension
imanolmzd-svg 5742354
feat(vscode): added session types
imanolmzd-svg 3b3813b
feat(cli): add endpoints for inserting a session
imanolmzd-svg cb0f039
feat(vscode): use session types from sdk for parsing
imanolmzd-svg 389db69
feat(kilo-vscode): parsing session project
imanolmzd-svg 35efa92
feat(vscode): parse legacy session details
imanolmzd-svg 722723a
feat(kilo-vscode): refactoring
imanolmzd-svg 01d640c
feat(vscode): parse legacy session messages
imanolmzd-svg a0525c8
feat(vscode): parse legacy session parts
imanolmzd-svg 025ff71
feat(vscode): added testing files and id creation
imanolmzd-svg 515fe87
feat(vscode): merge tool parts on imported session
imanolmzd-svg b1a1bdb
feat(vscode): session message part refactoring
imanolmzd-svg ee84ada
feat(vscode): cover provider-specific reasoning parts on session migr…
imanolmzd-svg 5003b56
feat(kilo-vscode): handle completion result parts
imanolmzd-svg d6f1469
feat: type hardening on session migration
imanolmzd-svg 29fbe67
feat(kilo-vscode): create tool part correctly
imanolmzd-svg 04c4e7e
feat(kilo-vscode): adjust session part processing
imanolmzd-svg da7eb2e
feat(vscode): persist migrated session in kilo.db
imanolmzd-svg a699aed
feat(vscode): add error handling to session migration
imanolmzd-svg 6bd734f
feat(vscode): add directory field to session migration
imanolmzd-svg 604526a
feat(kilo-vscode): display completion check on session migration
imanolmzd-svg d900359
feat(vscode): prevent migrating sessions twice
imanolmzd-svg eab2e4b
feat(cli): use correct project id when inserting migrated session
imanolmzd-svg 5a6b0de
feat(kilo-vscode): Use correct project id for session migration
imanolmzd-svg 7be4ba1
feat(kilo-vscode): load sessions on migration complete
imanolmzd-svg 982ca47
feat(kilo-vscode): ignore environment details user part when migratin…
imanolmzd-svg 8e4ec58
feat(cli): create project details following current backend logic
imanolmzd-svg 309ed8e
feat(kilo-vscode): cleaner messages without environment_details parts
imanolmzd-svg 70e5d51
feat(kilo-vscode): refactoring
imanolmzd-svg 143dd77
feat(kilo-vscode): refactoring and organization
imanolmzd-svg 386596c
feat(kilo-vscode): method renaming to improve clarity
imanolmzd-svg 89d7fee
feat(kilo-vscode): added session migration test strategy
imanolmzd-svg 398872d
test(kilo-vscode): implement legacy migration unit tests for all migr…
imanolmzd-svg d04cba6
style(kilo-vscode): apply prettier formatting across legacy migration…
imanolmzd-svg e5e7b01
Merge branch 'main' into imanol/migration
imanolmzd-svg 9f10736
fix(legacy-migration): filter out non-user/assistant entries before p…
imanolmzd-svg 48634f9
refactor(parts): skip part generation for non-conversational message …
imanolmzd-svg f064555
fix(ids): use semantic kind strings to prevent part ID collisions for…
imanolmzd-svg 23daed6
refactor(session-import): guard against empty worktree in legacy proj…
imanolmzd-svg 9eea8b0
perf(cli): cache MCP listTools results to avoid redundant RPCs per lo…
marius-kilocode 9852be9
fix(agent-manager): add retries to worktree cleanup for macOS .app bu…
marius-kilocode 20b15eb
chore: hide non-English localization files in GitHub PR diffs
kilo-code-bot[bot] cb297a4
feat(vscode): add Browse Marketplace button to MCP settings
kilo-code-bot[bot] a5a73d0
fix(vscode): preserve project directory when opening marketplace from…
kilo-code-bot[bot] c305c1e
feat(vscode): add Browse Marketplace button to agents and skills tabs
markijbema dca9f64
chore: update kilo-vscode visual regression baselines
github-actions[bot] 87bb29b
perf(agent-manager): extend slimPart to strip heavy tool metadata for…
marius-kilocode cfc2b53
Merge branch 'main' into imanol/migration
imanolmzd-svg bf75212
style(legacy-migration): reformat long reasoning push call for readab…
imanolmzd-svg 140ed5b
refactor(legacy-migration): filter non-user/assistant entries before …
imanolmzd-svg 631c78c
Merge branch 'main' into imanol/migration
imanolmzd-svg e7d3692
Merge branch 'main' into imanol/migration
imanolmzd-svg 2617f74
fix(legacy-migration): add `_migrated_` infix to generated IDs
imanolmzd-svg e93413c
refactor(legacy-migration): consolidate conversation parsing into `pa…
imanolmzd-svg d9493c7
fix(parts-builder): remove `toTextWithinMessage` and use `toText` dir…
imanolmzd-svg 26b9d4e
fix(parts-builder): skip provider-specific reasoning when explicit re…
imanolmzd-svg 2360ee7
test(legacy-migration): add coverage for edge cases in parts and tool…
imanolmzd-svg b7142f2
Merge branch 'main' into imanol/migration
imanolmzd-svg ab21a1b
feat(legacy-migration): remove session migration tracking from global…
imanolmzd-svg fddf23f
fix(session-import): skip duplicate session imports and child data
imanolmzd-svg 97c8037
refactor(parts-builder): mark legacy system error text parts as ignored
imanolmzd-svg ca717f7
feat(parts-util): extract feedback text from tool_result content into…
imanolmzd-svg e33e581
fix: formatting
imanolmzd-svg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/kilo-vscode/src/legacy-migration/sessions/lib/ids.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { createHash } from "node:crypto" | ||
|
|
||
| export function createProjectID(worktree?: string) { | ||
| return hash(worktree ?? "") | ||
| } | ||
|
|
||
| export function createSessionID(id: string) { | ||
| return prefixed("ses", id) | ||
| } | ||
|
|
||
| export function createMessageID(id: string, index: number) { | ||
| return prefixed("msg", `${id}:${index}`) | ||
| } | ||
|
|
||
| export function createPartID(id: string, index: number, part: number) { | ||
| return prefixed("prt", `${id}:${index}:${part}`) | ||
| } | ||
|
|
||
| export function createExtraPartID(id: string, index: number, kind: string) { | ||
| return prefixed("prt", `${id}:${index}:${kind}`) | ||
| } | ||
|
|
||
| function prefixed(prefix: string, value: string) { | ||
| return `${prefix}_migrated_${hash(value).slice(0, 26)}` | ||
| } | ||
|
|
||
| function hash(value: string) { | ||
| return createHash("sha1").update(value).digest("hex") | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
packages/kilo-vscode/src/legacy-migration/sessions/lib/legacy-conversation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import * as path from "node:path" | ||
| import * as vscode from "vscode" | ||
| import type { LegacyApiMessage } from "./legacy-types" | ||
|
|
||
| export async function getApiConversationHistory(id: string, dir: string) { | ||
| const file = path.join(dir, id, "api_conversation_history.json") | ||
| return vscode.workspace.fs.readFile(vscode.Uri.file(file)) | ||
| } | ||
|
|
||
| export function parseFile(file: Uint8Array): LegacyApiMessage[] { | ||
| const text = Buffer.from(file).toString("utf8") | ||
| const json = JSON.parse(text) as unknown | ||
| if (!Array.isArray(json)) { | ||
| throw new Error("Legacy conversation history must be a JSON array") | ||
| } | ||
| return json.filter((entry): entry is LegacyApiMessage => Boolean(entry && typeof entry === "object")) | ||
| } |
28 changes: 28 additions & 0 deletions
28
packages/kilo-vscode/src/legacy-migration/sessions/lib/legacy-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type { Anthropic } from "@anthropic-ai/sdk" | ||
|
|
||
| export interface LegacyHistoryItem { | ||
| id: string | ||
| rootTaskId?: string | ||
| parentTaskId?: string | ||
| ts?: number | ||
| task?: string | ||
| workspace?: string | ||
| mode?: string | ||
| } | ||
|
|
||
| export type LegacyApiMessage = Anthropic.MessageParam & { | ||
| ts?: number | ||
| isSummary?: boolean | ||
| id?: string | ||
| type?: "reasoning" | ||
| summary?: unknown[] | ||
| encrypted_content?: string | ||
| text?: string | ||
| reasoning_details?: unknown[] | ||
| reasoning_content?: string | ||
| condenseId?: string | ||
| condenseParent?: string | ||
| truncationId?: string | ||
| truncationParent?: string | ||
| isTruncationMarker?: boolean | ||
| } |
82 changes: 82 additions & 0 deletions
82
packages/kilo-vscode/src/legacy-migration/sessions/lib/messages.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { KilocodeSessionImportMessageData as Message } from "@kilocode/sdk/v2" | ||
| import type { LegacyApiMessage, LegacyHistoryItem } from "./legacy-types" | ||
| import { createMessageID, createSessionID } from "./ids" | ||
|
|
||
| type Body = NonNullable<Message["body"]> | ||
| type Data = Body["data"] | ||
| type User = Extract<Data, { role: "user" }> | ||
| type Assistant = Extract<Data, { role: "assistant" }> | ||
|
|
||
| export function parseMessagesFromConversation( | ||
| conversation: LegacyApiMessage[], | ||
| id: string, | ||
| item?: LegacyHistoryItem, | ||
| ): Array<NonNullable<Message["body"]>> { | ||
| return conversation | ||
| .filter((entry) => entry.role === "user" || entry.role === "assistant") | ||
| .map((entry, index) => parseMessage(entry, index, id, item)) | ||
| .filter((message): message is NonNullable<Message["body"]> => Boolean(message)) | ||
| } | ||
|
|
||
| function parseMessage( | ||
| entry: LegacyApiMessage, | ||
| index: number, | ||
| id: string, | ||
| item?: LegacyHistoryItem, | ||
| ): NonNullable<Message["body"]> | undefined { | ||
| const created = entry.ts ?? item?.ts ?? 0 | ||
|
|
||
| if (entry.role === "user") { | ||
| const data: User = { | ||
| role: "user", | ||
| time: { created }, | ||
| agent: "user", | ||
| model: { | ||
| providerID: "legacy", | ||
| modelID: "legacy", | ||
| }, | ||
| } | ||
|
|
||
| return { | ||
| id: createMessageID(id, index), | ||
| sessionID: createSessionID(id), | ||
| timeCreated: created, | ||
| data, | ||
| } | ||
| } | ||
|
|
||
| if (entry.role === "assistant") { | ||
| const data: Assistant = { | ||
| role: "assistant", | ||
| time: { created, completed: created }, | ||
| parentID: index > 0 ? createMessageID(id, index - 1) : createMessageID(id, index), | ||
|
imanolmzd-svg marked this conversation as resolved.
|
||
| modelID: "legacy", | ||
| providerID: "legacy", | ||
| mode: item?.mode ?? "code", | ||
| agent: "main", | ||
| path: { | ||
| cwd: item?.workspace ?? "", | ||
| root: item?.workspace ?? "", | ||
| }, | ||
| cost: 0, | ||
| tokens: { | ||
| input: 0, | ||
| output: 0, | ||
| reasoning: 0, | ||
| cache: { | ||
| read: 0, | ||
| write: 0, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return { | ||
| id: createMessageID(id, index), | ||
| sessionID: createSessionID(id), | ||
| timeCreated: created, | ||
| data, | ||
| } | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
packages/kilo-vscode/src/legacy-migration/sessions/lib/parts/merge-tools.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { KilocodeSessionImportPartData as Part } from "@kilocode/sdk/v2" | ||
| import type { LegacyApiMessage } from "../legacy-types" | ||
| import { getText, getToolUse, isToolResult, record } from "./parts-util" | ||
|
|
||
| type Body = NonNullable<Part["body"]> | ||
| type Data = Body["data"] | ||
| type Tool = Extract<Data, { type: "tool" }> | ||
| type ToolCompleted = Extract<Tool["state"], { status: "completed" }> | ||
|
|
||
| // This takes the "tool started" half and the matching "tool finished" half, | ||
| // and merges both so the migrated session keeps one complete tool action. | ||
| export function mergeToolUseAndResult( | ||
| partID: string, | ||
| messageID: string, | ||
| sessionID: string, | ||
| created: number, | ||
| conversation: LegacyApiMessage[], | ||
| result: { type?: string; tool_use_id?: string; content?: unknown }, | ||
| ): NonNullable<Part["body"]> | undefined { | ||
| const tool = getToolUseFromConversation(conversation, result.tool_use_id) | ||
| if (!tool) return undefined | ||
| const callID = typeof tool.id === "string" ? tool.id : partID | ||
| const name = typeof tool.name === "string" ? tool.name : "unknown" | ||
| const output = getText(result.content) ?? name | ||
| const state: ToolCompleted = { | ||
| status: "completed", | ||
| input: record(tool.input), | ||
| output, | ||
| title: name, | ||
| metadata: {}, | ||
| time: { | ||
| start: created, | ||
| end: created, | ||
| }, | ||
| } | ||
|
|
||
| const data: Tool = { | ||
| type: "tool", | ||
| callID, | ||
| tool: name, | ||
| state, | ||
| } | ||
|
|
||
| return { | ||
| id: partID, | ||
| messageID, | ||
| sessionID, | ||
| timeCreated: created, | ||
| data, | ||
| } | ||
| } | ||
|
|
||
| export function thereIsNoToolResult(conversation: LegacyApiMessage[], id: string | undefined) { | ||
| return !conversation.some( | ||
| (entry) => | ||
| Array.isArray(entry.content) && entry.content.some((part) => isToolResult(part) && part.tool_use_id === id), | ||
| ) | ||
| } | ||
|
|
||
| function getToolUseFromConversation(conversation: LegacyApiMessage[], id: string | undefined) { | ||
| for (const entry of conversation) { | ||
| const tool = getToolUse(entry, id) | ||
| if (tool) return tool | ||
| } | ||
| return undefined | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.