feat(desktop): seed claude and codex as default terminal presets#1401
Conversation
New users get claude and codex presets pre-populated on first launch using the existing terminalPresetsInitialized flag.
📝 WalkthroughWalkthroughThis change introduces a default terminal presets mechanism to the settings router. It adds DEFAULT_PRESETS containing preset configurations, implements initializeDefaultPresets() to generate IDs and persist presets to storage, and updates getTerminalPresets to automatically initialize defaults on first retrieval if not already done. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Router as Settings Router
participant DB as Database
Client->>Router: getTerminalPresets()
Router->>Router: Check terminalPresetsInitialized flag
alt Flag is false
Router->>Router: initializeDefaultPresets()
Router->>Router: Generate preset IDs
Router->>DB: Store presets with conflict update
Router->>DB: Mark terminalPresetsInitialized = true
else Flag is true
Router->>Router: Skip initialization
end
Router->>Client: Return presets
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/desktop/src/lib/trpc/routers/settings/index.ts`:
- Around line 51-77: initializeDefaultPresets currently overwrites existing user
presets when terminalPresetsInitialized is null; change it to merge
DEFAULT_PRESETS with any existing row.terminalPresets returned by getSettings()
instead of replacing them: build mergedPresets by taking existing presets first,
add defaults whose name is not already present (deduplicate by name), ensure
each added default gets a new id via crypto.randomUUID(), then upsert
terminalPresets to mergedPresets and set terminalPresetsInitialized = true (use
the same localDb.insert(...).onConflictDoUpdate(...) flow). Keep getSettings(),
initializeDefaultPresets(), and the upsert call as the touch points.
🧹 Nitpick comments (1)
apps/desktop/src/lib/trpc/routers/settings/index.ts (1)
97-103: Add a log entry when seeding default presets.Per coding guidelines, significant operations should use prefixed console logging. The initialization is a one-time side effect worth logging for debuggability.
Suggested change
getTerminalPresets: publicProcedure.query(() => { const row = getSettings(); if (!row.terminalPresetsInitialized) { + console.log("[settings/presets] Initializing default terminal presets"); return initializeDefaultPresets(); } return row.terminalPresets ?? []; }),As per coding guidelines, "Use prefixed console logging with consistent context pattern: [domain/operation] message for entry/exit of significant operations".
| function initializeDefaultPresets() { | ||
| const row = getSettings(); | ||
| if (row.terminalPresetsInitialized) return row.terminalPresets ?? []; | ||
|
|
||
| const presets: TerminalPreset[] = DEFAULT_PRESETS.map((p) => ({ | ||
| id: crypto.randomUUID(), | ||
| ...p, | ||
| })); | ||
|
|
||
| localDb | ||
| .insert(settings) | ||
| .values({ | ||
| id: 1, | ||
| terminalPresets: presets, | ||
| terminalPresetsInitialized: true, | ||
| }) | ||
| .onConflictDoUpdate({ | ||
| target: settings.id, | ||
| set: { | ||
| terminalPresets: presets, | ||
| terminalPresetsInitialized: true, | ||
| }, | ||
| }) | ||
| .run(); | ||
|
|
||
| return presets; | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for terminalPresetsInitialized usage and migrations
echo "=== Searching for terminalPresetsInitialized ==="
rg -n 'terminalPresetsInitialized' --type ts -A 2 -B 2
echo -e "\n=== Searching for database migrations ==="
find . -name "*migration*" -o -name "*schema*" | grep -E '\.(ts|js|sql)$' | head -20
echo -e "\n=== Checking for drizzle migrations ==="
fd -e ts -e sql 'migration'Repository: superset-sh/superset
Length of output: 2566
🏁 Script executed:
#!/bin/bash
# Look for getSettings implementation
echo "=== Finding getSettings implementation ==="
rg -n 'function getSettings|const getSettings' --type ts -A 10
echo -e "\n=== Check for database schema definition ==="
rg -n 'const settings|export const settings' --type ts -A 20 | head -60Repository: superset-sh/superset
Length of output: 6246
🏁 Script executed:
#!/bin/bash
# Check the initial migration schema for settings table
echo "=== Checking initial migration ==="
cat packages/local-db/drizzle/0000_initial_schema.sql | grep -A 20 "settings"
echo -e "\n=== Check if there are any other migration files ==="
ls -la packages/local-db/drizzle/Repository: superset-sh/superset
Length of output: 2746
🏁 Script executed:
#!/bin/bash
# Check package.json to understand drizzle setup and if migrations are auto-generated
echo "=== Checking local-db package config ==="
cat packages/local-db/package.json
echo -e "\n=== Check for any migration generation logs or pushdb ==="
grep -r "drizzle-kit" packages/local-db/ --type jsonRepository: superset-sh/superset
Length of output: 989
🏁 Script executed:
#!/bin/bash
# Search for all places that modify terminalPresets
echo "=== Searching for all writes to terminalPresets ==="
rg -n 'terminalPresets' --type ts -B 2 -A 2
echo -e "\n=== Check the full settings router to understand all preset operations ==="
cat apps/desktop/src/lib/trpc/routers/settings/index.tsRepository: superset-sh/superset
Length of output: 24817
Critical: initializeDefaultPresets overwrites existing user presets on upgrade.
The column terminalPresetsInitialized is uninitialized (null) for existing users after a schema migration. When getTerminalPresets is called post-upgrade, !row.terminalPresetsInitialized evaluates to true, and this function replaces any existing terminalPresets with only the two defaults — destroying presets the user may have already created.
Merge defaults with existing presets and deduplicate by name to avoid losing user-created presets and prevent adding defaults that match existing ones.
Proposed fix
function initializeDefaultPresets() {
const row = getSettings();
if (row.terminalPresetsInitialized) return row.terminalPresets ?? [];
- const presets: TerminalPreset[] = DEFAULT_PRESETS.map((p) => ({
+ const existing = row.terminalPresets ?? [];
+ const existingNames = new Set(existing.map((p) => p.name.toLowerCase()));
+
+ const newDefaults: TerminalPreset[] = DEFAULT_PRESETS
+ .filter((p) => !existingNames.has(p.name.toLowerCase()))
+ .map((p) => ({
id: crypto.randomUUID(),
...p,
}));
+ const presets = [...existing, ...newDefaults];
+
localDb
.insert(settings)
.values({🤖 Prompt for AI Agents
In `@apps/desktop/src/lib/trpc/routers/settings/index.ts` around lines 51 - 77,
initializeDefaultPresets currently overwrites existing user presets when
terminalPresetsInitialized is null; change it to merge DEFAULT_PRESETS with any
existing row.terminalPresets returned by getSettings() instead of replacing
them: build mergedPresets by taking existing presets first, add defaults whose
name is not already present (deduplicate by name), ensure each added default
gets a new id via crypto.randomUUID(), then upsert terminalPresets to
mergedPresets and set terminalPresetsInitialized = true (use the same
localDb.insert(...).onConflictDoUpdate(...) flow). Keep getSettings(),
initializeDefaultPresets(), and the upsert call as the touch points.
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
terminalPresetsInitializedflag in the settings table to ensure presets are only seeded onceTest plan
Summary by CodeRabbit
New Features