The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 08:00 UTC
refactor(web): move project script editing out of ChatView (#20401)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 17:43 UTC
bf990c625e7548a7b5b0d7886cf8befd9d94e2f4
3 files changed
+290
-242
apps/web/reactCompiledFiles.ts
+1
@@ -11,6 +11,7 @@ export const REACT_COMPILED_FILES = [
11
"apps/web/src/components/chat/usePendingThreadRequests.ts",
12
"apps/web/src/components/chat/composerFocusRedirect.ts",
13
"apps/web/src/components/chat/useChatShortcuts.ts",
14
+ "apps/web/src/components/chat/useProjectScriptEditing.ts",
15
"apps/web/src/components/chat/useQueuedRunEdit.ts",
16
"apps/web/src/components/chat/useUsageLimitsPanel.ts",
17
"apps/web/src/components/chat/useWorktreeSetup.ts",
apps/web/src/components/ChatView.tsx
+12
-242
@@ -25,6 +25,7 @@ import {
25
import { useLoadBalancedEnvironment } from "../hooks/useLoadBalancedEnvironment";
26
import { useScratchProject } from "../hooks/useScratchProject";
27
import { useStableCallback } from "../hooks/useStableCallback";
28
+import { useProjectScriptEditing } from "./chat/useProjectScriptEditing";
29
import { useThreadTerminalActions } from "./terminal/useThreadTerminalActions";
30
import { usePendingThreadRequests } from "./chat/usePendingThreadRequests";
31
import { isScratchProject } from "@t3tools/client-runtime/state/projects";
@@ -50,7 +51,6 @@ import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
51
import * as Schema from "effect/Schema";
52
import {
53
AuthOrchestrationOperateScope,
53
- AuthSettingsWriteScope,
54
AuthSourceControlWriteScope,
55
AuthPreviewOperateScope,
56
AuthTerminalReadScope,
@@ -60,7 +60,6 @@ import {
60
CommandId,
61
DEFAULT_MODEL,
62
isProviderNativeSubagentThread,
63
- EnvironmentAuthorizationError,
63
type EnvironmentId,
64
type MessageId,
65
type ModelSelection,
@@ -73,7 +72,6 @@ import {
72
type ThreadId,
73
type RunId,
74
type RuntimeRequestId,
76
- type KeybindingCommand,
75
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
76
ProviderInteractionMode,
77
ProviderDriverKind,
@@ -167,7 +165,6 @@ import {
165
squashAtomCommandFailure,
166
type AtomCommandResult,
167
} from "@t3tools/client-runtime/state/runtime";
170
-import * as Cause from "effect/Cause";
168
import { AsyncResult } from "effect/reactivity";
169
import { isElectron } from "../env";
170
import { readLocalApi } from "../localApi";
@@ -292,18 +289,7 @@ import {
289
import { cn, randomUUID } from "~/lib/utils";
290
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
291
import { stackedThreadToast, toastManager } from "./ui/toast";
295
-import {
296
- decodeProjectScriptKeybindingRule,
297
- keybindingValueForCommand,
298
-} from "~/lib/projectScriptKeybindings";
299
-import { type NewProjectScriptInput } from "./ProjectScriptsControl";
300
-import {
301
- buildProjectScript,
302
- commandForProjectScript,
303
- nextProjectScriptId,
304
- projectScriptIdFromCommand,
305
- releaseClaimedRoles,
306
-} from "~/projectScripts";
292
+import { projectScriptIdFromCommand } from "~/projectScripts";
293
import { newDraftId, newMessageId, newThreadId } from "~/lib/utils";
294
import { registerFaviconProjectForThread } from "~/browserFaviconStore";
295
import { getProviderModelCapabilities } from "../providerModels";
@@ -1101,15 +1087,6 @@ export default function ChatView(props: ChatViewProps) {
1087
currentRouteThreadKeyRef.current = null;
1088
};
1089
}, [routeThreadKey]);
1104
- const updateProjectScriptSettings = useAtomCommand(serverEnvironment.updateSettings, {
1105
- reportFailure: false,
1106
- });
1107
- const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
1108
- reportFailure: false,
1109
- });
1110
- const removeKeybinding = useAtomCommand(serverEnvironment.removeKeybinding, {
1111
- reportFailure: false,
1112
- });
1090
const createThread = useOrchestrationCommand(threadEnvironment.create, { reportFailure: false });
1091
const deleteThread = useOrchestrationCommand(threadEnvironment.delete, { reportFailure: false });
1092
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
@@ -3797,223 +3774,16 @@ export default function ChatView(props: ChatViewProps) {
3774
};
3775
const runShellCommandStable = useStableCallback(runShellCommand);
3776
3800
- const supportsProjectSettingsOverrides =
3801
- environmentById.get(environmentId)?.serverConfig?.environment.capabilities
3802
- .projectSettingsOverrides === true;
3803
- const persistProjectScripts = async (input: {
3804
- projectId: ProjectId;
3805
- projectCwd: string;
3806
- previousScripts: ReadonlyArray<ProjectScript>;
3807
- nextScripts: ReadonlyArray<ProjectScript>;
3808
- keybinding: NewProjectScriptInput["keybinding"];
3809
- keybindingCommand: KeybindingCommand | null;
3810
- }): Promise<AtomCommandResult<void, unknown>> => {
3811
- const previousKeybinding = keybindingValueForCommand(
3812
- appAtomRegistry.get(serverEnvironment.configValueAtom(environmentId))?.keybindings ?? [],
3813
- input.keybindingCommand,
3814
- );
3815
- const isDeletingScript = !input.nextScripts.some(
3816
- (script) => commandForProjectScript(script.id) === input.keybindingCommand,
3817
- );
3818
- const changesKeybinding =
3819
- input.keybinding !== undefined &&
3820
- (input.keybinding?.trim() || null) !== previousKeybinding &&
3821
- (!isDeletingScript || readEnvironmentScope(environmentId, AuthSettingsWriteScope));
3822
- if (changesKeybinding && !readEnvironmentScope(environmentId, AuthSettingsWriteScope)) {
3823
- return AsyncResult.failure(
3824
- Cause.fail(
3825
- new EnvironmentAuthorizationError({
3826
- requiredScope: AuthSettingsWriteScope,
3827
- message: "This connection cannot change keyboard shortcuts.",
3828
- }),
3829
- ),
3830
- );
3831
- }
3832
- const keybindingRule = changesKeybinding
3833
- ? decodeProjectScriptKeybindingRule({
3834
- keybinding: input.keybinding,
3835
- command: input.keybindingCommand,
3836
- })
3837
- : null;
3838
- const updateResult = mapAtomCommandResult(
3839
- await updateProjectScriptSettings({
3840
- environmentId,
3841
- input: {
3842
- patch: supportsProjectSettingsOverrides
3843
- ? {
3844
- projectSettingsOverrides: {
3845
- [input.projectId]: {
3846
- ...settings.projectSettingsOverrides[input.projectId],
3847
- defaultProjectScripts: input.nextScripts,
3848
- },
3849
- },
3850
- }
3851
- : {
3852
- projectScriptOverrides: {
3853
- [input.projectId]: input.nextScripts,
3854
- },
3855
- },
3856
- },
3857
- }),
3858
- () => undefined,
3859
- );
3860
- if (updateResult._tag === "Failure") {
3861
- return updateResult;
3862
- }
3863
-
3864
- if (!changesKeybinding) return updateResult;
3865
- if (!readEnvironmentScope(environmentId, AuthSettingsWriteScope)) {
3866
- return AsyncResult.failure(
3867
- Cause.fail(
3868
- new EnvironmentAuthorizationError({
3869
- requiredScope: AuthSettingsWriteScope,
3870
- message: isDeletingScript
3871
- ? "The script was deleted, but its keyboard shortcut could not be removed because permission changed."
3872
- : "The script was saved, but this connection can no longer change keyboard shortcuts.",
3873
- }),
3874
- ),
3875
- );
3876
- }
3877
-
3878
- const scriptId = input.keybindingCommand
3879
- ? projectScriptIdFromCommand(input.keybindingCommand)
3880
- : null;
3881
- if (!keybindingRule && !input.previousScripts.some((script) => script.id === scriptId)) {
3882
- return updateResult;
3883
- }
3884
- const retainedElsewhere =
3885
- !input.nextScripts.some((script) => script.id === scriptId) &&
3886
- (settings.defaultProjectScripts.some((script) => script.id === scriptId) ||
3887
- Object.entries(settings.projectSettingsOverrides).some(
3888
- ([projectId, entry]) =>
3889
- projectId !== input.projectId &&
3890
- entry.defaultProjectScripts?.some((script) => script.id === scriptId),
3891
- ) ||
3892
- allProjects.some(
3893
- (other) =>
3894
- other.environmentId === environmentId &&
3895
- other.id !== input.projectId &&
3896
- resolveProjectScripts(settings, other).some((script) => script.id === scriptId),
3897
- ));
3898
- if (!keybindingRule && retainedElsewhere) return updateResult;
3899
-
3900
- const previousRules = (
3901
- environmentById.get(environmentId)?.serverConfig?.keybindings ?? []
3902
- ).flatMap((binding) => {
3903
- if (binding.command !== input.keybindingCommand || binding.whenAst) return [];
3904
- const previous = decodeProjectScriptKeybindingRule({
3905
- keybinding: keybindingValueForCommand([binding], input.keybindingCommand),
3906
- command: input.keybindingCommand,
3907
- });
3908
- return previous ? [previous] : [];
3909
- });
3910
- const previous = previousRules.at(-1);
3911
- for (const rule of keybindingRule ? previousRules.slice(0, -1) : previousRules) {
3912
- const result = await removeKeybinding({ environmentId, input: rule });
3913
- if (result._tag === "Failure") return mapAtomCommandResult(result, () => undefined);
3914
- }
3915
- return keybindingRule
3916
- ? mapAtomCommandResult(
3917
- await upsertKeybinding({
3918
- environmentId,
3919
- input:
3920
- previous && previous.key !== keybindingRule.key
3921
- ? { ...keybindingRule, replace: previous }
3922
- : keybindingRule,
3923
- }),
3924
- () => undefined,
3925
- )
3926
- : updateResult;
3927
- };
3928
- const saveProjectScript = async (
3929
- input: NewProjectScriptInput,
3930
- ): Promise<AtomCommandResult<void, unknown>> => {
3931
- if (!activeProject) {
3932
- return AsyncResult.success(undefined);
3933
- }
3934
- const nextId = nextProjectScriptId(
3935
- input.name,
3936
- activeProjectScripts.map((script) => script.id),
3937
- );
3938
- const nextScript = buildProjectScript(nextId, input);
3939
- const nextScripts = [
3940
- ...activeProjectScripts.map((script) => releaseClaimedRoles(script, input)),
3941
- nextScript,
3942
- ];
3943
-
3944
- return persistProjectScripts({
3945
- projectId: activeProject.id,
3946
- projectCwd: activeProject.workspaceRoot,
3947
- previousScripts: activeProjectScripts,
3948
- nextScripts,
3949
- keybinding: input.keybinding,
3950
- keybindingCommand: commandForProjectScript(nextId),
3951
- });
3952
- };
3953
- const saveProjectScriptStable = useStableCallback(saveProjectScript);
3954
- const updateProjectScript = async (
3955
- scriptId: string,
3956
- input: NewProjectScriptInput,
3957
- ): Promise<AtomCommandResult<void, unknown>> => {
3958
- if (!activeProject) {
3959
- return AsyncResult.success(undefined);
3960
- }
3961
- const existingScript = activeProjectScripts.find((script) => script.id === scriptId);
3962
- if (!existingScript) {
3963
- return AsyncResult.failure(Cause.fail(new Error("Script not found.")));
3964
- }
3965
-
3966
- const updatedScript = buildProjectScript(existingScript.id, input);
3967
- const nextScripts = activeProjectScripts.map((script) =>
3968
- script.id === scriptId ? updatedScript : releaseClaimedRoles(script, input),
3969
- );
3970
-
3971
- return persistProjectScripts({
3972
- projectId: activeProject.id,
3973
- projectCwd: activeProject.workspaceRoot,
3974
- previousScripts: activeProjectScripts,
3975
- nextScripts,
3976
- keybinding: input.keybinding,
3977
- keybindingCommand: commandForProjectScript(scriptId),
3978
- });
3979
- };
3980
- const updateProjectScriptStable = useStableCallback(updateProjectScript);
3981
- const deleteProjectScript = async (
3982
- scriptId: string,
3983
- ): Promise<AtomCommandResult<void, unknown>> => {
3984
- if (!activeProject) {
3985
- return AsyncResult.success(undefined);
3986
- }
3987
- const nextScripts = activeProjectScripts.filter((script) => script.id !== scriptId);
3988
-
3989
- const deletedName = activeProjectScripts.find((s) => s.id === scriptId)?.name;
3990
-
3991
- const result = await persistProjectScripts({
3992
- projectId: activeProject.id,
3993
- projectCwd: activeProject.workspaceRoot,
3994
- previousScripts: activeProjectScripts,
3995
- nextScripts,
3996
- keybinding: null,
3997
- keybindingCommand: commandForProjectScript(scriptId),
3998
- });
3999
- if (result._tag === "Success") {
4000
- toastManager.add({
4001
- type: "success",
4002
- title: `Deleted action "${deletedName ?? "Unknown"}"`,
4003
- });
4004
- } else if (!isAtomCommandInterrupted(result)) {
4005
- const error = squashAtomCommandFailure(result);
4006
- toastManager.add(
4007
- stackedThreadToast({
4008
- type: "error",
4009
- title: "Could not delete action",
4010
- description: error instanceof Error ? error.message : "An unexpected error occurred.",
4011
- }),
4012
- );
4013
- }
4014
- return result;
4015
- };
4016
- const deleteProjectScriptStable = useStableCallback(deleteProjectScript);
3777
+ const {
3778
+ saveProjectScript: saveProjectScriptStable,
3779
+ updateProjectScript: updateProjectScriptStable,
3780
+ deleteProjectScript: deleteProjectScriptStable,
3781
+ } = useProjectScriptEditing({
3782
+ environmentId,
3783
+ project: activeProject,
3784
+ scripts: activeProjectScripts,
3785
+ settings,
3786
+ });
3787
3788
const handleRuntimeModeChange = (mode: RuntimeMode) => {
3789
if (mode === runtimeMode) return;
apps/web/src/components/chat/useProjectScriptEditing.ts
new
+277
@@ -0,0 +1,277 @@
1
+import type {
2
+ KeybindingCommand,
3
+ ProjectId,
4
+ ProjectScript,
5
+ EnvironmentId,
6
+} from "@t3tools/contracts";
7
+import { AuthSettingsWriteScope, EnvironmentAuthorizationError } from "@t3tools/contracts";
8
+import type { UnifiedSettings } from "@t3tools/contracts/settings";
9
+import {
10
+ isAtomCommandInterrupted,
11
+ mapAtomCommandResult,
12
+ squashAtomCommandFailure,
13
+ type AtomCommandResult,
14
+} from "@t3tools/client-runtime/state/runtime";
15
+import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
16
+import { resolveProjectScripts } from "@t3tools/shared/projectScripts";
17
+import * as Cause from "effect/Cause";
18
+import { AsyncResult } from "effect/reactivity";
19
+import { useStableCallback } from "../../hooks/useStableCallback";
20
+import {
21
+ decodeProjectScriptKeybindingRule,
22
+ keybindingValueForCommand,
23
+} from "../../lib/projectScriptKeybindings";
24
+import {
25
+ buildProjectScript,
26
+ commandForProjectScript,
27
+ nextProjectScriptId,
28
+ projectScriptIdFromCommand,
29
+ releaseClaimedRoles,
30
+} from "../../projectScripts";
31
+import { appAtomRegistry } from "../../rpc/atomRegistry";
32
+import { serverEnvironment } from "../../state/server";
33
+import { readEnvironmentScope } from "../../state/session";
34
+import { useAtomCommand } from "../../state/use-atom-command";
35
+import { useProjects } from "../../state/entities";
36
+import { type NewProjectScriptInput } from "../ProjectScriptsControl";
37
+import { stackedThreadToast, toastManager } from "../ui/toast";
38
+
39
+/**
40
+ * Adds, edits, and deletes the active project's scripts. A script's keyboard
41
+ * shortcut lives in the environment's keybindings, so each change writes the
42
+ * script settings first and then reconciles the shortcut.
43
+ */
44
+export function useProjectScriptEditing(input: {
45
+ readonly environmentId: EnvironmentId;
46
+ readonly project: EnvironmentProject | null;
47
+ readonly scripts: ReadonlyArray<ProjectScript>;
48
+ readonly settings: UnifiedSettings;
49
+}) {
50
+ const { environmentId, project, scripts, settings } = input;
51
+ const allProjects = useProjects();
52
+ const updateProjectScriptSettings = useAtomCommand(serverEnvironment.updateSettings, {
53
+ reportFailure: false,
54
+ });
55
+ const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
56
+ reportFailure: false,
57
+ });
58
+ const removeKeybinding = useAtomCommand(serverEnvironment.removeKeybinding, {
59
+ reportFailure: false,
60
+ });
61
+ const persistProjectScripts = async (input: {
62
+ projectId: ProjectId;
63
+ projectCwd: string;
64
+ previousScripts: ReadonlyArray<ProjectScript>;
65
+ nextScripts: ReadonlyArray<ProjectScript>;
66
+ keybinding: NewProjectScriptInput["keybinding"];
67
+ keybindingCommand: KeybindingCommand | null;
68
+ }): Promise<AtomCommandResult<void, unknown>> => {
69
+ const serverConfig = appAtomRegistry.get(serverEnvironment.configValueAtom(environmentId));
70
+ const previousKeybinding = keybindingValueForCommand(
71
+ serverConfig?.keybindings ?? [],
72
+ input.keybindingCommand,
73
+ );
74
+ const isDeletingScript = !input.nextScripts.some(
75
+ (script) => commandForProjectScript(script.id) === input.keybindingCommand,
76
+ );
77
+ const changesKeybinding =
78
+ input.keybinding !== undefined &&
79
+ (input.keybinding?.trim() || null) !== previousKeybinding &&
80
+ (!isDeletingScript || readEnvironmentScope(environmentId, AuthSettingsWriteScope));
81
+ if (changesKeybinding && !readEnvironmentScope(environmentId, AuthSettingsWriteScope)) {
82
+ return AsyncResult.failure(
83
+ Cause.fail(
84
+ new EnvironmentAuthorizationError({
85
+ requiredScope: AuthSettingsWriteScope,
86
+ message: "This connection cannot change keyboard shortcuts.",
87
+ }),
88
+ ),
89
+ );
90
+ }
91
+ const keybindingRule = changesKeybinding
92
+ ? decodeProjectScriptKeybindingRule({
93
+ keybinding: input.keybinding,
94
+ command: input.keybindingCommand,
95
+ })
96
+ : null;
97
+ const updateResult = mapAtomCommandResult(
98
+ await updateProjectScriptSettings({
99
+ environmentId,
100
+ input: {
101
+ patch:
102
+ serverConfig?.environment.capabilities.projectSettingsOverrides === true
103
+ ? {
104
+ projectSettingsOverrides: {
105
+ [input.projectId]: {
106
+ ...settings.projectSettingsOverrides[input.projectId],
107
+ defaultProjectScripts: input.nextScripts,
108
+ },
109
+ },
110
+ }
111
+ : {
112
+ projectScriptOverrides: {
113
+ [input.projectId]: input.nextScripts,
114
+ },
115
+ },
116
+ },
117
+ }),
118
+ () => undefined,
119
+ );
120
+ if (updateResult._tag === "Failure") {
121
+ return updateResult;
122
+ }
123
+
124
+ if (!changesKeybinding) return updateResult;
125
+ if (!readEnvironmentScope(environmentId, AuthSettingsWriteScope)) {
126
+ return AsyncResult.failure(
127
+ Cause.fail(
128
+ new EnvironmentAuthorizationError({
129
+ requiredScope: AuthSettingsWriteScope,
130
+ message: isDeletingScript
131
+ ? "The script was deleted, but its keyboard shortcut could not be removed because permission changed."
132
+ : "The script was saved, but this connection can no longer change keyboard shortcuts.",
133
+ }),
134
+ ),
135
+ );
136
+ }
137
+
138
+ const scriptId = input.keybindingCommand
139
+ ? projectScriptIdFromCommand(input.keybindingCommand)
140
+ : null;
141
+ if (!keybindingRule && !input.previousScripts.some((script) => script.id === scriptId)) {
142
+ return updateResult;
143
+ }
144
+ const retainedElsewhere =
145
+ !input.nextScripts.some((script) => script.id === scriptId) &&
146
+ (settings.defaultProjectScripts.some((script) => script.id === scriptId) ||
147
+ Object.entries(settings.projectSettingsOverrides).some(
148
+ ([projectId, entry]) =>
149
+ projectId !== input.projectId &&
150
+ entry.defaultProjectScripts?.some((script) => script.id === scriptId),
151
+ ) ||
152
+ allProjects.some(
153
+ (other) =>
154
+ other.environmentId === environmentId &&
155
+ other.id !== input.projectId &&
156
+ resolveProjectScripts(settings, other).some((script) => script.id === scriptId),
157
+ ));
158
+ if (!keybindingRule && retainedElsewhere) return updateResult;
159
+
160
+ const previousRules = (serverConfig?.keybindings ?? []).flatMap((binding) => {
161
+ if (binding.command !== input.keybindingCommand || binding.whenAst) return [];
162
+ const previous = decodeProjectScriptKeybindingRule({
163
+ keybinding: keybindingValueForCommand([binding], input.keybindingCommand),
164
+ command: input.keybindingCommand,
165
+ });
166
+ return previous ? [previous] : [];
167
+ });
168
+ const previous = previousRules.at(-1);
169
+ for (const rule of keybindingRule ? previousRules.slice(0, -1) : previousRules) {
170
+ const result = await removeKeybinding({ environmentId, input: rule });
171
+ if (result._tag === "Failure") return mapAtomCommandResult(result, () => undefined);
172
+ }
173
+ return keybindingRule
174
+ ? mapAtomCommandResult(
175
+ await upsertKeybinding({
176
+ environmentId,
177
+ input:
178
+ previous && previous.key !== keybindingRule.key
179
+ ? { ...keybindingRule, replace: previous }
180
+ : keybindingRule,
181
+ }),
182
+ () => undefined,
183
+ )
184
+ : updateResult;
185
+ };
186
+ const saveProjectScript = async (
187
+ input: NewProjectScriptInput,
188
+ ): Promise<AtomCommandResult<void, unknown>> => {
189
+ if (!project) {
190
+ return AsyncResult.success(undefined);
191
+ }
192
+ const nextId = nextProjectScriptId(
193
+ input.name,
194
+ scripts.map((script) => script.id),
195
+ );
196
+ const nextScript = buildProjectScript(nextId, input);
197
+ const nextScripts = [
198
+ ...scripts.map((script) => releaseClaimedRoles(script, input)),
199
+ nextScript,
200
+ ];
201
+
202
+ return persistProjectScripts({
203
+ projectId: project.id,
204
+ projectCwd: project.workspaceRoot,
205
+ previousScripts: scripts,
206
+ nextScripts,
207
+ keybinding: input.keybinding,
208
+ keybindingCommand: commandForProjectScript(nextId),
209
+ });
210
+ };
211
+ const updateProjectScript = async (
212
+ scriptId: string,
213
+ input: NewProjectScriptInput,
214
+ ): Promise<AtomCommandResult<void, unknown>> => {
215
+ if (!project) {
216
+ return AsyncResult.success(undefined);
217
+ }
218
+ const existingScript = scripts.find((script) => script.id === scriptId);
219
+ if (!existingScript) {
220
+ return AsyncResult.failure(Cause.fail(new Error("Script not found.")));
221
+ }
222
+
223
+ const updatedScript = buildProjectScript(existingScript.id, input);
224
+ const nextScripts = scripts.map((script) =>
225
+ script.id === scriptId ? updatedScript : releaseClaimedRoles(script, input),
226
+ );
227
+
228
+ return persistProjectScripts({
229
+ projectId: project.id,
230
+ projectCwd: project.workspaceRoot,
231
+ previousScripts: scripts,
232
+ nextScripts,
233
+ keybinding: input.keybinding,
234
+ keybindingCommand: commandForProjectScript(scriptId),
235
+ });
236
+ };
237
+ const deleteProjectScript = async (
238
+ scriptId: string,
239
+ ): Promise<AtomCommandResult<void, unknown>> => {
240
+ if (!project) {
241
+ return AsyncResult.success(undefined);
242
+ }
243
+ const nextScripts = scripts.filter((script) => script.id !== scriptId);
244
+
245
+ const deletedName = scripts.find((s) => s.id === scriptId)?.name;
246
+
247
+ const result = await persistProjectScripts({
248
+ projectId: project.id,
249
+ projectCwd: project.workspaceRoot,
250
+ previousScripts: scripts,
251
+ nextScripts,
252
+ keybinding: null,
253
+ keybindingCommand: commandForProjectScript(scriptId),
254
+ });
255
+ if (result._tag === "Success") {
256
+ toastManager.add({
257
+ type: "success",
258
+ title: `Deleted action "${deletedName ?? "Unknown"}"`,
259
+ });
260
+ } else if (!isAtomCommandInterrupted(result)) {
261
+ const error = squashAtomCommandFailure(result);
262
+ toastManager.add(
263
+ stackedThreadToast({
264
+ type: "error",
265
+ title: "Could not delete action",
266
+ description: error instanceof Error ? error.message : "An unexpected error occurred.",
267
+ }),
268
+ );
269
+ }
270
+ return result;
271
+ };
272
+ return {
273
+ saveProjectScript: useStableCallback(saveProjectScript),
274
+ updateProjectScript: useStableCallback(updateProjectScript),
275
+ deleteProjectScript: useStableCallback(deleteProjectScript),
276
+ };
277
+}