From c4d84eabce1fd2d1a3044498fb52a84edb03f20d Mon Sep 17 00:00:00 2001
From: lyxal <36217120+Lyxal@users.noreply.github.com>
Date: Mon, 13 Jan 2025 23:11:44 +1100
Subject: [PATCH 1/7] This will surely work first try (I have not built yet,
 but will in a bit)

---
 src/latest/data/releaseDates.json           |  1 +
 src/latest/scripts/interpreter/permalink.ts | 38 ++++++++++++++++++++-
 src/latest/scripts/ui/Theseus.tsx           | 11 +++---
 3 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 src/latest/data/releaseDates.json

diff --git a/src/latest/data/releaseDates.json b/src/latest/data/releaseDates.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/src/latest/data/releaseDates.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/latest/scripts/interpreter/permalink.ts b/src/latest/scripts/interpreter/permalink.ts
index a0a8446..00e6886 100644
--- a/src/latest/scripts/interpreter/permalink.ts
+++ b/src/latest/scripts/interpreter/permalink.ts
@@ -1,7 +1,10 @@
 import compatRaw from "../../data/compat.json?raw";
+import datesRaw from "../../data/releaseDates.json?raw";
 import { gunzipString, gzipString } from "gzip-utils";
 
 const compat = JSON.parse(compatRaw);
