From c15e53fb98ada5fb893d54bee8c3bd0160e7c2c2 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Tue, 3 Mar 2026 20:08:36 -0500 Subject: [PATCH] Add executionModel feature and refactor CLI into modular commands (#150) * Add executionModel feature and refactor CLI into modular commands - Add executionModel config option to memory plugin for specifying AI provider/model - Refactor monolithic CLI into modular commands: export, import, list, stats, cleanup - Add model selector UI with connected providers and recent models - Add showClear prop to Combobox component - Update documentation and bump version to 0.0.10 * Update execution model placeholder text * Update docs with new CLI commands and ocm-mem binary usage * Bump version to v0.9.06 * Add executionModel field to default config --- docs/features/memory.md | 68 +- .../settings/MemoryPluginConfig.tsx | 194 +++-- frontend/src/components/ui/combobox.tsx | 25 +- package.json | 3 +- packages/memory/README.md | 104 ++- packages/memory/config.json | 3 +- packages/memory/package.json | 8 +- packages/memory/src/agents/architect.ts | 2 +- packages/memory/src/cli/commands/cleanup.ts | 277 ++++++++ packages/memory/src/cli/commands/export.ts | 205 ++++++ packages/memory/src/cli/commands/import.ts | 279 ++++++++ packages/memory/src/cli/commands/list.ts | 116 +++ packages/memory/src/cli/commands/stats.ts | 136 ++++ packages/memory/src/cli/export.ts | 667 ------------------ packages/memory/src/cli/index.ts | 154 ++++ packages/memory/src/cli/utils.ts | 206 ++++++ packages/memory/src/index.ts | 16 +- packages/memory/src/setup.ts | 1 + packages/memory/src/types.ts | 1 + packages/memory/src/version.ts | 2 +- packages/memory/test/cli-export.test.ts | 34 +- shared/src/schemas/memory.ts | 1 + 22 files changed, 1719 insertions(+), 783 deletions(-) create mode 100644 packages/memory/src/cli/commands/cleanup.ts create mode 100644 packages/memory/src/cli/commands/export.ts create mode 100644 packages/memory/src/cli/commands/import.ts create mode 100644 packages/memory/src/cli/commands/list.ts create mode 100644 packages/memory/src/cli/commands/stats.ts delete mode 100644 packages/memory/src/cli/export.ts create mode 100644 packages/memory/src/cli/index.ts create mode 100644 packages/memory/src/cli/utils.ts diff --git a/docs/features/memory.md b/docs/features/memory.md index ebb39a23..71e92f5d 100644 --- a/docs/features/memory.md +++ b/docs/features/memory.md @@ -61,7 +61,8 @@ The file is only created if it does not already exist. The config is validated o "inlinePlanning": true, "maxContextTokens": 4000, "snapshotToKV": true - } + }, + "executionModel": "" } ``` @@ -105,6 +106,7 @@ Set `baseUrl` to point at any OpenAI-compatible self-hosted service (vLLM, Ollam | `compaction.inlinePlanning` | Include planning state in compaction context | `true` | | `compaction.maxContextTokens` | Max tokens for injected memory context | `4000` | | `compaction.snapshotToKV` | Save pre-compaction snapshot for recovery | `true` | +| `executionModel` | Model override for plan execution sessions (`provider/model`). Falls back to OpenCode's default model. | — | --- @@ -364,6 +366,8 @@ Create a new Code session and send an implementation plan as the first prompt. D Saves planning state (objective, phases, findings) for the Architect session, creates a new session via the OpenCode API, then sends the plan as the first message to the Code agent. Returns the session ID and title. Only the Architect agent has access to this tool — it is excluded from Code and Memory agents. +The model used for the new Code session is determined by `executionModel` in the plugin config (format: `provider/model`, e.g. `anthropic/claude-sonnet-4-20250514`). If not set, OpenCode's default model resolution is used — typically the `model` field from `opencode.json`. + --- ## Planning State @@ -564,6 +568,68 @@ The cleanup function is idempotent — calling it multiple times is safe. --- +## CLI + +The plugin includes the `ocm-mem` CLI for managing memories outside of OpenCode sessions. The CLI auto-detects the project ID from git and resolves the database path automatically. + +```bash +ocm-mem [options] +``` + +### Global Options + +| Flag | Description | +|------|-------------| +| `--db-path ` | Path to memory database | +| `--project, -p ` | Project name or SHA (auto-detected from git) | +| `--dir, -d ` | Git repo path for project detection | +| `--help, -h` | Show help | + +### Commands + +| Command | Description | +|---------|-------------| +| `export` | Export memories to file (JSON or Markdown) | +| `import` | Import memories from file | +| `list` | List projects with memory and session state counts | +| `stats` | Show memory statistics for a project | +| `cleanup` | Delete memories or session states by criteria | + +### Usage Examples + +```bash +# Export all memories as markdown +ocm-mem export --format markdown --output memories.md + +# Export filtered by scope +ocm-mem export --project my-project --scope convention + +# Import from JSON +ocm-mem import memories.json --project my-project + +# Import from Markdown, skip duplicate detection +ocm-mem import memories.md --project my-project --force + +# List all projects +ocm-mem list + +# Show stats for current project +ocm-mem stats + +# Preview cleanup of old memories (dry run) +ocm-mem cleanup --older-than 90 --dry-run + +# Delete specific memories +ocm-mem cleanup --ids 1,2,3 --force + +# Clean up expired session states +ocm-mem cleanup --sessions --older-than 30 +``` + +Run `ocm-mem --help` for full options on each command. + +--- + ## Troubleshooting ### Plugin shows "degraded" status diff --git a/frontend/src/components/settings/MemoryPluginConfig.tsx b/frontend/src/components/settings/MemoryPluginConfig.tsx index 387b0ca6..24774280 100644 --- a/frontend/src/components/settings/MemoryPluginConfig.tsx +++ b/frontend/src/components/settings/MemoryPluginConfig.tsx @@ -1,11 +1,15 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useMemo } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' +import { Combobox } from '@/components/ui/combobox' +import type { ComboboxOption } from '@/components/ui/combobox' +import { getProviders } from '@/api/providers' +import { useModelStore } from '@/stores/modelStore' import { Label } from '@/components/ui/label' import { Switch } from '@/components/ui/switch' -import { ChevronDown, ChevronRight, Save, Loader2, Database, Brain, AlertCircle, RefreshCw, Play } from 'lucide-react' +import { ChevronDown, ChevronRight, Save, Loader2, Database, Brain, AlertCircle, RefreshCw, Play, Cpu } from 'lucide-react' import { getPluginConfig, updatePluginConfig, reindexMemories, testEmbeddingConfig } from '@/api/memory' import { FetchError } from '@/api/fetchWrapper' import { settingsApi } from '@/api/settings' @@ -41,6 +45,54 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug enabled: memoryPluginEnabled && expanded, }) + const { data: providersData } = useQuery({ + queryKey: ['providers-for-execution-model'], + queryFn: getProviders, + staleTime: 60000, + enabled: memoryPluginEnabled && expanded, + }) + + const recentModels = useModelStore((s) => s.recentModels) + + const executionModelOptions = useMemo(() => { + if (!providersData?.providers) return [] + + const connectedProviders = providersData.providers.filter((p) => p.isConnected) + + const recentSet = new Set() + const recentOptions: ComboboxOption[] = [] + + for (const recent of recentModels) { + const modelValue = `${recent.providerID}/${recent.modelID}` + const provider = connectedProviders.find((p) => p.id === recent.providerID) + const model = provider?.models[recent.modelID] + if (!model || !provider) continue + recentSet.add(modelValue) + recentOptions.push({ + value: modelValue, + label: model.name || model.id, + description: provider.name, + group: 'Recent', + }) + } + + const providerOptions: ComboboxOption[] = [] + for (const provider of connectedProviders.sort((a, b) => a.name.localeCompare(b.name))) { + for (const [modelId, model] of Object.entries(provider.models)) { + const modelValue = `${provider.id}/${modelId}` + if (recentSet.has(modelValue)) continue + providerOptions.push({ + value: modelValue, + label: model.name || model.id, + description: modelId, + group: provider.name, + }) + } + } + + return [...recentOptions, ...providerOptions] + }, [providersData, recentModels]) + const config = data?.config const [localConfig, setLocalConfig] = useState(null) @@ -66,12 +118,8 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug const updateMutation = useMutation({ mutationFn: updatePluginConfig, onSuccess: (data) => { - showToast.success('Memory plugin configuration saved') queryClient.setQueryData(['memory-plugin-config'], { config: data.config }) }, - onError: () => { - showToast.error('Failed to save configuration') - }, }) const reindexMutation = useMutation({ @@ -112,16 +160,20 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug const handleSave = async () => { if (!localConfig) return + showToast.loading('Saving configuration...', { id: 'memory-save' }) updateMutation.mutate(localConfig, { onSuccess: async () => { - showToast.loading('Restarting OpenCode server...', { id: 'memory-restart' }) + showToast.loading('Restarting OpenCode server...', { id: 'memory-save' }) try { await settingsApi.restartOpenCodeServer() - showToast.success('Configuration saved and server restarted', { id: 'memory-restart' }) + showToast.success('Configuration saved and server restarted', { id: 'memory-save' }) } catch { - showToast.error('Failed to restart server', { id: 'memory-restart' }) + showToast.error('Failed to restart server', { id: 'memory-save' }) } }, + onError: () => { + showToast.error('Failed to save configuration', { id: 'memory-save' }) + }, }) } @@ -262,40 +314,93 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug )} + +
+
+ + Reindex +
+ +

+ Regenerate embeddings for all memories +

+
-
-
- - Storage +
+
+
+ + Storage +
+ +
+ +
+ { + setLocalConfig({ + ...displayConfig, + dedupThreshold: parseFloat(e.target.value), + }) + }} + className="flex-1" + /> + + {(displayConfig.dedupThreshold ?? 0.25).toFixed(2)} + +
+

