Skip to content

Commit 0f6c270

Browse files
committed
fix(app): default project picker to home
1 parent 284214c commit 0f6c270

12 files changed

Lines changed: 90 additions & 20 deletions

File tree

‎packages/app/src/components/dialog-select-directory-v2.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useGlobal } from "@/context/global"
99
import { useLanguage } from "@/context/language"
1010
import { ServerConnection } from "@/context/server"
1111
import type { Path } from "@opencode-ai/sdk/v2/client"
12+
import { locationPath } from "@/utils/location-path"
1213
import {
1314
absoluteTreePath,
1415
activeTreeNavigation,
@@ -70,10 +71,15 @@ export function DialogSelectDirectoryV2(props: DialogSelectDirectoryV2Props) {
7071
const [fallbackPath] = createResource(
7172
() => (missingBase() ? true : undefined),
7273
async (): Promise<Path | undefined> => {
73-
if ((await sdk.protocol) !== "v1") return
74-
return sdk.client.path
74+
if ((await sdk.protocol) === "v1") {
75+
return sdk.client.path
76+
.get()
77+
.then((result) => result.data)
78+
.catch(() => undefined)
79+
}
80+
return sdk.api.location
7581
.get()
76-
.then((result) => result.data)
82+
.then(locationPath)
7783
.catch(() => undefined)
7884
},
7985
{ initialValue: undefined },

‎packages/app/src/components/dialog-select-directory.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ServerConnection } from "@/context/server"
1010
import { useGlobal } from "@/context/global"
1111
import { cleanPickerInput, createDirectorySearch, displayPickerPath } from "./directory-picker-domain"
1212
import type { Path } from "@opencode-ai/sdk/v2/client"
13+
import { locationPath } from "@/utils/location-path"
1314

1415
interface DialogSelectDirectoryProps {
1516
title?: string
@@ -63,10 +64,15 @@ export function DialogSelectDirectory(props: DialogSelectDirectoryProps) {
6364
const [fallbackPath] = createResource(
6465
() => (missingHome() ? true : undefined),
6566
async (): Promise<Path | undefined> => {
66-
if ((await sdk.protocol) !== "v1") return
67-
return sdk.client.path
67+
if ((await sdk.protocol) === "v1") {
68+
return sdk.client.path
69+
.get()
70+
.then((result) => result.data)
71+
.catch(() => undefined)
72+
}
73+
return sdk.api.location
6874
.get()
69-
.then((result) => result.data)
75+
.then(locationPath)
7076
.catch(() => undefined)
7177
},
7278
{ initialValue: undefined },

‎packages/app/src/context/global-sync/bootstrap.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,21 @@ describe("config queries", () => {
227227

228228
describe("query keys", () => {
229229
test("partitions identical directories by server scope", () => {
230-
const client = {} as Parameters<typeof loadPathQuery>[2]
230+
const location = {} as Parameters<typeof loadPathQuery>[2]
231+
const client = {} as Parameters<typeof loadPathQuery>[3]
231232
const api = {} as CatalogApi
232233
const remote = "https://debian.example" as typeof ServerScope.local
233234

234-
expect([...loadPathQuery(ServerScope.local, "/repo", client).queryKey]).toEqual(["local", "/repo", "path"])
235-
expect([...loadPathQuery(remote, "/repo", client).queryKey]).toEqual(["https://debian.example", "/repo", "path"])
235+
expect([...loadPathQuery(ServerScope.local, "/repo", location, client).queryKey]).toEqual([
236+
"local",
237+
"/repo",
238+
"path",
239+
])
240+
expect([...loadPathQuery(remote, "/repo", location, client).queryKey]).toEqual([
241+
"https://debian.example",
242+
"/repo",
243+
"path",
244+
])
236245
expect([...loadProvidersQuery(remote, null, api).queryKey]).toEqual(["https://debian.example", null, "providers"])
237246
})
238247

‎packages/app/src/context/global-sync/bootstrap.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { ScopedKey, type ServerScope } from "@/utils/server-scope"
4545
import { normalizeSessionInfo } from "@/utils/session"
4646
import type { ServerProtocol } from "@/utils/server-protocol"
4747
import type { ServerApi } from "@/utils/server"
48+
import { locationPath } from "@/utils/location-path"
4849

4950
type GlobalStore = {
5051
ready: boolean
@@ -119,6 +120,11 @@ type ProjectApi = {
119120
readonly current: (input?: ProjectCurrentInput) => Promise<ProjectCurrentOutput>
120121
}
121122

123+
type LocationApi = {
124+
readonly get: (input?: {
125+
readonly location?: { readonly directory?: string; readonly workspace?: string }
126+
}) => Promise<unknown>
127+
}
122128
type McpApi = ServerApi["mcp"]
123129
type PermissionApi = ServerApi["permission"]
124130
type QuestionApi = ServerApi["question"]
@@ -142,7 +148,7 @@ export const loadProjectsQuery = (scope: ServerScope, api: ProjectApi) =>
142148

143149
export async function bootstrapGlobal(input: {
144150
serverSDK: OpencodeClient
145-
serverAPI: CatalogApi & { readonly project: ProjectApi }
151+
serverAPI: CatalogApi & { readonly location: LocationApi; readonly project: ProjectApi }
146152
protocol?: Promise<ServerProtocol>
147153
scope: ServerScope
148154
requestFailedTitle: string
@@ -157,7 +163,10 @@ export async function bootstrapGlobal(input: {
157163
input.queryClient.fetchQuery(
158164
loadProvidersQuery(input.scope, null, input.serverAPI, input.serverSDK, input.protocol),
159165
),
160-
() => input.queryClient.fetchQuery(loadPathQuery(input.scope, null, input.serverSDK, input.protocol)),
166+
() =>
167+
input.queryClient.fetchQuery(
168+
loadPathQuery(input.scope, null, input.serverAPI.location, input.serverSDK, input.protocol),
169+
),
161170
() =>
162171
input.queryClient
163172
.fetchQuery(loadProjectsQuery(input.scope, input.serverAPI.project))
@@ -298,15 +307,17 @@ export const loadCommands = (
298307
export const loadPathQuery = (
299308
scope: ServerScope,
300309
directory: string | null,
310+
api: LocationApi,
301311
sdk: OpencodeClient,
302312
protocol?: Promise<ServerProtocol>,
303313
) =>
304314
queryOptions<Path>({
305315
queryKey: [scope, directory, "path"],
306316
queryFn: async () => {
307-
if ((await protocol) !== "v1")
308-
return { state: "", config: "", worktree: "", directory: directory ?? "", home: "" }
309-
return retry(() => sdk.path.get({ directory: directory ?? undefined }).then((result) => result.data!))
317+
if ((await protocol) === "v1") {
318+
return retry(() => sdk.path.get({ directory: directory ?? undefined }).then((result) => result.data!))
319+
}
320+
return retry(() => api.get({ location: directory ? { directory } : undefined })).then(locationPath)
310321
},
311322
})
312323

@@ -336,6 +347,7 @@ export async function bootstrapDirectory(input: {
336347
readonly agent: AgentListApi
337348
readonly command: CommandListApi
338349
readonly mcp: McpApi
350+
readonly location: LocationApi
339351
readonly permission: PermissionApi
340352
readonly project: ProjectApi
341353
readonly question: QuestionApi
@@ -418,7 +430,7 @@ export async function bootstrapDirectory(input: {
418430
!seededPath &&
419431
(() =>
420432
input.queryClient
421-
.ensureQueryData(loadPathQuery(input.scope, input.directory, input.sdk, input.protocol))
433+
.ensureQueryData(loadPathQuery(input.scope, input.directory, input.api.location, input.sdk, input.protocol))
422434
.then((data) => {
423435
const next = projectID(data.directory ?? input.directory, input.global.project)
424436
if (next) input.setStore("project", next)

‎packages/app/src/context/server-sync.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function makeQueryOptionsApi(
189189
providers: (directory: PathKey | null) =>
190190
loadProvidersQuery(scope, directory, serverAPI, directory ? sdkFor(directory) : serverSDK(), protocol),
191191
path: (directory: PathKey | null) =>
192-
loadPathQuery(scope, directory, directory ? sdkFor(directory) : serverSDK(), protocol),
192+
loadPathQuery(scope, directory, serverAPI.location, directory ? sdkFor(directory) : serverSDK(), protocol),
193193
agents: (directory: PathKey) => loadAgentsQuery(scope, directory, serverAPI.agent, sdkFor(directory), protocol),
194194
references: (directory: PathKey) =>
195195
loadReferencesQuery(scope, directory, serverAPI.reference, sdkFor(directory), protocol),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Location } from "@opencode-ai/schema/location"
2+
import type { Path } from "@opencode-ai/sdk/v2/client"
3+
import { Schema } from "effect"
4+
5+
export function locationPath(input: unknown): Path {
6+
const location = Schema.decodeUnknownSync(Location.Details)(input)
7+
return {
8+
state: "",
9+
config: "",
10+
worktree: location.project.directory,
11+
directory: location.directory,
12+
home: location.home,
13+
}
14+
}

‎packages/client/src/generated/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export type LocationGetOutput = {
113113
readonly directory: string
114114
readonly workspaceID?: string
115115
readonly project: { readonly id: string; readonly directory: string }
116+
readonly home: string
116117
}
117118

118119
export type AgentsListInput = {

‎packages/core/src/location.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Context, Effect, Layer } from "effect"
2-
import { Info, Ref, response } from "@opencode-ai/schema/location"
2+
import { Details, Info, Ref, response } from "@opencode-ai/schema/location"
33
import { Project } from "./project"
44
import { LayerNode } from "./effect/layer-node"
55
import { makeLocationNode, tags } from "./effect/app-node"
66

77
export * as Location from "./location"
88

9-
export { Info, Ref, response }
9+
export { Details, Info, Ref, response }
1010

1111
export interface Interface extends Info {
1212
readonly vcs?: Project.Vcs

‎packages/protocol/src/groups/location.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const locationQueryOpenApi = OpenApi.annotations({
2929
export const LocationGroup = HttpApiGroup.make("server.location").add(
3030
HttpApiEndpoint.get("location.get", "/api/location", {
3131
query: LocationQuery,
32-
success: Location.Info,
32+
success: Location.Details,
3333
})
3434
.annotateMerge(locationQueryOpenApi)
3535
.annotateMerge(

‎packages/schema/src/location.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export class Info extends Schema.Class<Info>("Location.Info")({
2020
}),
2121
}) {}
2222

23+
export class Details extends Schema.Class<Details>("Location.Details")({
24+
...Info.fields,
25+
home: AbsolutePath,
26+
}) {}
27+
2328
export function response<S extends Schema.Top>(data: S) {
2429
return Schema.Struct({ location: Info, data })
2530
}

0 commit comments

Comments
 (0)