Файли
openidea/src/platform/workflowSettings.ts
T
l0ng-ai 401c542647 feat(vcs): improve Git workflows (#5174)
Improve OpenIDEA's Git workflows across commit and staging, branch and remote operations, merge and rebase, Git Log and signing, worktrees, stash and shelf, patch application, and clone settings. Adds a one-click stash for tracked changes across Git roots and lets users open a worktree branch's associated GitHub review from its context menu. Cloning now includes submodules by default (Settings › Version Control › Git, can be turned off).

Repository entry points added here run in each repository's execution scope, so they use the project's own git executable.
2026-11-22 21:57:30 +08:00

834 рядки
31 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Version Control, Build/Execution/Deployment and Tools settings as features
* consume them: every field present and in range (mirrors
* `ide-core::workflow_settings` defaults). Normalisation never throws.
*/
import type {
EmptyCherryPickAction,
FetchTagsMode,
GitAnnotateMovement,
GitSaveChangesPolicy,
StashDiffTarget,
} from "@/bindings";
import { useProject } from "./project";
import { DEFAULT_REMOTE, validateRemote, type RemoteSettings } from "./remoteSettings";
export type UpdateMethod = "merge" | "rebase";
export type IncomingCheck = "auto" | "always" | "check" | "never";
export type BuildToolWindowWhen = "always" | "onError" | "never";
export type VcsConfirm = "ask" | "silently" | "never";
export type PatchCreated = "ask" | "no" | "reveal";
export type CursorShape = "block" | "underline" | "bar";
export interface IssueLinkValid {
pattern: string;
link: string;
}
export interface GitSettingsValid {
annotate: { ignoreWhitespace: boolean; movement: GitAnnotateMovement };
inlineBlame: boolean;
inlineBlameClickable: boolean;
showBranchInProjectView: boolean;
syncBranchOperations: boolean;
executable: string;
cloneSubmodules: boolean;
updateMethod: UpdateMethod;
saveChangesPolicy: GitSaveChangesPolicy;
autoUpdateOnPushRejected: boolean;
warnCrlf: boolean;
warnDetachedHead: boolean;
incomingCheck: IncomingCheck;
/** Minutes between background checks for incoming commits. */
incomingCheckInterval: number;
fetchTagsMode: FetchTagsMode;
protectedBranches: string;
signOff: boolean;
addCherryPickOrigin: boolean;
emptyCherryPick: EmptyCherryPickAction;
warnLargeFiles: boolean;
largeFileMb: number;
warnBadFileNames: boolean;
showPushDialog: boolean;
pushDialogOnlyProtected: boolean;
combineStashAndShelf: boolean;
stashDiffTarget: StashDiffTarget;
stagingArea: boolean;
cliStatus: boolean;
}
export interface CommitSettingsValid {
nonModal: boolean;
includeChangesByDefault: boolean;
commitAllWhenNothingStaged: boolean;
clearInitialMessage: boolean;
analyzeCode: boolean;
postponeSlowChecks: boolean;
checkTodo: boolean;
reformat: boolean;
optimizeImports: boolean;
cleanup: boolean;
blankLineAfterSubject: boolean;
limitSubject: boolean;
subjectLimit: number;
limitBody: boolean;
bodyLimit: number;
showRightMargin: boolean;
wrapAtMargin: boolean;
/** Plugin before-commit checks turned off (`<plugin id>/<check id>`). */
disabledPluginChecks: string[];
/** Double-click opens the diff (`true`), the source file (`false`), or follows the interface (`null`). */
doubleClickOpensDiff: boolean | null;
/** Team conventions for Generate Commit Message with Agent, added to its prompt. */
agentInstructions: string;
/** The agent Generate Commit Message with Agent uses; empty follows the latest task's agent. */
agent: string;
/** That agent's model for commit messages; empty keeps the model the agent would use. */
agentModel: string;
/** That model's thinking level for commit messages; empty keeps the agent's. */
agentEffort: string;
/** Show the Generate Commit Message with Agent button above the commit message. */
agentButton: boolean;
}
export interface VcsSettingsValid {
showDirtyDirectories: boolean;
createChangelistsAutomatically: boolean;
/** Off: diffs the user opens show in a separate window. */
diffAsEditorTab: boolean;
limitHistory: boolean;
historyLimit: number;
git: GitSettingsValid;
commit: CommitSettingsValid;
confirmation: {
onCreate: VcsConfirm;
onDelete: VcsConfirm;
showUpdateOptions: boolean;
confirmDropCommits: boolean;
onPatchCreated: PatchCreated;
};
shelf: { removeApplied: boolean };
issueNavigation: IssueLinkValid[];
/** Directory Mappings: repository roots excluded from / added to the detected ones. */
mappings: { excluded: string[]; added: string[] };
}
/** Mirrors `ide-core::workflow_settings::LogLevelColors` defaults. */
export interface LogLevelColorsValid {
enabled: boolean;
error: string;
warn: string;
info: string;
debug: string;
trace: string;
}
export interface BuildSettingsValid {
openToolWindow: BuildToolWindowWhen;
focusToolWindow: BuildToolWindowWhen;
}
export interface ConsoleSettingsValid {
softWrap: boolean;
overrideBuffer: boolean;
bufferKb: number;
encoding: string;
foldPatterns: string[];
logColors: LogLevelColorsValid;
}
export interface DebuggerSettingsValid {
showOnBreakpoint: boolean;
focusAppOnBreakpoint: boolean;
hideOnTermination: boolean;
variablesOnBreakpoint: boolean;
breakpointsAnyFile: boolean;
runToCursorInlay: boolean;
inlineValues: boolean;
sortValues: boolean;
liveWatches: boolean;
valueTooltip: boolean;
valueTooltipOnSelection: boolean;
valueTooltipDelay: number;
skipLibraryCode: boolean;
debugServerPage: boolean;
flutterHotReloadOnSave: boolean;
python: { attachSubprocess: boolean; gevent: boolean };
}
export interface RunSettingsValid {
defaultTarget: string;
confirmRerun: boolean;
confirmTerminate: boolean;
showOnStart: boolean;
/** New Run/Debug tabs start pinned, so a later run doesn't take their place (IDEA's advanced setting). */
pinTabs: boolean;
terminationTimeoutMs: number;
}
/** Tools › External Diff Tools: the program Show Diff in External Tool starts. */
export interface ExternalDiffValid {
enabled: boolean;
path: string;
/** `%1` the left file, `%2` the right file, `%3` the title. */
parameters: string;
}
export type TerminalMaxFps = "unlimited" | "60" | "30" | "15" | "10";
/** When a title the program sets (OSC 0/2) names the terminal tab, as IDEA's option. */
export type TerminalAppTitle = "running" | "always" | "off";
export const TERMINAL_MAX_FPS_OPTIONS: readonly { value: TerminalMaxFps; label: string }[] = [
{ value: "unlimited", label: "Unlimited" },
{ value: "60", label: "60 FPS" },
{ value: "30", label: "30 FPS" },
{ value: "15", label: "15 FPS" },
{ value: "10", label: "10 FPS" },
];
export interface TerminalSettingsValid {
startDirectory: string;
env: Record<string, string>;
shellPath: string;
tabName: string;
appTitleAsTabName: TerminalAppTitle;
audibleBell: boolean;
closeOnExit: boolean;
mouseReporting: boolean;
copyOnSelection: boolean;
pasteOnMiddleClick: boolean;
overrideIdeShortcuts: boolean;
shellIntegration: boolean;
highlightHyperlinks: boolean;
highlightSelection: boolean;
optionAsMeta: boolean;
escapeToEditor: boolean;
cursorShape: CursorShape;
cursorBlink: boolean;
/**
* Cap how often PTY output is painted. `unlimited` writes every chunk;
* while the document is hidden a slower floor always applies (#4216).
*/
maxFps: TerminalMaxFps;
useEditorFont: boolean;
fontFamily: string;
fontSize: number;
lineHeight: number;
fallbackFontFamily: string;
columnWidth: number;
}
export interface ActionsOnSaveValid {
optimizeImports: boolean;
cleanup: boolean;
}
export interface ExternalToolValid {
id: string;
name: string;
description: string;
group: string;
enabled: boolean;
program: string;
arguments: string;
workingDirectory: string;
synchronizeAfter: boolean;
openConsole: boolean;
}
export interface AgentSecurityValid {
allowedCommands: string[];
blockedCommands: string[];
}
/** Agents › IDE MCP Server: the Run tool window's agent tabs (`run_command`). */
export interface AgentRunSettingsValid {
/** Finished agent tabs shown; older ones go to the archive. */
tabLimit: number;
/** Archived agent tabs kept; older ones are closed. */
archiveLimit: number;
}
export interface WorkflowSettings extends RemoteSettings {
vcs: VcsSettingsValid;
build: BuildSettingsValid;
console: ConsoleSettingsValid;
debugger: DebuggerSettingsValid;
run: RunSettingsValid;
terminal: TerminalSettingsValid;
actionsOnSave: ActionsOnSaveValid;
externalTools: ExternalToolValid[];
externalDiff: ExternalDiffValid;
agentSecurity: AgentSecurityValid;
}
export const WORKFLOW_LIMITS = {
historyLimit: { min: 10, max: 100_000 },
messageLimit: { min: 20, max: 500 },
largeFileMb: { min: 1, max: 100_000 },
incomingCheckInterval: { min: 1, max: 1440 },
bufferKb: { min: 16, max: 1_048_576 },
tooltipDelay: { min: 0, max: 10_000 },
terminationTimeoutMs: { min: 0, max: 600_000 },
agentTabLimit: { min: 0, max: 1000 },
agentArchiveLimit: { min: 0, max: 100_000 },
terminalFontSize: { min: 6, max: 72 },
terminalLineHeight: { min: 0.5, max: 3 },
terminalColumnWidth: { min: 0.5, max: 2 },
} as const;
export const DEFAULT_EXTERNAL_TOOL: ExternalToolValid = {
id: "",
name: "",
description: "",
group: "External Tools",
enabled: true,
program: "",
arguments: "",
workingDirectory: "$ProjectFileDir$",
synchronizeAfter: true,
openConsole: true,
};
export const DEFAULT_WORKFLOW: WorkflowSettings = {
vcs: {
// IDEA's VcsConfiguration.SHOW_DIRTY_RECURSIVELY is off by default.
showDirtyDirectories: false,
createChangelistsAutomatically: false,
diffAsEditorTab: true,
limitHistory: true,
historyLimit: 1000,
git: {
annotate: { ignoreWhitespace: true, movement: "none" },
inlineBlame: false,
inlineBlameClickable: true,
showBranchInProjectView: false,
syncBranchOperations: true,
executable: "",
cloneSubmodules: true,
updateMethod: "merge",
saveChangesPolicy: "shelve",
autoUpdateOnPushRejected: false,
warnCrlf: true,
warnDetachedHead: true,
incomingCheck: "auto",
incomingCheckInterval: 15,
fetchTagsMode: "auto",
protectedBranches: "master; main",
signOff: false,
addCherryPickOrigin: true,
emptyCherryPick: "skip",
warnLargeFiles: true,
largeFileMb: 50,
warnBadFileNames: true,
showPushDialog: true,
pushDialogOnlyProtected: false,
combineStashAndShelf: false,
stashDiffTarget: "local",
stagingArea: false,
cliStatus: false,
},
commit: {
nonModal: true,
includeChangesByDefault: true,
commitAllWhenNothingStaged: true,
clearInitialMessage: false,
analyzeCode: true,
postponeSlowChecks: true,
checkTodo: true,
reformat: false,
optimizeImports: false,
cleanup: false,
blankLineAfterSubject: true,
limitSubject: true,
subjectLimit: 72,
limitBody: false,
bodyLimit: 72,
showRightMargin: true,
wrapAtMargin: false,
disabledPluginChecks: [],
doubleClickOpensDiff: null,
agentInstructions: "",
agent: "",
agentModel: "",
agentEffort: "",
agentButton: true,
},
confirmation: {
onCreate: "ask",
onDelete: "ask",
showUpdateOptions: true,
confirmDropCommits: true,
onPatchCreated: "ask",
},
shelf: { removeApplied: false },
issueNavigation: [],
mappings: { excluded: [], added: [] },
},
build: {
openToolWindow: "always",
focusToolWindow: "never",
},
console: {
softWrap: false,
overrideBuffer: true,
bufferKb: 1024,
encoding: "UTF-8",
foldPatterns: [
"at java.base/jdk.internal.reflect.",
"at java.base/java.lang.reflect.Method.invoke",
"at org.junit.",
"at node:internal/",
"<frozen importlib._bootstrap",
],
logColors: {
enabled: false,
error: "var(--ansi-red)",
warn: "var(--ansi-yellow)",
info: "var(--ansi-green)",
debug: "var(--ansi-cyan)",
trace: "var(--ansi-magenta)",
},
},
debugger: {
showOnBreakpoint: true,
focusAppOnBreakpoint: false,
hideOnTermination: false,
variablesOnBreakpoint: true,
breakpointsAnyFile: false,
runToCursorInlay: true,
inlineValues: true,
sortValues: false,
liveWatches: false,
valueTooltip: true,
valueTooltipOnSelection: true,
valueTooltipDelay: 700,
skipLibraryCode: true,
debugServerPage: false,
flutterHotReloadOnSave: true,
python: { attachSubprocess: true, gevent: false },
},
run: {
defaultTarget: "",
confirmRerun: true,
confirmTerminate: true,
showOnStart: true,
pinTabs: false,
terminationTimeoutMs: 3000,
},
terminal: {
startDirectory: "",
env: {},
shellPath: "",
tabName: "Local",
appTitleAsTabName: "running",
audibleBell: true,
closeOnExit: true,
mouseReporting: true,
copyOnSelection: false,
pasteOnMiddleClick: true,
overrideIdeShortcuts: true,
shellIntegration: true,
highlightHyperlinks: true,
highlightSelection: true,
optionAsMeta: false,
escapeToEditor: false,
cursorShape: "block",
cursorBlink: true,
maxFps: "unlimited",
useEditorFont: true,
fontFamily: "JetBrains Mono",
fontSize: 13,
lineHeight: 1,
fallbackFontFamily: "",
columnWidth: 1,
},
actionsOnSave: { optimizeImports: false, cleanup: false },
externalTools: [],
externalDiff: { enabled: false, path: "", parameters: "%1 %2 %3" },
agentSecurity: {
allowedCommands: [],
blockedCommands: ["rm -rf *", "rm -rf /", "mkfs*", "dd *", ":(){ :|:& };:", "shutdown*", "reboot*"],
},
...DEFAULT_REMOTE,
};
type Obj = Record<string, unknown>;
const obj = (v: unknown): Obj => (v && typeof v === "object" && !Array.isArray(v) ? (v as Obj) : {});
const bool = (v: unknown, d: boolean) => (typeof v === "boolean" ? v : d);
/** A boolean the user may leave unset. */
const tri = (v: unknown): boolean | null => (typeof v === "boolean" ? v : null);
const text = (v: unknown, d: string) => (typeof v === "string" ? v : d);
const nonEmpty = (v: unknown, d: string) => (typeof v === "string" && v.trim() ? v : d);
const oneOf = <T extends string>(v: unknown, allowed: readonly T[], d: T): T =>
typeof v === "string" && (allowed as readonly string[]).includes(v) ? (v as T) : d;
const num = (v: unknown, d: number, { min, max }: { min: number; max: number }, int = false) => {
if (typeof v !== "number" || !Number.isFinite(v)) return d;
const n = Math.min(max, Math.max(min, v));
return int ? Math.round(n) : n;
};
const strings = (v: unknown, d: readonly string[]) =>
Array.isArray(v) ? v.filter((x): x is string => typeof x === "string" && !!x.trim()) : [...d];
export function validateVcs(raw: unknown): VcsSettingsValid {
const d = DEFAULT_WORKFLOW.vcs;
const v = obj(raw);
const g = obj(v.git);
const annotate = obj(g.annotate);
const c = obj(v.commit);
const conf = obj(v.confirmation);
const L = WORKFLOW_LIMITS;
const confirm = ["ask", "silently", "never"] as const;
return {
showDirtyDirectories: bool(v.showDirtyDirectories, d.showDirtyDirectories),
createChangelistsAutomatically: bool(v.createChangelistsAutomatically, d.createChangelistsAutomatically),
diffAsEditorTab: bool(v.diffAsEditorTab, d.diffAsEditorTab),
limitHistory: bool(v.limitHistory, d.limitHistory),
historyLimit: num(v.historyLimit, d.historyLimit, L.historyLimit, true),
git: {
annotate: {
ignoreWhitespace: bool(annotate.ignoreWhitespace, d.git.annotate.ignoreWhitespace),
movement: oneOf(annotate.movement, ["none", "withinFile", "acrossFiles"], d.git.annotate.movement),
},
inlineBlame: bool(g.inlineBlame, d.git.inlineBlame),
inlineBlameClickable: bool(g.inlineBlameClickable, d.git.inlineBlameClickable),
showBranchInProjectView: bool(g.showBranchInProjectView, d.git.showBranchInProjectView),
syncBranchOperations: bool(g.syncBranchOperations, d.git.syncBranchOperations),
executable: text(g.executable, d.git.executable).trim(),
cloneSubmodules: bool(g.cloneSubmodules, d.git.cloneSubmodules),
updateMethod: oneOf(g.updateMethod, ["merge", "rebase"] as const, d.git.updateMethod),
saveChangesPolicy: oneOf(g.saveChangesPolicy, ["shelve", "stash"] as const, d.git.saveChangesPolicy),
autoUpdateOnPushRejected: bool(g.autoUpdateOnPushRejected, d.git.autoUpdateOnPushRejected),
warnCrlf: bool(g.warnCrlf, d.git.warnCrlf),
warnDetachedHead: bool(g.warnDetachedHead, d.git.warnDetachedHead),
incomingCheck: oneOf(g.incomingCheck, ["auto", "always", "check", "never"] as const, d.git.incomingCheck),
incomingCheckInterval: num(g.incomingCheckInterval, d.git.incomingCheckInterval, L.incomingCheckInterval, true),
fetchTagsMode: oneOf(g.fetchTagsMode, ["auto", "sync", "always", "never"] as const, d.git.fetchTagsMode),
protectedBranches: text(g.protectedBranches, d.git.protectedBranches),
signOff: bool(g.signOff, d.git.signOff),
addCherryPickOrigin: bool(g.addCherryPickOrigin, d.git.addCherryPickOrigin),
emptyCherryPick: oneOf(g.emptyCherryPick, ["skip", "createEmpty"] as const, d.git.emptyCherryPick),
warnLargeFiles: bool(g.warnLargeFiles, d.git.warnLargeFiles),
largeFileMb: num(g.largeFileMb, d.git.largeFileMb, L.largeFileMb, true),
warnBadFileNames: bool(g.warnBadFileNames, d.git.warnBadFileNames),
showPushDialog: bool(g.showPushDialog, d.git.showPushDialog),
pushDialogOnlyProtected: bool(g.pushDialogOnlyProtected, d.git.pushDialogOnlyProtected),
combineStashAndShelf: bool(g.combineStashAndShelf, d.git.combineStashAndShelf),
stashDiffTarget: oneOf(g.stashDiffTarget, ["local", "parent"] as const, d.git.stashDiffTarget),
stagingArea: bool(g.stagingArea, d.git.stagingArea),
cliStatus: bool(g.cliStatus, d.git.cliStatus),
},
commit: {
nonModal: bool(c.nonModal, d.commit.nonModal),
includeChangesByDefault: bool(c.includeChangesByDefault, d.commit.includeChangesByDefault),
commitAllWhenNothingStaged: bool(c.commitAllWhenNothingStaged, d.commit.commitAllWhenNothingStaged),
clearInitialMessage: bool(c.clearInitialMessage, d.commit.clearInitialMessage),
analyzeCode: bool(c.analyzeCode, d.commit.analyzeCode),
postponeSlowChecks: bool(c.postponeSlowChecks, d.commit.postponeSlowChecks),
checkTodo: bool(c.checkTodo, d.commit.checkTodo),
reformat: bool(c.reformat, d.commit.reformat),
optimizeImports: bool(c.optimizeImports, d.commit.optimizeImports),
cleanup: bool(c.cleanup, d.commit.cleanup),
blankLineAfterSubject: bool(c.blankLineAfterSubject, d.commit.blankLineAfterSubject),
limitSubject: bool(c.limitSubject, d.commit.limitSubject),
subjectLimit: num(c.subjectLimit, d.commit.subjectLimit, L.messageLimit, true),
limitBody: bool(c.limitBody, d.commit.limitBody),
bodyLimit: num(c.bodyLimit, d.commit.bodyLimit, L.messageLimit, true),
showRightMargin: bool(c.showRightMargin, d.commit.showRightMargin),
wrapAtMargin: bool(c.wrapAtMargin, d.commit.wrapAtMargin),
disabledPluginChecks: strings(c.disabledPluginChecks, d.commit.disabledPluginChecks),
doubleClickOpensDiff: tri(c.doubleClickOpensDiff),
agentInstructions: text(c.agentInstructions, d.commit.agentInstructions),
agent: text(c.agent, d.commit.agent),
agentModel: text(c.agentModel, d.commit.agentModel),
agentEffort: text(c.agentEffort, d.commit.agentEffort),
agentButton: bool(c.agentButton, d.commit.agentButton),
},
confirmation: {
onCreate: oneOf(conf.onCreate, confirm, d.confirmation.onCreate),
onDelete: oneOf(conf.onDelete, confirm, d.confirmation.onDelete),
showUpdateOptions: bool(conf.showUpdateOptions, d.confirmation.showUpdateOptions),
confirmDropCommits: bool(conf.confirmDropCommits, d.confirmation.confirmDropCommits),
onPatchCreated: oneOf(conf.onPatchCreated, ["ask", "no", "reveal"] as const, d.confirmation.onPatchCreated),
},
shelf: { removeApplied: bool(obj(v.shelf).removeApplied, d.shelf.removeApplied) },
issueNavigation: Array.isArray(v.issueNavigation)
? v.issueNavigation
.map((x) => obj(x))
.map((x) => ({ pattern: text(x.pattern, ""), link: text(x.link, "") }))
.filter((x) => x.pattern.trim())
: [],
mappings: {
excluded: strings(obj(v.mappings).excluded, d.mappings.excluded),
added: strings(obj(v.mappings).added, d.mappings.added),
},
};
}
export function validateBuild(raw: unknown): BuildSettingsValid {
const d = DEFAULT_WORKFLOW.build;
const v = obj(raw);
const when = ["always", "onError", "never"] as const;
return {
openToolWindow: oneOf(v.openToolWindow, when, d.openToolWindow),
focusToolWindow: oneOf(v.focusToolWindow, when, d.focusToolWindow),
};
}
export function validateConsole(raw: unknown): ConsoleSettingsValid {
const d = DEFAULT_WORKFLOW.console;
const v = obj(raw);
const lc = obj(v.logColors);
const dl = d.logColors;
return {
softWrap: bool(v.softWrap, d.softWrap),
overrideBuffer: bool(v.overrideBuffer, d.overrideBuffer),
bufferKb: num(v.bufferKb, d.bufferKb, WORKFLOW_LIMITS.bufferKb, true),
encoding: nonEmpty(v.encoding, d.encoding),
foldPatterns: strings(v.foldPatterns, d.foldPatterns),
logColors: {
enabled: bool(lc.enabled, dl.enabled),
error: nonEmpty(lc.error, dl.error),
warn: nonEmpty(lc.warn, dl.warn),
info: nonEmpty(lc.info, dl.info),
debug: nonEmpty(lc.debug, dl.debug),
trace: nonEmpty(lc.trace, dl.trace),
},
};
}
export function validateDebugger(raw: unknown): DebuggerSettingsValid {
const d = DEFAULT_WORKFLOW.debugger;
const v = obj(raw);
const py = obj(v.python);
return {
showOnBreakpoint: bool(v.showOnBreakpoint, d.showOnBreakpoint),
focusAppOnBreakpoint: bool(v.focusAppOnBreakpoint, d.focusAppOnBreakpoint),
hideOnTermination: bool(v.hideOnTermination, d.hideOnTermination),
variablesOnBreakpoint: bool(v.variablesOnBreakpoint, d.variablesOnBreakpoint),
breakpointsAnyFile: bool(v.breakpointsAnyFile, d.breakpointsAnyFile),
runToCursorInlay: bool(v.runToCursorInlay, d.runToCursorInlay),
inlineValues: bool(v.inlineValues, d.inlineValues),
sortValues: bool(v.sortValues, d.sortValues),
liveWatches: bool(v.liveWatches, d.liveWatches),
valueTooltip: bool(v.valueTooltip, d.valueTooltip),
valueTooltipOnSelection: bool(v.valueTooltipOnSelection, d.valueTooltipOnSelection),
valueTooltipDelay: num(v.valueTooltipDelay, d.valueTooltipDelay, WORKFLOW_LIMITS.tooltipDelay, true),
skipLibraryCode: bool(v.skipLibraryCode, d.skipLibraryCode),
debugServerPage: bool(v.debugServerPage, d.debugServerPage),
flutterHotReloadOnSave: bool(v.flutterHotReloadOnSave, d.flutterHotReloadOnSave),
python: {
attachSubprocess: bool(py.attachSubprocess, d.python.attachSubprocess),
gevent: bool(py.gevent, d.python.gevent),
},
};
}
export function validateRun(raw: unknown): RunSettingsValid {
const d = DEFAULT_WORKFLOW.run;
const v = obj(raw);
return {
defaultTarget: text(v.defaultTarget, ""),
confirmRerun: bool(v.confirmRerun, d.confirmRerun),
confirmTerminate: bool(v.confirmTerminate, d.confirmTerminate),
showOnStart: bool(v.showOnStart, d.showOnStart),
pinTabs: bool(v.pinTabs, d.pinTabs),
terminationTimeoutMs: num(
v.terminationTimeoutMs,
d.terminationTimeoutMs,
WORKFLOW_LIMITS.terminationTimeoutMs,
true,
),
};
}
export function validateExternalDiff(raw: unknown): ExternalDiffValid {
const d = DEFAULT_WORKFLOW.externalDiff;
const v = obj(raw);
return {
enabled: bool(v.enabled, d.enabled),
path: text(v.path, d.path).trim(),
parameters: text(v.parameters, d.parameters),
};
}
export function validateTerminal(raw: unknown): TerminalSettingsValid {
const d = DEFAULT_WORKFLOW.terminal;
const v = obj(raw);
const env: Record<string, string> = {};
for (const [k, val] of Object.entries(obj(v.env))) if (k.trim() && typeof val === "string") env[k] = val;
return {
startDirectory: text(v.startDirectory, d.startDirectory).trim(),
env,
shellPath: text(v.shellPath, d.shellPath).trim(),
tabName: nonEmpty(v.tabName, d.tabName),
appTitleAsTabName: oneOf(v.appTitleAsTabName, ["running", "always", "off"] as const, d.appTitleAsTabName),
audibleBell: bool(v.audibleBell, d.audibleBell),
closeOnExit: bool(v.closeOnExit, d.closeOnExit),
mouseReporting: bool(v.mouseReporting, d.mouseReporting),
copyOnSelection: bool(v.copyOnSelection, d.copyOnSelection),
pasteOnMiddleClick: bool(v.pasteOnMiddleClick, d.pasteOnMiddleClick),
overrideIdeShortcuts: bool(v.overrideIdeShortcuts, d.overrideIdeShortcuts),
shellIntegration: bool(v.shellIntegration, d.shellIntegration),
highlightHyperlinks: bool(v.highlightHyperlinks, d.highlightHyperlinks),
highlightSelection: bool(v.highlightSelection, d.highlightSelection),
optionAsMeta: bool(v.optionAsMeta, d.optionAsMeta),
escapeToEditor: bool(v.escapeToEditor, d.escapeToEditor),
cursorShape: oneOf(v.cursorShape, ["block", "underline", "bar"] as const, d.cursorShape),
cursorBlink: bool(v.cursorBlink, d.cursorBlink),
maxFps: oneOf(v.maxFps, ["unlimited", "60", "30", "15", "10"] as const, d.maxFps),
useEditorFont: bool(v.useEditorFont, d.useEditorFont),
fontFamily: nonEmpty(v.fontFamily, d.fontFamily),
fontSize: num(v.fontSize, d.fontSize, WORKFLOW_LIMITS.terminalFontSize),
lineHeight: num(v.lineHeight, d.lineHeight, WORKFLOW_LIMITS.terminalLineHeight),
fallbackFontFamily: text(v.fallbackFontFamily, d.fallbackFontFamily).trim(),
columnWidth: num(v.columnWidth, d.columnWidth, WORKFLOW_LIMITS.terminalColumnWidth),
};
}
export function validateActionsOnSave(raw: unknown): ActionsOnSaveValid {
const v = obj(raw);
const d = DEFAULT_WORKFLOW.actionsOnSave;
return { optimizeImports: bool(v.optimizeImports, d.optimizeImports), cleanup: bool(v.cleanup, d.cleanup) };
}
export function validateExternalTools(raw: unknown): ExternalToolValid[] {
if (!Array.isArray(raw)) return [];
const d = DEFAULT_EXTERNAL_TOOL;
const seen = new Set<string>();
const out: ExternalToolValid[] = [];
raw.forEach((item, i) => {
const t = obj(item);
const name = text(t.name, "").trim();
if (!name) return;
let id = text(t.id, "").trim() || `tool${i + 1}`;
while (seen.has(id)) id += "_";
seen.add(id);
out.push({
id,
name,
description: text(t.description, d.description),
group: nonEmpty(t.group, d.group),
enabled: bool(t.enabled, d.enabled),
program: text(t.program, d.program),
arguments: text(t.arguments, d.arguments),
workingDirectory: text(t.workingDirectory, d.workingDirectory),
synchronizeAfter: bool(t.synchronizeAfter, d.synchronizeAfter),
openConsole: bool(t.openConsole, d.openConsole),
});
});
return out;
}
export function validateAgentSecurity(raw: unknown): AgentSecurityValid {
const v = obj(raw);
const d = DEFAULT_WORKFLOW.agentSecurity;
return {
allowedCommands: strings(v.allowedCommands, d.allowedCommands),
blockedCommands: strings(v.blockedCommands, d.blockedCommands),
};
}
export const DEFAULT_AGENT_RUNS: AgentRunSettingsValid = { tabLimit: 1, archiveLimit: 999 };
/** From `mcpServer` (Agents › IDE MCP Server). */
export function validateAgentRuns(raw: unknown): AgentRunSettingsValid {
const v = obj(raw);
const d = DEFAULT_AGENT_RUNS;
return {
tabLimit: num(v.agentTabLimit, d.tabLimit, WORKFLOW_LIMITS.agentTabLimit, true),
archiveLimit: num(v.agentArchiveLimit, d.archiveLimit, WORKFLOW_LIMITS.agentArchiveLimit, true),
};
}
export function validateWorkflow(raw: unknown): WorkflowSettings {
const root = obj(raw);
return {
vcs: validateVcs(root.vcs),
build: validateBuild(root.build),
console: validateConsole(root.console),
debugger: validateDebugger(root.debugger),
run: validateRun(root.run),
terminal: validateTerminal(root.terminal),
actionsOnSave: validateActionsOnSave(root.actionsOnSave),
externalTools: validateExternalTools(root.externalTools),
externalDiff: validateExternalDiff(root.externalDiff),
agentSecurity: validateAgentSecurity(root.agentSecurity),
...validateRemote(root),
};
}
// ---------------------------------------------------------------------------
// Live, normalised view of the effective settings.
let cachedRaw: unknown = Symbol("unset");
let cached: WorkflowSettings = DEFAULT_WORKFLOW;
/** Normalised settings of the open project (defaults without one). Cached per settings object. */
export function workflowSettings(): WorkflowSettings {
const raw = useProject.getState().settings;
if (raw !== cachedRaw) {
cachedRaw = raw;
cached = validateWorkflow(raw);
}
return cached;
}
/** React hook over one section, e.g. `useWorkflowSettings((s) => s.terminal)`. */
export function useWorkflowSettings<T>(select: (s: WorkflowSettings) => T): T {
return useProject((p) => {
if (p.settings !== cachedRaw) {
cachedRaw = p.settings;
cached = validateWorkflow(p.settings);
}
return select(cached);
});
}
/** Calls `listener` whenever a section changes (deep-compared by JSON), not initially. */
export function onWorkflowSettingsChange<T>(
select: (s: WorkflowSettings) => T,
listener: (value: T, prev: T) => void,
): () => void {
let prev = select(workflowSettings());
let prevJson = JSON.stringify(prev);
return useProject.subscribe((s, old) => {
if (s.settings === old.settings) return;
const next = select(workflowSettings());
const json = JSON.stringify(next);
if (json === prevJson) return;
const before = prev;
prev = next;
prevJson = json;
listener(next, before);
});
}
/** Macros usable in External Tools arguments / working directory (IDEA names). */
export const EXTERNAL_TOOL_MACROS: ReadonlyArray<{ name: string; description: string }> = [
{ name: "$FilePath$", description: "Absolute path of the current file" },
{ name: "$FileDir$", description: "Directory of the current file" },
{ name: "$FileName$", description: "Name of the current file" },
{ name: "$FileNameWithoutExtension$", description: "File name without extension" },
{ name: "$FileExt$", description: "Extension of the current file" },
{ name: "$FileRelativePath$", description: "Path of the current file relative to the project" },
{ name: "$FileDirRelativeToProjectRoot$", description: "Directory of the current file relative to the project" },
{ name: "$ProjectFileDir$", description: "Project root directory" },
{ name: "$ProjectName$", description: "Project name" },
{ name: "$LineNumber$", description: "Caret line number (1-based)" },
{ name: "$ColumnNumber$", description: "Caret column number (1-based)" },
{ name: "$SelectedText$", description: "Text selected in the editor" },
{ name: "$Prompt$", description: "Asks for a value when the tool runs" },
];
/** Agents › IDE MCP Server limits on the Run tool window's agent tabs. */
export function agentRunSettings(): AgentRunSettingsValid {
return validateAgentRuns(obj(useProject.getState().settings).mcpServer);
}
/** React hook over {@link agentRunSettings}. */
export function useAgentRunSettings(): AgentRunSettingsValid {
const raw = useProject((p) => obj(p.settings).mcpServer);
return validateAgentRuns(raw);
}