Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export function Autocomplete(props: {
const results: AutocompleteOption[] = []
const s = session()
for (const command of sync.data.command) {
if (command.name === "finished") continue
results.push({
display: "/" + command.name + (command.mcp ? " (MCP)" : ""),
description: command.description,
Expand All @@ -271,6 +272,13 @@ export function Autocomplete(props: {
})
}
if (s) {
if (s.parentID) {
results.push({
display: "/finished",
description: "summarize work and return to parent session",
onSelect: () => command.trigger("session.finished"),
})
}
results.push(
{
display: "/undo",
Expand Down
55 changes: 54 additions & 1 deletion packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { Filesystem } from "@/util/filesystem"
import { PermissionPrompt } from "./permission"
import { DialogExportOptions } from "../../ui/dialog-export-options"
import { formatTranscript } from "../../util/transcript"
import { Identifier } from "@/id/id"

addDefaultParsers(parsers.parsers)

Expand Down Expand Up @@ -357,6 +358,58 @@ export function Session() {
dialog.clear()
},
},
{
title: "Finish subtask",
value: "session.finished",
category: "Session",
onSelect: (dialog) => {
const selectedModel = local.model.current()
if (!selectedModel) {
toast.show({
variant: "warning",
message: "Connect a provider to finish this session",
duration: 3000,
})
return
}
sdk.client.session.command({
sessionID: route.sessionID,
command: "finished",
arguments: "",
agent: local.agent.current().name,
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
messageID: Identifier.ascending("message"),
variant: local.model.variant.current(),
})
dialog.clear()
},
},
{
title: "Finish subtask",
value: "session.finished",
category: "Session",
onSelect: (dialog) => {
const selectedModel = local.model.current()
if (!selectedModel) {
toast.show({
variant: "warning",
message: "Connect a provider to finish this session",
duration: 3000,
})
return
}
sdk.client.session.command({
sessionID: route.sessionID,
command: "finished",
arguments: "",
agent: local.agent.current().name,
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
messageID: Identifier.ascending("message"),
variant: local.model.variant.current(),
})
dialog.clear()
},
},
{
title: "Unshare session",
value: "session.unshare",
Expand Down Expand Up @@ -1025,7 +1078,7 @@ export function Session() {
<PermissionPrompt request={permissions()[0]} />
</Show>
<Prompt
visible={!session().parentID && permissions().length === 0}
visible={permissions().length === 0}
ref={(r) => {
prompt = r
promptRef.set(r)
Expand Down
7 changes: 7 additions & 0 deletions packages/opencode/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export namespace Command {
export const Default = {
INIT: "init",
REVIEW: "review",
FINISHED: "finished",
} as const

const state = Instance.state(async () => {
Expand All @@ -76,6 +77,12 @@ export namespace Command {
subtask: true,
hints: hints(PROMPT_REVIEW),
},
[Default.FINISHED]: {
name: Default.FINISHED,
description: "summarize work and return to parent session",
template: "Summarize the work done in this session so far and finish the task.",
hints: [],
},
}

for (const [name, command] of Object.entries(cfg.command ?? {})) {
Expand Down
16 changes: 16 additions & 0 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,22 @@ export namespace SessionPrompt {
variant: input.variant,
})) as MessageV2.WithParts

if (input.command === "finished") {
const session = await Session.get(input.sessionID)
if (session.parentID) {
const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
await prompt({
sessionID: session.parentID,
parts: [
{
type: "text",
text: `Subtask finished with the following summary:\n\n${text}\n\nSession: ${session.id}`,
},
],
})
}
}

Bus.publish(Command.Event.Executed, {
name: input.command,
sessionID: input.sessionID,
Expand Down
Loading