char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Sominitial commite6df845

main
565 B16 linesraw
1// atproto timestamp identifiers: 53 bits of microseconds and a 10-bit clock id, as sortable base32.
2
3const ALPHABET = "234567abcdefghijklmnopqrstuvwxyz";
4const CLOCK_ID = BigInt(Math.floor(Math.random() * 1024));
5
6export const TID_PATTERN = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/;
7
8let last = 0;
9
10export function tid(now = Date.now()): string {
11  last = Math.max(now * 1000, last + 1);
12  let n = (BigInt(last) << 10n) | CLOCK_ID;
13  let out = "";
14  for (let i = 0; i < 13; i++, n >>= 5n) out = ALPHABET[Number(n & 31n)] + out;
15  return out;
16}