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
8 changes: 8 additions & 0 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ export function Prompt(props: PromptProps) {
command: inputText,
})
setStore("mode", "normal")
} else if (inputText.match(/^\/(compact|summarize)(\s|$)/)) {
const args = inputText.replace(/^\/(compact|summarize)\s*/, "")
sdk.client.session.summarize({
sessionID,
modelID: selectedModel.modelID,
providerID: selectedModel.providerID,
args: args || undefined,
})
} else if (
inputText.startsWith("/") &&
iife(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ export namespace Server {
z.object({
providerID: z.string(),
modelID: z.string(),
args: z.string().optional(),
}),
),
async (c) => {
Expand All @@ -1076,6 +1077,7 @@ export namespace Server {
modelID: body.modelID,
},
auto: false,
args: body.args,
})
await SessionPrompt.loop(sessionID)
return c.json(true)
Expand Down
7 changes: 6 additions & 1 deletion packages/opencode/src/session/compaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export namespace SessionCompaction {
auto: boolean
}) {
const userMessage = input.messages.findLast((m) => m.info.id === input.parentID)!.info as MessageV2.User
const compactionPart = input.messages
.findLast((m) => m.info.id === input.parentID)!
.parts.find((p): p is MessageV2.CompactionPart => p.type === "compaction")
const agent = await Agent.get("compaction")
const model = agent.model
? await Provider.getModel(agent.model.providerID, agent.model.modelID)
Expand Down Expand Up @@ -129,7 +132,7 @@ export namespace SessionCompaction {
// Allow plugins to inject context for compaction
const compacting = await Plugin.trigger(
"experimental.session.compacting",
{ sessionID: input.sessionID },
{ sessionID: input.sessionID, args: compactionPart?.args },
{ context: [] },
)
const result = await processor.process({
Expand Down Expand Up @@ -195,6 +198,7 @@ export namespace SessionCompaction {
modelID: z.string(),
}),
auto: z.boolean(),
args: z.string().optional(),
}),
async (input) => {
const msg = await Session.updateMessage({
Expand All @@ -213,6 +217,7 @@ export namespace SessionCompaction {
sessionID: msg.sessionID,
type: "compaction",
auto: input.auto,
args: input.args,
})
},
)
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export namespace MessageV2 {
export const CompactionPart = PartBase.extend({
type: z.literal("compaction"),
auto: z.boolean(),
args: z.string().optional(),
}).meta({
ref: "CompactionPart",
})
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export interface Hooks {
* Called before session compaction starts. Allows plugins to append
* additional context to the compaction prompt.
*/
"experimental.session.compacting"?: (input: { sessionID: string }, output: { context: string[] }) => Promise<void>
"experimental.session.compacting"?: (
input: { sessionID: string; args?: string },
output: { context: string[] },
) => Promise<void>
"experimental.text.complete"?: (
input: { sessionID: string; messageID: string; partID: string },
output: { text: string },
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/js/src/v2/gen/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ export class Session extends HeyApiClient {
directory?: string
providerID?: string
modelID?: string
args?: string
},
options?: Options<never, ThrowOnError>,
) {
Expand All @@ -1139,6 +1140,7 @@ export class Session extends HeyApiClient {
{ in: "query", key: "directory" },
{ in: "body", key: "providerID" },
{ in: "body", key: "modelID" },
{ in: "body", key: "args" },
],
},
],
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export type CompactionPart = {
messageID: string
type: "compaction"
auto: boolean
args?: string
}

export type Part =
Expand Down Expand Up @@ -2733,6 +2734,7 @@ export type SessionSummarizeData = {
body?: {
providerID: string
modelID: string
args?: string
}
path: {
/**
Expand Down
Loading