Move the duplicated script normalization logic (dedup-by-id + single runOnWorktreeCreate enforcement) from apps/web/src/store.ts and apps/server/src/projectRegistry.ts into packages/contracts/src/project.ts so both consumers share one canonical implementation. Applied via @cursor push command
Showing the changes to apps/web/src (1 of 3 files). Show all
Unified · Split
| @@ -8,7 +8,7 @@ import { · 7 unmodified lines | ||
| 8 | 8 | useReducer, |
| 9 | 9 | } from "react"; |
| 10 | 10 | |
| 11 | −import type { ProviderEvent, ProviderSession, TerminalEvent } from "@t3tools/contracts"; | |
| 11 | +import { type ProviderEvent, type ProviderSession, type TerminalEvent, normalizeProjectScripts } from "@t3tools/contracts"; | |
| 12 | 12 | import { resolveModelSlug } from "./model-logic"; |
| 13 | 13 | import { hydratePersistedState, toPersistedState } from "./persistenceSchema"; |
| 14 | 14 | import { applyEventToMessages, asObject, asString, evolveSession } from "./session-logic"; |
| @@ -165,37 +165,6 @@ function normalizeRunningTerminalIds( · 150 unmodified lines | ||
| 165 | 165 | .filter((id) => id.length > 0 && validTerminalIdSet.has(id)); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | −function normalizeProjectScripts(scripts: ProjectScript[]): ProjectScript[] { | |
| 169 | − const deduped: ProjectScript[] = []; | |
| 170 | − const seenIds = new Set<string>(); | |
| 171 | − for (const script of scripts) { | |
| 172 | − const id = script.id.trim(); | |
| 173 | − if (id.length === 0 || seenIds.has(id)) continue; | |
| 174 | − seenIds.add(id); | |
| 175 | − deduped.push({ | |
| 176 | − ...script, | |
| 177 | − id, | |
| 178 | − name: script.name.trim(), | |
| 179 | − command: script.command.trim(), | |
| 180 | − }); | |
| 181 | − } | |
| 182 | − | |
| 183 | − let setupAssigned = false; | |
| 184 | − const normalized: ProjectScript[] = []; | |
| 185 | − for (const script of deduped) { | |
| 186 | − if (!script.runOnWorktreeCreate) { | |
| 187 | − normalized.push(script); | |
| 188 | − continue; | |
| 189 | − } | |
| 190 | − if (!setupAssigned) { | |
| 191 | − setupAssigned = true; | |
| 192 | − normalized.push(script); | |
| 193 | − continue; | |
| 194 | − } | |
| 195 | − normalized.push({ ...script, runOnWorktreeCreate: false }); | |
| 196 | − } | |
| 197 | − return normalized; | |
| 198 | −} | |
| 199 | 168 | |
| 200 | 169 | function normalizeTerminalGroupIds(terminalIds: string[]): string[] { |
| 201 | 170 | return [...new Set(terminalIds.map((id) => id.trim()).filter((id) => id.length > 0))]; |