Skip to content

Commit eeaab6f

Browse files
ammar-agentammario
andauthored
🤖 feat: add mode="compact" for /compact operations (#200)
Enables users to customize AI compaction behavior via instruction files. ## What Changed **Backend accepts mode as string** - No hardcoded mode restrictions, allowing future flexibility without backend changes. **Frontend sends mode="compact"** - When users run `/compact`, the system now passes `mode: "compact"` to include mode-specific instructions from AGENTS.md. **Documentation** - Added example `Mode: Compact` section showing how users can customize what information is preserved during automatic conversation history compaction. ## Example Usage Add to `~/.cmux/AGENTS.md` or `<workspace>/AGENTS.md`: ```markdown ## Mode: Compact When compacting conversation history: - Preserve key decisions and their rationale - Keep code snippets that are still relevant - Maintain context about ongoing tasks - Be extremely concise—prioritize information density ``` When the user runs `/compact`, the AI will receive these additional instructions and follow them during summarization. ## Technical Notes - Backend now accepts `mode?: string` for flexibility - Frontend uses type-safe literal: `mode: "compact" as const` - Available modes: exec, plan, compact (extensible without backend changes) _Generated with `cmux`_ Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
1 parent 716637e commit eeaab6f

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

docs/instruction-files.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,25 @@ When planning:
3939
- Focus on goals, constraints, and trade-offs
4040
- Propose alternatives with pros/cons
4141
- Defer implementation detail unless asked
42+
43+
## Mode: Compact
44+
45+
When compacting conversation history:
46+
47+
- Preserve key decisions and their rationale
48+
- Keep code snippets that are still relevant
49+
- Maintain context about ongoing tasks
50+
- Be extremely concise—prioritize information density
4251
```
4352

53+
### Available modes
54+
55+
- **exec** - Default mode for normal operations
56+
- **plan** - Activated when the user toggles plan mode in the UI
57+
- **compact** - Automatically used during `/compact` operations to guide how the AI summarizes conversation history
58+
59+
Customizing the `compact` mode is particularly useful for controlling what information is preserved during automatic history compaction.
60+
4461
## Practical layout
4562

4663
```

src/components/ChatInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
625625
thinkingLevel: isAnthropic ? "off" : sendMessageOptions.thinkingLevel,
626626
toolPolicy: [{ regex_match: "compact_summary", action: "require" }],
627627
maxOutputTokens: parsed.maxOutputTokens, // Pass to model directly
628+
mode: "compact" as const, // Allow users to customize compaction behavior via Mode: compact in AGENTS.md
628629
});
629630

630631
if (!result.success) {

src/services/aiService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class AIService extends EventEmitter {
390390
* @param additionalSystemInstructions Optional additional system instructions to append
391391
* @param maxOutputTokens Optional maximum tokens for model output
392392
* @param cmuxProviderOptions Optional provider-specific options
393-
* @param mode Optional UI permission mode ("exec" | "plan") - affects system message
393+
* @param mode Optional mode name - affects system message via Mode: sections in AGENTS.md
394394
* @returns Promise that resolves when streaming completes or fails
395395
*/
396396
async streamMessage(
@@ -403,7 +403,7 @@ export class AIService extends EventEmitter {
403403
additionalSystemInstructions?: string,
404404
maxOutputTokens?: number,
405405
cmuxProviderOptions?: CmuxProviderOptions,
406-
mode?: "exec" | "plan"
406+
mode?: string
407407
): Promise<Result<void, SendMessageError>> {
408408
try {
409409
if (this.mockModeEnabled && this.mockScenarioPlayer) {

src/types/ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export interface SendMessageOptions {
140140
additionalSystemInstructions?: string;
141141
maxOutputTokens?: number;
142142
providerOptions?: CmuxProviderOptions;
143-
mode?: "exec" | "plan"; // UI permission mode
143+
mode?: string; // Mode name - frontend narrows to specific values, backend accepts any string
144144
}
145145

146146
// API method signatures (shared between main and preload)

0 commit comments

Comments
 (0)