+const releaseDates = JSON.parse(datesRaw);
+const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "hacky ahh solution"
 
 type OldPermalinks = {
     format: 2,
@@ -13,7 +16,7 @@ type OldPermalinks = {
     version: string,
 };
 
-const latestPermalink = 3;
+const latestPermalink = 4;
 export type Permalink = {
     format: typeof latestPermalink,
     flags: string[],
@@ -24,7 +27,39 @@ export type Permalink = {
     version: string,
 };
 
+function decodeVersion(version: string): string {
+    // This is what happens when you let lyxal write a hack
+    // solution to something that probably required a bigger
+    // refactoring. (Comment written by, surprisingly, lyxal)
+
+    // Version will either be `x.y.z` or `dd/mm/yyyy`. So
+    // determine which one it is. If `x.y.z`, simply return
+    // it.
+
+    if (version.includes(".")) {
+        return version;
+    }
+
+    // It's a date, which means fun because that's the whole
+    // point of this function. The version can be determined
+    // by finding the first release on a date after the given
+    // date.
+
+    // But first, convert the string to a date object.
+    const date = new Date(version);
+
+    // Now, iterate through the release dates and find the
+    // first release after the given date.
+
+    const candidates = Object.entries(releaseDates).filter(([_, d]) => new Date(d.toString()) > date);
+    if (candidates.length === 0) {
+        return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
+    }
+    return candidates[0][1].toString();
+}
+
 function incompatible(permalinkVersion: string) {
+    if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return true; }
     return compat[permalinkVersion] ?? false;
 }
 
@@ -84,6 +119,7 @@ export async function decodeHash(hash: string): Promise<DecodeResult | null> {
         }
     }
     try {
+        let realVersion = decodeVersion(permalink.version);
         if (incompatible(permalink.version)) {
             return { compatible: false, version: permalink.version };
         }
diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index 33ff1bf..d6f44b0 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -74,10 +74,10 @@ export function Theseus({ permalink }: TheseusProps) {
 
     const [state, setState] = useState<RunState>({ name: autorun ? "starting" : "idle" });
     const [lastFocusedEditor, setLastFocusedEditor] = useState<ReactCodeMirrorRef | null>(null);
-    
+
     const runnerRef = useRef<VyTerminalRef | null>(null);
     const snowflakesRef = useRef<Snowflakes | null>(null);
-    
+
     useEffect(() => {
         switch (settingsState.theme) {
             case Theme.Dark:
@@ -109,13 +109,14 @@ export function Theseus({ permalink }: TheseusProps) {
     }, [settingsState]);
 
     useEffect(() => {
+        const date = new Date();
         encodeHash({
             header,
             code,
             footer,
             flags: [...serializeFlags(elementData.flagDefs, flags)],
             inputs: inputs.map(({ name, inputs }) => [name, inputs.map(({ input }) => input)]),
-            version: elementData.version,
+            version: `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`,
         }).then((hash) => history.replaceState(undefined, "", "#" + hash));
     }, [header, code, footer, flags, inputs, elementData]);
 
@@ -134,7 +135,7 @@ export function Theseus({ permalink }: TheseusProps) {
         utilWorker.formatBytecount(code, literate).then(setBytecount);
     }, [code, flags, utilWorker, literate]);
 
-    const literateToSbcs = useCallback(async() => {
+    const literateToSbcs = useCallback(async () => {
         runnerRef.current?.showMessage(`\x1b[1mSBCS translation:\x1b[0m\n${await utilWorker.sbcsify(code)}`);
     }, [code, runnerRef, utilWorker]);
 
@@ -174,7 +175,7 @@ export function Theseus({ permalink }: TheseusProps) {
                 if (view != null) {
                     view.dispatch(view.state.replaceSelection(char));
                 }
-            }} 
+            }}
         />
         <div className="w-100 h-100 vstack">
             <Header

From 3e7ac5df6871326839d66c8292934c0a1189cb51 Mon Sep 17 00:00:00 2001
From: lyxal <36217120+Lyxal@users.noreply.github.com>
Date: Mon, 13 Jan 2025 23:42:18 +1100
Subject: [PATCH 2/7] Fix the date linked permalink up

---
 src/latest/scripts/interpreter/permalink.ts | 18 +++++++++++-------
 src/latest/scripts/main.tsx                 |  4 +++-
 src/latest/scripts/ui/Theseus.tsx           |  2 +-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/latest/scripts/interpreter/permalink.ts b/src/latest/scripts/interpreter/permalink.ts
index 00e6886..8ae7435 100644
--- a/src/latest/scripts/interpreter/permalink.ts
+++ b/src/latest/scripts/interpreter/permalink.ts
@@ -4,7 +4,7 @@ import { gunzipString, gzipString } from "gzip-utils";
 
 const compat = JSON.parse(compatRaw);
 const releaseDates = JSON.parse(datesRaw);
-const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "hacky ahh solution"
+const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "latest"
 
 type OldPermalinks = {
     format: 2,
@@ -16,7 +16,7 @@ type OldPermalinks = {
     version: string,
 };
 
-const latestPermalink = 4;
+const latestPermalink = 3;
 export type Permalink = {
     format: typeof latestPermalink,
     flags: string[],
@@ -28,6 +28,7 @@ export type Permalink = {
 };
 
 function decodeVersion(version: string): string {
+
     // This is what happens when you let lyxal write a hack
     // solution to something that probably required a bigger
     // refactoring. (Comment written by, surprisingly, lyxal)
@@ -51,15 +52,16 @@ function decodeVersion(version: string): string {
     // Now, iterate through the release dates and find the
     // first release after the given date.
 
-    const candidates = Object.entries(releaseDates).filter(([_, d]) => new Date(d.toString()) > date);
+    const parsedDates: [string, Date][] = Object.entries(releaseDates).map(([v, d]) => [v, new Date(Date.parse(d as string))]);
+    const candidates = parsedDates.filter(([_, d]) => new Date(d) > date);
     if (candidates.length === 0) {
         return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
     }
-    return candidates[0][1].toString();
+    return candidates[0][0];
 }
 
 function incompatible(permalinkVersion: string) {
-    if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return true; }
+    if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return false; }
     return compat[permalinkVersion] ?? false;
 }
 
@@ -120,8 +122,10 @@ export async function decodeHash(hash: string): Promise<DecodeResult | null> {
     }
     try {
         let realVersion = decodeVersion(permalink.version);
-        if (incompatible(permalink.version)) {
-            return { compatible: false, version: permalink.version };
+        console.log("Real version:", realVersion);
+        console.log("Permalink version:", permalink.version);
+        if (incompatible(realVersion)) {
+            return { compatible: false, version: realVersion };
         }
         switch (permalink.format) {
             case 2: {
diff --git a/src/latest/scripts/main.tsx b/src/latest/scripts/main.tsx
index d73c259..c53558f 100644
--- a/src/latest/scripts/main.tsx
+++ b/src/latest/scripts/main.tsx
@@ -20,7 +20,9 @@ const fallback = document.getElementById("fallback-ui")!;
 fallback.hidden = true;
 const permalink = window.location.hash.length ? await decodeHash(window.location.hash.slice(1)) : null;
 if (permalink != null && !permalink.compatible) {
-    window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);
+    console.error("Incompatible permalink version!", permalink.version);
+    // window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);
+
 } else {
     // @ts-expect-error DATA_URI gets replaced by Webpack
     const elementData = parseElementData(await fetch(`${DATA_URI}/theseus.json`).then((r) => r.json()));
diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index d6f44b0..11348d3 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -116,7 +116,7 @@ export function Theseus({ permalink }: TheseusProps) {
             footer,
             flags: [...serializeFlags(elementData.flagDefs, flags)],
             inputs: inputs.map(({ name, inputs }) => [name, inputs.map(({ input }) => input)]),
-            version: `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`,
+            version: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`,
         }).then((hash) => history.replaceState(undefined, "", "#" + hash));
     }, [header, code, footer, flags, inputs, elementData]);
 

From e7637c2f3c71cd0d427dc1a1679c31798157c891 Mon Sep 17 00:00:00 2001
From: lyxal <lyxal@users.noreply.github.com>
Date: Mon, 13 Jan 2025 12:45:22 +0000
Subject: [PATCH 3/7] ESLint fixes

---
 src/latest/scripts/interpreter/permalink.ts | 8 +++++---
 src/latest/scripts/ui/Theseus.tsx           | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/latest/scripts/interpreter/permalink.ts b/src/latest/scripts/interpreter/permalink.ts
index 8ae7435..7f68ac2 100644
--- a/src/latest/scripts/interpreter/permalink.ts
+++ b/src/latest/scripts/interpreter/permalink.ts
@@ -4,7 +4,7 @@ import { gunzipString, gzipString } from "gzip-utils";
 
 const compat = JSON.parse(compatRaw);
 const releaseDates = JSON.parse(datesRaw);
-const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "latest"
+const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "latest";
 
 type OldPermalinks = {
     format: 2,
@@ -61,7 +61,9 @@ function decodeVersion(version: string): string {
 }
 
 function incompatible(permalinkVersion: string) {
-    if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return false; }
+    if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) {
+        return false; 
+    }
     return compat[permalinkVersion] ?? false;
 }
 
@@ -121,7 +123,7 @@ export async function decodeHash(hash: string): Promise<DecodeResult | null> {
         }
     }
     try {
-        let realVersion = decodeVersion(permalink.version);
+        const realVersion = decodeVersion(permalink.version);
         console.log("Real version:", realVersion);
         console.log("Permalink version:", permalink.version);
         if (incompatible(realVersion)) {
diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index 11348d3..45dcc88 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -135,7 +135,7 @@ export function Theseus({ permalink }: TheseusProps) {
         utilWorker.formatBytecount(code, literate).then(setBytecount);
     }, [code, flags, utilWorker, literate]);
 
-    const literateToSbcs = useCallback(async () => {
+    const literateToSbcs = useCallback(async() => {
         runnerRef.current?.showMessage(`\x1b[1mSBCS translation:\x1b[0m\n${await utilWorker.sbcsify(code)}`);
     }, [code, runnerRef, utilWorker]);
 

From e1eb4ca2ace5eabb66805c60d13075db3aa43b8e Mon Sep 17 00:00:00 2001
From: lyxal <36217120+Lyxal@users.noreply.github.com>
Date: Tue, 14 Jan 2025 00:22:32 +1100
Subject: [PATCH 4/7] Switch from checking dates to checking timestamps

---
 src/latest/scripts/interpreter/permalink.ts | 14 ++++++++------
 src/latest/scripts/main.tsx                 |  3 +--
 src/latest/scripts/ui/Theseus.tsx           |  4 ++--
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/latest/scripts/interpreter/permalink.ts b/src/latest/scripts/interpreter/permalink.ts
index 7f68ac2..2b32ee3 100644
--- a/src/latest/scripts/interpreter/permalink.ts
+++ b/src/latest/scripts/interpreter/permalink.ts
@@ -33,7 +33,7 @@ function decodeVersion(version: string): string {
     // solution to something that probably required a bigger
     // refactoring. (Comment written by, surprisingly, lyxal)
 
-    // Version will either be `x.y.z` or `dd/mm/yyyy`. So
+    // Version will either be `x.y.z` or a unix timestamp. So
     // determine which one it is. If `x.y.z`, simply return
     // it.
 
@@ -41,19 +41,21 @@ function decodeVersion(version: string): string {
         return version;
     }
 
-    // It's a date, which means fun because that's the whole
+    // It's a timestamp, which means fun because that's the whole
     // point of this function. The version can be determined
     // by finding the first release on a date after the given
     // date.
 
     // But first, convert the string to a date object.
-    const date = new Date(version);
+    // Multiply the "version" by 1000 to convert it to
+    // milliseconds.
+    const timestamp = Number.parseInt(version);
 
     // Now, iterate through the release dates and find the
     // first release after the given date.
 
-    const parsedDates: [string, Date][] = Object.entries(releaseDates).map(([v, d]) => [v, new Date(Date.parse(d as string))]);
-    const candidates = parsedDates.filter(([_, d]) => new Date(d) > date);
+    const parsedDates: [string, number][] = Object.entries(releaseDates).map(([v, d]) => [v, Number.parseInt(d as string)]);
+    const candidates = parsedDates.filter(([_, d]) => d > timestamp);
     if (candidates.length === 0) {
         return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
     }
@@ -62,7 +64,7 @@ function decodeVersion(version: string): string {
 
 function incompatible(permalinkVersion: string) {
     if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) {
-        return false; 
+        return false;
     }
     return compat[permalinkVersion] ?? false;
 }
diff --git a/src/latest/scripts/main.tsx b/src/latest/scripts/main.tsx
index c53558f..fba98f1 100644
--- a/src/latest/scripts/main.tsx
+++ b/src/latest/scripts/main.tsx
@@ -20,8 +20,7 @@ const fallback = document.getElementById("fallback-ui")!;
 fallback.hidden = true;
 const permalink = window.location.hash.length ? await decodeHash(window.location.hash.slice(1)) : null;
 if (permalink != null && !permalink.compatible) {
-    console.error("Incompatible permalink version!", permalink.version);
-    // window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);
+    window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);
 
 } else {
     // @ts-expect-error DATA_URI gets replaced by Webpack
diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index 45dcc88..99e66d2 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -116,7 +116,7 @@ export function Theseus({ permalink }: TheseusProps) {
             footer,
             flags: [...serializeFlags(elementData.flagDefs, flags)],
             inputs: inputs.map(({ name, inputs }) => [name, inputs.map(({ input }) => input)]),
-            version: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`,
+            version: `${Date.now()}`,
         }).then((hash) => history.replaceState(undefined, "", "#" + hash));
     }, [header, code, footer, flags, inputs, elementData]);
 
@@ -135,7 +135,7 @@ export function Theseus({ permalink }: TheseusProps) {
         utilWorker.formatBytecount(code, literate).then(setBytecount);
     }, [code, flags, utilWorker, literate]);
 
-    const literateToSbcs = useCallback(async() => {
+    const literateToSbcs = useCallback(async () => {
         runnerRef.current?.showMessage(`\x1b[1mSBCS translation:\x1b[0m\n${await utilWorker.sbcsify(code)}`);
     }, [code, runnerRef, utilWorker]);
 

From 96d2f47ed6f58618be1ee941a1dda662a889baec Mon Sep 17 00:00:00 2001
From: lyxal <lyxal@users.noreply.github.com>
Date: Mon, 13 Jan 2025 13:23:09 +0000
Subject: [PATCH 5/7] ESLint fixes

---
 src/latest/scripts/ui/Theseus.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index 99e66d2..aa64e12 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -135,7 +135,7 @@ export function Theseus({ permalink }: TheseusProps) {
         utilWorker.formatBytecount(code, literate).then(setBytecount);
     }, [code, flags, utilWorker, literate]);
 
-    const literateToSbcs = useCallback(async () => {
+    const literateToSbcs = useCallback(async() => {
         runnerRef.current?.showMessage(`\x1b[1mSBCS translation:\x1b[0m\n${await utilWorker.sbcsify(code)}`);
     }, [code, runnerRef, utilWorker]);
 

From b5b2caa14e83cefe8a04708ddc74793c31edb08d Mon Sep 17 00:00:00 2001
From: lyxal <36217120+lyxal@users.noreply.github.com>
Date: Tue, 14 Jan 2025 00:25:50 +1100
Subject: [PATCH 6/7] Fix code scanning alert no. 87: Disallow unused variables

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
---
 src/latest/scripts/interpreter/permalink.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/latest/scripts/interpreter/permalink.ts b/src/latest/scripts/interpreter/permalink.ts
index 2b32ee3..18c66d5 100644
--- a/src/latest/scripts/interpreter/permalink.ts
+++ b/src/latest/scripts/interpreter/permalink.ts
@@ -55,7 +55,7 @@ function decodeVersion(version: string): string {
     // first release after the given date.
 
     const parsedDates: [string, number][] = Object.entries(releaseDates).map(([v, d]) => [v, Number.parseInt(d as string)]);
-    const candidates = parsedDates.filter(([_, d]) => d > timestamp);
+    const candidates = parsedDates.filter(([, d]) => d > timestamp);
     if (candidates.length === 0) {
         return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
     }

From 6d9127fa3c3ec536b5c3ba1f553428c8d3327383 Mon Sep 17 00:00:00 2001
From: lyxal <36217120+lyxal@users.noreply.github.com>
Date: Tue, 14 Jan 2025 00:26:46 +1100
Subject: [PATCH 7/7] Fix code scanning alert no. 88: Disallow unused variables

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
---
 src/latest/scripts/ui/Theseus.tsx | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/latest/scripts/ui/Theseus.tsx b/src/latest/scripts/ui/Theseus.tsx
index aa64e12..31f3c60 100644
--- a/src/latest/scripts/ui/Theseus.tsx
+++ b/src/latest/scripts/ui/Theseus.tsx
@@ -109,7 +109,6 @@ export function Theseus({ permalink }: TheseusProps) {
     }, [settingsState]);
 
     useEffect(() => {
-        const date = new Date();
         encodeHash({
             header,
             code,