|
@@ -7,6 +7,7 @@ import { Log } from "../util/log"
|
|
|
import { Flag } from "@/flag/flag"
|
|
import { Flag } from "@/flag/flag"
|
|
|
import { Session } from "../session"
|
|
import { Session } from "../session"
|
|
|
import { work } from "../util/queue"
|
|
import { work } from "../util/queue"
|
|
|
|
|
+import { fn } from "@opencode-ai/util/fn"
|
|
|
|
|
|
|
|
export namespace Project {
|
|
export namespace Project {
|
|
|
const log = Log.create({ service: "project" })
|
|
const log = Log.create({ service: "project" })
|
|
@@ -14,8 +15,9 @@ export namespace Project {
|
|
|
.object({
|
|
.object({
|
|
|
id: z.string(),
|
|
id: z.string(),
|
|
|
worktree: z.string(),
|
|
worktree: z.string(),
|
|
|
- vcsDir: z.string().optional(),
|
|
|
|
|
vcs: z.literal("git").optional(),
|
|
vcs: z.literal("git").optional(),
|
|
|
|
|
+ name: z.string().optional(),
|
|
|
|
|
+ icon: z.string().optional(),
|
|
|
time: z.object({
|
|
time: z.object({
|
|
|
created: z.number(),
|
|
created: z.number(),
|
|
|
updated: z.number().optional(),
|
|
updated: z.number().optional(),
|
|
@@ -46,7 +48,6 @@ export namespace Project {
|
|
|
return project
|
|
return project
|
|
|
}
|
|
}
|
|
|
let worktree = path.dirname(git)
|
|
let worktree = path.dirname(git)
|
|
|
- const timer = log.time("git.rev-parse")
|
|
|
|
|
let id = await Bun.file(path.join(git, "opencode"))
|
|
let id = await Bun.file(path.join(git, "opencode"))
|
|
|
.text()
|
|
.text()
|
|
|
.then((x) => x.trim())
|
|
.then((x) => x.trim())
|
|
@@ -67,19 +68,12 @@ export namespace Project {
|
|
|
id = roots[0]
|
|
id = roots[0]
|
|
|
if (id) Bun.file(path.join(git, "opencode")).write(id)
|
|
if (id) Bun.file(path.join(git, "opencode")).write(id)
|
|
|
}
|
|
}
|
|
|
- timer.stop()
|
|
|
|
|
worktree = await $`git rev-parse --show-toplevel`
|
|
worktree = await $`git rev-parse --show-toplevel`
|
|
|
.quiet()
|
|
.quiet()
|
|
|
.nothrow()
|
|
.nothrow()
|
|
|
.cwd(worktree)
|
|
.cwd(worktree)
|
|
|
.text()
|
|
.text()
|
|
|
.then((x) => path.resolve(worktree, x.trim()))
|
|
.then((x) => path.resolve(worktree, x.trim()))
|
|
|
- const vcsDir = await $`git rev-parse --git-dir`
|
|
|
|
|
- .quiet()
|
|
|
|
|
- .nothrow()
|
|
|
|
|
- .cwd(worktree)
|
|
|
|
|
- .text()
|
|
|
|
|
- .then((x) => path.resolve(worktree, x.trim()))
|
|
|
|
|
const projectID = id || "global"
|
|
const projectID = id || "global"
|
|
|
const existing = id ? await Storage.read<Info>(["project", id]).catch(() => undefined) : undefined
|
|
const existing = id ? await Storage.read<Info>(["project", id]).catch(() => undefined) : undefined
|
|
|
if (!existing && id) {
|
|
if (!existing && id) {
|
|
@@ -89,7 +83,6 @@ export namespace Project {
|
|
|
...existing,
|
|
...existing,
|
|
|
id: projectID,
|
|
id: projectID,
|
|
|
worktree,
|
|
worktree,
|
|
|
- vcsDir,
|
|
|
|
|
vcs: "git",
|
|
vcs: "git",
|
|
|
time: {
|
|
time: {
|
|
|
created: Date.now(),
|
|
created: Date.now(),
|
|
@@ -135,4 +128,19 @@ export namespace Project {
|
|
|
const keys = await Storage.list(["project"])
|
|
const keys = await Storage.list(["project"])
|
|
|
return await Promise.all(keys.map((x) => Storage.read<Info>(x)))
|
|
return await Promise.all(keys.map((x) => Storage.read<Info>(x)))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ export const update = fn(
|
|
|
|
|
+ z.object({
|
|
|
|
|
+ projectID: z.string(),
|
|
|
|
|
+ name: z.string().optional(),
|
|
|
|
|
+ icon: z.string().optional(),
|
|
|
|
|
+ }),
|
|
|
|
|
+ async (input) => {
|
|
|
|
|
+ return await Storage.update<Info>(["project", input.projectID], (draft) => {
|
|
|
|
|
+ if (input.name !== undefined) draft.name = input.name
|
|
|
|
|
+ if (input.icon !== undefined) draft.icon = input.icon
|
|
|
|
|
+ draft.time.updated = Date.now()
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|