+ Lower values = more aggressive deduplication (0.0 - 0.4) +

+
-
- -
- { +
+
+ + Plan Execution +
+ +
+ + { setLocalConfig({ ...displayConfig, - dedupThreshold: parseFloat(e.target.value), + executionModel: value || undefined, }) }} - className="flex-1" + options={executionModelOptions} + placeholder="default model" + allowCustomValue + showClear /> - - {(displayConfig.dedupThreshold ?? 0.25).toFixed(2)} - +

+ Model used when executing plans from the Architect. Format: provider/model. Leave empty to use the current session's model. +

-

- Lower values = more aggressive deduplication (0.0 - 0.4) -

@@ -306,31 +411,6 @@ export function MemoryPluginConfig({ memoryPluginEnabled, onToggle }: MemoryPlug
)} -
-
-
- - Reindex -
- -
-

- Regenerate embeddings for all memories. Use when changing embedding model or if embeddings are missing. -

-
-
diff --git a/frontend/src/components/ui/combobox.tsx b/frontend/src/components/ui/combobox.tsx index 6fcdc9da..10d7e31b 100644 --- a/frontend/src/components/ui/combobox.tsx +++ b/frontend/src/components/ui/combobox.tsx @@ -1,6 +1,6 @@ import { useState, useRef, useEffect, useCallback } from 'react' import { cn } from '@/lib/utils' -import { ChevronDown } from 'lucide-react' +import { ChevronDown, X } from 'lucide-react' export interface ComboboxOption { value: string @@ -17,6 +17,7 @@ interface ComboboxProps { disabled?: boolean className?: string allowCustomValue?: boolean + showClear?: boolean } export function Combobox({ @@ -27,6 +28,7 @@ export function Combobox({ disabled = false, className, allowCustomValue = true, + showClear = false, }: ComboboxProps) { const [isOpen, setIsOpen] = useState(false) const [inputValue, setInputValue] = useState(() => { @@ -181,6 +183,22 @@ export function Combobox({ 'pr-8' )} /> + {showClear && value && ( + + )}