@devries-cameron20 / t3code Mirror · read-only
Fork 0

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 21, 06:00 UTC

main
ts 46 lines 1.69 KB
Raw
1 import { alchemyLabelKeys } from "../Labels.ts";
2
3 export const lastSegment = (value: string) => {
4 const trimmed = value.replace(/\/+$/, "");
5 const parts = trimmed.split("/");
6 return parts[parts.length - 1] || trimmed;
7 };
8
9 export const encodeDescription = (
10 labels: Record<string, string>,
11 description: string | undefined,
12 ): string => {
13 const marker = `[alchemy ${alchemyLabelKeys.stack}=${labels[alchemyLabelKeys.stack]} ${alchemyLabelKeys.stage}=${labels[alchemyLabelKeys.stage]} ${alchemyLabelKeys.id}=${labels[alchemyLabelKeys.id]}]`;
14 return description ? `${marker}\n${description}` : marker;
15 };
16
17 export const parseDescription = (
18 description: string | undefined,
19 ): {
20 labels: Record<string, string>;
21 description: string | undefined;
22 } => {
23 if (!description?.startsWith("[alchemy ")) {
24 return { labels: {}, description };
25 }
26 const end = description.indexOf("]");
27 if (end < 0) return { labels: {}, description };
28 const labels: Record<string, string> = {};
29 for (const part of description.slice("[alchemy ".length, end).split(/\s+/)) {
30 const eq = part.indexOf("=");
31 if (eq > 0) {
32 labels[part.slice(0, eq)] = part.slice(eq + 1);
33 }
34 }
35 const rest = description.slice(end + 1).replace(/^\n/, "");
36 return { labels, description: rest.length > 0 ? rest : undefined };
37 };
38
39 export const hasOwnershipMarker = (description: string | undefined) =>
40 Object.keys(parseDescription(description).labels).some((key) => key.startsWith("alchemy-"));
41
42 export const jsonEqual = (left: unknown, right: unknown) =>
43 JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
44
45 export const sortedStrings = (values: readonly string[] | undefined) =>
46 [...(values ?? [])].slice().sort();