MCPcopy Create free account
hub / github.com/pingdotgg/t3code / nextProjectScriptId

Function nextProjectScriptId

apps/web/src/projectScripts.ts:37–57  ·  view source on GitHub ↗
(name: string, existingIds: Iterable<string>)

Source from the content-addressed store, hash-verified

35}
36
37export function nextProjectScriptId(name: string, existingIds: Iterable<string>): string {
38 const taken = new Set(Array.from(existingIds));
39 const baseId = normalizeScriptId(name);
40 if (!taken.has(baseId)) return baseId;
41
42 let suffix = 2;
43 while (suffix < 10_000) {
44 const candidate = `${baseId}-${suffix}`;
45 const safeCandidate =
46 candidate.length <= MAX_SCRIPT_ID_LENGTH
47 ? candidate
48 : `${baseId.slice(0, Math.max(1, MAX_SCRIPT_ID_LENGTH - String(suffix).length - 1))}-${suffix}`;
49 if (!taken.has(safeCandidate)) {
50 return safeCandidate;
51 }
52 suffix += 1;
53 }
54
55 // This last-resort fallback only triggers after exhausting thousands of suffixes.
56 return `${baseId}-${Date.now()}`.slice(0, MAX_SCRIPT_ID_LENGTH);
57}
58
59export function primaryProjectScript(scripts: ReadonlyArray<ProjectScript>): ProjectScript | null {
60 const regular = scripts.find((script) => !script.runOnWorktreeCreate);

Callers 3

submitAddScriptFunction · 0.90
ChatViewContentFunction · 0.90

Calls 1

normalizeScriptIdFunction · 0.85

Tested by

no test coverage detected