feat: replace prompt templates with snippets
Replace the prompt-template workflow with snippet support that is compatible with opencode snippet conventions. Snippets are now stored and loaded from global and project snippet directories, including legacy pluralized paths, with frontmatter metadata for aliases and descriptions. Snippet expansion supports recursive references plus prepend and append sections, while inject sections are treated as unsupported no-ops so OpenChamber remains compatible without requiring an external plugin. Add the snippets settings experience and remove the old prompt-template settings surface. The new settings page and sidebar support creating, editing, deleting, selecting, and describing snippets, with localized copy across every supported locale. The settings navigation now exposes Snippets with a dedicated icon and metadata. Wire snippets into all prompt-entry surfaces that need them. Chat, multi-run groups, and scheduled task prompts now offer hash-trigger snippet autocomplete and expand snippets before sending work to OpenCode. Chat also uses an adaptive compact placeholder on mobile or narrow composer widths so helper trigger guidance stays readable in constrained layouts. Keep multi-run aligned with grouped prompts. Multi-run sessions now use a shared title builder that handles both legacy titles and the newer g1, g2 prompt-group title format. Fusion parsing now recognizes grouped multi-run titles, scopes fusion sources to the same prompt group, and creates fusion sessions under the matching group so outputs from different prompts are not mixed accidentally. Harden the icon sprite pipeline. The sprite generator now discovers icon names used through typed icon maps, JSX icon props, IconName returns, and generated-value flows without scanning unrelated string literals or the generated sprite itself. The generated sprite is strictly typed so invalid icon names are caught by type checking, and existing invalid or unsafe icon references were cleaned up across settings, provider, Git identity, scheduled task, voice, header, and sidebar surfaces. Update backend configuration routes and documentation for snippets. The OpenCode config route layer now exposes snippet CRUD and expansion endpoints, accepts JSON bodies for snippet writes, and removes the old prompt-template provider. Scheduled task runtime expansion now uses snippets before dispatching messages. Add regression coverage for snippet storage and expansion, config-route JSON handling, and multi-run title parsing. Validated with full type checking, full linting, targeted multi-run title tests, and targeted OpenCode snippet/config route tests.
This commit is contained in:
@@ -14,6 +14,7 @@ import { AgentSelector } from '@/components/sections/commands/AgentSelector';
|
||||
import { isPrimaryMode } from '@/components/chat/mobileControlsUtils';
|
||||
import { CommandAutocomplete, type CommandAutocompleteHandle, type CommandInfo } from '@/components/chat/CommandAutocomplete';
|
||||
import { FileMentionAutocomplete, type FileMentionHandle } from '@/components/chat/FileMentionAutocomplete';
|
||||
import { SnippetAutocomplete, type SnippetAutocompleteHandle } from '@/components/chat/SnippetAutocomplete';
|
||||
import { Icon } from "@/components/icon/Icon";
|
||||
import { useConfigStore } from '@/stores/useConfigStore';
|
||||
import { useUIStore } from '@/stores/useUIStore';
|
||||
@@ -618,6 +619,8 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
const [mentionQuery, setMentionQuery] = React.useState('');
|
||||
const [showCommandAutocomplete, setShowCommandAutocomplete] = React.useState(false);
|
||||
const [commandQuery, setCommandQuery] = React.useState('');
|
||||
const [showSnippetAutocomplete, setShowSnippetAutocomplete] = React.useState(false);
|
||||
const [snippetQuery, setSnippetQuery] = React.useState('');
|
||||
const [calendarMonth, setCalendarMonth] = React.useState<Date>(() => {
|
||||
const initialDate = parseISODateToLocal(task?.schedule?.date || '') || new Date();
|
||||
return new Date(initialDate.getFullYear(), initialDate.getMonth(), 1);
|
||||
@@ -626,6 +629,7 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
const promptTextareaRef = React.useRef<HTMLTextAreaElement>(null);
|
||||
const mentionRef = React.useRef<FileMentionHandle>(null);
|
||||
const commandRef = React.useRef<CommandAutocompleteHandle>(null);
|
||||
const snippetRef = React.useRef<SnippetAutocompleteHandle>(null);
|
||||
const localeUse24Hour = React.useMemo(() => getUses24Hour(locale), [locale]);
|
||||
const localeWeekStartsOn = React.useMemo(() => getWeekStartsOn(locale), [locale]);
|
||||
const use24Hour = React.useMemo(() => {
|
||||
@@ -828,6 +832,7 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
setCommandQuery(value.substring(1, commandEnd));
|
||||
setShowCommandAutocomplete(true);
|
||||
setShowFileMention(false);
|
||||
setShowSnippetAutocomplete(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -835,6 +840,21 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
setShowCommandAutocomplete(false);
|
||||
|
||||
const textBeforeCursor = value.substring(0, cursorPosition);
|
||||
const lastHashSymbol = textBeforeCursor.lastIndexOf('#');
|
||||
if (lastHashSymbol !== -1) {
|
||||
const charBefore = lastHashSymbol > 0 ? textBeforeCursor[lastHashSymbol - 1] : null;
|
||||
const textAfterHash = textBeforeCursor.substring(lastHashSymbol + 1);
|
||||
const isWordBoundary = !charBefore || /\s/.test(charBefore);
|
||||
if (isWordBoundary && !textAfterHash.includes(' ') && !textAfterHash.includes('\n')) {
|
||||
setSnippetQuery(textAfterHash);
|
||||
setShowSnippetAutocomplete(true);
|
||||
setShowFileMention(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setShowSnippetAutocomplete(false);
|
||||
|
||||
const lastAtSymbol = textBeforeCursor.lastIndexOf('@');
|
||||
if (lastAtSymbol !== -1) {
|
||||
const charBefore = lastAtSymbol > 0 ? textBeforeCursor[lastAtSymbol - 1] : null;
|
||||
@@ -921,6 +941,7 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
setPromptValue(nextPrompt);
|
||||
setShowCommandAutocomplete(false);
|
||||
setCommandQuery('');
|
||||
setShowSnippetAutocomplete(false);
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const currentTextarea = promptTextareaRef.current;
|
||||
@@ -933,6 +954,31 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
});
|
||||
}, [setPromptValue, updateAutocompleteState]);
|
||||
|
||||
const handleSnippetSelect = React.useCallback((_snippet: unknown, trigger: string) => {
|
||||
const promptValue = draft.execution.prompt;
|
||||
const textarea = promptTextareaRef.current;
|
||||
const cursorPosition = textarea?.selectionStart ?? promptValue.length;
|
||||
const textBeforeCursor = promptValue.substring(0, cursorPosition);
|
||||
const lastHashSymbol = textBeforeCursor.lastIndexOf('#');
|
||||
const startIndex = lastHashSymbol !== -1 ? lastHashSymbol : cursorPosition;
|
||||
const nextPrompt = `${promptValue.substring(0, startIndex)}#${trigger} ${promptValue.substring(cursorPosition)}`;
|
||||
const nextCursor = startIndex + trigger.length + 2;
|
||||
|
||||
setPromptValue(nextPrompt);
|
||||
setShowSnippetAutocomplete(false);
|
||||
setSnippetQuery('');
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const currentTextarea = promptTextareaRef.current;
|
||||
if (currentTextarea) {
|
||||
currentTextarea.selectionStart = nextCursor;
|
||||
currentTextarea.selectionEnd = nextCursor;
|
||||
currentTextarea.focus();
|
||||
}
|
||||
updateAutocompleteState(nextPrompt, nextCursor);
|
||||
});
|
||||
}, [draft.execution.prompt, setPromptValue, updateAutocompleteState]);
|
||||
|
||||
const handlePromptKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (showCommandAutocomplete && commandRef.current) {
|
||||
if (event.key === 'Enter' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Escape' || event.key === 'Tab') {
|
||||
@@ -948,7 +994,14 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
mentionRef.current.handleKeyDown(event.key);
|
||||
}
|
||||
}
|
||||
}, [showCommandAutocomplete, showFileMention]);
|
||||
|
||||
if (showSnippetAutocomplete && snippetRef.current) {
|
||||
if (event.key === 'Enter' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Escape' || event.key === 'Tab') {
|
||||
event.preventDefault();
|
||||
snippetRef.current.handleKeyDown(event.key);
|
||||
}
|
||||
}
|
||||
}, [showCommandAutocomplete, showFileMention, showSnippetAutocomplete]);
|
||||
|
||||
const handleSubmit = React.useCallback(async () => {
|
||||
const validationError = validateDraft(draft, t);
|
||||
@@ -1407,6 +1460,22 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{showSnippetAutocomplete ? (
|
||||
<SnippetAutocomplete
|
||||
ref={snippetRef}
|
||||
searchQuery={snippetQuery}
|
||||
onSnippetSelect={handleSnippetSelect}
|
||||
onClose={() => setShowSnippetAutocomplete(false)}
|
||||
style={{
|
||||
left: 0,
|
||||
top: 'auto',
|
||||
bottom: 'calc(100% + 6px)',
|
||||
marginBottom: 0,
|
||||
maxWidth: '100%',
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { MobileOverlayPanel } from '@/components/ui/MobileOverlayPanel';
|
||||
import { toast } from '@/components/ui';
|
||||
import { Icon } from "@/components/icon/Icon";
|
||||
import type { IconName } from "@/components/icon/icons";
|
||||
import { useUIStore } from '@/stores/useUIStore';
|
||||
import { useProjectsStore } from '@/stores/useProjectsStore';
|
||||
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
||||
@@ -147,7 +148,7 @@ const STATUS_META: Record<
|
||||
ScheduledTaskStatus,
|
||||
{
|
||||
tone: StatusTone;
|
||||
Icon: string;
|
||||
Icon: IconName;
|
||||
spin?: boolean;
|
||||
}
|
||||
> = {
|
||||
|
||||
Reference in New Issue
Block a user