char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somdiff: add (codemirror) inline editing of diffsc5dd844

main
718 B26 linesraw
1import type { ViewDestination } from "@berry/api/web.ts";
2
3let guard: ((destination: ViewDestination) => boolean | Promise<boolean>) | null = null;
4
5export function guardNavigation(check: NonNullable<typeof guard>) {
6  guard = check;
7  return () => {
8    if (guard === check) guard = null;
9  };
10}
11
12export function beforeNavigate(route: string): boolean | Promise<boolean> {
13  const [tid, extension, ...parts] = route.split("/");
14  const decode = (part: string) => {
15    try {
16      return decodeURIComponent(part);
17    } catch {
18      return part;
19    }
20  };
21  return guard?.({
22    tid: /^[a-z2-7]{13}$/.test(tid) ? tid : null,
23    extension: extension ?? null,
24    route: parts.map(decode).join("/"),
25  }) ?? true;
26}