feat(plugin): add vcs provider api (#44979)

This commit is contained in:
Shoubhit Dash
2026-08-25 19:37:06 +05:30
committed by GitHub
Unverified
parent 7601ab9fc4
commit 9c1787617c
22 changed files with 605 additions and 39 deletions
+1
View File
@@ -11,4 +11,5 @@ export { Model } from "@opencode-ai/schema/model"
export { Provider } from "@opencode-ai/schema/provider"
export { Reference } from "@opencode-ai/schema/reference"
export { Skill } from "@opencode-ai/schema/skill"
export { Vcs } from "@opencode-ai/schema/vcs"
export { WebSearch } from "@opencode-ai/schema/websearch"
+2
View File
@@ -15,6 +15,7 @@ import type { ShellDomain } from "./shell.js"
import type { SkillDomain } from "./skill.js"
import type { StorageDomain } from "./storage.js"
import type { ToolDomain } from "./tool.js"
import type { VcsDomain } from "./vcs.js"
import type { WebSearchDomain } from "./websearch.js"
export interface Context {
@@ -34,6 +35,7 @@ export interface Context {
readonly skill: SkillDomain
readonly storage: StorageDomain
readonly tool: ToolDomain
readonly vcs: VcsDomain
readonly websearch: WebSearchDomain
}
+45
View File
@@ -0,0 +1,45 @@
import type { VcsApi } from "@opencode-ai/client/effect/api"
import type { FileDiff } from "@opencode-ai/schema/file-diff"
import type { Vcs } from "@opencode-ai/schema/vcs"
import type { Effect } from "effect"
import type { Transform } from "./registration.js"
export interface VcsScope {
readonly directory: string
readonly worktree: string
readonly canonical: string
readonly store?: string
}
export interface VcsBranchesInput extends VcsScope {
readonly search?: string
readonly limit?: number
}
export interface VcsDiffInput extends VcsScope {
readonly mode: Vcs.Mode
readonly context: number
readonly maxOutputBytes: number
}
export interface VcsDefinition {
readonly id: string
readonly name: string
readonly info: (input: VcsScope) => Effect.Effect<Vcs.Info, unknown>
readonly branches: (input: VcsBranchesInput) => Effect.Effect<Vcs.BranchList, unknown>
readonly status: (input: VcsScope) => Effect.Effect<readonly Vcs.FileStatus[], unknown>
readonly diff: (input: VcsDiffInput) => Effect.Effect<readonly FileDiff.Info[], unknown>
}
export interface VcsDomain extends VcsApi<unknown> {
readonly transform: Transform<VcsDraft>
readonly reload: () => Effect.Effect<void>
}
export interface VcsDraft {
add(definition: VcsDefinition): void
readonly default: {
get(): string | undefined
set(selection: string): void
}
}
+25
View File
@@ -84,6 +84,7 @@ export function fromPromise(plugin: Plugin) {
const ReferenceEndpoints = ClientApi.groups["server.reference"].endpoints
const SessionEndpoints = ClientApi.groups["server.session"].endpoints
const SkillEndpoints = ClientApi.groups["server.skill"].endpoints
const VcsEndpoints = ClientApi.groups["server.vcs"].endpoints
const WebSearchEndpoints = ClientApi.groups["server.websearch"].endpoints
const context = yield* Effect.context<Scope.Scope>()
@@ -295,6 +296,30 @@ export function fromPromise(plugin: Plugin) {
hook: (name, callback) =>
register(host.tool.hook(name, (event) => Effect.promise(() => Promise.resolve(callback(event))))),
},
vcs: {
get: adaptApiMethod(VcsEndpoints["vcs.get"], host.vcs.get),
branches: adaptApiMethod(VcsEndpoints["vcs.branches"], host.vcs.branches),
status: adaptApiMethod(VcsEndpoints["vcs.status"], host.vcs.status),
diff: adaptApiMethod(VcsEndpoints["vcs.diff"], host.vcs.diff),
reload: () => run(host.vcs.reload()),
transform: (callback) =>
register(
host.vcs.transform((draft) => {
callback({
add: (definition) =>
draft.add({
id: definition.id,
name: definition.name,
info: (input) => attempt((signal) => definition.info(input, { signal })),
branches: (input) => attempt((signal) => definition.branches(input, { signal })),
status: (input) => attempt((signal) => definition.status(input, { signal })),
diff: (input) => attempt((signal) => definition.diff(input, { signal })),
}),
default: draft.default,
})
}),
),
},
websearch: {
providers: adaptApiMethod(WebSearchEndpoints["websearch.providers"], host.websearch.providers),
query: adaptApiMethod(WebSearchEndpoints["websearch.query"], host.websearch.query),
+1
View File
@@ -12,4 +12,5 @@ export { Model } from "@opencode-ai/schema/model"
export { Provider } from "@opencode-ai/schema/provider"
export { Reference } from "@opencode-ai/schema/reference"
export { Skill } from "@opencode-ai/schema/skill"
export { Vcs } from "@opencode-ai/schema/vcs"
export { WebSearch } from "@opencode-ai/schema/websearch"
+2
View File
@@ -14,6 +14,7 @@ import type { ShellDomain } from "./shell.js"
import type { SkillDomain } from "./skill.js"
import type { StorageDomain } from "./storage.js"
import type { ToolDomain } from "./tool.js"
import type { VcsDomain } from "./vcs.js"
import type { WebSearchDomain } from "./websearch.js"
export interface Context {
@@ -33,6 +34,7 @@ export interface Context {
readonly skill: SkillDomain
readonly storage: StorageDomain
readonly tool: ToolDomain
readonly vcs: VcsDomain
readonly websearch: WebSearchDomain
}
+44
View File
@@ -0,0 +1,44 @@
import type { VcsApi } from "@opencode-ai/client/promise/api"
import type { FileDiff } from "@opencode-ai/schema/file-diff"
import type { Vcs } from "@opencode-ai/schema/vcs"
import type { Transform } from "./registration.js"
export interface VcsScope {
readonly directory: string
readonly worktree: string
readonly canonical: string
readonly store?: string
}
export interface VcsBranchesInput extends VcsScope {
readonly search?: string
readonly limit?: number
}
export interface VcsDiffInput extends VcsScope {
readonly mode: Vcs.Mode
readonly context: number
readonly maxOutputBytes: number
}
export interface VcsDefinition {
readonly id: string
readonly name: string
readonly info: (input: VcsScope, context: { readonly signal: AbortSignal }) => Promise<Vcs.Info>
readonly branches: (input: VcsBranchesInput, context: { readonly signal: AbortSignal }) => Promise<Vcs.BranchList>
readonly status: (input: VcsScope, context: { readonly signal: AbortSignal }) => Promise<readonly Vcs.FileStatus[]>
readonly diff: (input: VcsDiffInput, context: { readonly signal: AbortSignal }) => Promise<readonly FileDiff.Info[]>
}
export interface VcsDomain extends VcsApi {
readonly transform: Transform<VcsDraft>
readonly reload: () => Promise<void>
}
export interface VcsDraft {
add(definition: VcsDefinition): void
readonly default: {
get(): string | undefined
set(selection: string): void
}
}