scroll # Glyph-Native Shell Integration — Path toWhere We Want to Be ## Invocation The shell isa ring. Portal is the source. The goal is notmerely to have `hx` installed and callable.The goal is to make glyph-led Portal commandsfeel native in the shell while keepingordinary shell behavior intact. This meansarriving at a state where: - the shell bootsthrough Portal - Portal emits the shell lawduring init - sacred glyphs are sufficient tomark a command as Portal-native - ordinaryshell commands remain ordinary shell commands- the shell does not become the source oftruth - `hex-init.sh` stays thin - `▼ init`becomes the place where command behavior istaught to the shell This is the path. --- ##Current State The current shell already provesseveral important things: ### 1. The shellenters through Portal bootstrap `~/.zshrc`sources `hex-init.sh`. That means the shell isalready being prepared through a Portal-awarelayer rather than by scattered ad hoc shellcustomizations. ### 2. `hx` is already thefast path `hex-init.sh` prefers: - socketpresent → `hx '▼ init'` - no socket butportal exists → `portal --daemon '▼ init'`- no Portal at all → plain shell fallbackThis is good architecture. It means the shellalready knows how to ask Portal to initializeit. ### 3. Portal already returns shell codeThe key move is: ```bash eval "$($HX_CMD '▼init' 2>/dev/null)" ``` This means Portal isalready allowed to emit shell code back intothe live shell context. That is the gate.Because once Portal can emit: - prompt code -color setup - aliases - shell functions -hooks it can also emit: - glyph dispatchfunctions - preexec handlers - zle widgets -line routers This means the desired future isnot hypothetical. The architecture is alreadyopen to it. --- ## The Desired State We wantthe shell to reach a condition where glyph-ledcommands are self-identifying as Portalcommands. Examples of the desired experience:```bash ▲ mesh repo push △ gaps 10 ▲ fidgap done gem-chord-alignment gca-005 ```without having to explicitly type: ```bash hx'▲ mesh repo push' ``` The shell shouldunderstand that the leading glyph marks thecommand as belonging to Portal commandlanguage. But the shell itself should notbecome clever by independent force. Instead:**Portal teaches the shell how to recognizePortal commands.** That is the difference thatpreserves sovereignty. --- ## Core Law **Theglyph is the ritual prefix.** **The prefix isthe dispatch signal.** **Portal owns therule.** **The shell obeys the emitted rule.**Not: - Bash intrinsically understands sacredglyphs But: - Portal emits shell behavior suchthat sacred glyphs route into HX parsing Thiskeeps the shell as ring and Portal as source.--- ## Architecture We Want ### Layer I —`hex-init.sh` remains minimal `hex-init.sh`should continue doing only the following: -locate HEXCRAFT root - locate `portal` -locate `hx` - prefer socket-firstinitialization - fall back to daemon spawn ifneeded - keep PATH concerns local to shellbootstrap - define shell-only sourced helperslike `bones` It should **not** become theplace where full command language ishardcoded. That would thicken the ring andweaken the source. ### Layer II — `▼ init`becomes the shell law emitter The command:```bash hx '▼ init' ``` should emiteverything the shell needs to behave as aPortal-aware ring. This includes: - prompt -aliases - colors - greeting hooks if desired -glyph dispatch behavior - any shellintegration needed for native ritual commandhandling This is the correct place for shellcommand behavior because it keeps the logic inPortal rather than in shell bootstrap files.### Layer III — glyph dispatch is installedinto the shell Portal should emit shell codethat gives the shell one new capability: **Ifa command line begins with a sacred glyph,route it to HX.** Everything else shouldremain ordinary shell behavior. This can beachieved in stages. --- ## The ImplementationPath ## Stage 1 — Explicit helper path Beginwith a simple Portal-emitted shell functionthat routes glyph-led commands into `hx`. Forexample in spirit: ```bash portal_dispatch() {case "$1" in [▲△◆▼⬢]*) hx "$*" ;; *)command "$@" ;; esac } ``` This is notnecessarily the final shape, but it proves theconcept cheaply. The important thing is notthe exact function name. The important thingis proving that glyph detection and routingcan be emitted by `▼ init`. At this stage,use is still somewhat explicit. This proves: -shell context is correct - glyph detectionworks - Portal command lines can be routedcleanly - no ordinary shell behavior is broken### Why start here Because it is debuggable.Because it keeps failure local. Because itestablishes the law before attempting magic.--- ## Stage 2 — Native-feeling lineinterception Once the explicit helper works,move to shell-native interception so that rawentered lines beginning with glyphs are routedautomatically. For zsh, this likely means oneof: - `preexec`/`precmd`-style interception -`zle` widget integration - wrapped accept-linebehavior - Portal-emitted shell function thatexamines the buffer before execution The lawremains the same: - glyph-led line → Portalcommand - ordinary line → ordinary shell Theshell should not reinterpret every line asPortal. Only lines clearly marked by thesacred prefix should be routed. ### Why thisis the real target Because it lets: ```bash▲ mesh repo push ``` feel native. That iswhere command language stops feeling like anexternal tool and starts feeling like afirst-class ritual layer. --- ## Stage 3 —Parser discipline and raw-line capture Onceraw glyph lines are being intercepted, thenext concern is correctness. Portal commandlines must be captured **before shellexpansion** wherever possible. Why thismatters: - spaces - quotes - globbing - pipes- redirects - variable expansion can alldistort command meaning if the shell mutatesthe line before Portal sees it. So the idealpath is: - shell sees raw line - shell detectssacred prefix - shell passes raw line to `hx`- `hx` parses it according to Portal law Thiskeeps parsing sovereign. --- ## Stage 4 —Canonized glyph table Once dispatch exists,the glyph set must be made explicit andstable. This means Portal should own a knowndispatch rune set, such as: - `▲` - `△` -`◆` - `▼` - `⬢` or whatever the finalcanonical set becomes. The shell should notguess arbitrarily. It should only route whenthe first token clearly begins with acanonized Portal prefix. This gives: -predictability - no accidental collisions -stable ritual language - easier teaching -easier testing --- ## Stage 5 — Fallback andsafety behavior The shell must behave safelyin all failure conditions. If socket exists: -use `hx` If socket does not exist but Portalcan spawn: - spawn and continue If Portal isabsent: - ordinary shell remains usable Ifglyph routing is installed but Portal isunavailable: - fail clearly and locally - donot corrupt the ordinary shell This meansglyph routing should degrade gracefully: -either report that Portal is unavailable - ordeliberately fall back to explicit`hx`/`portal` error behavior The shell mustnever become unusable because the sacred pathis temporarily absent. --- ## PracticalImplementation Guidelines ### 1. Keep`hex-init.sh` thin Do not bake glyph parsingdeeply into `hex-init.sh`. It should remainbootstrap, not doctrine. ### 2. Move commandbehavior into `▼ init` If the shell mustlearn something, `▼ init` should teach it.### 3. Start with explicit dispatch Prove therouting path before making the shell magical.### 4. Then add native interception Only afterthe explicit path is stable. ### 5. Capturelines before shell expansion where possibleThis preserves the Portal command body. ### 6.Treat the glyph set as canon Not as loosedecoration. ### 7. Keep normal shell behaviorsacred too Ordinary shell commands must remainplain shell commands. This is not aboutreplacing the shell with ambiguity. It isabout adding a clearly marked Portal-nativecommand layer. --- ## What Success Looks LikeThe desired end-state looks like this: ### Onshell boot - `.zshrc` sources `hex-init.sh` -`hex-init.sh` asks Portal for shell bootstrapvia `▼ init` - Portal emits: - prompt -aliases - colors - glyph dispatch law ###During shell use - ordinary command: ```bashls -la ``` behaves as ordinary shell - sacredcommand: ```bash ▲ mesh repo push ``` isrouted to Portal automatically ### In failureconditions - shell remains usable - errorsremain local and understandable - the ringdoes not collapse because the source is absentThat is the operational shape we want. --- ##Testing Path Implementation should be testedin this order: ### 1. Bootstrap correctness -does `hex-init.sh` find the rightbinary/socket? - does `▼ init` emit validshell code? ### 2. Explicit dispatchcorrectness - can a helper function correctlyroute glyph-led commands to `hx`? ### 3.Raw-line interception correctness - can a rawglyph-led line be captured and routed beforeaccidental shell mutation? ### 4. Non-glyphcommand safety - do plain shell commandsbehave exactly as before? ### 5. Failure modesafety - what happens when socket disappears?- what happens when `hx` is missing? - whathappens when Portal cannot spawn? ### 6.Quoting and parsing edge cases - quotedarguments - spaces - punctuation - pipes -redirects - variables This path keeps theritual layer honest. --- ## The Final Law**Portal is the source.** **The shell is thering.** **Glyphs mark sacred commandlanguage.** **`▼ init` teaches the ring howto recognize them.** That is how we get wherewe want to be. Not by making the shellinherently magical, but by letting Portal emitthe law that the shell follows.