Repository navigation
feat(cli): enable /remember, /forget, /dream in ACP mode #4819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b073377
f4daa97
a9ba0ca
7940f31
843b82d
6221642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ export const dreamCommand: SlashCommand = { | |||||||||||||||||||||||||
| return t('Consolidate managed auto-memory topic files.'); | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| kind: CommandKind.BUILT_IN, | ||||||||||||||||||||||||||
| supportedModes: ['interactive', 'acp'] as const, | ||||||||||||||||||||||||||
| action: async (context) => { | ||||||||||||||||||||||||||
| const config = context.services.config; | ||||||||||||||||||||||||||
| if (!config) { | ||||||||||||||||||||||||||
|
|
@@ -26,25 +27,41 @@ export const dreamCommand: SlashCommand = { | |||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const projectRoot = config.getProjectRoot(); | ||||||||||||||||||||||||||
| const memoryRoot = getAutoMemoryRoot(projectRoot); | ||||||||||||||||||||||||||
| const transcriptDir = path.join( | ||||||||||||||||||||||||||
| new Storage(projectRoot).getProjectDir(), | ||||||||||||||||||||||||||
| 'chats', | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| const projectRoot = config.getProjectRoot(); | ||||||||||||||||||||||||||
| const memoryRoot = getAutoMemoryRoot(projectRoot); | ||||||||||||||||||||||||||
| const transcriptDir = path.join( | ||||||||||||||||||||||||||
| new Storage(projectRoot).getProjectDir(), | ||||||||||||||||||||||||||
| 'chats', | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const prompt = config | ||||||||||||||||||||||||||
| .getMemoryManager() | ||||||||||||||||||||||||||
| .buildConsolidationPrompt(memoryRoot, transcriptDir); | ||||||||||||||||||||||||||
| const prompt = config | ||||||||||||||||||||||||||
| .getMemoryManager() | ||||||||||||||||||||||||||
| .buildConsolidationPrompt(memoryRoot, transcriptDir); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| type: 'submit_prompt', | ||||||||||||||||||||||||||
| content: prompt, | ||||||||||||||||||||||||||
| onComplete: async () => { | ||||||||||||||||||||||||||
| await config | ||||||||||||||||||||||||||
| const recordDream = async () => | ||||||||||||||||||||||||||
| config | ||||||||||||||||||||||||||
| .getMemoryManager() | ||||||||||||||||||||||||||
| .writeDreamManualRun(projectRoot, config.getSessionId()); | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (context.executionMode === 'acp') { | ||||||||||||||||||||||||||
| recordDream().catch(() => {}); | ||||||||||||||||||||||||||
|
doudouOUC marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||
| return { type: 'submit_prompt', content: prompt }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| type: 'submit_prompt', | ||||||||||||||||||||||||||
| content: prompt, | ||||||||||||||||||||||||||
| onComplete: recordDream, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The
Suggested change
Suggested test: it('returns error when buildConsolidationPrompt throws', async () => {
const context = createMockCommandContext({
services: {
config: {
getProjectRoot: vi.fn().mockReturnValue(path.join('tmp', 'p')),
getMemoryManager: vi.fn().mockReturnValue({
buildConsolidationPrompt: vi.fn().mockImplementation(() => {
throw new Error('corrupted memory index');
}),
}),
getSessionId: vi.fn().mockReturnValue('session-1'),
},
},
});
const result = await dreamCommand.action?.(context, '');
expect(result).toEqual({
type: 'message',
messageType: 'error',
content: expect.stringContaining('corrupted memory index'),
});
});— qwen3.7-max via Qwen Code /review |
||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| type: 'message', | ||||||||||||||||||||||||||
| messageType: 'error', | ||||||||||||||||||||||||||
| content: t('Failed to process /dream: {{message}}', { | ||||||||||||||||||||||||||
| message: error instanceof Error ? error.message : String(error), | ||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { forgetCommand } from './forgetCommand.js'; | ||
| import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; | ||
|
|
||
| describe('forgetCommand', () => { | ||
| it('returns error when no argument is given', async () => { | ||
| const context = createMockCommandContext(); | ||
| const result = await forgetCommand.action?.(context, ''); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('/forget'), | ||
| }); | ||
| }); | ||
|
|
||
| it('returns error when config is not loaded', async () => { | ||
| const context = createMockCommandContext({ services: { config: null } }); | ||
| const result = await forgetCommand.action?.(context, 'something'); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('Config'), | ||
| }); | ||
| }); | ||
|
|
||
| it('returns info message on successful forget', async () => { | ||
| const context = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getProjectRoot: vi.fn().mockReturnValue('/tmp/test-project'), | ||
| getMemoryManager: vi.fn().mockReturnValue({ | ||
| selectForgetCandidates: vi | ||
| .fn() | ||
| .mockResolvedValue({ matches: [{ id: '1' }] }), | ||
| forgetMatches: vi | ||
| .fn() | ||
| .mockResolvedValue({ systemMessage: 'Forgot 1 entry.' }), | ||
| }), | ||
| }, | ||
| }, | ||
| }); | ||
| const result = await forgetCommand.action?.(context, 'old preference'); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Forgot 1 entry.', | ||
| }); | ||
| }); | ||
|
|
||
| it('returns fallback message when no entries match', async () => { | ||
| const context = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getProjectRoot: vi.fn().mockReturnValue('/tmp/test-project'), | ||
| getMemoryManager: vi.fn().mockReturnValue({ | ||
| selectForgetCandidates: vi.fn().mockResolvedValue({ matches: [] }), | ||
| forgetMatches: vi.fn().mockResolvedValue({ systemMessage: null }), | ||
| }), | ||
| }, | ||
| }, | ||
| }); | ||
| const result = await forgetCommand.action?.(context, 'nonexistent'); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: expect.stringContaining('nonexistent'), | ||
| }); | ||
| }); | ||
|
|
||
| it('returns error message when memory manager throws', async () => { | ||
| const context = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getProjectRoot: vi.fn().mockReturnValue('/tmp/test-project'), | ||
| getMemoryManager: vi.fn().mockReturnValue({ | ||
| selectForgetCandidates: vi | ||
| .fn() | ||
| .mockRejectedValue(new Error('EACCES: permission denied')), | ||
| }), | ||
| }, | ||
| }, | ||
| }); | ||
| const result = await forgetCommand.action?.(context, 'something'); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('EACCES: permission denied'), | ||
| }); | ||
| }); | ||
|
|
||
| it('declares acp in supportedModes', () => { | ||
| expect(forgetCommand.supportedModes).toEqual(['interactive', 'acp']); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||||||||||||
| /** | ||||||||||||||
| * @license | ||||||||||||||
| * Copyright 2026 Qwen Team | ||||||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| import { describe, expect, it, vi } from 'vitest'; | ||||||||||||||
| import { rememberCommand } from './rememberCommand.js'; | ||||||||||||||
| import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; | ||||||||||||||
|
|
||||||||||||||
| describe('rememberCommand', () => { | ||||||||||||||
| it('returns error when no argument is given', () => { | ||||||||||||||
| const context = createMockCommandContext(); | ||||||||||||||
| const result = rememberCommand.action?.(context, ''); | ||||||||||||||
| expect(result).toEqual({ | ||||||||||||||
| type: 'message', | ||||||||||||||
| messageType: 'error', | ||||||||||||||
| content: expect.stringContaining('/remember'), | ||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('returns error when config is not loaded', () => { | ||||||||||||||
| const context = createMockCommandContext({ services: { config: null } }); | ||||||||||||||
| const result = rememberCommand.action?.(context, 'something'); | ||||||||||||||
| expect(result).toEqual({ | ||||||||||||||
| type: 'message', | ||||||||||||||
| messageType: 'error', | ||||||||||||||
| content: expect.stringContaining('Config'), | ||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('returns submit_prompt for managed auto-memory', () => { | ||||||||||||||
| const context = createMockCommandContext({ | ||||||||||||||
| services: { | ||||||||||||||
| config: { | ||||||||||||||
| getManagedAutoMemoryEnabled: vi.fn().mockReturnValue(true), | ||||||||||||||
| getProjectRoot: vi.fn().mockReturnValue('/tmp/test-project'), | ||||||||||||||
| }, | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
| const result = rememberCommand.action?.(context, 'user prefers dark mode'); | ||||||||||||||
| expect(result).toMatchObject({ | ||||||||||||||
| type: 'submit_prompt', | ||||||||||||||
| content: expect.stringContaining('user prefers dark mode'), | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The managed-memory test only verifies the user fact (
Suggested change
Or split into two assertions: expect(result).toMatchObject({
type: 'submit_prompt',
content: expect.stringContaining('user prefers dark mode'),
});
expect((result as any).content).toContain('.qwen/memory');— qwen3.7-max via Qwen Code /review |
||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('returns submit_prompt for non-managed memory (QWEN.md fallback)', () => { | ||||||||||||||
| const context = createMockCommandContext({ | ||||||||||||||
| services: { | ||||||||||||||
| config: { | ||||||||||||||
| getManagedAutoMemoryEnabled: vi.fn().mockReturnValue(false), | ||||||||||||||
| getProjectRoot: vi.fn().mockReturnValue('/tmp/test-project'), | ||||||||||||||
| }, | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
| const result = rememberCommand.action?.(context, 'some fact'); | ||||||||||||||
| expect(result).toMatchObject({ | ||||||||||||||
| type: 'submit_prompt', | ||||||||||||||
| content: expect.stringContaining('some fact'), | ||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it('declares acp in supportedModes', () => { | ||||||||||||||
| expect(rememberCommand.supportedModes).toEqual(['interactive', 'acp']); | ||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.