repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | """ |
| #2 | Mnemosyne AAAK Dialect |
| #3 | Full-fledged compression scheme for AI memory context. |
| #4 | Lossless shorthand that LLMs parse efficiently without a decoder. |
| #5 | """ |
| #6 | |
| #7 | import re |
| #8 | from typing import List, Tuple |
| #9 | |
| #10 | # Category prefixes → AAAK codes |
| #11 | CATEGORY_MAP = { |
| #12 | "PREFERENCE": "PREF", |
| #13 | "TRAIT": "TRAIT", |
| #14 | "STATUS": "STAT", |
| #15 | "INSTRUCTION": "INST", |
| #16 | "PROJECT": "PROJ", |
| #17 | "LOCATION": "LOC", |
| #18 | "FAMILY": "FAM", |
| #19 | "OCCUPATION": "OCC", |
| #20 | "DECISION": "DEC", |
| #21 | "EVENT": "EVT", |
| #22 | "TOOL": "TOOL", |
| #23 | "FACT": "FACT", |
| #24 | "OPINION": "OPN", |
| #25 | } |
| #26 | |
| #27 | # Common structural phrases → compressed forms |
| #28 | PHRASE_MAP = { |
| #29 | "User asked ": "ASK ", |
| #30 | "User wants ": "WANT ", |
| #31 | "User prefers ": "PREF ", |
| #32 | "User likes ": "LIKE ", |
| #33 | "User dislikes ": "DISLIKE ", |
| #34 | "User is ": "IS ", |
| #35 | "User has ": "HAS ", |
| #36 | "User built ": "BUILT ", |
| #37 | "User asked for ": "ASK ", |
| #38 | "User requested ": "REQ ", |
| #39 | "Married to ": "MARRIED→", |
| #40 | "Email: ": "@", |
| #41 | "GitHub: ": "GH:", |
| #42 | "Location: ": "LOC:", |
| #43 | "Phone: ": "PH:", |
| #44 | "User email is ": "@", |
| #45 | "User voice message ": "VM ", |
| #46 | "User stack: ": "STACK|", |
| #47 | "Full-stack developer": "FSDEV", |
| #48 | "Software Developer": "SDEV", |
| #49 | "AI Systems Engineer": "AIENG", |
| #50 | "real-time": "RT", |
| #51 | "Real-time": "RT", |
| #52 | "bilingual": "bi", |
| #53 | "Bilingual": "bi", |
| #54 | "self-hosted": "selfhost", |
| #55 | "automation": "auto", |
| #56 | "transcription": "transc", |
| #57 | "translation": "transl", |
| #58 | } |
| #59 | |
| #60 | # Structural replacements (order matters) |
| #61 | STRUCTURAL_REPLACEMENTS: List[Tuple[str, str]] = [ |
| #62 | # Sentence/phrase separators |
| #63 | (" - ", " | "), |
| #64 | (" -- ", " | "), |
| #65 | (" | ", " | "), # normalize |
| #66 | |
| #67 | # Lists become pipe-delimited |
| #68 | (", ", " | "), |
| #69 | |
| #70 | # Conjunctions |
| #71 | (" and ", "+"), |
| #72 | (" or ", "/"), |
| #73 | |
| #74 | # Directional / relational |
| #75 | (" for ", "→"), |
| #76 | (" to ", "→"), |
| #77 | (" with ", " w/ "), |
| #78 | (" over ", ">"), |
| #79 | (" instead of ", "!>"), |
| #80 | (" because of ", "∵"), |
| #81 | (" due to ", "∵"), |
| #82 | |
| #83 | # Container words |
| #84 | (" using ", "→"), |
| #85 | (" built ", "→"), |
| #86 | (" in ", ":"), |
| #87 | (" at ", "@"), |
| #88 | (" on ", "@"), |
| #89 | (" from ", "<-"), |
| #90 | ] |
| #91 | |
| #92 | # Reverse maps for decode |
| #93 | REV_CATEGORY = {v: k for k, v in CATEGORY_MAP.items()} |
| #94 | REV_PHRASE = {v: k for k, v in PHRASE_MAP.items()} |
| #95 | |
| #96 | |
| #97 | def _apply_category_prefixes(text: str) -> str: |
| #98 | """Compress CATEGORY: prefix to CODE|""" |
| #99 | for full, code in CATEGORY_MAP.items(): |
| #100 | if text.startswith(f"{full}: "): |
| #101 | return text.replace(f"{full}: ", f"{code}|", 1) |
| #102 | return text |
| #103 | |
| #104 | |
| #105 | def _apply_phrases(text: str) -> str: |
| #106 | """Replace common phrases with shorthand.""" |
| #107 | # Sort by length descending to avoid partial matches |
| #108 | for phrase, shorthand in sorted(PHRASE_MAP.items(), key=lambda x: -len(x[0])): |
| #109 | text = text.replace(phrase, shorthand) |
| #110 | return text |
| #111 | |
| #112 | |
| #113 | def _apply_structural(text: str) -> str: |
| #114 | """Apply structural compression.""" |
| #115 | for pattern, replacement in STRUCTURAL_REPLACEMENTS: |
| #116 | text = text.replace(pattern, replacement) |
| #117 | return text |
| #118 | |
| #119 | |
| #120 | def _compact_parens(text: str) -> str: |
| #121 | """Remove spaces inside parentheses.""" |
| #122 | return re.sub(r"\(\s*", "(", text).replace(" )", ")") |
| #123 | |
| #124 | |
| #125 | def encode(text: str) -> str: |
| #126 | """ |
| #127 | Compress natural language memory into AAAK dialect. |
| #128 | |
| #129 | Example: |
| #130 | >>> encode("PREFERENCE: Imperial units for GPS, 12-hour time format (5:30 PM)") |
| #131 | "PREF|imperial-units→GPS|12h-timefmt(5:30PM)" |
| #132 | """ |
| #133 | if not text: |
| #134 | return text |
| #135 | |
| #136 | # Skip if already looks like AAAK (has pipe delimiters and no spaces) |
| #137 | if "|" in text and len(text.split()) <= 3: |
| #138 | return text |
| #139 | |
| #140 | result = text.strip() |
| #141 | result = _apply_category_prefixes(result) |
| #142 | result = _apply_phrases(result) |
| #143 | result = _apply_structural(result) |
| #144 | result = _compact_parens(result) |
| #145 | |
| #146 | # Compact common trailing phrases |
| #147 | result = result.replace("working correctly", "OK") |
| #148 | result = result.replace("working", "OK") |
| #149 | result = result.replace("complete", "DONE") |
| #150 | result = result.replace("completed", "DONE") |
| #151 | |
| #152 | return result.strip() |
| #153 |