Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type { SessionRoute } from "./context/route"
import { Session as SessionApi } from "@/session"
import { TuiEvent } from "./event"
import { KVProvider, useKV } from "./context/kv"
import { iife } from "@/util/iife"

export function tui(input: {
url: string
Expand All @@ -40,9 +41,9 @@ export function tui(input: {
return new Promise<void>((resolve) => {
const routeData: Route | undefined = input.sessionID
? {
type: "session",
sessionID: input.sessionID,
}
type: "session",
sessionID: input.sessionID,
}
: undefined

const onExit = async () => {
Expand Down Expand Up @@ -109,6 +110,7 @@ function App() {
const toast = useToast()
const [sessionExists, setSessionExists] = createSignal(false)
const { theme } = useTheme()
const sdk = useSDK()

useKeyboard(async (evt) => {
if (evt.meta && evt.name === "t") {
Expand Down Expand Up @@ -163,6 +165,57 @@ function App() {
dialog.clear()
},
},
{
title: "Create/update AGENTS.md",
value: "session.init",
keybind: "project_init",
onSelect: async () => {
const sessionID = await iife(async () => {
if (route.data.type === "session" && route.data.sessionID)
return route.data.sessionID
const response = await sdk.client.session.create({ throwOnError: true })
.catch((err) => {
return toast.show({
title: "Failed to create session",
message: err.message,
variant: "error",
})
})
const sessionID = response?.data.id
if (sessionID)
route.navigate({
type: "session",
sessionID,
})
return sessionID
})

if (!sessionID)
return toast.show({
message: "Failed to create session",
variant: "error",
})

const { modelID, providerID } = local.model.current()
sdk.client.session.init({
body: {
providerID,
modelID,
},
path: {
id: sessionID,
},
throwOnError: true,
}).catch((err) => {
toast.show({
title: "Failed to initialize session",
message: err.message,
variant: "error",
})
})
},
category: "Session",
},
{
title: "Switch model",
value: "model.list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ export function Autocomplete(props: {
description: "create a new session",
onSelect: () => command.trigger("session.new"),
},
{
display: "/init",
description: "create/update AGENTS.md",
onSelect: () => command.trigger("session.init"),
},
{
display: "/models",
description: "list models",
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ export namespace Config {
.describe("Insert newline in input"),
history_previous: z.string().optional().default("up").describe("Previous history item"),
history_next: z.string().optional().default("down").describe("Previous history item"),
project_init: z.string().optional().default("none").describe("Create or update AGENTS.md"),
})
.strict()
.meta({
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ export namespace Session {
sessionID: Identifier.schema("session"),
modelID: z.string(),
providerID: z.string(),
messageID: Identifier.schema("message"),
messageID: Identifier.schema("message").optional(),
}),
async (input) => {
await SessionPrompt.prompt({
sessionID: input.sessionID,
sessionID: input.sessionID ?? Identifier.ascending("message"),
messageID: input.messageID,
model: {
providerID: input.providerID,
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk/js/src/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export type KeybindsConfig = {
* Previous history item
*/
history_next?: string
/**
* Create or update AGENTS.md
*/
project_init?: string
}

export type AgentConfig = {
Expand Down Expand Up @@ -1697,7 +1701,7 @@ export type SessionInitData = {
body?: {
modelID: string
providerID: string
messageID: string
messageID?: string
}
path: {
/**
Expand Down