mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-01 15:32:11 +08:00
refactor(vscode): reuse Agent Manager diff scope helpers
This commit is contained in:
@@ -22,6 +22,14 @@ describe("agent-manager webview diff scope descriptors", () => {
|
||||
expect(descriptors[3]!.id).toBe("local#session:ses_abc")
|
||||
})
|
||||
|
||||
it("preserves legacy and malformed ids and parses the final separator", () => {
|
||||
expect(parseDiffId("local")).toEqual({ ctx: "local", scope: "branch" })
|
||||
expect(parseDiffId("wt_1#bogus")).toEqual({ ctx: "wt_1#bogus", scope: "branch" })
|
||||
expect(parseDiffId("wt_1#")).toEqual({ ctx: "wt_1#", scope: "branch" })
|
||||
expect(parseDiffId("wt#1#staged")).toEqual({ ctx: "wt#1", scope: "staged" })
|
||||
expect(parseDiffId("local#session:")).toEqual({ ctx: "local", scope: "session", sessionId: "" })
|
||||
})
|
||||
|
||||
it("round-trips the session descriptor id", () => {
|
||||
expect(parseDiffId(composeDiffId("wt_1", "session", "ses_abc"))).toEqual({
|
||||
ctx: "wt_1",
|
||||
|
||||
@@ -13,31 +13,15 @@
|
||||
import { createMemo, createSignal, type Accessor } from "solid-js"
|
||||
import type { DiffSourceDescriptor } from "../../src/diff/sources/types"
|
||||
|
||||
export type DiffScope = "branch" | "staged" | "unstaged" | "session"
|
||||
import { composeDiffId, DEFAULT_DIFF_SCOPE, type DiffScope } from "../../src/agent-manager/diff-scope"
|
||||
|
||||
export const DEFAULT_DIFF_SCOPE: DiffScope = "branch"
|
||||
|
||||
const SEP = "#"
|
||||
const SESSION_TOKEN = "session:"
|
||||
|
||||
export function composeDiffId(ctx: string, scope: DiffScope, sessionId?: string): string {
|
||||
if (scope === "session" && sessionId) return `${ctx}${SEP}${SESSION_TOKEN}${sessionId}`
|
||||
return `${ctx}${SEP}${scope}`
|
||||
}
|
||||
|
||||
export function parseDiffId(id: string): { ctx: string; scope: DiffScope; sessionId?: string } {
|
||||
const idx = id.lastIndexOf(SEP)
|
||||
if (idx === -1) return { ctx: id, scope: DEFAULT_DIFF_SCOPE }
|
||||
const token = id.slice(idx + SEP.length)
|
||||
const ctx = id.slice(0, idx)
|
||||
if (token.startsWith(SESSION_TOKEN)) return { ctx, scope: "session", sessionId: token.slice(SESSION_TOKEN.length) }
|
||||
if (isDiffScope(token)) return { ctx, scope: token }
|
||||
return { ctx: id, scope: DEFAULT_DIFF_SCOPE }
|
||||
}
|
||||
|
||||
export function isDiffScope(value: string): value is DiffScope {
|
||||
return value === "branch" || value === "staged" || value === "unstaged" || value === "session"
|
||||
}
|
||||
export {
|
||||
composeDiffId,
|
||||
parseDiffId,
|
||||
isDiffScope,
|
||||
DEFAULT_DIFF_SCOPE,
|
||||
type DiffScope,
|
||||
} from "../../src/agent-manager/diff-scope"
|
||||
|
||||
/**
|
||||
* The fixed scope descriptors for a context. `workspace` maps to the Branch
|
||||
|
||||
@@ -179,18 +179,6 @@
|
||||
"owner": "kilo-ui",
|
||||
"reason": "Existing duplication before the ratchet; remove through a focused, behavior-preserving extraction."
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"packages/kilo-vscode/src/agent-manager/diff-scope.ts",
|
||||
"packages/kilo-vscode/webview-ui/agent-manager/diff-scope-state.ts"
|
||||
],
|
||||
"fingerprint": "b4d0b555891237a8",
|
||||
"maxMatches": 1,
|
||||
"maxTokens": 233,
|
||||
"kind": "legacy",
|
||||
"owner": "kilo-vscode",
|
||||
"reason": "Existing duplication before the ratchet; remove through a focused, behavior-preserving extraction."
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"packages/kilo-vscode/src/agent-manager/orchestration-bridge.ts",
|
||||
|
||||
Reference in New Issue
Block a user