Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions apps/desktop/src/lib/trpc/routers/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,51 @@ function getSettings() {
return row;
}

const DEFAULT_PRESETS: Omit<TerminalPreset, "id">[] = [
{
name: "claude",
description: "Danger mode: All permissions auto-approved",
cwd: "",
commands: ["claude --dangerously-skip-permissions"],
},
{
name: "codex",
description: "Danger mode: All permissions auto-approved",
cwd: "",
commands: [
'codex -c model_reasoning_effort="high" --ask-for-approval never --sandbox danger-full-access -c model_reasoning_summary="detailed" -c model_supports_reasoning_summaries=true',
],
},
];

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;
}
Comment on lines +51 to +77

@coderabbitai coderabbitai Bot Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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 -60

Repository: 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 json

Repository: 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.ts

Repository: 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!


/** Get presets tagged with a given auto-apply field, falling back to the isDefault preset */
export function getPresetsForTrigger(
field: "applyOnWorkspaceCreated" | "applyOnNewTab",
Expand All @@ -51,6 +96,9 @@ export const createSettingsRouter = () => {
}),
getTerminalPresets: publicProcedure.query(() => {
const row = getSettings();
if (!row.terminalPresetsInitialized) {
return initializeDefaultPresets();
}
return row.terminalPresets ?? [];
}),
createTerminalPreset: publicProcedure
Expand Down
Loading