diff --git a/packages/client/src/generated/types.ts b/packages/client/src/generated/types.ts index 3b3188c8742a..95a20e6d04ab 100644 --- a/packages/client/src/generated/types.ts +++ b/packages/client/src/generated/types.ts @@ -669,6 +669,21 @@ export type SessionsContextOutput = { readonly reason: "auto" | "manual" readonly summary: string readonly recent: string + readonly diagnostics?: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } readonly id: string readonly metadata?: { readonly [x: string]: JsonValue } readonly time: { readonly created: number } @@ -1075,6 +1090,7 @@ export type SessionsHistoryOutput = { readonly sessionID: string readonly messageID: string readonly reason: "auto" | "manual" + readonly requested?: "prepend" | "suffix" } } | { @@ -1090,6 +1106,59 @@ export type SessionsHistoryOutput = { readonly reason: "auto" | "manual" readonly text: string readonly recent: string + readonly diagnostics?: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } + } + } + | { + readonly id: string + readonly metadata?: { readonly [x: string]: JsonValue } + readonly type: "session.next.compaction.failed" + readonly durable?: { readonly aggregateID: string; readonly seq: number; readonly version: number } + readonly location?: { readonly directory: string; readonly workspaceID?: string } + readonly data: { + readonly timestamp: number + readonly sessionID: string + readonly messageID: string + readonly reason: "auto" | "manual" + readonly failure: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + | "interrupted" + readonly diagnostics: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } } } | { @@ -1533,6 +1602,7 @@ export type SessionsEventsOutput = readonly sessionID: string readonly messageID: string readonly reason: "auto" | "manual" + readonly requested?: "prepend" | "suffix" } } | { @@ -1548,6 +1618,59 @@ export type SessionsEventsOutput = readonly reason: "auto" | "manual" readonly text: string readonly recent: string + readonly diagnostics?: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } + } + } + | { + readonly id: string + readonly metadata?: { readonly [x: string]: unknown } + readonly type: "session.next.compaction.failed" + readonly durable?: { readonly aggregateID: string; readonly seq: number; readonly version: number } + readonly location?: { readonly directory: string; readonly workspaceID?: string } + readonly data: { + readonly timestamp: number + readonly sessionID: string + readonly messageID: string + readonly reason: "auto" | "manual" + readonly failure: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + | "interrupted" + readonly diagnostics: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } } } | { @@ -1747,6 +1870,21 @@ export type SessionsMessageOutput = { readonly reason: "auto" | "manual" readonly summary: string readonly recent: string + readonly diagnostics?: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } readonly id: string readonly metadata?: { readonly [x: string]: JsonValue } readonly time: { readonly created: number } @@ -1919,6 +2057,21 @@ export type MessagesListOutput = { readonly reason: "auto" | "manual" readonly summary: string readonly recent: string + readonly diagnostics?: { + readonly requested?: "prepend" | "suffix" + readonly used?: "prepend" | "suffix" + readonly fallback?: + | "context" + | "plugin_prompt" + | "provider_tool" + | "provider_error" + | "tool_choice" + | "tool_call" + | "empty_summary" + | "invalid_summary" + readonly durationMs?: number + readonly tokens?: { readonly input?: number; readonly cached?: number; readonly output?: number } + } readonly id: string readonly metadata?: { readonly [x: string]: JsonValue } readonly time: { readonly created: number } diff --git a/packages/core/src/config/compaction.ts b/packages/core/src/config/compaction.ts index 3c5960c83556..e70d7b0cc832 100644 --- a/packages/core/src/config/compaction.ts +++ b/packages/core/src/config/compaction.ts @@ -8,6 +8,9 @@ export class Keep extends Schema.Class("ConfigV2.Compaction.Keep")({ }) {} export class Info extends Schema.Class("ConfigV2.Compaction")({ + mode: Schema.Literals(["prepend", "suffix"]).pipe(Schema.optional).annotate({ + description: "Compaction request mode. Suffix is experimental and off by default; prepend remains the default.", + }), auto: Schema.Boolean.pipe(Schema.optional), prune: Schema.Boolean.pipe(Schema.optional), keep: Keep.pipe(Schema.optional), diff --git a/packages/core/src/session/compaction-suffix.ts b/packages/core/src/session/compaction-suffix.ts new file mode 100644 index 000000000000..c55c25f80d0b --- /dev/null +++ b/packages/core/src/session/compaction-suffix.ts @@ -0,0 +1,131 @@ +export * as SessionCompactionSuffix from "./compaction-suffix" + +export const SUMMARY_OUTPUT_TOKENS = 4_096 + +export const SUMMARY_TEMPLATE = `Output exactly the Markdown structure shown inside