interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

Comparing ed2d94907a3a96a12f3f4c88d2abec35d659865c ... 0edf96695034397f7767fda1b48f48a7944142eb

20 files changed, +8020 -0

.gitignore+1-0
Linux/README.md+39-0
Linux/apps.om+949-0
Linux/build.om+608-0
Linux/chat.om+843-0
Linux/core.om+197-0
Linux/files.om+1714-0
Linux/install.om+949-0
Linux/main.om+205-0
Linux/tests/apps_check.py+201-0
Linux/tests/build_record_check.py+52-0
Linux/tests/chat_check.py+193-0
Linux/tests/check.py+65-0
Linux/tests/combined_check.py+209-0
Linux/tests/files_check.py+415-0
Linux/tests/install_check.py+209-0
Linux/tests/window_check.py+209-0
Linux/window.om+948-0
README.md+2-0
build.sh+12-0

.gitignore

@@ -1,3 +1,4 @@
11 build/
22 dist/
33 .DS_Store
4+/Linux/tests/__pycache__/

Linux/README.md

new file mode 100644
@@ -0,0 +1,39 @@
1+# Hop on Linux
2+
3+This is the first Linux desktop edition, for the Spark. It opens a native window, finds and launches applications, finds and opens your indexed files, and offers Ask when you connect a model. It runs separately from the Mac edition.
4+
5+This edition is still in development. Clipboard history, account storage, voice, the coding-agent screen and a global keyboard shortcut have not been ported. The window uses a basic system font; international text rendering is incomplete. Native Wayland and XWayland are unverified. Ask sends one question at a time, and the window waits for the answer.
6+
7+## Build and install
8+
9+Run `./build.sh` from this repository on the Spark. It reads the current `main` from `~/git/omega-mv.git`, checks the compiler's own checksum, and builds the Linux program and its matching helper. `OMEGA_STORE` can name another local Omega repository. The build follows that repository's current `main`; it does not use the Mac edition's historical compiler pin. The compiler revision is recorded in `build/linux-toolchain/source-commit`.
10+
11+Run `./build.sh install` to build and install the Linux edition. Installation requires a clean source checkout whose exact commit is the current published Hop `main`. Development branches are refused. Existing unrelated files are preserved. The installer adds Hop to your application menu and puts the `hop` command in your personal programs folder. It keeps previous versions for recovery.
12+
13+A successful clean build records its source and compiler revisions and the checksums of the compiler and both program files. The installer checks those records and the copied programs before publishing the launchers. A failed or unfinished build cannot reuse the previous build's record.
14+
15+The desktop needs a local X11 session and its normal display authorization. Hop never disables display authorization. On a machine without a desktop session it reports the missing display and exits. The terminal commands below work without a desktop.
16+
17+## Use
18+
19+Open Hop from the application menu. Start typing an application's name, choose a result with the arrows or the mouse, and press Enter. Escape closes the window.
20+
21+Type `find ` followed by words from a filename to search your file list. If you do not have a list yet, Enter builds one. Unreadable folders produce a coverage warning while the usable results remain available. A failed save preserves the previous good list. Rebuilding is explicit; there is no background rescan loop. The default scan leaves out hidden and generated folders and the Spark's scratch copies under `work/hive` and `work/lanes`.
22+
23+For Ask, your agent can configure `HOP_MODEL_URL` with your OpenAI-compatible server's base address and `HOP_MODEL` with the model's name. An optional `HOP_API_KEY` supplies its sign-in key. Hop does not guess a server, contact an AI provider until you send a question, or store that key on disk. Type `ask ` followed by your question, then press Enter. These settings must be present in Hop's launching environment, including when the application menu starts it; a settings screen is not implemented yet.
24+
25+`hop --search TEXT` prints matching application names. `hop --open TEXT` opens the first match. `hop --reindex [ROOT ...]` rebuilds the file list, and `hop --find TEXT` returns matching paths as JSON. `hop --selftest` checks the actual Linux search helper. `hop --help` lists the available commands.
26+
27+The file list lives in `$XDG_CACHE_HOME/hop/files.idx`, or `~/.cache/hop/files.idx` when that setting is absent. Its format retains filenames with line breaks. It records paths and coverage, not file contents. The file-index gate checks that an alarm on a large index never truncates it or stops the work. The Mac remote-file builder still uses the older route; this Linux implementation does not claim that the installed Mac caller has been updated.
28+
29+## Implementation and verification
30+
31+All new application and build logic is seeded Omega. `window.om` connects directly to the X11 protocol. `apps.om` reads the desktop's application entries. `core.om` talks to the unchanged `Omega/hopcore.om` helper through its existing protocol. `chat.om` owns request construction and answer parsing. `build.om` builds the programs, and `install.om` installs only published source.
32+
33+The system commands that remain are explicit platform dependencies: `gio` launches desktop application entries with the desktop's own permissions and argument rules; `env` carries the user's desktop session into child programs; `curl` carries HTTP and HTTPS requests with certificate verification. Their exact build-host versions are generated in `build/linux/dependency-*.txt`. The intended Omega replacements are desktop-entry execution and D-Bus activation, inherited-environment execution, and the existing Omega TLS implementation with native DNS and HTTP. New first-party production code is Omega. Python is used only by the independent verification tools under `tests/`.
34+
35+The small shell entry in the existing `build.sh`, plus Git and tar, bootstraps the current seeded Omega build driver. The previous Mac build remains in that script. The Mac generators still refer to their historical compiler; replacing those generators is separate migration work.
36+
37+The build and installer also use the system's `sha256sum` as a read-only verification tool. Its exact version is recorded with the other build dependencies. It is not needed to run the installed application.
38+
39+The acceptance checks use private application fixtures, a private authenticated virtual desktop and a local model stand-in. They do not contact a live AI provider, change a desktop session or install into the real home folder. Run the verifiers with their `--help` option for their compiler and evidence arguments. The combined acceptance evidence is recorded beside the landing receipt; isolated component tests alone do not establish that the combined application works.

Linux/apps.om

new file mode 100644
@@ -0,0 +1,949 @@
1+note Linux application discovery and launch. SPDX-License-Identifier: Apache-2.0
2+note Platform contracts: freedesktop Desktop Entry 1.5 and XDG Base Directory 0.8.
3+note gio owns Desktop Entry Exec field codes, Terminal and D-Bus activation; build records its exact version.
4+note env preserves the desktop session environment without shell evaluation; build records its exact version.
5+note Omega successor: native Desktop Entry Exec expansion and D-Bus activation; neither is claimed here.
6+note PATH_MAX buffer is Linux pathname syscall boundary. getdents64 record length is a u16 wire field.
7+note Tables and input lines grow with input. Executable packed-list boundaries are compiler contracts,
8+note checked before exec: 65536 bytes and 1024 records. No environment is silently discarded.
9+global ha_path uchar 4096
10+global ha_read uchar 4096
11+global ha_dent uchar 65536
12+global ha_env uchar 131072
13+global ha_exec uchar 65536
14+global ha_wait uchar 4
15+global ha_stat uchar 128
16+global ha_line uchar *
17+global ha_text uchar *
18+global ha_meta ulong *
19+global ha_dirs uchar *
20+global ha_dmeta ulong *
21+global ha_hits ulong *
22+global ha_scores ulong *
23+global ha_n ulong 1
24+global ha_tn ulong 1
25+global ha_dn ulong 1
26+global ha_db ulong 1
27+global ha_ln ulong 1
28+global ha_pn ulong 1
29+global ha_state ulong 8
30+global ha_hn ulong 1
31+text ha_home "HOME="
32+text ha_data "XDG_DATA_HOME="
33+text ha_xdirs "XDG_DATA_DIRS="
34+text ha_local "/.local/share"
35+text ha_apps "/applications"
36+text ha_def "/usr/local/share:/usr/share"
37+text ha_ext ".desktop"
38+text ha_group "[Desktop Entry]"
39+text ha_name "Name"
40+text ha_type "Type"
41+text ha_hidden "Hidden"
42+text ha_nodisp "NoDisplay"
43+text ha_cmd "Exec"
44+text ha_dbus "DBusActivatable"
45+text ha_true "true"
46+text ha_app "Application"
47+text ha_only "OnlyShowIn"
48+text ha_not "NotShowIn"
49+text ha_try "TryExec"
50+text ha_session "XDG_CURRENT_DESKTOP="
51+text ha_pathenv "PATH="
52+text ha_defpath "/usr/local/bin:/usr/bin:/bin"
53+text ha_envbin "/usr/bin/env"
54+text ha_options "--"
55+text ha_gio "/usr/bin/gio"
56+text ha_launch "launch"
57+text ha_open "open"
58+text ha_errmem "Hop: Linux application list could not grow.\n"
59+text ha_errpath "Hop: application pathname exceeds the Linux pathname boundary.\n"
60+text ha_errexec "Hop: application launch exceeds the compiler argument packet boundary.\n"
61+text ha_errlaunch "Hop: the desktop could not launch that application.\n"
62+text ha_errenv "Hop: an environment entry could not be read in full.\n"
63+
64+fn ha_die textv view uchar * to void
65+x = write 2 textv 0 len textv
66+exit 1
67+end
68+
69+fn ha_reserve need ulong which ulong to void
70+r = long 0
71+if eq which 0
72+if gt need len ha_text
73+r = enlarge ha_text add need add len ha_text 4096
74+end
75+end
76+if eq which 1
77+if gt need len ha_meta
78+r = enlarge ha_meta add need add len ha_meta 64
79+end
80+end
81+if eq which 2
82+if gt need len ha_dirs
83+r = enlarge ha_dirs add need add len ha_dirs 4096
84+end
85+end
86+if eq which 3
87+if gt need len ha_dmeta
88+r = enlarge ha_dmeta add need add len ha_dmeta 64
89+end
90+end
91+if eq which 4
92+if gt need len ha_line
93+r = enlarge ha_line add need add len ha_line 256
94+end
95+end
96+if eq which 5
97+if gt need len ha_hits
98+r = enlarge ha_hits add need add len ha_hits 64
99+if ge r 0
100+r = enlarge ha_scores len ha_hits
101+end
102+end
103+end
104+if lt r 0
105+ha_die ha_errmem
106+end
107+end
108+
109+fn ha_envkey key view uchar * to bool
110+for j ulong len key bound 9223372036854775807
111+if ne get ha_env j get key j
112+ret false
113+end
114+end
115+ret true
116+end
117+
118+fn ha_envget key view uchar * to long
119+for i ulong ulong envcnt bound 9223372036854775807
120+n = envread i ha_env 0 len ha_env
121+if lt n 0
122+ha_die ha_errenv
123+end
124+if ge ulong n len key
125+if ha_envkey key
126+amount = sub ulong n len key
127+ha_envshift len key amount
128+ret long amount
129+end
130+end
131+end
132+ret -1
133+end
134+
135+fn ha_envshift start ulong size ulong to void
136+for j ulong size bound 9223372036854775807
137+c = get ha_env add j start
138+put ha_env j c
139+end
140+end
141+
142+fn ha_setpath src view uchar * to void
143+if ge len src len ha_path
144+ha_die ha_errpath
145+end
146+for i ulong len src bound 9223372036854775807
147+put ha_path i get src i
148+end
149+put ha_pn 0 len src
150+end
151+
152+fn ha_pathadd src view uchar * to void
153+p = get ha_pn 0
154+if ge add p len src len ha_path
155+ha_die ha_errpath
156+end
157+for i ulong len src bound 9223372036854775807
158+put ha_path add p i get src i
159+end
160+put ha_pn 0 add p len src
161+end
162+
163+fn ha_envpath n ulong to void
164+if ge n len ha_path
165+ha_die ha_errpath
166+end
167+for i ulong n bound 9223372036854775807
168+put ha_path i get ha_env i
169+end
170+put ha_pn 0 n
171+end
172+
173+fn ha_queue root ulong to void
174+n = get ha_pn 0
175+p = get ha_db 0
176+k = get ha_dn 0
177+ha_reserve add p n 2
178+ha_reserve mul add k 1 3 3
179+for i ulong n bound 9223372036854775807
180+put ha_dirs add p i get ha_path i
181+end
182+put ha_dmeta mul k 3 p
183+put ha_dmeta add mul k 3 1 n
184+put ha_dmeta add mul k 3 2 root
185+put ha_dn 0 add k 1
186+put ha_db 0 add p n
187+end
188+
189+fn ha_lower c uchar to uchar
190+if and ge c 65 le c 90
191+ret add c 32
192+end
193+ret c
194+end
195+
196+fn ha_lineeq start ulong size ulong value view uchar * to bool
197+if ne size len value
198+ret false
199+end
200+for i ulong size bound 9223372036854775807
201+if ne get ha_line add start i get value i
202+ret false
203+end
204+end
205+ret true
206+end
207+
208+fn ha_recordline to void
209+n = get ha_ln 0
210+if eq n 0
211+ret
212+end
213+if eq get ha_line sub n 1 13
214+n = sub n 1
215+end
216+if eq n 0
217+ret
218+end
219+if eq get ha_line 0 91
220+active = ha_lineeq 0 n ha_group
221+put ha_state 0 0
222+if active
223+put ha_state 0 1
224+end
225+ret
226+end
227+if eq get ha_state 0 0
228+ret
229+end
230+k = ulong 0
231+while lt k n bound 9223372036854775807
232+if eq get ha_line k 61
233+break
234+end
235+k = add k 1
236+end
237+if eq k n
238+ret
239+end
240+v = add k 1
241+vn = sub n v
242+if ha_lineeq 0 k ha_name
243+p = get ha_tn 0
244+ha_reserve add p vn 0
245+j = ulong 0
246+while lt j vn bound 9223372036854775807
247+c = get ha_line add v j
248+if and eq c 92 lt add j 1 vn
249+j = add j 1
250+c = get ha_line add v j
251+if or or eq c 115 eq c 110 or eq c 114 eq c 116
252+c = 32
253+end
254+end
255+if or lt c 32 eq c 127
256+c = 32
257+end
258+put ha_text p c
259+p = add p 1
260+j = add j 1
261+end
262+put ha_state 1 get ha_tn 0
263+put ha_state 2 sub p get ha_tn 0
264+put ha_tn 0 p
265+end
266+if ha_lineeq 0 k ha_type
267+put ha_state 3 0
268+if ha_lineeq v vn ha_app
269+put ha_state 3 1
270+end
271+end
272+if or ha_lineeq 0 k ha_hidden ha_lineeq 0 k ha_nodisp
273+if ha_lineeq v vn ha_true
274+put ha_state 4 1
275+end
276+end
277+if ha_lineeq 0 k ha_cmd
278+if gt vn 0
279+put ha_state 5 1
280+end
281+end
282+if ha_lineeq 0 k ha_dbus
283+if ha_lineeq v vn ha_true
284+put ha_state 5 1
285+end
286+end
287+if ha_lineeq 0 k ha_only
288+if not ha_insession v vn
289+put ha_state 6 1
290+end
291+end
292+if ha_lineeq 0 k ha_not
293+if ha_insession v vn
294+put ha_state 6 1
295+end
296+end
297+if ha_lineeq 0 k ha_try
298+if not ha_tryexec v vn
299+put ha_state 7 1
300+end
301+end
302+end
303+
304+fn ha_insession start ulong size ulong to bool
305+n = ha_envget ha_session
306+if le n 0
307+ret false
308+end
309+lo = ulong 0
310+for i ulong add size 1 bound 9223372036854775807
311+sep = eq i size
312+if not sep
313+sep = eq get ha_line add start i 59
314+end
315+if sep
316+if ha_sessionhas add start lo sub i lo ulong n
317+ret true
318+end
319+lo = add i 1
320+end
321+end
322+ret false
323+end
324+
325+fn ha_sessionhas start ulong size ulong envsize ulong to bool
326+if eq size 0
327+ret false
328+end
329+lo = ulong 0
330+for i ulong add envsize 1 bound 9223372036854775807
331+sep = eq i envsize
332+if not sep
333+sep = eq get ha_env i 58
334+end
335+if sep
336+if eq sub i lo size
337+if ha_sessioneq start lo size
338+ret true
339+end
340+end
341+lo = add i 1
342+end
343+end
344+ret false
345+end
346+
347+fn ha_sessioneq start ulong envstart ulong size ulong to bool
348+for j ulong size bound 9223372036854775807
349+c = get ha_line add start j
350+if ne c get ha_env add envstart j
351+ret false
352+end
353+end
354+ret true
355+end
356+
357+fn ha_tryexec start ulong size ulong to bool
358+if eq size 0
359+ret false
360+end
361+slash = false
362+for i ulong size bound 9223372036854775807
363+if eq get ha_line add start i 47
364+slash = true
365+end
366+end
367+if slash
368+ha_trypath 0 0 start size
369+ret ha_executable
370+end
371+n = ha_envget ha_pathenv
372+if le n 0
373+for i ulong len ha_defpath
374+put ha_env i get ha_defpath i
375+end
376+n = long len ha_defpath
377+end
378+lo = ulong 0
379+for i ulong add ulong n 1 bound 9223372036854775807
380+sep = eq i ulong n
381+if not sep
382+sep = eq get ha_env i 58
383+end
384+if sep
385+ha_trypath lo sub i lo start size
386+if ha_executable
387+ret true
388+end
389+lo = add i 1
390+end
391+end
392+ret false
393+end
394+
395+fn ha_trypath envstart ulong envsize ulong start ulong size ulong to void
396+extra = ulong 0
397+if gt envsize 0
398+extra = 1
399+end
400+total = add add envsize extra size
401+if ge total len ha_path
402+ha_die ha_errpath
403+end
404+for i ulong envsize bound 9223372036854775807
405+c = get ha_env add envstart i
406+put ha_path i c
407+end
408+if gt extra 0
409+put ha_path envsize 47
410+end
411+for i ulong size bound 9223372036854775807
412+c = get ha_line add start i
413+put ha_path add add envsize extra i c
414+end
415+put ha_pn 0 total
416+end
417+
418+fn ha_regular to bool
419+r = stat ha_path 0 get ha_pn 0 ha_stat 0 len ha_stat
420+if lt r 0
421+ret false
422+end
423+note asm-generic/stat.h st_mode offset16, bits/stat.h S_IFMT=0170000 and S_IFREG=0100000.
424+note Decimal conversions: calc:48b0ef104b499352fffecc0c0f52c5a98d33fcc80282357db3f03dd3c6d51c3d
425+note and calc:ee2ba7a0bf702c139c1496ff5510397b56b897779b6783b8158f5f5c15a2511f.
426+mode = add ulong get ha_stat 16 shl ulong get ha_stat 17 8
427+ret eq and mode 61440 32768
428+end
429+
430+fn ha_executable to bool
431+if not ha_regular
432+ret false
433+end
434+ret eq faccess ha_path 0 get ha_pn 0 1 0
435+end
436+
437+fn ha_readentry index ulong to void
438+for i ulong 8
439+put ha_state i 0
440+end
441+if not ha_regular
442+ret
443+end
444+fd = int fopen ha_path 0 get ha_pn 0 0 0
445+if lt fd 0
446+ret
447+end
448+put ha_ln 0 0
449+done = false
450+while not done bound 9223372036854775807
451+n = read fd ha_read 0 len ha_read
452+if lt n 0
453+x = fclose fd
454+ret
455+end
456+if eq n 0
457+done = true
458+ha_recordline
459+else
460+for i ulong ulong n bound 9223372036854775807
461+c = get ha_read i
462+if eq c 10
463+ha_recordline
464+put ha_ln 0 0
465+else
466+j = get ha_ln 0
467+ha_reserve add j 1 4
468+put ha_line j c
469+put ha_ln 0 add j 1
470+end
471+end
472+end
473+end
474+x = fclose fd
475+if and eq get ha_state 3 1 eq get ha_state 4 0
476+if eq get ha_state 5 1
477+if and eq get ha_state 6 0 eq get ha_state 7 0
478+put ha_meta add mul index 6 4 get ha_state 1
479+put ha_meta add mul index 6 5 get ha_state 2
480+end
481+end
482+end
483+end
484+
485+fn ha_addentry root ulong to void
486+n = get ha_pn 0
487+start = add root 1
488+if le n start
489+ret
490+end
491+idn = sub n start
492+for i ulong get ha_n 0 bound 9223372036854775807
493+m = mul i 6
494+if eq get ha_meta add m 1 idn
495+if ha_sameid start idn get ha_meta m
496+ret
497+end
498+end
499+end
500+k = get ha_n 0
501+ha_reserve mul add k 1 6 1
502+p = get ha_tn 0
503+ha_reserve add add p idn n 0
504+put ha_meta mul k 6 p
505+put ha_meta add mul k 6 1 idn
506+for i ulong idn bound 9223372036854775807
507+c = get ha_path add start i
508+if eq c 47
509+c = 45
510+end
511+put ha_text add p i c
512+end
513+p = add p idn
514+put ha_meta add mul k 6 2 p
515+put ha_meta add mul k 6 3 n
516+put ha_meta add mul k 6 4 0
517+put ha_meta add mul k 6 5 0
518+for i ulong n bound 9223372036854775807
519+put ha_text add p i get ha_path i
520+end
521+put ha_tn 0 add p n
522+put ha_n 0 add k 1
523+ha_readentry k
524+end
525+
526+fn ha_sameid start ulong size ulong offset ulong to bool
527+for j ulong size bound 9223372036854775807
528+c = get ha_path add start j
529+if eq c 47
530+c = 45
531+end
532+if ne c get ha_text add offset j
533+ret false
534+end
535+end
536+ret true
537+end
538+
539+fn ha_direntry pos ulong root ulong base ulong to void
540+sz = ulong 0
541+while ne get ha_dent add add pos 19 sz 0 bound 65536
542+sz = add sz 1
543+end
544+if eq sz 0
545+ret
546+end
547+if eq get ha_dent add pos 19 46
548+if eq sz 1
549+ret
550+end
551+if eq sz 2
552+if eq get ha_dent add pos 20 46
553+ret
554+end
555+end
556+end
557+if ge add add base 1 sz len ha_path
558+ha_die ha_errpath
559+end
560+put ha_path base 47
561+for i ulong sz bound 9223372036854775807
562+put ha_path add add base 1 i get ha_dent add add pos 19 i
563+end
564+put ha_pn 0 add add base 1 sz
565+typ = get ha_dent add pos 18
566+if eq typ 4
567+ha_queue root
568+ret
569+end
570+if lt sz len ha_ext
571+ret
572+end
573+for i ulong len ha_ext
574+if ne get ha_dent add add pos 19 add sub sz len ha_ext i get ha_ext i
575+ret
576+end
577+end
578+ha_addentry root
579+end
580+
581+fn ha_scanroot to void
582+if eq get ha_pn 0 0
583+ret
584+end
585+if ne get ha_path 0 47
586+ret
587+end
588+ha_pathadd ha_apps
589+put ha_dn 0 0
590+put ha_db 0 0
591+ha_queue get ha_pn 0
592+di = ulong 0
593+while lt di get ha_dn 0 bound 9223372036854775807
594+m = mul di 3
595+base = get ha_dmeta add m 1
596+root = get ha_dmeta add m 2
597+off = get ha_dmeta m
598+ha_dirpath off base
599+put ha_pn 0 base
600+fd = int fopen ha_path 0 base 0 0
601+if ge fd 0
602+done = false
603+while not done bound 9223372036854775807
604+n = getdnts fd ha_dent 0 len ha_dent
605+if le n 0
606+done = true
607+else
608+ha_parseents ulong n root base off
609+end
610+end
611+x = fclose fd
612+end
613+di = add di 1
614+end
615+end
616+
617+fn ha_parseents size ulong root ulong base ulong offset ulong to void
618+pos = ulong 0
619+while lt pos size bound 65536
620+low = ulong get ha_dent add pos 16
621+high = ulong get ha_dent add pos 17
622+rec = add low shl high 8
623+if or lt rec 20 gt add pos rec size
624+ret
625+end
626+ha_dirpath offset base
627+ha_direntry pos root base
628+pos = add pos rec
629+end
630+end
631+
632+fn ha_dirpath offset ulong size ulong to void
633+for j ulong size bound 9223372036854775807
634+c = get ha_dirs add offset j
635+put ha_path j c
636+end
637+end
638+
639+fn ha_init to int
640+put ha_n 0 0
641+put ha_tn 0 0
642+n = ha_envget ha_data
643+valid = false
644+if gt n 0
645+valid = eq get ha_env 0 47
646+end
647+if valid
648+ha_envpath ulong n
649+else
650+n = ha_envget ha_home
651+if gt n 0
652+ha_envpath ulong n
653+ha_pathadd ha_local
654+else
655+put ha_pn 0 0
656+end
657+end
658+ha_scanroot
659+n = ha_envget ha_xdirs
660+if le n 0
661+for i ulong len ha_def
662+put ha_env i get ha_def i
663+end
664+n = long len ha_def
665+end
666+note Preserve the directory list while each scan reads environment-independent files.
667+list = new uchar 131072 0
668+for i ulong ulong n bound 9223372036854775807
669+put list i get ha_env i
670+end
671+lo = ulong 0
672+for i ulong add ulong n 1 bound 9223372036854775807
673+sep = eq i ulong n
674+if not sep
675+sep = eq get list i 58
676+end
677+if sep
678+size = sub i lo
679+if gt size 0
680+ha_scanpart list lo size
681+end
682+lo = add i 1
683+end
684+end
685+ret 0
686+end
687+
688+fn ha_scanpart list view uchar * start ulong size ulong to void
689+if ge size len ha_path
690+ha_die ha_errpath
691+end
692+for j ulong size bound 9223372036854775807
693+c = get list add start j
694+put ha_path j c
695+end
696+put ha_pn 0 size
697+ha_scanroot
698+end
699+
700+fn ha_literal nameoff ulong namesize ulong to bool
701+qn = get lx_qn 0
702+if eq qn 0
703+ret true
704+end
705+if gt qn namesize
706+ret false
707+end
708+for i ulong add sub namesize qn 1 bound 9223372036854775807
709+same = true
710+for j ulong qn bound 9223372036854775807
711+if ne ha_lower get lx_query j ha_lower get ha_text add add nameoff i j
712+same = false
713+break
714+end
715+end
716+if same
717+ret true
718+end
719+end
720+ret false
721+end
722+
723+fn ha_word c uchar to ulong
724+v = ulong ha_lower c
725+alpha = or and ge c 65 le c 90 and ge c 97 le c 122
726+if or alpha and ge c 48 le c 57
727+v = or v 4294967296
728+end
729+if or eq c 32 and ge c 9 le c 13
730+v = or v 8589934592
731+end
732+ret v
733+end
734+
735+fn ha_ascii nameoff ulong namesize ulong to bool
736+for j ulong get lx_qn 0 bound 9223372036854775807
737+if ge get lx_query j 128
738+ret false
739+end
740+end
741+for j ulong namesize bound 9223372036854775807
742+if ge get ha_text add nameoff j 128
743+ret false
744+end
745+end
746+ret true
747+end
748+
749+fn ha_score nameoff ulong namesize ulong to ulong
750+qn = get lx_qn 0
751+if eq qn 0
752+ret 1
753+end
754+note Hop's existing helper wire format permits64 query words and184 name words.
755+note Longer input and non-ASCII names use full literal matching, never a cut-short fuzzy request.
756+if or gt qn 64 gt namesize 184
757+if ha_literal nameoff namesize
758+ret 1
759+end
760+ret 0
761+end
762+if not ha_ascii nameoff namesize
763+if ha_literal nameoff namesize
764+ret 1
765+end
766+ret 0
767+end
768+packet = new ulong 256 0
769+put packet 0 1212568922
770+put packet 1 1
771+put packet 2 qn
772+put packet 3 namesize
773+for j ulong qn bound 64
774+put packet add 8 j ha_word get lx_query j
775+end
776+for j ulong namesize bound 184
777+put packet add 72 j ha_word get ha_text add nameoff j
778+end
779+ret hp_fuzz packet
780+end
781+
782+fn ha_inserthit index ulong score ulong to void
783+k = get ha_hn 0
784+ha_reserve add k 1 5
785+while gt k 0 bound 9223372036854775807
786+prev = get ha_scores sub k 1
787+if ge prev score
788+break
789+end
790+old = get ha_hits sub k 1
791+put ha_hits k old
792+put ha_scores k prev
793+k = sub k 1
794+end
795+put ha_hits k index
796+put ha_scores k score
797+put ha_hn 0 add get ha_hn 0 1
798+end
799+
800+fn ha_query to void
801+put lx_rn 0 0
802+put ha_hn 0 0
803+for i ulong get ha_n 0 bound 9223372036854775807
804+m = mul i 6
805+n = get ha_meta add m 5
806+if gt n 0
807+p = get ha_meta add m 4
808+score = ha_score p n
809+if gt score 0
810+ha_inserthit i score
811+end
812+end
813+end
814+for j ulong get ha_hn 0 bound 9223372036854775807
815+ha_addrow get ha_hits j
816+end
817+end
818+
819+fn ha_addrow index ulong to void
820+m = mul index 6
821+n = get ha_meta add m 5
822+p = get ha_meta add m 4
823+pos = get lx_rn 0
824+r = enlarge lx_rows add add pos n 1
825+if lt r 0
826+ha_die ha_errmem
827+end
828+ha_rowcopy pos p n
829+put lx_rows add pos n 10
830+put lx_rn 0 add add pos n 1
831+end
832+
833+fn ha_rowcopy dest ulong source ulong size ulong to void
834+for j ulong size bound 9223372036854775807
835+c = get ha_text add source j
836+put lx_rows add dest j c
837+end
838+end
839+
840+fn ha_packetrec pos ulong value view uchar * to ulong
841+if or gt len value 65535 gt add add pos 2 len value len ha_exec
842+ha_die ha_errexec
843+end
844+put ha_exec pos uchar and len value 255
845+put ha_exec add pos 1 uchar shr len value 8
846+for j ulong len value bound 9223372036854775807
847+put ha_exec add add pos 2 j get value j
848+end
849+ret add add pos 2 len value
850+end
851+
852+fn ha_activate to int
853+k = get lx_pick 0
854+if ge k get ha_hn 0
855+ret 0
856+end
857+index = get ha_hits k
858+p = get ha_meta add mul index 6 2
859+n = get ha_meta add mul index 6 3
860+if ge n len ha_path
861+ha_die ha_errpath
862+end
863+for i ulong n bound 9223372036854775807
864+put ha_path i get ha_text add p i
865+end
866+put ha_pn 0 n
867+ret ha_runpath ha_launch
868+end
869+
870+fn ha_openfile path view uchar * to int
871+ha_setpath path
872+ret ha_runpath ha_open
873+end
874+
875+fn ha_privateenv entry view uchar * to bool
876+note Hop's private settings belong to Hop and its configured model, never a desktop program.
877+if lt len entry 4
878+ret false
879+end
880+if ne get entry 0 72
881+ret false
882+end
883+if ne get entry 1 79
884+ret false
885+end
886+if ne get entry 2 80
887+ret false
888+end
889+ret eq get entry 3 95
890+end
891+
892+fn ha_runpath action view uchar * to int
893+note env is an external platform wrapper: no shell parses the environment or pathname.
894+pos = ha_packetrec 2 ha_envbin
895+pos = ha_packetrec pos ha_options
896+nc = ulong 5
897+envbuf = new uchar 131072 0
898+for i ulong ulong envcnt bound 9223372036854775807
899+n = envread i envbuf 0 len envbuf
900+if lt n 0
901+ha_die ha_errenv
902+end
903+if not ha_privateenv part envbuf 0 ulong n
904+nc = add nc 1
905+if gt nc 1024
906+ha_die ha_errexec
907+end
908+pos = ha_packetrec pos part envbuf 0 ulong n
909+end
910+end
911+pos = ha_packetrec pos ha_gio
912+pos = ha_packetrec pos action
913+pos = ha_packetpath pos get ha_pn 0
914+put ha_exec 0 uchar and nc 255
915+put ha_exec 1 uchar shr nc 8
916+pid = int fork
917+if eq pid 0
918+x = execprog ha_exec 0 pos
919+x = write 2 ha_errlaunch 0 len ha_errlaunch
920+exit 1
921+end
922+if lt pid 0
923+x = write 2 ha_errlaunch 0 len ha_errlaunch
924+ret 0
925+end
926+status = waitpid pid ha_wait 0 4 0
927+if lt status 0
928+x = write 2 ha_errlaunch 0 len ha_errlaunch
929+ret 0
930+end
931+if ne or get ha_wait 0 get ha_wait 1 0
932+x = write 2 ha_errlaunch 0 len ha_errlaunch
933+ret 0
934+end
935+ret 1
936+end
937+
938+fn ha_packetpath pos ulong size ulong to ulong
939+if or gt size 65535 gt add add pos 2 size len ha_exec
940+ha_die ha_errexec
941+end
942+put ha_exec pos uchar and size 255
943+put ha_exec add pos 1 uchar shr size 8
944+for i ulong size bound 9223372036854775807
945+c = get ha_path i
946+put ha_exec add add pos 2 i c
947+end
948+ret add add pos 2 size
949+end

Linux/build.om

new file mode 100644
@@ -0,0 +1,608 @@
1+om2
2+note Linux build driver. Compiler inputs, concatenation and subprocesses are owned by Omega.
3+note Bootstrap this file with OMEGA_MV/seed/out/omc; run it from Hop's source root.
4+text hb_usage "Usage: linux-build OMEGA_MV [install]\n"
5+text hb_error "Hop Linux build failed. The failing tool's diagnostic is above.\n"
6+text hb_done "Built build/linux/hop and its matching helper.\n"
7+text hb_root "/seed/out/omc"
8+text hb_ngsrc "build/linux/ngbuild.om"
9+text hb_ngboot "build/linux/ngbuild"
10+text hb_ng "build/linux/ng"
11+text hb_units "seed/ng/ng.units"
12+text hb_sha "/seed/ng/sha256.om"
13+text hb_builder "/seed/ng/ngbuild.om"
14+text hb_ngunits "/seed/ng/ng.units"
15+text hb_s1 "Linux/window.om"
16+text hb_s2 "Linux/apps.om"
17+text hb_s3 "Linux/core.om"
18+text hb_s4 "Linux/main.om"
19+text hb_s5 "Linux/chat.om"
20+text hb_s6 "Linux/files.om"
21+text hb_join "build/linux/hop.om"
22+text hb_hop "build/linux/hop"
23+text hb_core "Omega/hopcore.om"
24+text hb_front "@ng front-ir\n"
25+text hb_opt "@ng opt\n"
26+text hb_a64 "@ng a64\n"
27+text hb_ci "build/linux/core-input.om"
28+text hb_ir "build/linux/core.ir"
29+text hb_oi "build/linux/opt-input"
30+text hb_or "build/linux/core.opt.ir"
31+text hb_ai "build/linux/elf-input"
32+text hb_co "build/linux/hopcore"
33+text hb_build "build"
34+text hb_dir "build/linux"
35+text hb_empty ""
36+text hb_slash "/"
37+text hb_gio "/usr/bin/gio"
38+text hb_env "/usr/bin/env"
39+text hb_curl "/usr/bin/curl"
40+text hb_version "version"
41+text hb_vflag "--version"
42+text hb_glog "build/linux/dependency-gio.txt"
43+text hb_elog "build/linux/dependency-env.txt"
44+text hb_clog "build/linux/dependency-curl.txt"
45+text hb_isrc "Linux/install.om"
46+text hb_ibin "build/linux/install"
47+text hb_iarg "install"
48+text hb_dd "--"
49+text hb_git "/usr/bin/git"
50+text hb_status "status"
51+text hb_porcelain "--porcelain=v1"
52+text hb_all "--untracked-files=all"
53+text hb_statuslog "build/linux/SOURCE_STATUS"
54+text hb_headlog "build/linux/SOURCE_HEAD"
55+text hb_revparse "rev-parse"
56+text hb_head "HEAD"
57+text hb_privatekey "HOP_API_KEY="
58+text hb_record "build/linux/BUILD_RECORD"
59+text hb_recordtmp "build/linux/BUILD_RECORD.pending"
60+text hb_magic "HOPBUILD1\n"
61+text hb_compilerhead "/source-commit"
62+text hb_sum "/usr/bin/sha256sum"
63+text hb_sumlog "build/linux/build-hash.txt"
64+text hb_sumversion "build/linux/dependency-sha256sum.txt"
65+text hb_newline "\n"
66+global hb_tree uchar 4096
67+global hb_tn ulong 1
68+global hb_cwd uchar 4096
69+global hb_cn ulong 1
70+global hb_tool uchar 4096
71+global hb_tl ulong 1
72+global hb_out uchar 4096
73+global hb_on ulong 1
74+global hb_src uchar 4096
75+global hb_sn ulong 1
76+global hb_pkt uchar 65536
77+global hb_pn ulong 1
78+global hb_ac ulong 1
79+global hb_input uchar 4096
80+global hb_in ulong 1
81+global hb_cd ulong 1
82+global hb_doins ulong 1
83+global hb_initial uchar 128
84+global hb_initialn ulong 1
85+
86+fn hb_fail to void
87+k = write 2 hb_error 0 len hb_error
88+exit 1
89+end
90+
91+fn hb_path dest int suffix view uchar * to void
92+n = get hb_tn 0
93+if gt add n len suffix 4096
94+hb_fail
95+end
96+for i ulong n
97+if eq dest 0
98+put hb_tool i get hb_tree i
99+else
100+put hb_src i get hb_tree i
101+end
102+end
103+for i ulong len suffix
104+if eq dest 0
105+put hb_tool add n i get suffix i
106+else
107+put hb_src add n i get suffix i
108+end
109+end
110+if eq dest 0
111+put hb_tl 0 add n len suffix
112+else
113+put hb_sn 0 add n len suffix
114+end
115+end
116+
117+fn hb_arg a view uchar * to void
118+p = get hb_pn 0
119+if gt add add p 2 len a len hb_pkt
120+hb_fail
121+end
122+put hb_pkt p uchar and len a 255
123+put hb_pkt add p 1 uchar shr len a 8
124+p = add p 2
125+for i ulong len a
126+put hb_pkt add p i get a i
127+end
128+put hb_pn 0 add p len a
129+put hb_ac 0 add get hb_ac 0 1
130+end
131+
132+fn hb_absarg a view uchar * to void
133+b = new uchar 4096 0
134+n = get hb_cn 0
135+if gt add add n 1 len a len b
136+hb_fail
137+end
138+for i ulong n
139+put b i get hb_cwd i
140+end
141+put b n 47
142+for i ulong len a
143+put b add add n 1 i get a i
144+end
145+hb_arg part b 0 add add n 1 len a
146+end
147+
148+fn hb_reset to void
149+put hb_pn 0 2
150+put hb_ac 0 0
151+put hb_cd 0 0
152+put hb_in 0 0
153+put hb_on 0 0
154+end
155+
156+fn hb_addtool to void
157+b = new uchar 4096 0
158+n = get hb_tl 0
159+for i ulong n
160+put b i get hb_tool i
161+end
162+hb_arg part b 0 n
163+end
164+
165+fn hb_redirect path view uchar * input bool to void
166+if input
167+for i ulong len path
168+put hb_input i get path i
169+end
170+put hb_in 0 len path
171+else
172+for i ulong len path
173+put hb_out i get path i
174+end
175+put hb_on 0 len path
176+end
177+end
178+
179+fn hb_run to void
180+st = new uchar 4 0
181+put hb_pkt 0 uchar and get hb_ac 0 255
182+put hb_pkt 1 uchar shr get hb_ac 0 8
183+pid = fork
184+if eq pid 0
185+if gt get hb_in 0 0
186+fd = fopen hb_input 0 get hb_in 0 0 0
187+if lt fd 0
188+exit 126
189+end
190+k = dupfd int fd 0 0
191+if lt k 0
192+exit 126
193+end
194+end
195+if gt get hb_on 0 0
196+fd = fopen hb_out 0 get hb_on 0 577 420
197+if lt fd 0
198+exit 126
199+end
200+k = dupfd int fd 1 0
201+if lt k 0
202+exit 126
203+end
204+end
205+if ne get hb_cd 0 0
206+k = chdir hb_tree 0 get hb_tn 0
207+if ne k 0
208+exit 126
209+end
210+end
211+k = execprog hb_pkt 0 get hb_pn 0
212+exit 127
213+end
214+if lt pid 0
215+hb_fail
216+end
217+k = waitpid int pid st 0 4 0
218+if ne k pid
219+hb_fail
220+end
221+if ne get st 0 0
222+hb_fail
223+end
224+if ne get st 1 0
225+hb_fail
226+end
227+end
228+
229+fn hb_copy fd int path view uchar * to void
230+buf = new uchar 65536 0
231+src = fopen path 0 len path 0 0
232+if lt src 0
233+k = write 2 path 0 len path
234+hb_fail
235+end
236+while true bound 9223372036854775807
237+n = read int src buf 0 len buf
238+if lt n 0
239+hb_fail
240+end
241+if eq n 0
242+break
243+end
244+p = ulong 0
245+while lt p ulong n bound 65536
246+k = write fd buf p sub ulong n p
247+if le k 0
248+hb_fail
249+end
250+p = add p ulong k
251+end
252+end
253+k = fclose int src
254+end
255+
256+fn hb_sourcecopy fd int to void
257+b = new uchar 4096 0
258+n = get hb_sn 0
259+for i ulong n
260+put b i get hb_src i
261+end
262+hb_copy fd part b 0 n
263+end
264+
265+fn hb_chmod path view uchar * to void
266+fd = fopen path 0 len path 0 0
267+if lt fd 0
268+hb_fail
269+end
270+k = fchmod int fd 493
271+if ne k 0
272+hb_fail
273+end
274+k = fclose int fd
275+end
276+
277+fn hb_compile input view uchar * output view uchar * to void
278+hb_reset
279+hb_path 0 hb_root
280+hb_addtool
281+hb_redirect input true
282+hb_redirect output false
283+hb_run
284+hb_chmod output
285+end
286+
287+fn hb_stage prefix view uchar * input view uchar * feed view uchar * to void
288+fd = fopen feed 0 len feed 577 420
289+if lt fd 0
290+hb_fail
291+end
292+k = write int fd prefix 0 len prefix
293+if ne k long len prefix
294+hb_fail
295+end
296+hb_copy int fd input
297+k = fclose int fd
298+end
299+
300+fn hb_ngrun feed view uchar * output view uchar * to void
301+hb_reset
302+hb_absarg hb_ng
303+hb_redirect feed true
304+hb_redirect output false
305+hb_run
306+end
307+
308+fn hb_dependency tool view uchar * arg view uchar * output view uchar * to void
309+hb_reset
310+hb_arg tool
311+hb_arg arg
312+hb_redirect output false
313+hb_run
314+end
315+
316+fn hb_session to void
317+e = new uchar 131072 0
318+hb_arg hb_env
319+hb_arg hb_dd
320+for i ulong ulong envcnt bound 9223372036854775807
321+n = envread i e 0 len e
322+if lt n 0
323+hb_fail
324+end
325+privatev = ge ulong n len hb_privatekey
326+if privatev
327+for j ulong len hb_privatekey
328+if ne get e j get hb_privatekey j
329+privatev = false
330+break
331+end
332+end
333+end
334+if not privatev
335+hb_arg part e 0 ulong n
336+end
337+end
338+end
339+
340+fn hb_provenance to void
341+statusv = new uchar 1 0
342+hb_reset
343+hb_arg hb_git
344+hb_arg hb_status
345+hb_arg hb_porcelain
346+hb_arg hb_all
347+hb_redirect hb_statuslog false
348+hb_run
349+fd = fopen hb_statuslog 0 len hb_statuslog 0 0
350+if lt fd 0
351+hb_fail
352+end
353+n = read int fd statusv 0 1
354+k = fclose int fd
355+if lt n 0
356+hb_fail
357+end
358+if ne n 0
359+note Development builds are useful but must never acquire an installable source stamp.
360+fd = fopen hb_headlog 0 len hb_headlog 577 420
361+if lt fd 0
362+hb_fail
363+end
364+k = fclose int fd
365+ret
366+end
367+hb_reset
368+hb_arg hb_git
369+hb_arg hb_revparse
370+hb_arg hb_head
371+hb_redirect hb_headlog false
372+hb_run
373+end
374+
375+fn hb_hash fd int path view uchar * to void
376+hb_reset
377+hb_arg hb_sum
378+hb_redirect path true
379+hb_redirect hb_sumlog false
380+hb_run
381+b = new uchar 66 0
382+src = fopen hb_sumlog 0 len hb_sumlog 0 0
383+if lt src 0
384+hb_fail
385+end
386+n = read int src b 0 len b
387+k = fclose int src
388+if ne n 66
389+hb_fail
390+end
391+for i ulong 64
392+c = get b i
393+digit = and ge c 48 le c 57
394+letter = and ge c 97 le c 102
395+if not or digit letter
396+hb_fail
397+end
398+end
399+k = write fd b 0 64
400+if ne k 64
401+hb_fail
402+end
403+k = write fd hb_newline 0 1
404+if ne k 1
405+hb_fail
406+end
407+end
408+
409+fn hb_recordbuild to void
410+b = new uchar 1 0
411+src = fopen hb_headlog 0 len hb_headlog 0 0
412+if lt src 0
413+hb_fail
414+end
415+n = read int src b 0 1
416+k = fclose int src
417+if eq n 0
418+ret
419+end
420+if lt n 0
421+hb_fail
422+end
423+fd = fopen hb_recordtmp 0 len hb_recordtmp 577 420
424+if lt fd 0
425+hb_fail
426+end
427+k = write int fd hb_magic 0 len hb_magic
428+if ne k long len hb_magic
429+hb_fail
430+end
431+hb_copy int fd hb_headlog
432+hb_path 1 hb_compilerhead
433+hb_sourcecopy int fd
434+hb_path 1 hb_root
435+p = new uchar 4096 0
436+for i ulong get hb_sn 0
437+put p i get hb_src i
438+end
439+hb_hash int fd part p 0 get hb_sn 0
440+hb_hash int fd hb_hop
441+hb_hash int fd hb_co
442+k = fsync int fd
443+if ne k 0
444+hb_fail
445+end
446+k = fclose int fd
447+if ne k 0
448+hb_fail
449+end
450+hb_reset
451+hb_arg hb_recordtmp
452+hb_arg hb_record
453+put hb_pkt 0 2
454+put hb_pkt 1 0
455+k = renames hb_pkt 0 get hb_pn 0 0
456+if ne k 0
457+hb_fail
458+end
459+end
460+
461+fn hb_checksource first bool to void
462+b = new uchar 128 0
463+src = fopen hb_headlog 0 len hb_headlog 0 0
464+if lt src 0
465+hb_fail
466+end
467+n = read int src b 0 len b
468+k = fclose int src
469+if or lt n 0 ge n long len b
470+hb_fail
471+end
472+if first
473+put hb_initialn 0 ulong n
474+for i ulong ulong n
475+put hb_initial i get b i
476+end
477+else
478+stable = eq ulong n get hb_initialn 0
479+if stable
480+for i ulong ulong n
481+if ne get hb_initial i get b i
482+stable = false
483+end
484+end
485+end
486+if not stable
487+note A source change during compilation cannot acquire a successful proof.
488+fd = fopen hb_headlog 0 len hb_headlog 577 420
489+if lt fd 0
490+hb_fail
491+end
492+k = fclose int fd
493+end
494+end
495+end
496+
497+fn main to int
498+b = new uchar 4096 0
499+if and ne argcnt 2 ne argcnt 3
500+k = write 2 hb_usage 0 len hb_usage
501+ret 2
502+end
503+n = argread 1 b 0 len b
504+if or le n 0 ge n long len b
505+hb_fail
506+end
507+if ne get b 0 47
508+hb_fail
509+end
510+for i ulong ulong n
511+put hb_tree i get b i
512+end
513+put hb_tn 0 ulong n
514+if eq argcnt 3
515+n = argread 2 b 0 len b
516+if ne n long len hb_iarg
517+k = write 2 hb_usage 0 len hb_usage
518+ret 2
519+end
520+for i ulong len hb_iarg
521+if ne get b i get hb_iarg i
522+k = write 2 hb_usage 0 len hb_usage
523+ret 2
524+end
525+end
526+put hb_doins 0 1
527+end
528+n = cwd b 0 len b
529+if le n 0
530+hb_fail
531+end
532+put hb_cn 0 sub ulong n 1
533+for i ulong get hb_cn 0
534+put hb_cwd i get b i
535+end
536+k = makedir hb_build 0 len hb_build 493
537+if and lt k 0 ne k -17
538+hb_fail
539+end
540+k = makedir hb_dir 0 len hb_dir 493
541+if and lt k 0 ne k -17
542+hb_fail
543+end
544+note Invalidate the previous proof before any executable can be overwritten.
545+fd = fopen hb_record 0 len hb_record 577 420
546+if lt fd 0
547+hb_fail
548+end
549+k = fclose int fd
550+hb_provenance
551+hb_checksource true
552+fd = fopen hb_ngsrc 0 len hb_ngsrc 577 420
553+if lt fd 0
554+hb_fail
555+end
556+hb_path 1 hb_sha
557+hb_sourcecopy int fd
558+hb_path 1 hb_builder
559+hb_sourcecopy int fd
560+k = fclose int fd
561+hb_compile hb_ngsrc hb_ngboot
562+hb_reset
563+hb_absarg hb_ngboot
564+hb_arg hb_build
565+hb_path 0 hb_root
566+hb_addtool
567+hb_arg hb_units
568+hb_absarg hb_ng
569+put hb_cd 0 1
570+hb_run
571+hb_chmod hb_ng
572+hb_stage hb_front hb_core hb_ci
573+hb_ngrun hb_ci hb_ir
574+hb_stage hb_opt hb_ir hb_oi
575+hb_ngrun hb_oi hb_or
576+hb_stage hb_a64 hb_or hb_ai
577+hb_ngrun hb_ai hb_co
578+hb_chmod hb_co
579+fd = fopen hb_join 0 len hb_join 577 420
580+if lt fd 0
581+hb_fail
582+end
583+hb_copy int fd hb_s1
584+hb_copy int fd hb_s2
585+hb_copy int fd hb_s3
586+hb_copy int fd hb_s5
587+hb_copy int fd hb_s6
588+hb_copy int fd hb_s4
589+k = fclose int fd
590+hb_compile hb_join hb_hop
591+hb_compile hb_isrc hb_ibin
592+hb_dependency hb_gio hb_version hb_glog
593+hb_dependency hb_env hb_vflag hb_elog
594+hb_dependency hb_curl hb_vflag hb_clog
595+hb_dependency hb_sum hb_vflag hb_sumversion
596+hb_provenance
597+hb_checksource false
598+hb_recordbuild
599+k = write 1 hb_done 0 len hb_done
600+if ne get hb_doins 0 0
601+hb_reset
602+hb_session
603+hb_absarg hb_ibin
604+hb_absarg hb_empty
605+hb_run
606+end
607+ret 0
608+end

Linux/chat.om

new file mode 100644
@@ -0,0 +1,843 @@
1+note Linux Ask. Model endpoint and model are explicit HOP_MODEL_URL and HOP_MODEL settings.
2+note curl is the platform HTTP/TLS transport; build/linux/dependency-curl.txt records its exact version.
3+note Successor: Omega om/tls client plus native DNS/HTTP transport. No shell or host language runtime.
4+note curl reads URL, request and optional API key from anonymous memory on stdin, never argv or a disk file.
5+note No redirects, ambient proxy, curlrc, cookies, retries or TLS verification overrides.
6+note Ask is synchronous: the window waits for the configured server. The transport deadline is 60 seconds.
7+global hc_cfg uchar *
8+global hc_json uchar *
9+global hc_str uchar *
10+global hc_body uchar *
11+global hc_url uchar *
12+global hc_model uchar *
13+global hc_key uchar *
14+global hc_ans uchar *
15+global hc_n ulong 8
16+global hc_pos ulong 1
17+global hc_found ulong 1
18+global hc_http ulong 1
19+global hc_env uchar 131072
20+global hc_io uchar 8192
21+global hc_pipe uchar 16
22+global hc_wait uchar 4
23+global hc_exec uchar 128
24+text hc_uk "HOP_MODEL_URL="
25+text hc_mk "HOP_MODEL="
26+text hc_kk "HOP_API_KEY="
27+text hc_h "http://"
28+text hc_hs "https://"
29+text hc_tail "/chat/completions"
30+text hc_curl "/usr/bin/curl"
31+text hc_q "-q"
32+text hc_config "--config"
33+text hc_dash "-"
34+text hc_memname "hop-model-request"
35+text hc_ct "silent\nshow-error\nfail-with-body\ngloboff\nconnect-timeout = 10\nmax-time = 60\nproto = \"=http,https\"\nproxy = \"\"\nrequest = \"POST\"\nheader = \"Content-Type: application/json\"\nurl = \""
36+text hc_auth "\"\nheader = \"Authorization: Bearer "
37+text hc_data "\"\ndata-binary = \""
38+text hc_end "\"\nwrite-out = \"\\n%{http_code}\"\n"
39+text hc_b1 "{\"model\":\""
40+text hc_b2 "\",\"messages\":[{\"role\":\"user\",\"content\":\""
41+text hc_b3 "\"}],\"stream\":false}"
42+text hc_choices "choices"
43+text hc_message "message"
44+text hc_content "content"
45+text hc_true "true"
46+text hc_false "false"
47+text hc_null "null"
48+text hc_need "Ask needs a model. Set HOP_MODEL_URL to your OpenAI-compatible server's base address and HOP_MODEL to its model name."
49+text hc_badurl "Ask: use an http:// or https:// model base address without control characters, query or fragment."
50+text hc_badkey "Ask: HOP_API_KEY contains a control character and cannot be used as a request header."
51+text hc_transport "Ask: the model request failed. Check the server address, model name, sign-in and network. curl with HTTPS support is required."
52+text hc_server "Ask: the server returned HTTP "
53+text hc_serverend ". Check the model settings and sign-in."
54+text hc_badjson "Ask: the server did not return a valid chat answer (choices[0].message.content must be text)."
55+text hc_mem "Hop Ask: the system could not allocate memory.\n"
56+text hc_action "Ask: "
57+
58+fn hc_res which ulong need ulong to void
59+r = long 0
60+if eq which 0
61+if gt need len hc_cfg
62+r = enlarge hc_cfg add need add len hc_cfg 256
63+end
64+end
65+if eq which 1
66+if gt need len hc_json
67+r = enlarge hc_json add need add len hc_json 8192
68+end
69+end
70+if eq which 2
71+if gt need len hc_str
72+r = enlarge hc_str add need add len hc_str 256
73+end
74+end
75+if eq which 3
76+if gt need len hc_body
77+r = enlarge hc_body add need add len hc_body 256
78+end
79+end
80+if eq which 4
81+if gt need len hc_url
82+r = enlarge hc_url add need add len hc_url 256
83+end
84+end
85+if eq which 5
86+if gt need len hc_model
87+r = enlarge hc_model add need add len hc_model 256
88+end
89+end
90+if eq which 6
91+if gt need len hc_key
92+r = enlarge hc_key add need add len hc_key 256
93+end
94+end
95+if eq which 7
96+if gt need len hc_ans
97+r = enlarge hc_ans add need add len hc_ans 256
98+end
99+end
100+if lt r 0
101+x = write 2 hc_mem 0 len hc_mem
102+exit 1
103+end
104+end
105+
106+fn hc_add which ulong c uchar to void
107+p = get hc_n which
108+hc_res which add p 1
109+if eq which 0
110+put hc_cfg p c
111+end
112+if eq which 1
113+put hc_json p c
114+end
115+if eq which 2
116+put hc_str p c
117+end
118+if eq which 3
119+put hc_body p c
120+end
121+if eq which 4
122+put hc_url p c
123+end
124+if eq which 5
125+put hc_model p c
126+end
127+if eq which 6
128+put hc_key p c
129+end
130+if eq which 7
131+put hc_ans p c
132+end
133+put hc_n which add p 1
134+end
135+
136+fn hc_get which ulong p ulong to uchar
137+if eq which 0
138+ret get hc_cfg p
139+end
140+if eq which 1
141+ret get hc_json p
142+end
143+if eq which 2
144+ret get hc_str p
145+end
146+if eq which 3
147+ret get hc_body p
148+end
149+if eq which 4
150+ret get hc_url p
151+end
152+if eq which 5
153+ret get hc_model p
154+end
155+if eq which 6
156+ret get hc_key p
157+end
158+ret get hc_ans p
159+end
160+
161+fn hc_text which ulong s view uchar * to void
162+for i ulong len s bound 9223372036854775807
163+hc_add which get s i
164+end
165+end
166+
167+fn hc_rows s view uchar * to void
168+r = enlarge lx_rows len s
169+if lt r 0
170+x = write 2 hc_mem 0 len hc_mem
171+exit 1
172+end
173+for i ulong len s bound 9223372036854775807
174+put lx_rows i get s i
175+end
176+put lx_rn 0 len s
177+put lx_pick 0 0
178+end
179+
180+fn hc_envget key view uchar * which ulong to bool
181+put hc_n which 0
182+for i ulong ulong envcnt bound 9223372036854775807
183+n = envread i hc_env 0 len hc_env
184+if lt n 0
185+ret false
186+end
187+if ge ulong n len key
188+same = true
189+for j ulong len key bound 9223372036854775807
190+if ne get hc_env j get key j
191+same = false
192+end
193+end
194+if same
195+p = len key
196+while lt p ulong n bound 9223372036854775807
197+hc_add which get hc_env p
198+p = add p 1
199+end
200+ret true
201+end
202+end
203+end
204+ret false
205+end
206+
207+fn hc_prefix which ulong s view uchar * to bool
208+if lt get hc_n which len s
209+ret false
210+end
211+for i ulong len s bound 9223372036854775807
212+if ne hc_get which i get s i
213+ret false
214+end
215+end
216+ret true
217+end
218+
219+fn hc_jbyte c uchar to void
220+if or eq c 34 eq c 92
221+hc_add 3 92
222+hc_add 3 c
223+ret
224+end
225+if lt c 32
226+hc_add 3 92
227+hc_add 3 117
228+hc_add 3 48
229+hc_add 3 48
230+v = add uchar 48 shr c 4
231+if gt v 57
232+v = add v 39
233+end
234+hc_add 3 v
235+v = add uchar 48 and c 15
236+if gt v 57
237+v = add v 39
238+end
239+hc_add 3 v
240+ret
241+end
242+hc_add 3 c
243+end
244+
245+fn hc_cfgesc which ulong to void
246+for i ulong get hc_n which bound 9223372036854775807
247+c = hc_get which i
248+if or eq c 34 eq c 92
249+hc_add 0 92
250+end
251+hc_add 0 c
252+end
253+end
254+
255+fn hc_prepare to bool
256+a = hc_envget hc_uk 4
257+b = hc_envget hc_mk 5
258+k = hc_envget hc_kk 6
259+if or or not a not b or eq get hc_n 4 0 eq get hc_n 5 0
260+hc_rows hc_need
261+ret false
262+end
263+if not or hc_prefix 4 hc_h hc_prefix 4 hc_hs
264+hc_rows hc_badurl
265+ret false
266+end
267+for i ulong get hc_n 4 bound 9223372036854775807
268+c = get hc_url i
269+if or lt c 33 or eq c 127 or eq c 63 eq c 35
270+hc_rows hc_badurl
271+ret false
272+end
273+end
274+for i ulong get hc_n 6 bound 9223372036854775807
275+c = get hc_key i
276+if or lt c 32 eq c 127
277+hc_rows hc_badkey
278+ret false
279+end
280+end
281+while gt get hc_n 4 0 bound 9223372036854775807
282+if ne get hc_url sub get hc_n 4 1 47
283+break
284+end
285+put hc_n 4 sub get hc_n 4 1
286+end
287+hc_text 4 hc_tail
288+put hc_n 3 0
289+hc_text 3 hc_b1
290+for i ulong get hc_n 5 bound 9223372036854775807
291+hc_jbyte get hc_model i
292+end
293+hc_text 3 hc_b2
294+p = ulong 4
295+while lt p get lx_qn 0 bound 9223372036854775807
296+hc_jbyte get lx_query p
297+p = add p 1
298+end
299+hc_text 3 hc_b3
300+put hc_n 0 0
301+hc_text 0 hc_ct
302+hc_cfgesc 4
303+if gt get hc_n 6 0
304+hc_text 0 hc_auth
305+hc_cfgesc 6
306+end
307+hc_text 0 hc_data
308+hc_cfgesc 3
309+hc_text 0 hc_end
310+ret true
311+end
312+
313+fn hc_pack p ulong s view uchar * to ulong
314+put hc_exec p uchar and len s 255
315+put hc_exec add p 1 uchar shr len s 8
316+for i ulong len s bound 128
317+put hc_exec add add p 2 i get s i
318+end
319+ret add add p 2 len s
320+end
321+
322+fn hc_readfd p ulong to int
323+v = or ulong get hc_pipe p shl ulong get hc_pipe add p 1 8
324+v = or v shl ulong get hc_pipe add p 2 16
325+v = or v shl ulong get hc_pipe add p 3 24
326+ret int v
327+end
328+
329+fn hc_request to bool
330+put hc_http 0 0
331+put hc_exec 0 4
332+put hc_exec 1 0
333+p = hc_pack 2 hc_curl
334+p = hc_pack p hc_q
335+p = hc_pack p hc_config
336+p = hc_pack p hc_dash
337+plen = p
338+input = memfd hc_memname 0 len hc_memname 1
339+if lt input 0
340+ret false
341+end
342+p = ulong 0
343+while lt p get hc_n 0 bound 9223372036854775807
344+k = write int input hc_cfg p sub get hc_n 0 p
345+if eq k -4
346+continue
347+end
348+if le k 0
349+k = fclose int input
350+ret false
351+end
352+p = add p ulong k
353+end
354+k = fseek int input 0 0
355+if lt k 0
356+k = fclose int input
357+ret false
358+end
359+k = pipefds hc_pipe 8 8 524288
360+if ne k 0
361+k = fclose int input
362+ret false
363+end
364+pid = fork
365+if eq pid 0
366+k = dupfd int input 0 0
367+if lt k 0
368+exit 126
369+end
370+k = dupfd hc_readfd 12 1 0
371+if lt k 0
372+exit 126
373+end
374+note discard transport diagnostics: model URLs or server text can contain sensitive information.
375+note All failures are reported in Hop without echoing the key, URL or response.
376+k = dupfd hc_readfd 12 2 0
377+if lt k 0
378+exit 126
379+end
380+k = execprog hc_exec 0 plen
381+exit 127
382+end
383+k = fclose int input
384+k = fclose hc_readfd 12
385+if lt pid 0
386+k = fclose hc_readfd 8
387+ret false
388+end
389+ok = true
390+note Erase credential-bearing configuration after forking its anonymous input.
391+for i ulong get hc_n 0 bound 9223372036854775807
392+put hc_cfg i 0
393+end
394+for i ulong get hc_n 6 bound 9223372036854775807
395+put hc_key i 0
396+end
397+put hc_n 0 0
398+put hc_n 6 0
399+put hc_n 1 0
400+while true bound 9223372036854775807
401+k = read hc_readfd 8 hc_io 0 len hc_io
402+if eq k -4
403+continue
404+end
405+if lt k 0
406+ok = false
407+break
408+end
409+if eq k 0
410+break
411+end
412+for i ulong ulong k bound 8192
413+hc_add 1 get hc_io i
414+end
415+end
416+k = fclose hc_readfd 8
417+k = waitpid int pid hc_wait 0 4 0
418+if ne k pid
419+ret false
420+end
421+if lt get hc_n 1 4
422+ret false
423+end
424+p = sub get hc_n 1 4
425+if ne get hc_json p 10
426+ret false
427+end
428+statusv = ulong 0
429+for i ulong 3
430+c = get hc_json add add p 1 i
431+if or lt c 48 gt c 57
432+ret false
433+end
434+statusv = add mul statusv 10 ulong sub c 48
435+end
436+put hc_http 0 statusv
437+put hc_n 1 p
438+if or lt statusv 200 ge statusv 300
439+ret false
440+end
441+ret and ok and eq get hc_wait 0 0 eq get hc_wait 1 0
442+end
443+
444+fn hc_space to void
445+while lt get hc_pos 0 get hc_n 1 bound 9223372036854775807
446+c = get hc_json get hc_pos 0
447+if not or eq c 32 or eq c 9 or eq c 10 eq c 13
448+break
449+end
450+put hc_pos 0 add get hc_pos 0 1
451+end
452+end
453+
454+fn hc_next to int
455+hc_space
456+if ge get hc_pos 0 get hc_n 1
457+ret -1
458+end
459+ret int get hc_json get hc_pos 0
460+end
461+
462+fn hc_hex c uchar to long
463+if and ge c 48 le c 57
464+ret long sub c 48
465+end
466+if and ge c 65 le c 70
467+ret add long sub c 65 10
468+end
469+if and ge c 97 le c 102
470+ret add long sub c 97 10
471+end
472+ret -1
473+end
474+
475+fn hc_code to long
476+v = long 0
477+for i ulong 4
478+if ge get hc_pos 0 get hc_n 1
479+ret -1
480+end
481+h = hc_hex get hc_json get hc_pos 0
482+if lt h 0
483+ret -1
484+end
485+v = add mul v 16 h
486+put hc_pos 0 add get hc_pos 0 1
487+end
488+ret v
489+end
490+
491+fn hc_utf cp ulong to void
492+if lt cp 128
493+hc_add 2 uchar cp
494+ret
495+end
496+if lt cp 2048
497+hc_add 2 uchar or 192 shr cp 6
498+else
499+if ge cp 65536
500+hc_add 2 uchar or 240 shr cp 18
501+hc_add 2 uchar or 128 and shr cp 12 63
502+else
503+hc_add 2 uchar or 224 shr cp 12
504+end
505+hc_add 2 uchar or 128 and shr cp 6 63
506+end
507+hc_add 2 uchar or 128 and cp 63
508+end
509+
510+fn hc_string to bool
511+if ne hc_next 34
512+ret false
513+end
514+put hc_pos 0 add get hc_pos 0 1
515+put hc_n 2 0
516+while lt get hc_pos 0 get hc_n 1 bound 9223372036854775807
517+c = get hc_json get hc_pos 0
518+put hc_pos 0 add get hc_pos 0 1
519+if eq c 34
520+ret true
521+end
522+if lt c 32
523+ret false
524+end
525+if ne c 92
526+hc_add 2 c
527+continue
528+end
529+if ge get hc_pos 0 get hc_n 1
530+ret false
531+end
532+c = get hc_json get hc_pos 0
533+put hc_pos 0 add get hc_pos 0 1
534+if or eq c 34 or eq c 92 eq c 47
535+hc_add 2 c
536+continue
537+end
538+if eq c 110
539+hc_add 2 10
540+continue
541+end
542+if eq c 114
543+hc_add 2 13
544+continue
545+end
546+if eq c 116
547+hc_add 2 9
548+continue
549+end
550+if eq c 98
551+hc_add 2 8
552+continue
553+end
554+if eq c 102
555+hc_add 2 12
556+continue
557+end
558+if ne c 117
559+ret false
560+end
561+cp = hc_code
562+if lt cp 0
563+ret false
564+end
565+if and ge cp 55296 le cp 56319
566+if gt add get hc_pos 0 2 get hc_n 1
567+ret false
568+end
569+if ne get hc_json get hc_pos 0 92
570+ret false
571+end
572+if ne get hc_json add get hc_pos 0 1 117
573+ret false
574+end
575+put hc_pos 0 add get hc_pos 0 2
576+lo = hc_code
577+if or lt lo 56320 gt lo 57343
578+ret false
579+end
580+cp = add 65536 add mul sub cp 55296 1024 sub lo 56320
581+else
582+if and ge cp 56320 le cp 57343
583+ret false
584+end
585+end
586+hc_utf ulong cp
587+end
588+ret false
589+end
590+
591+fn hc_streq s view uchar * to bool
592+if ne get hc_n 2 len s
593+ret false
594+end
595+for i ulong len s bound 9223372036854775807
596+if ne get hc_str i get s i
597+ret false
598+end
599+end
600+ret true
601+end
602+
603+fn hc_literal s view uchar * to bool
604+if gt add get hc_pos 0 len s get hc_n 1
605+ret false
606+end
607+for i ulong len s bound 9223372036854775807
608+if ne get hc_json add get hc_pos 0 i get s i
609+ret false
610+end
611+end
612+put hc_pos 0 add get hc_pos 0 len s
613+ret true
614+end
615+
616+fn hc_digit to bool
617+if ge get hc_pos 0 get hc_n 1
618+ret false
619+end
620+c = get hc_json get hc_pos 0
621+ret and ge c 48 le c 57
622+end
623+
624+fn hc_digits to void
625+while hc_digit bound 9223372036854775807
626+put hc_pos 0 add get hc_pos 0 1
627+end
628+end
629+
630+fn hc_number to bool
631+if eq hc_next 45
632+put hc_pos 0 add get hc_pos 0 1
633+end
634+if not hc_digit
635+ret false
636+end
637+if eq get hc_json get hc_pos 0 48
638+put hc_pos 0 add get hc_pos 0 1
639+else
640+hc_digits
641+end
642+if lt get hc_pos 0 get hc_n 1
643+if eq get hc_json get hc_pos 0 46
644+put hc_pos 0 add get hc_pos 0 1
645+if not hc_digit
646+ret false
647+end
648+hc_digits
649+end
650+end
651+if lt get hc_pos 0 get hc_n 1
652+c = get hc_json get hc_pos 0
653+if or eq c 101 eq c 69
654+put hc_pos 0 add get hc_pos 0 1
655+if lt get hc_pos 0 get hc_n 1
656+c = get hc_json get hc_pos 0
657+if or eq c 43 eq c 45
658+put hc_pos 0 add get hc_pos 0 1
659+end
660+end
661+if not hc_digit
662+ret false
663+end
664+hc_digits
665+end
666+end
667+ret true
668+end
669+
670+fn hc_value mode ulong to bool
671+c = hc_next
672+if eq c 123
673+put hc_pos 0 add get hc_pos 0 1
674+if eq hc_next 125
675+put hc_pos 0 add get hc_pos 0 1
676+ret true
677+end
678+while true bound 9223372036854775807
679+if not hc_string
680+ret false
681+end
682+next = ulong 0
683+if and eq mode 1 hc_streq hc_choices
684+next = 2
685+end
686+if and eq mode 3 hc_streq hc_message
687+next = 4
688+end
689+if and eq mode 4 hc_streq hc_content
690+next = 5
691+end
692+if ne hc_next 58
693+ret false
694+end
695+put hc_pos 0 add get hc_pos 0 1
696+if not hc_value next
697+ret false
698+end
699+c = hc_next
700+put hc_pos 0 add get hc_pos 0 1
701+if eq c 125
702+ret true
703+end
704+if ne c 44
705+ret false
706+end
707+end
708+end
709+if eq c 91
710+put hc_pos 0 add get hc_pos 0 1
711+if eq hc_next 93
712+put hc_pos 0 add get hc_pos 0 1
713+ret true
714+end
715+idx = ulong 0
716+while true bound 9223372036854775807
717+next = ulong 0
718+if and eq mode 2 eq idx 0
719+next = 3
720+end
721+if not hc_value next
722+ret false
723+end
724+idx = add idx 1
725+c = hc_next
726+put hc_pos 0 add get hc_pos 0 1
727+if eq c 93
728+ret true
729+end
730+if ne c 44
731+ret false
732+end
733+end
734+end
735+if eq c 34
736+if not hc_string
737+ret false
738+end
739+if eq mode 5
740+if ne get hc_found 0 0
741+ret false
742+end
743+put hc_n 7 0
744+for i ulong get hc_n 2 bound 9223372036854775807
745+hc_add 7 get hc_str i
746+end
747+put hc_found 0 1
748+end
749+ret true
750+end
751+if eq c 116
752+ret hc_literal hc_true
753+end
754+if eq c 102
755+ret hc_literal hc_false
756+end
757+if eq c 110
758+ret hc_literal hc_null
759+end
760+if or eq c 45 and ge c 48 le c 57
761+ret hc_number
762+end
763+ret false
764+end
765+
766+fn hc_query to int
767+if lt get lx_qn 0 5
768+ret 0
769+end
770+if or ne get lx_query 0 97 ne get lx_query 1 115
771+ret 0
772+end
773+if or ne get lx_query 2 107 ne get lx_query 3 32
774+ret 0
775+end
776+r = enlarge lx_rows add get lx_qn 0 1
777+if lt r 0
778+x = write 2 hc_mem 0 len hc_mem
779+exit 1
780+end
781+for i ulong len hc_action
782+put lx_rows i get hc_action i
783+end
784+p = len hc_action
785+i = ulong 4
786+while lt i get lx_qn 0 bound 9223372036854775807
787+put lx_rows p get lx_query i
788+p = add p 1
789+i = add i 1
790+end
791+put lx_rn 0 p
792+put lx_pick 0 0
793+ret 1
794+end
795+
796+fn hc_activate to int
797+if not hc_prepare
798+ret 0
799+end
800+if not hc_request
801+if gt get hc_http 0 0
802+put hc_n 7 0
803+hc_text 7 hc_server
804+hc_add 7 uchar add 48 div get hc_http 0 100
805+hc_add 7 uchar add 48 rem div get hc_http 0 10 10
806+hc_add 7 uchar add 48 rem get hc_http 0 10
807+hc_text 7 hc_serverend
808+r = enlarge lx_rows get hc_n 7
809+if lt r 0
810+x = write 2 hc_mem 0 len hc_mem
811+exit 1
812+end
813+for i ulong get hc_n 7 bound 9223372036854775807
814+put lx_rows i get hc_ans i
815+end
816+put lx_rn 0 get hc_n 7
817+put lx_pick 0 0
818+ret 0
819+end
820+hc_rows hc_transport
821+ret 0
822+end
823+put hc_pos 0 0
824+put hc_found 0 0
825+put hc_n 7 0
826+ok = hc_value 1
827+hc_space
828+if or not ok or ne get hc_found 0 1 ne get hc_pos 0 get hc_n 1
829+hc_rows hc_badjson
830+ret 0
831+end
832+r = enlarge lx_rows get hc_n 7
833+if lt r 0
834+x = write 2 hc_mem 0 len hc_mem
835+exit 1
836+end
837+for i ulong get hc_n 7 bound 9223372036854775807
838+put lx_rows i get hc_ans i
839+end
840+put lx_rn 0 get hc_n 7
841+put lx_pick 0 0
842+ret 0
843+end

Linux/core.om

new file mode 100644
@@ -0,0 +1,197 @@
1+note Linux adapter for Hop's unchanged Omega matching helper.
2+note Requests use the existing Omega/README.md kind1 protocol, not a second matcher.
3+note An anonymous local socket carries stdio so send uses MSG_NOSIGNAL if the helper dies.
4+text hp_link "/proc/self/exe"
5+text hp_tail "/hopcore"
6+text hp_fail "Hop could not use its search helper. Rebuild Hop before launching it.\n"
7+global hp_fd int 3
8+
9+fn hp_le a view uchar * p ulong n ulong to ulong
10+v = ulong 0
11+for i ulong n
12+v = or v shl ulong get a add p i mul i 8
13+end
14+ret v
15+end
16+
17+fn hp_put a edit uchar * p ulong v ulong n ulong to void
18+for i ulong n
19+put a add p i uchar and shr v mul i 8 255
20+end
21+end
22+
23+fn hp_bad to void
24+k = write 2 hp_fail 0 len hp_fail
25+end
26+
27+fn hp_start to int
28+hp_path = new uchar 4096 0
29+hp_exec = new uchar 4104 0
30+hp_addr = new uchar 19 0
31+put hp_fd 0 -1
32+put hp_fd 1 -1
33+put hp_fd 2 -1
34+n = readlnk hp_link 0 len hp_link hp_path 0 len hp_path
35+if le n 0
36+hp_bad
37+ret 1
38+end
39+if eq n long len hp_path
40+hp_bad
41+ret 1
42+end
43+p = ulong n
44+while gt p 0 bound 4096
45+if eq get hp_path sub p 1 47
46+break
47+end
48+p = sub p 1
49+end
50+if or eq p 0 gt add p len hp_tail len hp_path
51+hp_bad
52+ret 1
53+end
54+p = sub p 1
55+for i ulong len hp_tail
56+put hp_path add p i get hp_tail i
57+end
58+p = add p len hp_tail
59+hp_put hp_exec 0 1 2
60+hp_put hp_exec 2 p 2
61+for i ulong p
62+put hp_exec add i 4 get hp_path i
63+end
64+server = socknew 1 1 0
65+if lt server 0
66+hp_bad
67+ret 1
68+end
69+put hp_addr 0 1
70+k = random hp_addr 3 16 0
71+if ne k 16
72+k = fclose int server
73+hp_bad
74+ret 1
75+end
76+k = bind int server hp_addr 0 len hp_addr
77+if ne k 0
78+k = fclose int server
79+hp_bad
80+ret 1
81+end
82+k = listen int server 1
83+if ne k 0
84+k = fclose int server
85+hp_bad
86+ret 1
87+end
88+pid = fork
89+if eq pid 0
90+sock = socknew 1 1 0
91+if lt sock 0
92+exit 126
93+end
94+k = connect int sock hp_addr 0 len hp_addr
95+if ne k 0
96+exit 126
97+end
98+k = dupfd int sock 0 0
99+if lt k 0
100+exit 126
101+end
102+k = dupfd int sock 1 0
103+if lt k 0
104+exit 126
105+end
106+k = execprog hp_exec 0 add p 4
107+exit 127
108+end
109+if lt pid 0
110+k = fclose int server
111+hp_bad
112+ret 1
113+end
114+put hp_fd 2 int pid
115+ready = waitio int server 1 2000000000
116+if le ready 0
117+k = fclose int server
118+hp_stop
119+hp_bad
120+ret 1
121+end
122+sock = accept int server 0
123+k = fclose int server
124+if lt sock 0
125+hp_stop
126+hp_bad
127+ret 1
128+end
129+put hp_fd 0 int sock
130+put hp_fd 1 int sock
131+ret 0
132+end
133+
134+fn hp_fuzz inp view ulong 256 to ulong
135+hp_req = new uchar 2056 0
136+hp_rep = new uchar 11 0
137+if lt get hp_fd 0 0
138+ret 0
139+end
140+hp_put hp_req 0 1 4
141+hp_put hp_req 4 2048 4
142+for i ulong 256
143+hp_put hp_req add 8 mul i 8 get inp i 8
144+end
145+p = ulong 0
146+while lt p len hp_req bound 2056
147+k = send get hp_fd 0 hp_req p sub len hp_req p 0
148+if le k 0
149+hp_bad
150+ret 0
151+end
152+p = add p ulong k
153+end
154+p = ulong 0
155+while lt p 11 bound 11
156+ready = waitio get hp_fd 1 1 2000000000
157+if le ready 0
158+hp_bad
159+ret 0
160+end
161+k = read get hp_fd 1 hp_rep p sub 11 p
162+if le k 0
163+hp_bad
164+ret 0
165+end
166+p = add p ulong k
167+end
168+if ne hp_le hp_rep 0 4 0
169+hp_bad
170+ret 0
171+end
172+if ne hp_le hp_rep 4 4 3
173+hp_bad
174+ret 0
175+end
176+if ne get hp_rep 8 1
177+ret 0
178+end
179+ret hp_le hp_rep 9 2
180+end
181+
182+fn hp_stop to void
183+hp_state = new uchar 4 0
184+if ge get hp_fd 0 0
185+k = fclose get hp_fd 0
186+end
187+if and ge get hp_fd 1 0 ne get hp_fd 1 get hp_fd 0
188+k = fclose get hp_fd 1
189+end
190+put hp_fd 0 -1
191+put hp_fd 1 -1
192+if gt get hp_fd 2 0
193+k = killpid get hp_fd 2 15
194+k = waitpid get hp_fd 2 hp_state 0 4 0
195+put hp_fd 2 -1
196+end
197+end

Linux/files.om

new file mode 100644
@@ -0,0 +1,1714 @@
1+note Hop Linux file-list foundation. SPDX-License-Identifier: Apache-2.0
2+note No timer or scan runs until explicitly requested. Symlink directories are never traversed.
3+note File format HOPFIND1:64-byte header, then NUL-terminated absolute pathname byte strings.
4+note CLI JSON follows RFC8259 section7 and UTF-8 validation RFC3629 sections3/4.
5+note Invalid filesystem UTF-8 bytes use the reversible surrogateescape convention U+DC80..U+DCFF;
6+note agents must retain these escapes when round-tripping such names. Ordinary Unicode is encoded normally.
7+note Header0..7 magic; u64 little-endian at8 record count,16 partial-warning count,24 body bytes,
8+note 32 attempted-directory count;40..63 reserved zero. A newline is an ordinary pathname byte.
9+note Linux AArch64 stat and fcntl layouts are those of installed kernel UAPI headers.
10+note Directory flags O_NOFOLLOW|O_DIRECTORY=49152 calc:a636669bf8335bbaf4882cbbea217a1bbb71e5037a035961710684bb41f1597c.
11+note Temp flags O_NOFOLLOW|O_CREAT|O_EXCL|O_WRONLY=32961 calc:a20ca9614e5701d380af7d625ecc52fc9d081fc5f1c2dbce397542e1bb81313a.
12+note Lock flags O_NOFOLLOW|O_CREAT|O_NONBLOCK|O_RDWR=34882 calc:55d3315f96faa89f2851ea6d22b07a20adda0081bf621917b0eca71661a94ceb.
13+note Fixed4096 pathname buffers reflect the Linux pathname syscall boundary; directories and records grow.
14+note All cache operations occur relative to an open cache directory, then the original working directory is restored.
15+note This avoids imposing the compiler's4096-byte packed-rename boundary on a pair of long absolute paths.
16+global ff_path uchar 4096
17+global ff_cache uchar 4096
18+global ff_home uchar 4096
19+global ff_cwd uchar 4096
20+global ff_tmp uchar 96
21+global ff_hdr uchar 64
22+global ff_buf uchar 65536
23+global ff_stat uchar 128
24+global ff_arg uchar 131072
25+global ff_rename uchar 128
26+global ff_nul uchar 1
27+global ff_out uchar 4096
28+global ff_on ulong 1
29+global ff_queue uchar *
30+global ff_qmeta ulong *
31+global ff_seen ulong *
32+global ff_oldseen ulong *
33+global ff_data uchar *
34+global ff_hits ulong *
35+global ff_terms uchar *
36+global ff_s ulong 32
37+global ff_fd int 4
38+note ff_s fields:0 path bytes,1 cache bytes,2 temp-name bytes,3 records,4 partial warnings,
39+note 5 body bytes,6 attempted directories,7 queued dirs,8 queue bytes,9 seen count,10 seen slots,
40+note 11 alarm threshold,12 alarm emitted,13 error,14 UI mode,15 loaded bytes,16 hits,
41+note 17 term bytes,18 home bytes,19 cwd bytes,20 temp exists,21 leading status rows.
42+text ff_magic "HOPFIND1"
43+text ff_index "files.idx"
44+text ff_lock "files.lock"
45+text ff_tempstart ".files."
46+text ff_dot "."
47+text ff_reindexarg "--reindex"
48+text ff_tmpend ".tmp"
49+text ff_homekey "HOME="
50+text ff_cachekey "XDG_CACHE_HOME="
51+text ff_cachetail "/.cache"
52+text ff_hoptail "/hop"
53+text ff_hive "/work/hive"
54+text ff_lanes "/work/lanes"
55+text ff_alarmkey "HOP_INDEX_ALARM_ENTRIES="
56+text ff_node "node_modules"
57+text ff_target "target"
58+text ff_build "build"
59+text ff_dist "dist"
60+text ff_py "__pycache__"
61+text ff_venv "venv"
62+text ff_dotvenv ".venv"
63+text ff_site "site-packages"
64+text ff_slash "/"
65+text ff_partialmsg "Hop kept the file list it could read. Some folders were unavailable; coverage is partial.\n"
66+text ff_failmsg "Hop could not replace its file list. The previous list has been kept.\n"
67+text ff_cachemsg "Hop needs an absolute private cache folder and a valid home folder or explicit root.\n"
68+text ff_busymsg "Hop's file list is already being built. The current list is unchanged.\n"
69+text ff_badmsg "Hop's file list is damaged. Rebuild it before searching.\n"
70+text ff_missingmsg "Hop has no file list yet. Use --reindex or choose Build file list.\n"
71+text ff_memmsg "Hop could not grow its file-list memory.\n"
72+text ff_alarmmsg "ALARM Hop file-list entries "
73+text ff_alarmmid " crossed HOP_INDEX_ALARM_ENTRIES="
74+text ff_alarmend "; indexing continues.\n"
75+text ff_alarmbad "Hop: invalid HOP_INDEX_ALARM_ENTRIES; using the default alarm threshold.\n"
76+text ff_buildrow "Build file list\n"
77+text ff_rebuildrow "File list is damaged. Build it again\n"
78+text ff_warnrow "Some folders could not be read. Results below are partial\n"
79+text ff_emptyrow "No files match that search\n"
80+text ff_hex "0123456789abcdef"
81+
82+fn ff_message message view uchar * to void
83+k = write 2 message 0 len message
84+end
85+
86+fn ff_reserve which ulong need ulong to bool
87+r = long 0
88+if eq which 0
89+if gt need len ff_queue
90+r = enlarge ff_queue add need add len ff_queue 4096
91+end
92+end
93+if eq which 1
94+if gt need len ff_qmeta
95+r = enlarge ff_qmeta add need add len ff_qmeta 64
96+end
97+end
98+if eq which 2
99+r = enlarge ff_seen need
100+end
101+if eq which 3
102+r = enlarge ff_oldseen need
103+end
104+if eq which 4
105+if gt need len ff_data
106+r = enlarge ff_data add need add len ff_data 65536
107+end
108+end
109+if eq which 5
110+if gt need len ff_hits
111+r = enlarge ff_hits add need add len ff_hits 128
112+end
113+end
114+if eq which 6
115+if gt need len ff_terms
116+r = enlarge ff_terms add need add len ff_terms 128
117+end
118+end
119+if lt r 0
120+put ff_s 13 1
121+ff_message ff_memmsg
122+ret false
123+end
124+ret true
125+end
126+
127+fn ff_pathset source view uchar * to bool
128+if ge len source len ff_path
129+ret false
130+end
131+for i ulong len source bound 9223372036854775807
132+c = get source i
133+put ff_path i c
134+end
135+put ff_s 0 len source
136+ret true
137+end
138+
139+fn ff_pathadd source view uchar * to bool
140+p = get ff_s 0
141+if ge add p len source len ff_path
142+ret false
143+end
144+for i ulong len source bound 9223372036854775807
145+c = get source i
146+put ff_path add p i c
147+end
148+put ff_s 0 add p len source
149+ret true
150+end
151+
152+fn ff_envpath n ulong to bool
153+if ge n len ff_path
154+ret false
155+end
156+for i ulong n bound 9223372036854775807
157+c = get ha_env i
158+put ff_path i c
159+end
160+put ff_s 0 n
161+ret true
162+end
163+
164+fn ff_normalize to bool
165+n = get ff_s 0
166+if eq n 0
167+ret false
168+end
169+if ne get ff_path 0 47
170+ret false
171+end
172+r = ulong 1
173+w = ulong 1
174+while lt r n bound 4096
175+while lt r n bound 4096
176+if ne get ff_path r 47
177+break
178+end
179+r = add r 1
180+end
181+start = r
182+while lt r n bound 4096
183+if eq get ff_path r 47
184+break
185+end
186+r = add r 1
187+end
188+size = sub r start
189+if eq size 1
190+if eq get ff_path start 46
191+size = 0
192+end
193+end
194+if eq size 2
195+if eq get ff_path start 46
196+if eq get ff_path add start 1 46
197+if gt w 1
198+w = sub w 1
199+while gt w 1 bound 4096
200+if eq get ff_path sub w 1 47
201+break
202+end
203+w = sub w 1
204+end
205+if gt w 1
206+w = sub w 1
207+end
208+end
209+size = 0
210+end
211+end
212+end
213+if gt size 0
214+if gt w 1
215+put ff_path w 47
216+w = add w 1
217+end
218+ff_pathmove start w size
219+w = add w size
220+end
221+end
222+put ff_s 0 w
223+ret true
224+end
225+
226+fn ff_pathmove source ulong dest ulong size ulong to void
227+for i ulong size bound 4096
228+c = get ff_path add source i
229+put ff_path add dest i c
230+end
231+end
232+
233+fn ff_statword offset ulong size ulong to ulong
234+v = ulong 0
235+for i ulong size bound 8
236+c = ulong get ff_stat add offset i
237+v = or v shl c mul i 8
238+end
239+ret v
240+end
241+
242+fn ff_mode to ulong
243+ret and ff_statword 16 4 61440
244+end
245+
246+fn ff_getstat follow bool to bool
247+r = long 0
248+if follow
249+r = stat ff_path 0 get ff_s 0 ff_stat 0 len ff_stat
250+else
251+r = lstat ff_path 0 get ff_s 0 ff_stat 0 len ff_stat
252+end
253+ret ge r 0
254+end
255+
256+fn ff_setup create bool to bool
257+for i ulong 4
258+put ff_fd i -1
259+end
260+put ff_s 20 0
261+put ff_s 18 0
262+n = ha_envget ff_homekey
263+if gt n 0
264+if eq get ha_env 0 47
265+if ff_envpath ulong n
266+if ff_normalize
267+ff_savehome
268+end
269+end
270+end
271+end
272+n = cwd ff_cwd 0 len ff_cwd
273+if le n 0
274+ret false
275+end
276+put ff_s 19 sub ulong n 1
277+n = ha_envget ff_cachekey
278+valid = false
279+if gt n 0
280+valid = eq get ha_env 0 47
281+end
282+if valid
283+if not ff_envpath ulong n
284+ret false
285+end
286+else
287+if eq get ff_s 18 0
288+ret false
289+end
290+ff_homepath
291+if not ff_pathadd ff_cachetail
292+ret false
293+end
294+end
295+if not ff_pathadd ff_hoptail
296+ret false
297+end
298+if not ff_normalize
299+ret false
300+end
301+ff_savecache
302+if create
303+if not ff_mkdirs
304+ret false
305+end
306+end
307+ret true
308+end
309+
310+fn ff_savehome to void
311+n = get ff_s 0
312+for i ulong n bound 4096
313+c = get ff_path i
314+put ff_home i c
315+end
316+put ff_s 18 n
317+end
318+
319+fn ff_homepath to void
320+n = get ff_s 18
321+for i ulong n bound 4096
322+c = get ff_home i
323+put ff_path i c
324+end
325+put ff_s 0 n
326+end
327+
328+fn ff_savecache to void
329+n = get ff_s 0
330+for i ulong n bound 4096
331+c = get ff_path i
332+put ff_cache i c
333+end
334+put ff_s 1 n
335+end
336+
337+fn ff_cachepath to void
338+n = get ff_s 1
339+for i ulong n bound 4096
340+c = get ff_cache i
341+put ff_path i c
342+end
343+put ff_s 0 n
344+end
345+
346+fn ff_mkdirs to bool
347+n = get ff_s 0
348+for i ulong add n 1 bound 4097
349+sep = eq i n
350+if not sep
351+sep = eq get ff_path i 47
352+end
353+if and sep gt i 0
354+r = makedir ff_path 0 i 448
355+if and lt r 0 ne r -17
356+ret false
357+end
358+end
359+end
360+if not ff_getstat false
361+ret false
362+end
363+if ne ff_mode 16384
364+ret false
365+end
366+if ne ff_statword 24 4 ulong getuid
367+ret false
368+end
369+ret eq and ff_statword 16 4 63 0
370+end
371+
372+fn ff_enter to bool
373+old = int fopen ff_dot 0 len ff_dot 0 0
374+if lt old 0
375+ret false
376+end
377+put ff_fd 0 old
378+ff_cachepath
379+cache = int fopen ff_path 0 get ff_s 0 49152 0
380+if lt cache 0
381+put ff_s 24 ulong neg long cache
382+ret false
383+end
384+put ff_fd 1 cache
385+ret eq fchdir cache 0
386+end
387+
388+fn ff_cleanup to void
389+if ge get ff_fd 3 0
390+k = fclose get ff_fd 3
391+put ff_fd 3 -1
392+end
393+if ne get ff_s 20 0
394+k = unlink ff_tmp 0 get ff_s 2
395+put ff_s 20 0
396+end
397+if ge get ff_fd 2 0
398+k = fclose get ff_fd 2
399+put ff_fd 2 -1
400+end
401+if ge get ff_fd 0 0
402+k = fchdir get ff_fd 0
403+if ne k 0
404+put ff_s 13 1
405+end
406+k = fclose get ff_fd 0
407+put ff_fd 0 -1
408+end
409+if ge get ff_fd 1 0
410+k = fclose get ff_fd 1
411+put ff_fd 1 -1
412+end
413+end
414+
415+fn ff_temptext source view uchar * to void
416+p = get ff_s 2
417+for i ulong len source bound 96
418+c = get source i
419+put ff_tmp add p i c
420+end
421+put ff_s 2 add p len source
422+end
423+
424+fn ff_tempnum value ulong to void
425+digits = new uchar 20 0
426+n = ulong 0
427+v = value
428+while true bound 20
429+put digits n uchar add 48 rem v 10
430+n = add n 1
431+v = div v 10
432+if eq v 0
433+break
434+end
435+end
436+p = get ff_s 2
437+for i ulong n bound 20
438+put ff_tmp add p i get digits sub sub n i 1
439+end
440+put ff_s 2 add p n
441+end
442+
443+fn ff_startoutput to int
444+lockfd = int fopen ff_lock 0 len ff_lock 34882 384
445+if lt lockfd 0
446+ret 1
447+end
448+put ff_fd 2 lockfd
449+k = fstat lockfd ff_stat 0 len ff_stat
450+if lt k 0
451+ret 1
452+end
453+if ne ff_mode 32768
454+ret 1
455+end
456+k = flock lockfd 6
457+if eq k -11
458+ret 3
459+end
460+if ne k 0
461+ret 1
462+end
463+put ff_s 2 0
464+ff_temptext ff_tempstart
465+ff_tempnum ulong getpid
466+ff_temptext ff_dot
467+ff_tempnum ulong monons
468+ff_temptext ff_tmpend
469+fd = int fopen ff_tmp 0 get ff_s 2 32961 384
470+if lt fd 0
471+ret 1
472+end
473+put ff_s 20 1
474+put ff_fd 3 fd
475+ff_header
476+ret ff_writeheader
477+end
478+
479+fn ff_headernum offset ulong value ulong to void
480+for i ulong 8
481+c = uchar and shr value mul i 8 255
482+put ff_hdr add offset i c
483+end
484+end
485+
486+fn ff_header to void
487+for i ulong len ff_hdr
488+put ff_hdr i 0
489+end
490+for i ulong len ff_magic
491+put ff_hdr i get ff_magic i
492+end
493+ff_headernum 8 get ff_s 3
494+ff_headernum 16 get ff_s 4
495+ff_headernum 24 get ff_s 5
496+ff_headernum 32 get ff_s 6
497+end
498+
499+fn ff_writeheader to int
500+p = ulong 0
501+while lt p len ff_hdr bound 64
502+k = write get ff_fd 3 ff_hdr p sub len ff_hdr p
503+if eq k -4
504+continue
505+end
506+if le k 0
507+put ff_s 13 1
508+ret 1
509+end
510+p = add p ulong k
511+end
512+ret 0
513+end
514+
515+fn ff_dataword offset ulong to ulong
516+v = ulong 0
517+for i ulong 8
518+c = ulong get ff_data add offset i
519+v = or v shl c mul i 8
520+end
521+ret v
522+end
523+
524+fn ff_load to int
525+put ff_s 13 0
526+put ff_s 15 0
527+put ff_s 16 0
528+put ff_s 4 0
529+put ff_s 24 0
530+if not ff_setup false
531+ret 3
532+end
533+if not ff_enter
534+ff_cleanup
535+if eq get ff_s 24 2
536+ret 1
537+end
538+ret 3
539+end
540+fd = int fopen ff_index 0 len ff_index 34816 0
541+if lt fd 0
542+ff_cleanup
543+if eq fd -2
544+ret 1
545+end
546+ret 3
547+end
548+put ff_fd 3 fd
549+k = fstat fd ff_stat 0 len ff_stat
550+if or lt k 0 ne ff_mode 32768
551+ff_cleanup
552+ret 2
553+end
554+while true bound 9223372036854775807
555+n = read fd ff_buf 0 len ff_buf
556+if eq n -4
557+continue
558+end
559+if lt n 0
560+ff_cleanup
561+ret 3
562+end
563+if eq n 0
564+break
565+end
566+if not ff_loadpart ulong n
567+ff_cleanup
568+ret 3
569+end
570+end
571+ff_cleanup
572+if ne get ff_s 13 0
573+ret 3
574+end
575+if not ff_validate
576+ret 2
577+end
578+ret 0
579+end
580+
581+fn ff_loadpart size ulong to bool
582+p = get ff_s 15
583+if not ff_reserve 4 add p size
584+ret false
585+end
586+for i ulong size bound 65536
587+c = get ff_buf i
588+put ff_data add p i c
589+end
590+put ff_s 15 add p size
591+ret true
592+end
593+
594+fn ff_validate to bool
595+n = get ff_s 15
596+if lt n 64
597+ret false
598+end
599+for i ulong len ff_magic
600+if ne get ff_data i get ff_magic i
601+ret false
602+end
603+end
604+for i ulong 24
605+if ne get ff_data add i 40 0
606+ret false
607+end
608+end
609+if ne ff_dataword 24 sub n 64
610+ret false
611+end
612+p = ulong 64
613+count = ulong 0
614+while lt p n bound 9223372036854775807
615+if ne get ff_data p 47
616+ret false
617+end
618+start = p
619+while lt p n bound 4096
620+if eq get ff_data p 0
621+break
622+end
623+p = add p 1
624+if ge sub p start 4096
625+ret false
626+end
627+end
628+if eq p n
629+ret false
630+end
631+count = add count 1
632+p = add p 1
633+end
634+if ne count ff_dataword 8
635+ret false
636+end
637+put ff_s 3 count
638+put ff_s 4 ff_dataword 16
639+put ff_s 5 ff_dataword 24
640+put ff_s 6 ff_dataword 32
641+ret true
642+end
643+
644+fn ff_termwhite c uchar to bool
645+ret or eq c 32 and ge c 9 le c 13
646+end
647+
648+fn ff_pathhas start ulong size ulong term ulong termsize ulong to bool
649+if gt termsize size
650+ret false
651+end
652+for i ulong add sub size termsize 1 bound 4096
653+if ff_pathterm add start i term termsize
654+ret true
655+end
656+end
657+ret false
658+end
659+
660+fn ff_pathterm start ulong term ulong size ulong to bool
661+for j ulong size bound 9223372036854775807
662+a = ha_lower get ff_data add start j
663+b = ha_lower get ff_terms add term j
664+if ne a b
665+ret false
666+end
667+end
668+ret true
669+end
670+
671+fn ff_match start ulong size ulong to bool
672+n = get ff_s 17
673+p = ulong 0
674+while lt p n bound 9223372036854775807
675+while lt p n bound 9223372036854775807
676+if not ff_termwhite get ff_terms p
677+break
678+end
679+p = add p 1
680+end
681+lo = p
682+while lt p n bound 9223372036854775807
683+if ff_termwhite get ff_terms p
684+break
685+end
686+p = add p 1
687+end
688+if gt p lo
689+if not ff_pathhas start size lo sub p lo
690+ret false
691+end
692+end
693+end
694+ret true
695+end
696+
697+fn ff_search to bool
698+put ff_s 16 0
699+p = ulong 64
700+n = get ff_s 15
701+while lt p n bound 9223372036854775807
702+start = p
703+while ne get ff_data p 0 bound 4096
704+p = add p 1
705+end
706+if ff_match start sub p start
707+k = get ff_s 16
708+if not ff_reserve 5 mul add k 1 2
709+ret false
710+end
711+put ff_hits mul k 2 start
712+put ff_hits add mul k 2 1 sub p start
713+put ff_s 16 add k 1
714+end
715+p = add p 1
716+end
717+ret true
718+end
719+
720+fn ff_rowbyte c uchar to void
721+p = get lx_rn 0
722+if eq p len lx_rows
723+r = enlarge lx_rows add add p p 128
724+if lt r 0
725+put ff_s 13 1
726+ret
727+end
728+end
729+put lx_rows p c
730+put lx_rn 0 add p 1
731+end
732+
733+fn ff_rowtext value view uchar * to void
734+for i ulong len value bound 4096
735+ff_rowbyte get value i
736+end
737+end
738+
739+fn ff_rowpath start ulong size ulong to void
740+for i ulong size bound 4096
741+c = get ff_data add start i
742+if eq c 10
743+ff_rowbyte 92
744+ff_rowbyte 110
745+else
746+if eq c 13
747+ff_rowbyte 92
748+ff_rowbyte 114
749+else
750+if eq c 9
751+ff_rowbyte 92
752+ff_rowbyte 116
753+else
754+if eq c 92
755+ff_rowbyte 92
756+ff_rowbyte 92
757+else
758+if or lt c 32 eq c 127
759+ff_rowbyte 92
760+ff_rowbyte 120
761+ff_rowbyte get ff_hex shr c 4
762+ff_rowbyte get ff_hex and c 15
763+else
764+ff_rowbyte c
765+end
766+end
767+end
768+end
769+end
770+end
771+ff_rowbyte 10
772+end
773+
774+fn ff_queryterms start ulong size ulong to bool
775+if not ff_reserve 6 size
776+ret false
777+end
778+for i ulong size bound 9223372036854775807
779+c = get lx_query add start i
780+put ff_terms i c
781+end
782+put ff_s 17 size
783+ret true
784+end
785+
786+fn ff_isfind to bool
787+n = get lx_qn 0
788+if lt n 4
789+ret false
790+end
791+if ne ha_lower get lx_query 0 102
792+ret false
793+end
794+if ne ha_lower get lx_query 1 105
795+ret false
796+end
797+if ne ha_lower get lx_query 2 110
798+ret false
799+end
800+if ne ha_lower get lx_query 3 100
801+ret false
802+end
803+if eq n 4
804+ret true
805+end
806+ret eq get lx_query 4 32
807+end
808+
809+fn ff_query to int
810+if not ff_isfind
811+ret 0
812+end
813+start = ulong 4
814+if gt get lx_qn 0 4
815+start = 5
816+end
817+put lx_rn 0 0
818+put lx_pick 0 0
819+put ff_s 14 3
820+put ff_s 21 0
821+if not ff_queryterms start sub get lx_qn 0 start
822+ret 1
823+end
824+loaded = ff_load
825+if ne loaded 0
826+if eq loaded 1
827+put ff_s 14 1
828+ff_rowtext ff_buildrow
829+else
830+if eq loaded 2
831+put ff_s 14 1
832+ff_rowtext ff_rebuildrow
833+else
834+ff_rowtext ff_failmsg
835+end
836+end
837+ret 1
838+end
839+if not ff_search
840+ff_rowtext ff_memmsg
841+ret 1
842+end
843+if ne get ff_s 4 0
844+ff_rowtext ff_warnrow
845+put ff_s 21 1
846+end
847+if eq get ff_s 16 0
848+ff_rowtext ff_emptyrow
849+ret 1
850+end
851+put ff_s 14 2
852+for i ulong get ff_s 16 bound 9223372036854775807
853+ff_rowhit i
854+end
855+if eq get ff_s 21 1
856+put lx_pick 0 1
857+end
858+ret 1
859+end
860+
861+fn ff_rowhit index ulong to void
862+p = get ff_hits mul index 2
863+n = get ff_hits add mul index 2 1
864+ff_rowpath p n
865+end
866+
867+fn ff_activate to int
868+mode = get ff_s 14
869+if eq mode 1
870+if eq ff_rebuild 0
871+k = ff_query
872+end
873+ret 0
874+end
875+if ne mode 2
876+ret 0
877+end
878+pick = get lx_pick 0
879+if lt pick get ff_s 21
880+ret 0
881+end
882+pick = sub pick get ff_s 21
883+if ge pick get ff_s 16
884+ret 0
885+end
886+p = get ff_hits mul pick 2
887+n = get ff_hits add mul pick 2 1
888+path = new uchar 4096 0
889+for i ulong n bound 4096
890+c = get ff_data add p i
891+put path i c
892+end
893+ret ha_openfile part path 0 n
894+end
895+
896+fn ff_partial to ulong
897+ret get ff_s 4
898+end
899+
900+fn ff_flush to bool
901+p = ulong 0
902+n = get ff_on 0
903+while lt p n bound 4096
904+k = write 1 ff_out p sub n p
905+if eq k -4
906+continue
907+end
908+if le k 0
909+put ff_s 13 1
910+ret false
911+end
912+p = add p ulong k
913+end
914+put ff_on 0 0
915+ret true
916+end
917+
918+fn ff_outbyte c uchar to void
919+if eq get ff_on 0 len ff_out
920+if not ff_flush
921+ret
922+end
923+end
924+p = get ff_on 0
925+put ff_out p c
926+put ff_on 0 add p 1
927+end
928+
929+fn ff_jsonhex scalar ulong to void
930+ff_outbyte 92
931+ff_outbyte 117
932+ff_outbyte get ff_hex and shr scalar 12 15
933+ff_outbyte get ff_hex and shr scalar 8 15
934+ff_outbyte get ff_hex and shr scalar 4 15
935+ff_outbyte get ff_hex and scalar 15
936+end
937+
938+fn ff_scalar pos ulong endpos ulong to ulong
939+put ff_s 25 1
940+c = ulong get ff_data pos
941+if lt c 128
942+ret c
943+end
944+count = ulong 0
945+value = ulong 0
946+if and ge c 194 le c 223
947+count = 2
948+value = and c 31
949+end
950+if and ge c 224 le c 239
951+count = 3
952+value = and c 15
953+end
954+if and ge c 240 le c 244
955+count = 4
956+value = and c 7
957+end
958+if or eq count 0 gt add pos count endpos
959+ret add 56320 c
960+end
961+for i ulong sub count 1 bound 3
962+d = ulong get ff_data add add pos i 1
963+if or lt d 128 gt d 191
964+ret add 56320 c
965+end
966+value = or shl value 6 and d 63
967+end
968+if and eq count 2 lt value 128
969+ret add 56320 c
970+end
971+if and eq count 3 lt value 2048
972+ret add 56320 c
973+end
974+if and eq count 4 lt value 65536
975+ret add 56320 c
976+end
977+if or and ge value 55296 le value 57343 gt value 1114111
978+ret add 56320 c
979+end
980+put ff_s 25 count
981+ret value
982+end
983+
984+fn ff_jsonpath start ulong size ulong to void
985+ff_outbyte 34
986+p = start
987+endpos = add start size
988+while lt p endpos bound 4096
989+v = ff_scalar p endpos
990+if or eq v 34 eq v 92
991+ff_outbyte 92
992+ff_outbyte uchar v
993+else
994+if or lt v 32 ge v 127
995+if le v 65535
996+ff_jsonhex v
997+else
998+partv = sub v 65536
999+ff_jsonhex add 55296 shr partv 10
1000+ff_jsonhex add 56320 and partv 1023
1001+end
1002+else
1003+ff_outbyte uchar v
1004+end
1005+end
1006+p = add p get ff_s 25
1007+end
1008+ff_outbyte 34
1009+end
1010+
1011+fn ff_json to int
1012+put ff_on 0 0
1013+ff_outbyte 91
1014+for i ulong get ff_s 16 bound 9223372036854775807
1015+if ne i 0
1016+ff_outbyte 44
1017+end
1018+ff_jsonhit i
1019+end
1020+ff_outbyte 93
1021+ff_outbyte 10
1022+if not ff_flush
1023+ret 1
1024+end
1025+if ne get ff_s 13 0
1026+ret 1
1027+end
1028+ret 0
1029+end
1030+
1031+fn ff_jsonhit index ulong to void
1032+p = get ff_hits mul index 2
1033+n = get ff_hits add mul index 2 1
1034+ff_jsonpath p n
1035+end
1036+
1037+fn ff_cliterms to bool
1038+put ff_s 17 0
1039+if le argcnt 2
1040+ret true
1041+end
1042+n = argread 2 ff_arg 0 len ff_arg
1043+if lt n 0
1044+ret false
1045+end
1046+if not ff_reserve 6 ulong n
1047+ret false
1048+end
1049+for i ulong ulong n bound 131072
1050+c = get ff_arg i
1051+put ff_terms i c
1052+end
1053+put ff_s 17 ulong n
1054+ret true
1055+end
1056+
1057+fn ff_cli mode int to int
1058+if eq mode 0
1059+ret ff_rebuild
1060+end
1061+if gt argcnt 3
1062+ret 2
1063+end
1064+if not ff_cliterms
1065+ret 1
1066+end
1067+loaded = ff_load
1068+if ne loaded 0
1069+if eq loaded 1
1070+ff_message ff_missingmsg
1071+else
1072+if eq loaded 2
1073+ff_message ff_badmsg
1074+else
1075+ff_message ff_failmsg
1076+end
1077+end
1078+ret 1
1079+end
1080+if not ff_search
1081+ret 1
1082+end
1083+if ne get ff_s 4 0
1084+ff_message ff_partialmsg
1085+end
1086+ret ff_json
1087+end
1088+
1089+fn ff_record to bool
1090+n = get ff_s 0
1091+p = ulong 0
1092+while lt p n bound 4096
1093+k = write get ff_fd 3 ff_path p sub n p
1094+if eq k -4
1095+continue
1096+end
1097+if le k 0
1098+put ff_s 13 1
1099+ret false
1100+end
1101+p = add p ulong k
1102+end
1103+k = write get ff_fd 3 ff_nul 0 1
1104+if ne k 1
1105+put ff_s 13 1
1106+ret false
1107+end
1108+put ff_s 3 add get ff_s 3 1
1109+put ff_s 5 add get ff_s 5 add n 1
1110+ff_alarm
1111+ret true
1112+end
1113+
1114+fn ff_printnum value ulong to void
1115+b = new uchar 20 0
1116+v = value
1117+n = ulong 20
1118+while true bound 20
1119+n = sub n 1
1120+put b n uchar add 48 rem v 10
1121+v = div v 10
1122+if eq v 0
1123+break
1124+end
1125+end
1126+k = write 2 b n sub 20 n
1127+end
1128+
1129+fn ff_alarm to void
1130+if ne get ff_s 12 0
1131+ret
1132+end
1133+if le get ff_s 3 get ff_s 11
1134+ret
1135+end
1136+put ff_s 12 1
1137+ff_message ff_alarmmsg
1138+ff_printnum get ff_s 3
1139+ff_message ff_alarmmid
1140+ff_printnum get ff_s 11
1141+ff_message ff_alarmend
1142+end
1143+
1144+fn ff_alarmsetting to void
1145+put ff_s 11 1000000
1146+n = ha_envget ff_alarmkey
1147+if lt n 0
1148+ret
1149+end
1150+if eq n 0
1151+ff_message ff_alarmbad
1152+ret
1153+end
1154+v = ulong 0
1155+for i ulong ulong n bound 131072
1156+c = get ha_env i
1157+if or lt c 48 gt c 57
1158+ff_message ff_alarmbad
1159+ret
1160+end
1161+d = ulong sub c 48
1162+if gt v div sub 18446744073709551615 d 10
1163+ff_message ff_alarmbad
1164+ret
1165+end
1166+v = add mul v 10 d
1167+end
1168+put ff_s 11 v
1169+end
1170+
1171+fn ff_seenplace device ulong inode ulong cap ulong to ulong
1172+slot = rem xor device inode cap
1173+while ne get ff_seen add mul slot 3 2 0 bound 9223372036854775807
1174+if eq get ff_seen mul slot 3 device
1175+if eq get ff_seen add mul slot 3 1 inode
1176+ret slot
1177+end
1178+end
1179+slot = rem add slot 1 cap
1180+end
1181+ret slot
1182+end
1183+
1184+fn ff_seengrow to bool
1185+oldcap = get ff_s 10
1186+cap = ulong 64
1187+if gt oldcap 0
1188+cap = mul oldcap 2
1189+end
1190+if not ff_reserve 3 mul oldcap 3
1191+ret false
1192+end
1193+for i ulong mul oldcap 3 bound 9223372036854775807
1194+c = get ff_seen i
1195+put ff_oldseen i c
1196+end
1197+if not ff_reserve 2 mul cap 3
1198+ret false
1199+end
1200+for i ulong cap bound 9223372036854775807
1201+put ff_seen add mul i 3 2 0
1202+end
1203+for i ulong oldcap bound 9223372036854775807
1204+if ne get ff_oldseen add mul i 3 2 0
1205+ff_rehash i cap
1206+end
1207+end
1208+put ff_s 10 cap
1209+ret true
1210+end
1211+
1212+fn ff_rehash oldslot ulong cap ulong to void
1213+device = get ff_oldseen mul oldslot 3
1214+inode = get ff_oldseen add mul oldslot 3 1
1215+slot = ff_seenplace device inode cap
1216+put ff_seen mul slot 3 device
1217+put ff_seen add mul slot 3 1 inode
1218+put ff_seen add mul slot 3 2 1
1219+end
1220+
1221+fn ff_remember device ulong inode ulong to int
1222+if ge mul get ff_s 9 2 get ff_s 10
1223+if not ff_seengrow
1224+ret -1
1225+end
1226+end
1227+slot = ff_seenplace device inode get ff_s 10
1228+if ne get ff_seen add mul slot 3 2 0
1229+ret 0
1230+end
1231+put ff_seen mul slot 3 device
1232+put ff_seen add mul slot 3 1 inode
1233+put ff_seen add mul slot 3 2 1
1234+put ff_s 9 add get ff_s 9 1
1235+ret 1
1236+end
1237+
1238+fn ff_homesuffix suffix view uchar * to bool
1239+n = get ff_s 18
1240+if eq n 0
1241+ret false
1242+end
1243+if ne get ff_s 0 add n len suffix
1244+ret false
1245+end
1246+for i ulong n bound 4096
1247+if ne get ff_path i get ff_home i
1248+ret false
1249+end
1250+end
1251+for i ulong len suffix bound 4096
1252+if ne get ff_path add n i get suffix i
1253+ret false
1254+end
1255+end
1256+ret true
1257+end
1258+
1259+fn ff_excludedpath to bool
1260+if ff_skipcurrent
1261+ret true
1262+end
1263+if eq get ff_s 0 get ff_s 1
1264+same = true
1265+for i ulong get ff_s 1 bound 4096
1266+if ne get ff_path i get ff_cache i
1267+same = false
1268+break
1269+end
1270+end
1271+if same
1272+ret true
1273+end
1274+end
1275+if ff_homesuffix ff_hive
1276+ret true
1277+end
1278+ret ff_homesuffix ff_lanes
1279+end
1280+
1281+fn ff_enqueue to bool
1282+if ff_excludedpath
1283+ret true
1284+end
1285+if not ff_getstat false
1286+ff_warn
1287+ret true
1288+end
1289+if ne ff_mode 16384
1290+ff_warn
1291+ret true
1292+end
1293+device = ff_statword 0 8
1294+inode = ff_statword 8 8
1295+newdir = ff_remember device inode
1296+if lt newdir 0
1297+ret false
1298+end
1299+if eq newdir 0
1300+ret true
1301+end
1302+q = get ff_s 7
1303+p = get ff_s 8
1304+n = get ff_s 0
1305+if not ff_reserve 0 add p n
1306+ret false
1307+end
1308+if not ff_reserve 1 mul add q 1 4
1309+ret false
1310+end
1311+ff_queuecopy p n
1312+put ff_qmeta mul q 4 p
1313+put ff_qmeta add mul q 4 1 n
1314+put ff_qmeta add mul q 4 2 device
1315+put ff_qmeta add mul q 4 3 inode
1316+put ff_s 7 add q 1
1317+put ff_s 8 add p n
1318+ret ff_record
1319+end
1320+
1321+fn ff_queuecopy dest ulong size ulong to void
1322+for i ulong size bound 4096
1323+c = get ff_path i
1324+put ff_queue add dest i c
1325+end
1326+end
1327+
1328+fn ff_queuepath index ulong to void
1329+p = get ff_qmeta mul index 4
1330+n = get ff_qmeta add mul index 4 1
1331+for i ulong n bound 4096
1332+c = get ff_queue add p i
1333+put ff_path i c
1334+end
1335+put ff_s 0 n
1336+end
1337+
1338+fn ff_warn to void
1339+put ff_s 4 add get ff_s 4 1
1340+end
1341+
1342+fn ff_skipname pos ulong size ulong to bool
1343+b = new uchar 4096 0
1344+if ge size len b
1345+ret true
1346+end
1347+for i ulong size bound 4096
1348+put b i get ff_buf add pos i
1349+end
1350+ret ff_skipvalue part b 0 size
1351+end
1352+
1353+fn ff_skipcurrent to bool
1354+b = new uchar 4096 0
1355+n = get ff_s 0
1356+start = n
1357+while gt start 0 bound 4096
1358+if eq get ff_path sub start 1 47
1359+break
1360+end
1361+start = sub start 1
1362+end
1363+size = sub n start
1364+for i ulong size bound 4096
1365+put b i get ff_path add start i
1366+end
1367+ret ff_skipvalue part b 0 size
1368+end
1369+
1370+fn ff_equal a view uchar * b view uchar * to bool
1371+if ne len a len b
1372+ret false
1373+end
1374+for i ulong len a bound 4096
1375+if ne get a i get b i
1376+ret false
1377+end
1378+end
1379+ret true
1380+end
1381+
1382+fn ff_skipvalue value view uchar * to bool
1383+if eq len value 0
1384+ret false
1385+end
1386+if eq get value 0 46
1387+ret true
1388+end
1389+if ff_equal value ff_node
1390+ret true
1391+end
1392+if ff_equal value ff_target
1393+ret true
1394+end
1395+if ff_equal value ff_build
1396+ret true
1397+end
1398+if ff_equal value ff_dist
1399+ret true
1400+end
1401+if ff_equal value ff_py
1402+ret true
1403+end
1404+if ff_equal value ff_venv
1405+ret true
1406+end
1407+if ff_equal value ff_dotvenv
1408+ret true
1409+end
1410+ret ff_equal value ff_site
1411+end
1412+
1413+fn ff_childpath dir ulong pos ulong size ulong to bool
1414+ff_queuepath dir
1415+base = get ff_s 0
1416+extra = ulong 1
1417+if eq base 1
1418+extra = 0
1419+end
1420+if ge add add base extra size len ff_path
1421+ff_warn
1422+ret false
1423+end
1424+if ne extra 0
1425+put ff_path base 47
1426+end
1427+for i ulong size bound 65536
1428+c = get ff_buf add pos i
1429+put ff_path add add base extra i c
1430+end
1431+put ff_s 0 add add base extra size
1432+ret true
1433+end
1434+
1435+fn ff_entry dir ulong pos ulong endpos ulong to bool
1436+start = add pos 19
1437+n = ulong 0
1438+while lt add start n endpos bound 65536
1439+if eq get ff_buf add start n 0
1440+break
1441+end
1442+n = add n 1
1443+end
1444+if eq add start n endpos
1445+ff_warn
1446+ret true
1447+end
1448+if eq n 0
1449+ret true
1450+end
1451+if eq get ff_buf start 46
1452+if eq n 1
1453+ret true
1454+end
1455+if eq n 2
1456+if eq get ff_buf add start 1 46
1457+ret true
1458+end
1459+end
1460+end
1461+if not ff_childpath dir start n
1462+ret true
1463+end
1464+if not ff_getstat false
1465+ff_warn
1466+ret true
1467+end
1468+kind = ff_mode
1469+if eq kind 16384
1470+if ff_skipname start n
1471+ret true
1472+end
1473+ret ff_enqueue
1474+end
1475+if or eq kind 32768 eq kind 40960
1476+ret ff_record
1477+end
1478+ret true
1479+end
1480+
1481+fn ff_dirbytes dir ulong size ulong to bool
1482+p = ulong 0
1483+while lt p size bound 65536
1484+if lt sub size p 20
1485+ff_warn
1486+ret true
1487+end
1488+low = ulong get ff_buf add p 16
1489+high = ulong get ff_buf add p 17
1490+rec = add low shl high 8
1491+if or lt rec 20 gt add p rec size
1492+ff_warn
1493+ret true
1494+end
1495+if not ff_entry dir p add p rec
1496+ret false
1497+end
1498+p = add p rec
1499+end
1500+ret true
1501+end
1502+
1503+fn ff_scandir dir ulong to bool
1504+ff_queuepath dir
1505+fd = int fopen ff_path 0 get ff_s 0 49152 0
1506+put ff_s 6 add get ff_s 6 1
1507+if lt fd 0
1508+ff_warn
1509+ret true
1510+end
1511+k = fstat fd ff_stat 0 len ff_stat
1512+if lt k 0
1513+k = fclose fd
1514+ff_warn
1515+ret true
1516+end
1517+if not ff_samedir dir
1518+k = fclose fd
1519+ff_warn
1520+ret true
1521+end
1522+ok = true
1523+while true bound 9223372036854775807
1524+n = getdnts fd ff_buf 0 len ff_buf
1525+if eq n -4
1526+continue
1527+end
1528+if lt n 0
1529+ff_warn
1530+break
1531+end
1532+if eq n 0
1533+break
1534+end
1535+if not ff_dirbytes dir ulong n
1536+ok = false
1537+break
1538+end
1539+end
1540+k = fclose fd
1541+ret ok
1542+end
1543+
1544+fn ff_samedir dir ulong to bool
1545+if ne ff_mode 16384
1546+ret false
1547+end
1548+if ne ff_statword 0 8 get ff_qmeta add mul dir 4 2
1549+ret false
1550+end
1551+ret eq ff_statword 8 8 get ff_qmeta add mul dir 4 3
1552+end
1553+
1554+fn ff_rootarg source view uchar * to bool
1555+if eq len source 0
1556+ret false
1557+end
1558+if eq get source 0 47
1559+if not ff_pathset source
1560+ret false
1561+end
1562+else
1563+n = get ff_s 19
1564+for i ulong n bound 4096
1565+c = get ff_cwd i
1566+put ff_path i c
1567+end
1568+put ff_s 0 n
1569+if not ff_pathadd ff_slash
1570+ret false
1571+end
1572+if not ff_pathadd source
1573+ret false
1574+end
1575+end
1576+ret ff_normalize
1577+end
1578+
1579+fn ff_roots to bool
1580+if not ff_rootargs
1581+if eq get ff_s 18 0
1582+put ff_s 13 1
1583+ret false
1584+end
1585+ff_homepath
1586+ret ff_enqueue
1587+end
1588+for i ulong sub ulong argcnt 2 bound 9223372036854775807
1589+n = argread add i 2 ff_arg 0 len ff_arg
1590+if lt n 0
1591+ff_warn
1592+else
1593+if ff_rootargbuf ulong n
1594+if not ff_enqueue
1595+ret false
1596+end
1597+else
1598+ff_warn
1599+end
1600+end
1601+end
1602+ret true
1603+end
1604+
1605+fn ff_rootargs to bool
1606+if le argcnt 2
1607+ret false
1608+end
1609+b = new uchar 16 0
1610+n = argread 1 b 0 len b
1611+if ne n long len ff_reindexarg
1612+ret false
1613+end
1614+for i ulong len ff_reindexarg
1615+if ne get b i get ff_reindexarg i
1616+ret false
1617+end
1618+end
1619+ret true
1620+end
1621+
1622+fn ff_rootargbuf size ulong to bool
1623+local = new uchar 4096 0
1624+if ge size len local
1625+ret false
1626+end
1627+for j ulong size bound 4096
1628+put local j get ff_arg j
1629+end
1630+ret ff_rootarg part local 0 size
1631+end
1632+
1633+fn ff_publish to bool
1634+ff_header
1635+k = fseek get ff_fd 3 0 0
1636+if ne k 0
1637+ret false
1638+end
1639+if ne ff_writeheader 0
1640+ret false
1641+end
1642+if ne fsync get ff_fd 3 0
1643+ret false
1644+end
1645+put ff_rename 0 2
1646+put ff_rename 1 0
1647+n = get ff_s 2
1648+put ff_rename 2 uchar n
1649+put ff_rename 3 0
1650+for i ulong n bound 96
1651+c = get ff_tmp i
1652+put ff_rename add i 4 c
1653+end
1654+p = add n 4
1655+put ff_rename p uchar len ff_index
1656+put ff_rename add p 1 0
1657+for i ulong len ff_index
1658+put ff_rename add add p 2 i get ff_index i
1659+end
1660+k = renames ff_rename 0 add add p 2 len ff_index 0
1661+if ne k 0
1662+ret false
1663+end
1664+put ff_s 20 0
1665+ret true
1666+end
1667+
1668+fn ff_rebuild to int
1669+for i ulong 32
1670+put ff_s i 0
1671+end
1672+if not ff_setup true
1673+ff_message ff_cachemsg
1674+ff_cleanup
1675+ret 1
1676+end
1677+if not ff_enter
1678+ff_message ff_failmsg
1679+ff_cleanup
1680+ret 1
1681+end
1682+started = ff_startoutput
1683+if ne started 0
1684+if eq started 3
1685+ff_message ff_busymsg
1686+else
1687+ff_message ff_failmsg
1688+end
1689+ff_cleanup
1690+ret started
1691+end
1692+ff_alarmsetting
1693+ok = ff_roots
1694+di = ulong 0
1695+while and ok lt di get ff_s 7 bound 9223372036854775807
1696+ok = ff_scandir di
1697+di = add di 1
1698+end
1699+if ok
1700+ok = ff_publish
1701+end
1702+if not ok
1703+put ff_s 13 1
1704+end
1705+ff_cleanup
1706+if ne get ff_s 13 0
1707+ff_message ff_failmsg
1708+ret 1
1709+end
1710+if ne get ff_s 4 0
1711+ff_message ff_partialmsg
1712+end
1713+ret 0
1714+end

Linux/install.om

new file mode 100644
@@ -0,0 +1,949 @@
1+om2
2+note Linux per-user installer. git is a read-only source-verification oracle, never a runtime dependency of installed Hop.
3+note SOURCE_HEAD is written by the build driver from git, not typed. All checks precede filesystem publication.
4+note /usr/bin/env is a desktop-launch adapter: GLib mischecks literal percent signs in executable paths before field-code expansion. No shell is used.
5+note Existing versions and dated launcher/desktop backups are retained; no service, timer or system directory is changed.
6+text hi_git "/usr/bin/git"
7+text hi_homekey "HOME="
8+text hi_datakey "XDG_DATA_HOME="
9+text hi_storekey "HOP_GIT_STORE="
10+text hi_storesuffix "/git/hop.git"
11+text hi_datasuffix "/.local/share"
12+text hi_libsuffix "/.local/lib/hop"
13+text hi_binsuffix "/.local/bin"
14+text hi_appsuffix "/applications"
15+text hi_hop "/hop"
16+text hi_core "/hopcore"
17+text hi_license "/LICENSE"
18+text hi_licdest "/LICENSE"
19+text hi_stamp "/SOURCE_HEAD"
20+text hi_buildhop "/build/linux/hop"
21+text hi_buildcore "/build/linux/hopcore"
22+text hi_buildstamp "/build/linux/SOURCE_HEAD"
23+text hi_buildrecord "/build/linux/BUILD_RECORD"
24+text hi_recorddest "/BUILD_RECORD"
25+text hi_compilerhead "/build/linux-toolchain/source-commit"
26+text hi_compiler "/build/linux-toolchain/seed/out/omc"
27+text hi_sum "/usr/bin/sha256sum"
28+text hi_magic "HOPBUILD1"
29+text hi_desktop "/hop.desktop"
30+text hi_tempdesktop "/.hop.desktop."
31+text hi_backdesktop "/hop.desktop.backup."
32+text hi_templink "/.hop."
33+text hi_backlink "/hop.backup."
34+text hi_dash "-"
35+text hi_slash "/"
36+text hi_main "refs/heads/main"
37+text hi_C "-C"
38+text hi_gitdir "--git-dir"
39+text hi_revparse "rev-parse"
40+text hi_HEAD "HEAD"
41+text hi_status "status"
42+text hi_porcelain "--porcelain=v1"
43+text hi_untracked "--untracked-files=normal"
44+text hi_managed "X-Hop-Managed=true\n"
45+text hi_deskhead "[Desktop Entry]\nType=Application\nName=Hop\nComment=Find apps and files, ask, and work with your agent\nTerminal=false\nCategories=Utility;\nX-Hop-Managed=true\nExec=/usr/bin/env \""
46+text hi_desktail "\"\n"
47+text hi_usage "Usage: linux-install SOURCE_ROOT\n"
48+text hi_bad "Hop installation stopped; no existing version was deleted.\n"
49+text hi_badsource "Hop installs only a clean checkout of the current published main. Land and rebuild the change first.\n"
50+text hi_badbuild "Hop's build does not identify the current source. Rebuild from the published main first.\n"
51+text hi_badcollision "A launcher or desktop entry named Hop belongs to something else. It was left alone.\n"
52+text hi_badpath "Hop needs absolute HOME and data paths without control characters or an equals sign.\n"
53+text hi_done "Installed Hop. Open Hop from your application menu. Previous versions and dated backups were kept.\n"
54+global hi_home uchar 4096
55+global hi_hn ulong 1
56+global hi_data uchar 4096
57+global hi_dn ulong 1
58+global hi_root uchar 4096
59+global hi_rn ulong 1
60+global hi_store uchar 4096
61+global hi_sn ulong 1
62+global hi_lib uchar 4096
63+global hi_ln ulong 1
64+global hi_bin uchar 4096
65+global hi_bn ulong 1
66+global hi_apps uchar 4096
67+global hi_an ulong 1
68+global hi_ver uchar 4096
69+global hi_vn ulong 1
70+global hi_path uchar 4096
71+global hi_pn ulong 1
72+global hi_other uchar 4096
73+global hi_on ulong 1
74+global hi_env uchar 4096
75+global hi_packet uchar 65536
76+global hi_pk ulong 2
77+global hi_pipe uchar 8
78+global hi_statusbuf uchar 4
79+global hi_output uchar *
80+global hi_outn ulong 1
81+global hi_head uchar *
82+global hi_hd ulong 1
83+global hi_buf uchar *
84+global hi_bytes uchar 65536
85+global hi_id uchar 80
86+global hi_idn ulong 1
87+global hi_desktxt uchar *
88+global hi_dekn ulong 1
89+global hi_oldlink uchar 4096
90+global hi_oldn ulong 1
91+global hi_deskold ulong 1
92+global hi_record uchar *
93+global hi_recsize ulong 1
94+global hi_fields ulong 6
95+global hi_sizes ulong 6
96+global hi_hashinput ulong 1
97+
98+fn hi_die msg view uchar * to void
99+k = write 2 msg 0 len msg
100+exit 1
101+end
102+fn hi_fail to void
103+hi_die hi_bad
104+end
105+fn hi_envget key view uchar * to ulong
106+for i ulong ulong envcnt bound 9223372036854775807
107+n = envread i hi_env 0 len hi_env
108+if ge n long len key
109+ok = true
110+for j ulong len key bound 4096
111+if ne get key j get hi_env j
112+ok = false
113+end
114+end
115+if ok
116+ret hi_envcopy len key ulong n
117+end
118+end
119+end
120+put hi_pn 0 0
121+ret 0
122+end
123+fn hi_envcopy start ulong total ulong to ulong
124+count = sub total start
125+for j ulong count bound 4096
126+put hi_path j get hi_env add start j
127+end
128+put hi_pn 0 count
129+ret count
130+end
131+fn hi_checkpath a view uchar * to void
132+if eq len a 0
133+hi_die hi_badpath
134+end
135+if ne get a 0 47
136+hi_die hi_badpath
137+end
138+for i ulong len a bound 4096
139+c = get a i
140+if or lt c 32 eq c 61
141+hi_die hi_badpath
142+end
143+end
144+end
145+fn hi_setpath base view uchar * tail view uchar * to void
146+if gt add len base len tail 4095
147+hi_die hi_badpath
148+end
149+for i ulong len base bound 4096
150+put hi_path i get base i
151+end
152+for i ulong len tail bound 4096
153+put hi_path add len base i get tail i
154+end
155+put hi_pn 0 add len base len tail
156+end
157+fn hi_arg a view uchar * to void
158+p = get hi_pk 0
159+if gt add add p 2 len a len hi_packet
160+hi_fail
161+end
162+put hi_packet p uchar and len a 255
163+put hi_packet add p 1 uchar shr len a 8
164+p = add p 2
165+for i ulong len a bound 65536
166+put hi_packet add p i get a i
167+end
168+put hi_pk 0 add p len a
169+put hi_pk 1 add get hi_pk 1 1
170+end
171+fn hi_argpath to void
172+b = new uchar 4096 0
173+for i ulong get hi_pn 0 bound 4096
174+put b i get hi_path i
175+end
176+hi_arg part b 0 get hi_pn 0
177+end
178+fn hi_reset to void
179+put hi_pk 0 2
180+put hi_pk 1 0
181+put hi_hashinput 0 0
182+hi_arg hi_git
183+end
184+fn hi_run to void
185+put hi_packet 0 uchar and get hi_pk 1 255
186+put hi_packet 1 uchar shr get hi_pk 1 8
187+k = pipefds hi_pipe 0 8 0
188+if ne k 0
189+hi_fail
190+end
191+readfd = int or uint get hi_pipe 0 shl uint get hi_pipe 1 8
192+readfd = or readfd int shl uint get hi_pipe 2 16
193+readfd = or readfd int shl uint get hi_pipe 3 24
194+writefd = int or uint get hi_pipe 4 shl uint get hi_pipe 5 8
195+writefd = or writefd int shl uint get hi_pipe 6 16
196+writefd = or writefd int shl uint get hi_pipe 7 24
197+pid = fork
198+if eq pid 0
199+if ne get hi_hashinput 0 0
200+fd = fopen hi_path 0 get hi_pn 0 0 0
201+if lt fd 0
202+exit 126
203+end
204+k = dupfd int fd 0 0
205+if lt k 0
206+exit 126
207+end
208+end
209+k = dupfd writefd 1 0
210+if lt k 0
211+exit 126
212+end
213+k = execprog hi_packet 0 get hi_pk 0
214+exit 127
215+end
216+if lt pid 0
217+hi_fail
218+end
219+k = fclose writefd
220+used = ulong 0
221+while true bound 9223372036854775807
222+r = enlarge hi_output add used 4096
223+if lt r 0
224+hi_fail
225+end
226+k = read readfd hi_output used 4096
227+if eq k -4
228+continue
229+end
230+if lt k 0
231+hi_fail
232+end
233+if eq k 0
234+break
235+end
236+used = add used ulong k
237+end
238+k = fclose readfd
239+k = waitpid int pid hi_statusbuf 0 4 0
240+if ne k pid
241+hi_fail
242+end
243+if or ne get hi_statusbuf 0 0 ne get hi_statusbuf 1 0
244+hi_die hi_badsource
245+end
246+put hi_outn 0 used
247+end
248+fn hi_rootarg to void
249+b = new uchar 4096 0
250+for i ulong get hi_rn 0 bound 4096
251+put b i get hi_root i
252+end
253+hi_arg part b 0 get hi_rn 0
254+end
255+fn hi_sourcecheck to void
256+hi_reset
257+hi_arg hi_C
258+hi_rootarg
259+hi_arg hi_revparse
260+hi_arg hi_HEAD
261+hi_run
262+n = get hi_outn 0
263+if eq n 0
264+hi_die hi_badsource
265+end
266+r = enlarge hi_head n
267+if lt r 0
268+hi_fail
269+end
270+for i ulong n bound 9223372036854775807
271+put hi_head i get hi_output i
272+end
273+put hi_hd 0 n
274+hi_reset
275+hi_arg hi_gitdir
276+b = new uchar 4096 0
277+for i ulong get hi_sn 0 bound 4096
278+put b i get hi_store i
279+end
280+hi_arg part b 0 get hi_sn 0
281+hi_arg hi_revparse
282+hi_arg hi_main
283+hi_run
284+if ne get hi_outn 0 n
285+hi_die hi_badsource
286+end
287+for i ulong n bound 9223372036854775807
288+if ne get hi_head i get hi_output i
289+hi_die hi_badsource
290+end
291+end
292+hi_reset
293+hi_arg hi_C
294+hi_rootarg
295+hi_arg hi_status
296+hi_arg hi_porcelain
297+hi_arg hi_untracked
298+hi_run
299+if ne get hi_outn 0 0
300+hi_die hi_badsource
301+end
302+end
303+fn hi_srcpath tail view uchar * to void
304+b = new uchar 4096 0
305+for i ulong get hi_rn 0 bound 4096
306+put b i get hi_root i
307+end
308+hi_setpath part b 0 get hi_rn 0 tail
309+end
310+fn hi_fileload to ulong
311+fd = fopen hi_path 0 get hi_pn 0 0 0
312+if lt fd 0
313+ret 0
314+end
315+used = ulong 0
316+while true bound 9223372036854775807
317+r = enlarge hi_buf add used 4096
318+if lt r 0
319+hi_fail
320+end
321+k = read int fd hi_buf used 4096
322+if eq k -4
323+continue
324+end
325+if lt k 0
326+hi_fail
327+end
328+if eq k 0
329+break
330+end
331+used = add used ulong k
332+end
333+k = fclose int fd
334+ret used
335+end
336+fn hi_buildcheck to void
337+hi_srcpath hi_buildstamp
338+n = hi_fileload
339+if ne n get hi_hd 0
340+hi_die hi_badbuild
341+end
342+for i ulong n bound 9223372036854775807
343+if ne get hi_buf i get hi_head i
344+hi_die hi_badbuild
345+end
346+end
347+hi_srcpath hi_buildhop
348+if ne faccess hi_path 0 get hi_pn 0 1 0
349+hi_die hi_badbuild
350+end
351+hi_srcpath hi_buildcore
352+if ne faccess hi_path 0 get hi_pn 0 1 0
353+hi_die hi_badbuild
354+end
355+hi_srcpath hi_buildrecord
356+n = hi_fileload
357+if eq get hi_recsize 0 0
358+if eq n 0
359+hi_die hi_badbuild
360+end
361+r = enlarge hi_record n
362+if lt r 0
363+hi_fail
364+end
365+for i ulong n
366+put hi_record i get hi_buf i
367+end
368+put hi_recsize 0 n
369+hi_parseproof
370+else
371+if ne n get hi_recsize 0
372+hi_die hi_badbuild
373+end
374+for i ulong n
375+if ne get hi_buf i get hi_record i
376+hi_die hi_badbuild
377+end
378+end
379+end
380+if ne add get hi_sizes 1 1 get hi_hd 0
381+hi_die hi_badbuild
382+end
383+for i ulong get hi_sizes 1
384+if ne get hi_record add get hi_fields 1 i get hi_head i
385+hi_die hi_badbuild
386+end
387+end
388+hi_srcpath hi_compilerhead
389+n = hi_fileload
390+if ne n add get hi_sizes 2 1
391+hi_die hi_badbuild
392+end
393+for i ulong get hi_sizes 2
394+if ne get hi_buf i get hi_record add get hi_fields 2 i
395+hi_die hi_badbuild
396+end
397+end
398+if ne get hi_buf sub n 1 10
399+hi_die hi_badbuild
400+end
401+hi_srcpath hi_compiler
402+hi_hashcheck 3
403+hi_srcpath hi_buildhop
404+hi_hashcheck 4
405+hi_srcpath hi_buildcore
406+hi_hashcheck 5
407+end
408+fn hi_parseproof to void
409+slot = ulong 0
410+start = ulong 0
411+for i ulong get hi_recsize 0
412+if eq get hi_record i 10
413+if ge slot 6
414+hi_die hi_badbuild
415+end
416+put hi_fields slot start
417+put hi_sizes slot sub i start
418+slot = add slot 1
419+start = add i 1
420+end
421+end
422+if or ne slot 6 ne start get hi_recsize 0
423+hi_die hi_badbuild
424+end
425+if ne get hi_sizes 0 len hi_magic
426+hi_die hi_badbuild
427+end
428+for i ulong len hi_magic
429+if ne get hi_record i get hi_magic i
430+hi_die hi_badbuild
431+end
432+end
433+for f ulong 5
434+idx = add f 1
435+n = get hi_sizes idx
436+if le idx 2
437+if and ne n 40 ne n 64
438+hi_die hi_badbuild
439+end
440+else
441+if ne n 64
442+hi_die hi_badbuild
443+end
444+end
445+for i ulong n
446+c = get hi_record add get hi_fields idx i
447+if not or and ge c 48 le c 57 and ge c 97 le c 102
448+hi_die hi_badbuild
449+end
450+end
451+end
452+end
453+fn hi_hashcheck slot ulong to void
454+put hi_pk 0 2
455+put hi_pk 1 0
456+put hi_hashinput 0 1
457+hi_arg hi_sum
458+hi_run
459+put hi_hashinput 0 0
460+if lt get hi_outn 0 66
461+hi_die hi_badbuild
462+end
463+for i ulong 64
464+if ne get hi_output i get hi_record add get hi_fields slot i
465+hi_die hi_badbuild
466+end
467+end
468+if ne get hi_output 64 32
469+hi_die hi_badbuild
470+end
471+end
472+fn hi_suffix base view uchar * tail view uchar * to void
473+hi_setpath base tail
474+p = get hi_pn 0
475+if gt add p get hi_idn 0 4095
476+hi_die hi_badpath
477+end
478+for i ulong get hi_idn 0 bound 80
479+put hi_path add p i get hi_id i
480+end
481+put hi_pn 0 add p get hi_idn 0
482+end
483+fn hi_idnum n ulong to void
484+b = new uchar 32 0
485+v = n
486+count = ulong 0
487+while true bound 32
488+put b count uchar add rem v 10 48
489+count = add count 1
490+v = div v 10
491+if eq v 0
492+break
493+end
494+end
495+p = get hi_idn 0
496+for i ulong count bound 32
497+put hi_id add p i get b sub sub count i 1
498+end
499+put hi_idn 0 add p count
500+end
501+fn hi_dir path view uchar * to void
502+for i ulong len path bound 4096
503+if and gt i 0 eq get path i 47
504+k = makedir path 0 i 493
505+if and ne k 0 ne k -17
506+hi_fail
507+end
508+end
509+end
510+k = makedir path 0 len path 493
511+if and ne k 0 ne k -17
512+hi_fail
513+end
514+end
515+fn hi_linkcheck to void
516+b = new uchar 4096 0
517+for i ulong get hi_bn 0 bound 4096
518+put b i get hi_bin i
519+end
520+hi_setpath part b 0 get hi_bn 0 hi_hop
521+n = readlnk hi_path 0 get hi_pn 0 hi_oldlink 0 len hi_oldlink
522+if eq n -2
523+put hi_oldn 0 0
524+ret
525+end
526+if le n 0
527+hi_die hi_badcollision
528+end
529+if ge n long len hi_oldlink
530+hi_die hi_badcollision
531+end
532+if le n long add get hi_ln 0 5
533+hi_die hi_badcollision
534+end
535+for i ulong get hi_ln 0 bound 4096
536+if ne get hi_oldlink i get hi_lib i
537+hi_die hi_badcollision
538+end
539+end
540+if ne get hi_oldlink get hi_ln 0 47
541+hi_die hi_badcollision
542+end
543+for i ulong len hi_hop bound 16
544+if ne get hi_oldlink add sub ulong n len hi_hop i get hi_hop i
545+hi_die hi_badcollision
546+end
547+end
548+if not hi_versionname add get hi_ln 0 1 sub ulong n len hi_hop
549+hi_die hi_badcollision
550+end
551+put hi_oldn 0 ulong n
552+end
553+fn hi_versionname start ulong last ulong to bool
554+if ge start last
555+ret false
556+end
557+dash = false
558+for i ulong sub last start bound 4096
559+c = get hi_oldlink add start i
560+if eq c 45
561+if or or dash eq i 0 eq add i 1 sub last start
562+ret false
563+end
564+dash = true
565+else
566+if or lt c 48 gt c 57
567+ret false
568+end
569+end
570+end
571+ret dash
572+end
573+fn hi_deskcheck to void
574+b = new uchar 4096 0
575+for i ulong get hi_an 0 bound 4096
576+put b i get hi_apps i
577+end
578+hi_setpath part b 0 get hi_an 0 hi_desktop
579+fd = fopen hi_path 0 get hi_pn 0 131072 0
580+if eq fd -2
581+put hi_deskold 0 0
582+ret
583+end
584+if lt fd 0
585+hi_die hi_badcollision
586+end
587+k = fclose int fd
588+n = hi_fileload
589+found = false
590+for i ulong n bound 9223372036854775807
591+if le add i len hi_managed n
592+start = eq i 0
593+if gt i 0
594+start = eq get hi_buf sub i 1 10
595+end
596+if start
597+if hi_marker i
598+found = true
599+end
600+end
601+end
602+end
603+if not found
604+hi_die hi_badcollision
605+end
606+put hi_deskold 0 1
607+end
608+fn hi_marker offset ulong to bool
609+for j ulong len hi_managed bound 64
610+if ne get hi_buf add offset j get hi_managed j
611+ret false
612+end
613+end
614+ret true
615+end
616+fn hi_copyfile mode int to void
617+src = fopen hi_path 0 get hi_pn 0 0 0
618+if lt src 0
619+hi_fail
620+end
621+outfd = fopen hi_other 0 get hi_on 0 193 mode
622+if lt outfd 0
623+hi_fail
624+end
625+while true bound 9223372036854775807
626+n = read int src hi_bytes 0 len hi_bytes
627+if eq n -4
628+continue
629+end
630+if lt n 0
631+hi_fail
632+end
633+if eq n 0
634+break
635+end
636+p = ulong 0
637+while lt p ulong n bound 65536
638+k = write int outfd hi_bytes p sub ulong n p
639+if eq k -4
640+continue
641+end
642+if le k 0
643+hi_fail
644+end
645+p = add p ulong k
646+end
647+end
648+k = fsync int outfd
649+if ne k 0
650+hi_fail
651+end
652+k = fclose int outfd
653+if ne k 0
654+hi_fail
655+end
656+k = fclose int src
657+end
658+fn hi_saveother to void
659+n = get hi_pn 0
660+for i ulong n bound 4096
661+put hi_other i get hi_path i
662+end
663+put hi_on 0 n
664+end
665+fn hi_verpath tail view uchar * to void
666+b = new uchar 4096 0
667+for i ulong get hi_vn 0 bound 4096
668+put b i get hi_ver i
669+end
670+hi_setpath part b 0 get hi_vn 0 tail
671+end
672+fn hi_copyitem source view uchar * dest view uchar * mode int to void
673+hi_verpath dest
674+hi_saveother
675+hi_srcpath source
676+hi_copyfile mode
677+end
678+fn hi_pair a view uchar * b view uchar * to void
679+put hi_pk 0 2
680+put hi_pk 1 0
681+hi_arg a
682+hi_arg b
683+put hi_packet 0 2
684+put hi_packet 1 0
685+if gt get hi_pk 0 4096
686+hi_die hi_badpath
687+end
688+end
689+fn hi_symlink a view uchar * b view uchar * to void
690+hi_pair a b
691+k = symlnk hi_packet 0 get hi_pk 0
692+if ne k 0
693+hi_fail
694+end
695+end
696+fn hi_rename a view uchar * b view uchar * to void
697+hi_pair a b
698+k = renames hi_packet 0 get hi_pk 0 0
699+if ne k 0
700+hi_fail
701+end
702+end
703+fn hi_desktopbyte c uchar to void
704+p = get hi_dekn 0
705+r = enlarge hi_desktxt add p 1
706+if lt r 0
707+hi_fail
708+end
709+put hi_desktxt p c
710+put hi_dekn 0 add p 1
711+end
712+fn hi_desktext a view uchar * to void
713+for i ulong len a bound 4096
714+hi_desktopbyte get a i
715+end
716+end
717+fn hi_deskexec to void
718+b = new uchar 4096 0
719+hi_verpath hi_hop
720+for i ulong get hi_pn 0 bound 4096
721+put b i get hi_path i
722+end
723+for i ulong get hi_pn 0 bound 4096
724+c = get b i
725+if eq c 37
726+hi_desktopbyte 37
727+end
728+if eq c 92
729+hi_desktopbyte 92
730+hi_desktopbyte 92
731+hi_desktopbyte 92
732+else
733+if or or eq c 34 eq c 36 eq c 96
734+hi_desktopbyte 92
735+hi_desktopbyte 92
736+end
737+end
738+hi_desktopbyte c
739+end
740+end
741+fn hi_publishlink to void
742+bin = new uchar 4096 0
743+for i ulong get hi_bn 0 bound 4096
744+put bin i get hi_bin i
745+end
746+old = new uchar 4096 0
747+for i ulong get hi_oldn 0 bound 4096
748+put old i get hi_oldlink i
749+end
750+b = new uchar 4096 0
751+if gt get hi_oldn 0 0
752+hi_suffix part bin 0 get hi_bn 0 hi_backlink
753+for i ulong get hi_pn 0 bound 4096
754+put b i get hi_path i
755+end
756+hi_symlink part old 0 get hi_oldn 0 part b 0 get hi_pn 0
757+end
758+hi_suffix part bin 0 get hi_bn 0 hi_templink
759+hi_saveother
760+hi_verpath hi_hop
761+src = new uchar 4096 0
762+for i ulong get hi_pn 0 bound 4096
763+put src i get hi_path i
764+end
765+sn = get hi_pn 0
766+dst = new uchar 4096 0
767+for i ulong get hi_on 0 bound 4096
768+put dst i get hi_other i
769+end
770+dn = get hi_on 0
771+hi_symlink part src 0 sn part dst 0 dn
772+hi_setpath part bin 0 get hi_bn 0 hi_hop
773+for i ulong get hi_pn 0 bound 4096
774+put src i get hi_path i
775+end
776+hi_rename part dst 0 dn part src 0 get hi_pn 0
777+end
778+fn hi_publishdesktop to void
779+apps = new uchar 4096 0
780+for i ulong get hi_an 0 bound 4096
781+put apps i get hi_apps i
782+end
783+if ne get hi_deskold 0 0
784+hi_suffix part apps 0 get hi_an 0 hi_backdesktop
785+hi_saveother
786+hi_setpath part apps 0 get hi_an 0 hi_desktop
787+hi_copyfile 420
788+end
789+hi_suffix part apps 0 get hi_an 0 hi_tempdesktop
790+hi_saveother
791+note Building the Exec field uses hi_path as scratch; restore the temporary output path after generating it.
792+hi_desktext hi_deskhead
793+hi_deskexec
794+hi_desktext hi_desktail
795+for i ulong get hi_on 0 bound 4096
796+put hi_path i get hi_other i
797+end
798+put hi_pn 0 get hi_on 0
799+fd = fopen hi_path 0 get hi_pn 0 193 420
800+if lt fd 0
801+hi_fail
802+end
803+p = ulong 0
804+while lt p get hi_dekn 0 bound 9223372036854775807
805+k = write int fd hi_desktxt p sub get hi_dekn 0 p
806+if le k 0
807+hi_fail
808+end
809+p = add p ulong k
810+end
811+k = fsync int fd
812+if ne k 0
813+hi_fail
814+end
815+k = fclose int fd
816+source = new uchar 4096 0
817+sn = get hi_on 0
818+for i ulong sn bound 4096
819+put source i get hi_other i
820+end
821+hi_setpath part apps 0 get hi_an 0 hi_desktop
822+last = new uchar 4096 0
823+for i ulong get hi_pn 0 bound 4096
824+put last i get hi_path i
825+end
826+hi_rename part source 0 sn part last 0 get hi_pn 0
827+end
828+fn hi_config to void
829+b = new uchar 4096 0
830+n = hi_envget hi_homekey
831+if eq n 0
832+hi_die hi_badpath
833+end
834+for i ulong n bound 4096
835+put hi_home i get hi_path i
836+end
837+put hi_hn 0 n
838+n = hi_envget hi_datakey
839+if eq n 0
840+for i ulong get hi_hn 0 bound 4096
841+put b i get hi_home i
842+end
843+hi_setpath part b 0 get hi_hn 0 hi_datasuffix
844+n = get hi_pn 0
845+end
846+for i ulong n bound 4096
847+put hi_data i get hi_path i
848+end
849+put hi_dn 0 n
850+n = hi_envget hi_storekey
851+if eq n 0
852+for i ulong get hi_hn 0 bound 4096
853+put b i get hi_home i
854+end
855+hi_setpath part b 0 get hi_hn 0 hi_storesuffix
856+n = get hi_pn 0
857+end
858+for i ulong n bound 4096
859+put hi_store i get hi_path i
860+end
861+put hi_sn 0 n
862+end
863+fn hi_paths to void
864+b = new uchar 4096 0
865+for i ulong get hi_hn 0 bound 4096
866+put b i get hi_home i
867+end
868+hi_checkpath part b 0 get hi_hn 0
869+hi_setpath part b 0 get hi_hn 0 hi_libsuffix
870+for i ulong get hi_pn 0 bound 4096
871+put hi_lib i get hi_path i
872+end
873+put hi_ln 0 get hi_pn 0
874+hi_setpath part b 0 get hi_hn 0 hi_binsuffix
875+for i ulong get hi_pn 0 bound 4096
876+put hi_bin i get hi_path i
877+end
878+put hi_bn 0 get hi_pn 0
879+for i ulong get hi_dn 0 bound 4096
880+put b i get hi_data i
881+end
882+hi_checkpath part b 0 get hi_dn 0
883+hi_setpath part b 0 get hi_dn 0 hi_appsuffix
884+for i ulong get hi_pn 0 bound 4096
885+put hi_apps i get hi_path i
886+end
887+put hi_an 0 get hi_pn 0
888+hi_idnum ulong realns
889+put hi_id get hi_idn 0 45
890+put hi_idn 0 add get hi_idn 0 1
891+hi_idnum ulong getpid
892+for i ulong get hi_ln 0 bound 4096
893+put b i get hi_lib i
894+end
895+hi_suffix part b 0 get hi_ln 0 hi_slash
896+for i ulong get hi_pn 0 bound 4096
897+put hi_ver i get hi_path i
898+end
899+put hi_vn 0 get hi_pn 0
900+end
901+fn hi_makedirs to void
902+b = new uchar 4096 0
903+for i ulong get hi_vn 0 bound 4096
904+put b i get hi_ver i
905+end
906+hi_dir part b 0 get hi_vn 0
907+for i ulong get hi_bn 0 bound 4096
908+put b i get hi_bin i
909+end
910+hi_dir part b 0 get hi_bn 0
911+for i ulong get hi_an 0 bound 4096
912+put b i get hi_apps i
913+end
914+hi_dir part b 0 get hi_an 0
915+end
916+fn main to int
917+if ne argcnt 2
918+k = write 2 hi_usage 0 len hi_usage
919+ret 2
920+end
921+n = argread 1 hi_root 0 len hi_root
922+if le n 0
923+hi_die hi_badpath
924+end
925+put hi_rn 0 ulong n
926+hi_config
927+hi_paths
928+hi_sourcecheck
929+hi_buildcheck
930+hi_linkcheck
931+hi_deskcheck
932+hi_makedirs
933+hi_copyitem hi_buildhop hi_hop 493
934+hi_copyitem hi_buildcore hi_core 493
935+hi_copyitem hi_license hi_licdest 420
936+hi_copyitem hi_buildstamp hi_stamp 420
937+hi_copyitem hi_buildrecord hi_recorddest 420
938+hi_sourcecheck
939+hi_buildcheck
940+note Verify the staged bytes, not merely the source paths, before publishing either launcher.
941+hi_verpath hi_hop
942+hi_hashcheck 4
943+hi_verpath hi_core
944+hi_hashcheck 5
945+hi_publishlink
946+hi_publishdesktop
947+k = write 1 hi_done 0 len hi_done
948+ret 0
949+end

Linux/main.om

new file mode 100644
@@ -0,0 +1,205 @@
1+note Hop's Linux entrypoint and shared UI and command actions.
2+text hm_help "Hop for Linux\n\nOpen Hop to find and launch your applications. Type find followed by words from a filename to search your file list. Type ask followed by a question to use a model you configured.\n\nCommands:\n hop Open the launcher\n hop --search TEXT Print matching application names\n hop --open TEXT Open the first matching application\n hop --find TEXT Print matching file paths as JSON\n hop --reindex [ROOT] Rebuild the file list\n hop --selftest Check the search helper\n hop --version Show the Linux edition\n hop --help Show this help\n\nAsk settings: HOP_MODEL_URL and HOP_MODEL; HOP_API_KEY is optional.\nThis edition needs a local X11 desktop or XWayland. Clipboard history, saved accounts and voice are not available yet.\n"
3+text hm_ver "Hop Linux development edition\n"
4+text hm_search "--search"
5+text hm_open "--open"
6+text hm_test "--selftest"
7+text hm_version "--version"
8+text hm_dashhelp "--help"
9+text hm_plainhelp "help"
10+text hm_reindex "--reindex"
11+text hm_find "--find"
12+text hm_badarg "Hop could not understand that command. Run hop --help.\n"
13+text hm_ok "PASS Linux search helper\n"
14+text hm_no "FAIL Linux search helper\n"
15+global hm_wrap uchar *
16+global hm_mode ulong 1
17+
18+fn hop_query to void
19+if ne ff_query 0
20+put hm_mode 0 2
21+ret
22+end
23+if ne hc_query 0
24+put hm_mode 0 1
25+ret
26+end
27+put hm_mode 0 0
28+ha_query
29+end
30+
31+fn hop_activate to int
32+if eq get hm_mode 0 2
33+ret ff_activate
34+end
35+if eq get hm_mode 0 1
36+resultv = hc_activate
37+hm_wrapanswer
38+ret resultv
39+end
40+ret ha_activate
41+end
42+
43+fn hm_wrapanswer to void
44+note The X11 fixed font uses six pixels per character; wrap to the row's actual drawable width.
45+cols = div sub get lx_s 11 64 6
46+if eq cols 0
47+ret
48+end
49+n = get lx_rn 0
50+r = enlarge hm_wrap add mul n 2 1
51+if lt r 0
52+ret
53+end
54+p = ulong 0
55+column = ulong 0
56+for i ulong n bound 9223372036854775807
57+c = get lx_rows i
58+if eq c 10
59+column = 0
60+else
61+if ne and c 192 128
62+if ge column cols
63+put hm_wrap p 10
64+p = add p 1
65+column = 0
66+end
67+column = add column 1
68+end
69+end
70+put hm_wrap p c
71+p = add p 1
72+end
73+r = enlarge lx_rows p
74+if lt r 0
75+ret
76+end
77+for i ulong p bound 9223372036854775807
78+put lx_rows i get hm_wrap i
79+end
80+put lx_rn 0 p
81+end
82+
83+fn hm_equal a view uchar * b view uchar * to bool
84+if ne len a len b
85+ret false
86+end
87+for i ulong len a
88+if ne get a i get b i
89+ret false
90+end
91+end
92+ret true
93+end
94+
95+fn hm_selftest to int
96+inp = new ulong 256 0
97+put inp 0 1212568922
98+put inp 1 1
99+put inp 2 2
100+put inp 3 5
101+put inp 8 or ulong 102 shl ulong 1 32
102+put inp 9 or ulong 105 shl ulong 1 32
103+put inp 72 or ulong 102 shl ulong 1 32
104+put inp 73 or ulong 105 shl ulong 1 32
105+put inp 74 or ulong 108 shl ulong 1 32
106+put inp 75 or ulong 101 shl ulong 1 32
107+put inp 76 or ulong 115 shl ulong 1 32
108+score = hp_fuzz inp
109+put inp 8 or ulong 122 shl ulong 1 32
110+put inp 9 or ulong 122 shl ulong 1 32
111+wrong = hp_fuzz inp
112+note Prefix score 160-(5-2)=157, calc:ba69e77a30c85acf63f8374eceeb39df95c290c8b55d0f26a64e0d5b4b5ba9da.
113+if and eq score 157 eq wrong 0
114+k = write 1 hm_ok 0 len hm_ok
115+ret 0
116+end
117+k = write 2 hm_no 0 len hm_no
118+ret 1
119+end
120+
121+fn main to int
122+a = new uchar 4096 0
123+if gt argcnt 1
124+n = argread 1 a 0 len a
125+if or lt n 0 eq n long len a
126+k = write 2 hm_badarg 0 len hm_badarg
127+ret 2
128+end
129+if or hm_equal part a 0 ulong n hm_dashhelp hm_equal part a 0 ulong n hm_plainhelp
130+k = write 1 hm_help 0 len hm_help
131+ret 0
132+end
133+if hm_equal part a 0 ulong n hm_version
134+k = write 1 hm_ver 0 len hm_ver
135+ret 0
136+end
137+if hm_equal part a 0 ulong n hm_reindex
138+ret ff_cli 0
139+end
140+if hm_equal part a 0 ulong n hm_find
141+ret ff_cli 1
142+end
143+end
144+if ne hp_start 0
145+ret 1
146+end
147+if gt argcnt 1
148+n = argread 1 a 0 len a
149+if hm_equal part a 0 ulong n hm_test
150+resultv = hm_selftest
151+hp_stop
152+ret resultv
153+end
154+searchv = hm_equal part a 0 ulong n hm_search
155+openv = hm_equal part a 0 ulong n hm_open
156+if or not or searchv openv ne argcnt 3
157+k = write 2 hm_badarg 0 len hm_badarg
158+hp_stop
159+ret 2
160+end
161+n = argread 2 a 0 len a
162+if lt n 0
163+k = write 2 hm_badarg 0 len hm_badarg
164+hp_stop
165+ret 2
166+end
167+k = enlarge lx_query ulong n
168+if lt k 0
169+hp_stop
170+ret 1
171+end
172+for i ulong ulong n
173+put lx_query i get a i
174+end
175+put lx_qn 0 ulong n
176+if ne ha_init 0
177+hp_stop
178+ret 1
179+end
180+ha_query
181+if eq get lx_rn 0 0
182+hp_stop
183+ret 1
184+end
185+if searchv
186+k = write 1 lx_rows 0 get lx_rn 0
187+hp_stop
188+ret 0
189+end
190+put lx_pick 0 0
191+opened = ha_activate
192+hp_stop
193+if eq opened 1
194+ret 0
195+end
196+ret 1
197+end
198+if ne ha_init 0
199+hp_stop
200+ret 1
201+end
202+resultv = lx_main
203+hp_stop
204+ret resultv
205+end

Linux/tests/apps_check.py

new file mode 100644
@@ -0,0 +1,201 @@
1+#!/usr/bin/env python3
2+"""Independent Linux desktop-entry fixtures. Python is a verifier only."""
3+from __future__ import annotations
4+
5+import argparse
6+import json
7+import os
8+from pathlib import Path
9+import shutil
10+import subprocess
11+import tempfile
12+
13+ROOT = Path(__file__).resolve().parents[2]
14+HEADER = """om2
15+global lx_query uchar *
16+global lx_rows uchar *
17+global lx_qn ulong 1
18+global lx_rn ulong 1
19+global lx_pick ulong 1
20+"""
21+MAIN = """
22+fn main to int
23+if ne hp_start 0
24+ret 10
25+end
26+x = ha_init
27+if gt argcnt 1
28+n = argread 1 ha_env 0 len ha_env
29+if lt n 0
30+ret 8
31+end
32+r = enlarge lx_query ulong n
33+if lt r 0
34+ret 9
35+end
36+for i ulong ulong n bound 9223372036854775807
37+c = get ha_env i
38+put lx_query i c
39+end
40+put lx_qn 0 ulong n
41+end
42+ha_query
43+if gt argcnt 2
44+x = ha_activate
45+if eq x 0
46+hp_stop
47+ret 7
48+end
49+else
50+y = write 1 lx_rows 0 get lx_rn 0
51+end
52+hp_stop
53+ret 0
54+end
55+"""
56+
57+
58+def compile_one(omc: Path, source: str, path: Path) -> None:
59+ result = subprocess.run([str(omc)], input=source.encode(), capture_output=True, check=False)
60+ if result.returncode:
61+ raise AssertionError(f"compile failed {result.returncode}: {result.stderr.decode()}")
62+ path.write_bytes(result.stdout)
63+ path.chmod(0o755)
64+
65+
66+def entry(path: Path, name: str, extra: str = "", command: str = "/usr/bin/true") -> None:
67+ path.parent.mkdir(parents=True, exist_ok=True)
68+ path.write_text(f"[Desktop Entry]\nType=Application\nName={name}\nExec={command}\n{extra}")
69+
70+
71+def main() -> None:
72+ parser = argparse.ArgumentParser()
73+ parser.add_argument("omc", type=Path)
74+ parser.add_argument("--core", type=Path, default=ROOT / "build/linux/hopcore")
75+ args = parser.parse_args()
76+ source = (ROOT / "Linux/apps.om").read_text()
77+ core_source = (ROOT / "Linux/core.om").read_text()
78+ passed = 0
79+
80+ def check(condition: bool, name: str) -> None:
81+ nonlocal passed
82+ if not condition:
83+ raise AssertionError(name)
84+ passed += 1
85+ print(f"PASS {name}")
86+
87+ with tempfile.TemporaryDirectory(prefix="hop-apps-") as folder:
88+ tmp = Path(folder)
89+ exe = tmp / "apps"
90+ if not args.core.is_file():
91+ raise AssertionError("Build the unchanged Linux matching helper first with sh build.sh")
92+ shutil.copy2(args.core, tmp / "hopcore")
93+ compile_one(args.omc.resolve(), HEADER + source + core_source + MAIN, exe)
94+ home, user, system, second = (tmp / name for name in ("home", "user data", "system", "second"))
95+ for root in (user, system, second):
96+ (root / "applications").mkdir(parents=True)
97+ env = dict(PATH=os.defpath, HOME=str(home), XDG_DATA_HOME=str(user),
98+ XDG_DATA_DIRS=f"{system}:relative:{second}", XDG_CURRENT_DESKTOP="test:GNOME")
99+ env["DESKTOP_SESSION_TEST"] = "kept exactly = $() ; π" + "x" * 10000
100+ env["HOP_API_KEY"] = "fixture-private-hop-key-never-forward"
101+ env["HOP_MODEL_URL"] = "http://fixture-model.invalid/v1"
102+
103+ def listing(query: str = "", program: Path = exe, run_env: dict[str, str] = env) -> list[str]:
104+ result = subprocess.run([str(program), query], env=run_env, capture_output=True, timeout=15)
105+ check(result.returncode == 0,
106+ f"listing completed {query!r} (exit={result.returncode}, stderr={result.stderr.decode(errors='replace')!r})")
107+ return result.stdout.decode().splitlines()
108+
109+ entry(system / "applications/system.desktop", "System App")
110+ entry(second / "applications/second.desktop", "Second App")
111+ entry(user / "applications/plain.desktop", "Alpha App", "[Desktop Action Other]\nName=Wrong Action\n")
112+ entry(system / "applications/override.desktop", "Stale System Name")
113+ entry(user / "applications/override.desktop", "User Override")
114+ entry(system / "applications/deleted.desktop", "Must Stay Hidden")
115+ (user / "applications/deleted.desktop").write_text("[Desktop Entry]\nHidden=true\n")
116+ entry(system / "applications/foo-bar.desktop", "Stale Nested Name")
117+ entry(user / "applications/foo/bar.desktop", "Nested Override")
118+ entry(user / "applications/private.desktop", "Private App", "NoDisplay=true\n")
119+ entry(user / "applications/link.desktop", "Link App", "Type=Link\n")
120+ entry(user / "applications/only.desktop", "GNOME Only", "OnlyShowIn=KDE;GNOME;\n")
121+ entry(user / "applications/not.desktop", "Not GNOME", "NotShowIn=GNOME;\n")
122+ entry(user / "applications/missing.desktop", "Missing Executable", "TryExec=/hop-does-not-exist\n")
123+ entry(user / "applications/directory.desktop", "Directory Executable", "TryExec=/tmp\n")
124+ entry(user / "applications/try.desktop", "Try Found", "TryExec=true\n")
125+ entry(user / "applications/escaped.desktop", "Escaped\\sName")
126+ entry(user / "applications/long.desktop", "Long Line", "Comment=" + "x" * 15000 + "\n")
127+ entry(user / "applications/unicode.desktop", "Café π")
128+ os.mkfifo(user / "applications/pipe.desktop")
129+ names = set(listing())
130+ check(names == {"Alpha App", "User Override", "Nested Override", "System App", "Second App",
131+ "GNOME Only", "Try Found", "Escaped Name", "Long Line", "Café π"},
132+ "XDG precedence, hidden tombstones, recursive ids, visibility, group and escaped-name rules")
133+ check(listing("aLPHa") == ["Alpha App"], "ASCII case-insensitive matching")
134+ check(listing("π") == ["Café π"], "UTF-8 bytes survive names and matching")
135+ check(listing("unmatched query") == [], "no app selected for unmatched query")
136+ entry(user / "applications/vscode.desktop", "Visual Studio Code")
137+ entry(user / "applications/firefox.desktop", "Firefox")
138+ entry(user / "applications/bonfire.desktop", "Bonfire")
139+ check(listing("vsc") == ["Visual Studio Code"], "shared Hop helper matches app initials")
140+ check(listing("firefx") == ["Firefox"], "shared Hop helper matches a missing-letter typo")
141+ check(listing("fire") == ["Firefox", "Bonfire"], "higher shared-core score is shown first")
142+ long_name = "q" * 200
143+ entry(user / "applications/long-name.desktop", long_name)
144+ check(listing("q" * 100) == [long_name], "long names and queries are matched in full without truncation")
145+ check(listing("q" * 201) == [], "long query is never truncated to create a match")
146+ for i in range(400):
147+ entry(user / f"applications/bulk-{i}.desktop", f"Bulk {i}")
148+ check(len(listing("Bulk ")) == 400, "tables grow beyond hundreds of applications")
149+
150+ default = home / ".local/share/applications"
151+ entry(default / "fallback.desktop", "Home Fallback")
152+ relative_env = dict(env, XDG_DATA_HOME="relative")
153+ check("Home Fallback" in listing(run_env=relative_env), "relative XDG_DATA_HOME falls back to HOME")
154+
155+ marker = tmp / "launch-result.json"
156+ helper = tmp / "launch helper.py"
157+ helper.write_text("#!/usr/bin/python3\nimport os,sys,json\n"
158+ "result={'args':sys.argv[1:],'env':dict(os.environ),"
159+ "'cmdline':open('/proc/self/cmdline','rb').read().decode()}\n"
160+ f"open({str(marker)!r},'w').write(json.dumps(result))\n")
161+ helper.chmod(0o755)
162+ dangerous = "$(touch SHOULD_NOT_EXIST); literal.desktop"
163+ entry(user / "applications" / dangerous, "Launch Probe",
164+ command=f'"{helper}" "one spaced argument" "Ï€" %f')
165+ result = subprocess.run([str(exe), "Launch Probe", "launch"], env=env, capture_output=True, timeout=15)
166+ check(result.returncode == 0, "gio launch completed")
167+ for _ in range(100):
168+ if marker.exists():
169+ break
170+ import time
171+ time.sleep(.01)
172+ check(marker.exists(), "real desktop activation executed fixture")
173+ launched = json.loads(marker.read_text())
174+ check(launched['args'] == ["one spaced argument", "Ï€"] and
175+ launched['env']['DESKTOP_SESSION_TEST'] == env['DESKTOP_SESSION_TEST'],
176+ "Exec quoting and field codes, UTF-8 and unrelated desktop environment retained")
177+ check(not any(k.startswith('HOP_') for k in launched['env']) and
178+ env['HOP_API_KEY'] not in launched['cmdline'] and
179+ env['HOP_API_KEY'] not in marker.read_text(),
180+ "private Hop settings reach neither launched app environment nor command line")
181+ check(not (ROOT / "SHOULD_NOT_EXIST").exists(), "desktop pathname receives no shell evaluation")
182+
183+ entry(user / "applications/broken.desktop", "Broken Launch", command="/hop-no-such-executable")
184+ result = subprocess.run([str(exe), "Broken Launch", "launch"], env=env, capture_output=True, timeout=15)
185+ check(result.returncode == 7 and b"could not launch" in result.stderr,
186+ "failed desktop activation stays a failure")
187+
188+ mutant = tmp / "mutant"
189+ changed = source.replace("if or ha_lineeq 0 k ha_hidden ha_lineeq 0 k ha_nodisp", "if false")
190+ check(changed != source, "visibility negative control applied")
191+ compile_one(args.omc.resolve(), HEADER + changed + core_source + MAIN, mutant)
192+ check("Private App" in listing(program=mutant), "negative control exposes forbidden entry")
193+ ignored = core_source.replace("ret hp_le hp_rep 9 2", "ret 0")
194+ check(ignored != core_source, "search-helper-output negative control applied")
195+ compile_one(args.omc.resolve(), HEADER + source + ignored + MAIN, mutant)
196+ check(listing("vsc", program=mutant) == [], "discarded shared-helper answer loses initials match")
197+ print(f"HOP-LINUX-APPS PASS checks={passed}")
198+
199+
200+if __name__ == "__main__":
201+ main()

Linux/tests/build_record_check.py

new file mode 100644
@@ -0,0 +1,52 @@
1+#!/usr/bin/env python3
2+"""Independent checks of successful-build proofs and failed-build invalidation."""
3+import hashlib
4+import json
5+from pathlib import Path
6+import shutil
7+import subprocess
8+import tempfile
9+
10+
11+def sha(path):
12+ return hashlib.sha256(path.read_bytes()).hexdigest()
13+
14+
15+def main():
16+ root = Path(__file__).resolve().parents[2]
17+ build = root / 'build/linux'
18+ toolchain = root / 'build/linux-toolchain'
19+ head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip()
20+ expected = ['HOPBUILD1', head, (toolchain / 'source-commit').read_text().strip(),
21+ sha(toolchain / 'seed/out/omc'), sha(build / 'hop'), sha(build / 'hopcore')]
22+ proof = (build / 'BUILD_RECORD').read_bytes()
23+ assert proof == ('\n'.join(expected) + '\n').encode(), proof
24+ with tempfile.TemporaryDirectory(prefix='hop-build-proof-') as raw:
25+ source = Path(raw) / 'source'
26+ subprocess.run(['git', 'clone', '--quiet', '--no-hardlinks', str(root), str(source)], check=True)
27+ output = source / 'build/linux'
28+ output.mkdir(parents=True)
29+ record = output / 'BUILD_RECORD'
30+ record.write_bytes(proof)
31+ (source / 'Linux/window.om').unlink()
32+ result = subprocess.run([str(build.parent / 'linux-build'), str(toolchain)],
33+ cwd=source, capture_output=True)
34+ assert result.returncode != 0, result.stdout
35+ assert record.read_bytes() == b'', 'failed build retained an installable proof'
36+ shutil.copyfile(root / 'Linux/window.om', source / 'Linux/window.om')
37+ with (source / 'Linux/window.om').open('ab') as stream:
38+ stream.write(b'\nnote independent dirty-source control\n')
39+ record.write_bytes(proof)
40+ result = subprocess.run([str(build.parent / 'linux-build'), str(toolchain)],
41+ cwd=source, capture_output=True)
42+ assert result.returncode == 0, (result.stdout, result.stderr)
43+ assert record.read_bytes() == b'', 'dirty build acquired an installable proof'
44+ assert (output / 'SOURCE_HEAD').read_bytes() == b''
45+ print(json.dumps({'status': 'PASS', 'checks': [
46+ 'successful proof binds source, compiler revision and actual compiler/hop/hopcore hashes',
47+ 'failed build invalidates a previous proof',
48+ 'successful dirty-source development build stays un-installable']}))
49+
50+
51+if __name__ == '__main__':
52+ main()

Linux/tests/chat_check.py

new file mode 100644
@@ -0,0 +1,193 @@
1+#!/usr/bin/env python3
2+"""Independent fake-server and JSON oracle for Linux/chat.om. No model calls."""
3+import argparse
4+import http.server
5+import json
6+import os
7+from pathlib import Path
8+import subprocess
9+import tempfile
10+import threading
11+
12+ROOT = Path(__file__).resolve().parents[2]
13+PRE = """om2
14+global lx_query uchar *
15+global lx_rows uchar *
16+global lx_qn ulong 1
17+global lx_rn ulong 1
18+global lx_pick ulong 1
19+"""
20+POST = """
21+text ht_parse "parse"
22+text ht_bad "BAD"
23+fn main to int
24+n = argread 1 hc_io 0 len hc_io
25+if eq n 5
26+if eq get hc_io 0 112
27+while true bound 9223372036854775807
28+r = read 0 hc_io 0 len hc_io
29+if le r 0
30+break
31+end
32+for i ulong ulong r bound 8192
33+hc_add 1 get hc_io i
34+end
35+end
36+ok = hc_value 1
37+hc_space
38+if and ok and eq get hc_found 0 1 eq get hc_pos 0 get hc_n 1
39+r = write 1 hc_ans 0 get hc_n 7
40+ret 0
41+end
42+r = write 1 ht_bad 0 len ht_bad
43+ret 1
44+end
45+end
46+r = enlarge lx_query ulong n
47+for i ulong ulong n bound 8192
48+put lx_query i get hc_io i
49+end
50+put lx_qn 0 ulong n
51+if eq hc_query 0
52+ret 2
53+end
54+if gt argcnt 2
55+r = write 1 lx_rows 0 get lx_rn 0
56+ret 0
57+end
58+k = hc_activate
59+r = write 1 lx_rows 0 get lx_rn 0
60+ret 0
61+end
62+"""
63+
64+
65+def check(omc):
66+ passed = 0
67+
68+ def verify(condition, name):
69+ nonlocal passed
70+ if not condition:
71+ raise AssertionError(name)
72+ passed += 1
73+
74+ with tempfile.TemporaryDirectory(prefix="hop-chat-") as td:
75+ binary = Path(td) / "chat"
76+ source = PRE + (ROOT / "Linux/chat.om").read_text() + POST
77+ result = subprocess.run([omc], input=source.encode(), capture_output=True)
78+ if result.returncode:
79+ raise RuntimeError(result.stderr.decode())
80+ binary.write_bytes(result.stdout)
81+ binary.chmod(0o700)
82+ env = {k: v for k, v in os.environ.items() if not k.startswith("HOP_")}
83+
84+ def run(query="ask hello", settings=None, **kwargs):
85+ return subprocess.run([str(binary), query], env=env | (settings or {}),
86+ capture_output=True, timeout=15, **kwargs)
87+
88+ missing = run()
89+ verify(missing.returncode == 0 and b"Set HOP_MODEL_URL" in missing.stdout,
90+ "missing configuration is explained")
91+ verify(run("hello").returncode == 2, "plain searches do not become network requests")
92+ action = subprocess.run([str(binary), "ask hello", "action"], capture_output=True)
93+ verify(action.stdout == b"Ask: hello", "query is offered as an explicit Ask action")
94+ settings = {"HOP_MODEL_URL": "file:///etc/passwd", "HOP_MODEL": "test"}
95+ verify(b"use an http://" in run(settings=settings).stdout, "non-HTTP URL refused")
96+ settings["HOP_MODEL_URL"] = "https://example.invalid/v1?foo=bar"
97+ verify(b"use an http://" in run(settings=settings).stdout, "query-bearing base URL refused")
98+ settings["HOP_MODEL_URL"] = "http://127.0.0.1:1/v1"
99+ settings["HOP_API_KEY"] = "secret\r\nInjected: header"
100+ bad = run(settings=settings)
101+ verify(b"control character" in bad.stdout and b"secret" not in bad.stdout,
102+ "header injection refused without echoing key")
103+
104+ answers = ["plain", "line\nnext\tend", 'quote " slash \\ /', "Ω 😀 中文", "",
105+ "backspace\bformfeed\freturn\r", "x" * 50000]
106+ for answer in answers:
107+ body = json.dumps({"ignored": [True, None, -1.25e3, {"content": "wrong"}],
108+ "choices": [{"message": {"content": answer}}]}).encode()
109+ r = run("parse", input=body)
110+ verify(r.returncode == 0 and r.stdout == answer.encode(),
111+ "independent JSON decoding " + repr(answer[:20]))
112+ valid = b'{"choices":[{"message":{"content":"yes"}}]}'
113+ bad_json = [valid + b"garbage", valid[:-1], b"[]", b"{}",
114+ b'{"choices":[{"message":{"content":null}}]}',
115+ b'{"choices":[{}, {"message":{"content":"wrong choice"}}]}',
116+ b'{"choices":[{"message":{"content":"\\ud800"}}]}',
117+ b'{"choices":[{"message":{"content":"\\udc00"}}]}',
118+ b'{"choices":[{"message":{"content":"\\ud800\\u0041"}}]}',
119+ b'{"choices":[{"message":{"content":"\\x42"}}]}',
120+ b'{"choices":[{"message":{"content":"a","content":"b"}}]}',
121+ valid.replace(b'"yes"', b'"bad\nstring"'),
122+ b'{"ignore":01,"choices":[{"message":{"content":"yes"}}]}',
123+ b'{"ignore":1.,"choices":[{"message":{"content":"yes"}}]}']
124+ for idx, body in enumerate(bad_json):
125+ r = run("parse", input=body)
126+ verify(r.returncode == 1 and r.stdout == b"BAD", f"malformed/mismatched JSON {idx}")
127+
128+ observed = []
129+ response = {"status": 200, "body": valid}
130+
131+ class Handler(http.server.BaseHTTPRequestHandler):
132+ def log_message(self, *_):
133+ pass
134+
135+ def do_POST(self):
136+ body = self.rfile.read(int(self.headers["Content-Length"]))
137+ observed.append((self.path, dict(self.headers), body))
138+ out = response["body"]
139+ self.send_response(response["status"])
140+ if response["status"] == 302:
141+ self.send_header("Location", "/must-not-be-followed")
142+ self.send_header("Content-Length", str(len(out)))
143+ self.end_headers()
144+ self.wfile.write(out)
145+
146+ server = http.server.HTTPServer(("127.0.0.1", 0), Handler)
147+ thread = threading.Thread(target=server.serve_forever, daemon=True)
148+ thread.start()
149+ try:
150+ query = 'What?\n"quote" \\slash Ω $(touch NEVER_RUN) `touch NEVER_RUN`'
151+ key = 'test"key\\other'
152+ model = 'model"quote\\slash'
153+ settings = {"HOP_MODEL_URL": f"http://127.0.0.1:{server.server_port}/v1/",
154+ "HOP_MODEL": model, "HOP_API_KEY": key}
155+ result = run("ask " + query, settings)
156+ verify(result.returncode == 0 and result.stdout == b"yes" and result.stderr == b"",
157+ "configured fake-server response reaches Hop")
158+ path, headers, body = observed[-1]
159+ verify(path == "/v1/chat/completions", "base URL and slash normalized")
160+ verify(headers["Authorization"] == "Bearer " + key, "API key transmitted literally")
161+ verify(json.loads(body) == {"model": model,
162+ "messages": [{"role": "user", "content": query}],
163+ "stream": False}, "prompt/model escape to exact independent JSON")
164+ verify(not (Path.cwd() / "NEVER_RUN").exists(), "prompt is not evaluated by a shell")
165+ settings.pop("HOP_API_KEY")
166+ response["body"] = json.dumps({"choices": [{"message": {"content": "Ω 😀"}}]}).encode()
167+ verify(run(settings=settings).stdout == "Ω 😀".encode(), "Unicode reaches UI through transport")
168+ verify("Authorization" not in observed[-1][1], "absent key sends no authorization")
169+ response["body"] = b'{"error":{"message":"private server details"}}'
170+ response["status"] = 401
171+ result = run(settings=settings)
172+ verify(b"HTTP 401" in result.stdout and b"private" not in result.stdout,
173+ "HTTP authentication failure is explicit and does not expose server details")
174+ response["status"] = 200
175+ verify(b"valid chat answer" in run(settings=settings).stdout,
176+ "success status without an answer fails explicitly")
177+ response["body"] = valid
178+ response["status"] = 302
179+ before = len(observed)
180+ verify(b"HTTP 302" in run(settings=settings).stdout,
181+ "redirect response is an explicit failure")
182+ verify(len(observed) == before + 1, "transport never follows redirects")
183+ finally:
184+ server.shutdown()
185+ server.server_close()
186+ thread.join()
187+ print(f"PASS Linux Ask checks={passed}; local fake server only")
188+
189+
190+if __name__ == "__main__":
191+ parser = argparse.ArgumentParser()
192+ parser.add_argument("omc")
193+ check(parser.parse_args().omc)

Linux/tests/check.py

new file mode 100644
@@ -0,0 +1,65 @@
1+#!/usr/bin/env python3
2+"""Run the Linux acceptance instruments and retain a source-bound receipt."""
3+import argparse
4+import hashlib
5+import json
6+from pathlib import Path
7+import subprocess
8+import sys
9+
10+
11+def main():
12+ parser = argparse.ArgumentParser(description=__doc__)
13+ parser.add_argument('--evidence', required=True, type=Path)
14+ args = parser.parse_args()
15+ root = Path(__file__).resolve().parents[2]
16+ evidence = args.evidence.resolve()
17+ evidence.mkdir(parents=True, exist_ok=False)
18+ head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip()
19+ assert not subprocess.check_output(['git', 'status', '--porcelain'], cwd=root), 'source is dirty'
20+ omc = root / 'build/linux-toolchain/seed/out/omc'
21+ runs = [
22+ ('build', ['sh', 'build.sh']),
23+ ('build-record', [sys.executable, 'Linux/tests/build_record_check.py']),
24+ ('shell-syntax', ['sh', '-n', 'build.sh', 'install.sh']),
25+ ('window', [sys.executable, 'Linux/tests/window_check.py', '--compiler', str(omc),
26+ '--evidence', str(evidence / 'window')]),
27+ ('apps', [sys.executable, 'Linux/tests/apps_check.py', str(omc),
28+ '--core', str(root / 'build/linux/hopcore')]),
29+ ('chat', [sys.executable, 'Linux/tests/chat_check.py', str(omc)]),
30+ ('files', [sys.executable, 'Linux/tests/files_check.py', str(omc), '--evidence', str(evidence / 'files')]),
31+ ('install', [sys.executable, 'Linux/tests/install_check.py', '--compiler', str(omc),
32+ '--evidence', str(evidence / 'install')]),
33+ ('combined', [sys.executable, 'Linux/tests/combined_check.py',
34+ '--binary', str(root / 'build/linux/hop'),
35+ '--evidence', str(evidence / 'combined')]),
36+ ]
37+ receipt = {'head': head, 'results': [], 'status': 'RUNNING',
38+ 'not_run': ['Mac build and desktop', 'physical Linux desktop session',
39+ 'native Wayland', 'XWayland', 'live AI provider']}
40+ for name, command in runs:
41+ result = subprocess.run(command, cwd=root, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
42+ log = evidence / f'{name}.log'
43+ log.write_bytes(result.stdout)
44+ receipt['results'].append({'name': name, 'command': command, 'exit': result.returncode,
45+ 'log': str(log), 'log_sha256': hashlib.sha256(result.stdout).hexdigest()})
46+ (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n')
47+ print(f'{name}: exit {result.returncode}; {log}', flush=True)
48+ if result.returncode:
49+ receipt['status'] = 'FAIL'
50+ (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n')
51+ print(result.stdout.decode(errors='replace'), file=sys.stderr)
52+ raise SystemExit(1)
53+ assert not subprocess.check_output(['git', 'status', '--porcelain'], cwd=root), 'checks changed source'
54+ receipt['status'] = 'PASS'
55+ receipt['omega_head'] = (root / 'build/linux-toolchain/source-commit').read_text().strip()
56+ receipt['compiler_sha256'] = hashlib.sha256(omc.read_bytes()).hexdigest()
57+ receipt['artifacts'] = {p.name: hashlib.sha256(p.read_bytes()).hexdigest()
58+ for p in (root / 'build/linux/hop', root / 'build/linux/hopcore',
59+ root / 'build/linux/install')}
60+ (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n')
61+ print(f'PASS {evidence / "RECEIPT.json"}')
62+
63+
64+if __name__ == '__main__':
65+ main()

Linux/tests/combined_check.py

new file mode 100644
@@ -0,0 +1,209 @@
1+#!/usr/bin/env python3
2+"""Independent measurements of the built Linux app, using a private desktop.
3+
4+Python, Xvfb and xdotool are verification instruments, never installed components.
5+"""
6+import argparse
7+import hashlib
8+import http.server
9+import json
10+import os
11+from pathlib import Path
12+import secrets
13+import shutil
14+import socket
15+import struct
16+import subprocess
17+import threading
18+import time
19+
20+
21+def run(args, env, **kwargs):
22+ return subprocess.run(args, env=env, capture_output=True, timeout=20, **kwargs)
23+
24+
25+def wait_for(predicate, explanation, timeout=8):
26+ deadline = time.monotonic() + timeout
27+ while time.monotonic() < deadline:
28+ result = predicate()
29+ if result:
30+ return result
31+ time.sleep(.025)
32+ raise AssertionError(explanation)
33+
34+
35+def check(binary, evidence):
36+ binary = binary.resolve()
37+ root = Path(__file__).resolve().parents[2]
38+ evidence.mkdir(parents=True, exist_ok=False)
39+ checks = []
40+ home = evidence / 'home'
41+ apps = home / 'data' / 'applications'
42+ apps.mkdir(parents=True)
43+ marker = evidence / 'launched'
44+ (apps / 'hop-probe.desktop').write_text(
45+ '[Desktop Entry]\nType=Application\nName=Hop Test Editor\n'
46+ f'Exec=/usr/bin/touch "{marker}"\n')
47+ env = {k: v for k, v in os.environ.items()
48+ if not k.startswith('HOP_') and k not in ('DISPLAY', 'XAUTHORITY')}
49+ config = home / 'config'
50+ config.mkdir()
51+ opened_file = evidence / 'file-opened'
52+ (apps / 'hop-test-viewer.desktop').write_text(
53+ '[Desktop Entry]\nType=Application\nName=Hop Test Viewer\nNoDisplay=true\n'
54+ 'MimeType=text/plain;\n' + f'Exec=/usr/bin/touch "{opened_file}"\n')
55+ (apps / 'mimeinfo.cache').write_text('[MIME Cache]\ntext/plain=hop-test-viewer.desktop;\n')
56+ (config / 'mimeapps.list').write_text('[Default Applications]\ntext/plain=hop-test-viewer.desktop;\n')
57+ files = home / 'Documents'
58+ files.mkdir()
59+ report_file = files / 'Report July.txt'
60+ report_file.write_text('A private file-search fixture.\n')
61+ env.update(HOME=str(home), XDG_DATA_HOME=str(home / 'data'),
62+ XDG_CACHE_HOME=str(home / 'cache'), XDG_CONFIG_HOME=str(config),
63+ XDG_DATA_DIRS=str(home / 'empty'), XDG_CURRENT_DESKTOP='GNOME',
64+ GIO_USE_VFS='local', DBUS_SESSION_BUS_ADDRESS='unix:path=' + str(home / 'no-session-bus'))
65+ got = run([str(binary), '--selftest'], env)
66+ assert got.returncode == 0, got.stderr
67+ checks.append('built program talks to its actual shared matching helper')
68+ got = run([str(binary), '--search', 'Hop Test Editor'], env)
69+ assert got.returncode == 0 and got.stdout == b'Hop Test Editor\n', (got.stdout, got.stderr)
70+ checks.append('headless search reads the same application fixture as the desktop')
71+ got = run([str(binary), '--reindex', str(files)], env)
72+ assert got.returncode == 0, (got.stdout, got.stderr)
73+ got = run([str(binary), '--find', 'report'], env)
74+ assert got.returncode == 0 and json.loads(got.stdout) == [str(report_file)], (got.stdout, got.stderr)
75+ checks.append('built command indexes fixture files and returns the exact path through Find JSON')
76+ broken = evidence / 'missing-helper'
77+ broken.mkdir()
78+ shutil.copy2(binary, broken / 'hop')
79+ got = run([str(broken / 'hop'), '--selftest'], env)
80+ assert got.returncode != 0 and b'helper' in got.stderr, (got.stdout, got.stderr)
81+ checks.append('missing matching helper refuses visibly')
82+
83+ mutated = evidence / 'changed-helper'
84+ mutated.mkdir()
85+ shutil.copy2(binary, mutated / 'hop')
86+ source = (root / 'Omega/hopcore.om').read_bytes()
87+ old = b'ret sub 160 minu 30 sub nl ql'
88+ assert source.count(old) == 1
89+ changed = source.replace(old, b'ret sub 161 minu 30 sub nl ql')
90+ ng = binary.parent / 'ng'
91+ ir = subprocess.run([str(ng)], input=b'@ng front-ir\n' + changed,
92+ capture_output=True, check=True).stdout
93+ opt = subprocess.run([str(ng)], input=b'@ng opt\n' + ir,
94+ capture_output=True, check=True).stdout
95+ core = subprocess.run([str(ng)], input=b'@ng a64\n' + opt,
96+ capture_output=True, check=True).stdout
97+ (mutated / 'hopcore').write_bytes(core)
98+ (mutated / 'hopcore').chmod(0o755)
99+ got = run([str(mutated / 'hop'), '--selftest'], env)
100+ assert got.returncode != 0 and b'FAIL' in got.stderr, (got.stdout, got.stderr)
101+ checks.append('changed real shared-core scoring rule fails the application self-test')
102+
103+ class Model(http.server.BaseHTTPRequestHandler):
104+ requests = []
105+
106+ def do_POST(self):
107+ body = json.loads(self.rfile.read(int(self.headers['Content-Length'])))
108+ self.requests.append((self.path, body))
109+ answer = json.dumps({'choices': [{'message': {'content': 'Local test answer.'}}]}).encode()
110+ self.send_response(200)
111+ self.send_header('Content-Type', 'application/json')
112+ self.send_header('Content-Length', str(len(answer)))
113+ self.end_headers()
114+ self.wfile.write(answer)
115+
116+ def log_message(self, *args):
117+ pass
118+
119+ httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Model)
120+ threading.Thread(target=httpd.serve_forever, daemon=True).start()
121+ env.update(HOP_MODEL_URL=f'http://127.0.0.1:{httpd.server_port}/v1', HOP_MODEL='fixture-model')
122+ display = next(n for n in range(210, 510) if not Path(f'/tmp/.X11-unix/X{n}').exists())
123+ auth = evidence / 'Xauthority'
124+ fields = [socket.gethostname().encode(), str(display).encode(),
125+ b'MIT-MAGIC-COOKIE-1', secrets.token_bytes(16)]
126+ auth.write_bytes(struct.pack('>H', 256) + b''.join(struct.pack('>H', len(v)) + v for v in fields))
127+ auth.chmod(0o600)
128+ env.update(DISPLAY=f':{display}.0', XAUTHORITY=str(auth))
129+ server_log = open(evidence / 'xvfb.log', 'wb')
130+ xserver = subprocess.Popen(['Xvfb', f':{display}', '-screen', '0', '1024x768x24',
131+ '-nolisten', 'tcp', '-auth', str(auth)],
132+ stdout=server_log, stderr=server_log)
133+ app = None
134+ try:
135+ wait_for(lambda: Path(f'/tmp/.X11-unix/X{display}').exists(), 'private display did not start')
136+
137+ def start_app():
138+ proc = subprocess.Popen([str(binary)], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
139+ def find_window():
140+ if proc.poll() is not None:
141+ raise AssertionError(proc.communicate())
142+ q = run(['xdotool', 'search', '--name', '^Hop$'], env)
143+ return q.stdout.splitlines()[-1].decode() if q.stdout.strip() else None
144+ win = wait_for(find_window, 'combined Hop window did not appear')
145+ run(['xdotool', 'windowfocus', '--sync', win], env, check=True)
146+ return proc, win
147+
148+ app, win = start_app()
149+ run(['xdotool', 'type', '--clearmodifiers', '--delay', '8', 'Hop Test Editor'], env, check=True)
150+ run(['xdotool', 'key', 'Return'], env, check=True)
151+ wait_for(marker.exists, 'Enter did not launch the selected real desktop entry')
152+ out, err = app.communicate(timeout=5)
153+ assert app.returncode == 0 and not err, (out, err)
154+ app = None
155+ checks.append('combined desktop: typing finds an app and Enter launches the selected desktop entry')
156+
157+ app, win = start_app()
158+ run(['xdotool', 'type', '--clearmodifiers', '--delay', '8', 'find report'], env, check=True)
159+ run(['xdotool', 'key', 'Return'], env, check=True)
160+ wait_for(opened_file.exists, 'Find did not open the selected file through its configured test handler')
161+ out, err = app.communicate(timeout=5)
162+ assert app.returncode == 0 and not err, (out, err)
163+ app = None
164+ checks.append('combined desktop: Find opens the selected raw path through the configured file handler')
165+
166+ app, win = start_app()
167+ run(['xdotool', 'type', '--clearmodifiers', '--delay', '8', 'ask Does Linux work?'], env, check=True)
168+ run(['xdotool', 'key', 'Return'], env, check=True)
169+ wait_for(lambda: Model.requests, 'Ask did not reach the private model stand-in')
170+ path, body = Model.requests[0]
171+ assert path == '/v1/chat/completions'
172+ assert body['model'] == 'fixture-model'
173+ assert body['messages'] == [{'role': 'user', 'content': 'Does Linux work?'}]
174+ time.sleep(.2)
175+ assert app.poll() is None, 'window unexpectedly quit after the answer'
176+ xwd = run(['xwd', '-silent', '-id', win], env, check=True).stdout
177+ (evidence / 'ask-window.xwd').write_bytes(xwd)
178+ from PIL import Image
179+ header = struct.unpack('>25I', xwd[:100])
180+ Image.frombytes('RGB', (header[4], header[5]),
181+ xwd[header[0] + header[19] * 12:], 'raw', 'BGRX', header[12]).save(evidence / 'ask-window.png')
182+ run(['xdotool', 'key', 'Escape'], env, check=True)
183+ out, err = app.communicate(timeout=5)
184+ assert app.returncode == 0 and not err, (out, err)
185+ app = None
186+ checks.append('combined desktop: Ask sends the typed question, remains open with the answer, and Escape exits')
187+ finally:
188+ if app is not None and app.poll() is None:
189+ app.terminate()
190+ app.communicate(timeout=5)
191+ xserver.terminate()
192+ xserver.wait(timeout=5)
193+ server_log.close()
194+ httpd.shutdown()
195+ httpd.server_close()
196+ result = {'status': 'PASS', 'checks': checks,
197+ 'binary_sha256': hashlib.sha256(binary.read_bytes()).hexdigest(),
198+ 'core_sha256': hashlib.sha256((binary.parent / 'hopcore').read_bytes()).hexdigest(),
199+ 'not_run': ['physical desktop session', 'XWayland', 'native Wayland', 'live AI provider']}
200+ (evidence / 'result.json').write_text(json.dumps(result, indent=2) + '\n')
201+ print(json.dumps(result, indent=2))
202+
203+
204+if __name__ == '__main__':
205+ p = argparse.ArgumentParser(description=__doc__)
206+ p.add_argument('--binary', type=Path, required=True)
207+ p.add_argument('--evidence', type=Path, required=True)
208+ options = p.parse_args()
209+ check(options.binary, options.evidence.resolve())

Linux/tests/files_check.py

new file mode 100644
@@ -0,0 +1,415 @@
1+#!/usr/bin/env python3
2+"""Independent native-Omega file-index oracle; all trees and caches are temporary."""
3+from __future__ import annotations
4+
5+import argparse
6+import fcntl
7+import hashlib
8+import json
9+import os
10+from pathlib import Path
11+import resource
12+import signal
13+import struct
14+import subprocess
15+import tempfile
16+
17+ROOT = Path(__file__).resolve().parents[2]
18+HEADER = """om2
19+global lx_query uchar *
20+global lx_rows uchar *
21+global lx_qn ulong 1
22+global lx_rn ulong 1
23+global lx_pick ulong 1
24+"""
25+MAIN = """
26+fn ft_setquery source view uchar * to void
27+r = enlarge lx_query len source
28+if lt r 0
29+exit 1
30+end
31+for i ulong len source bound 131072
32+put lx_query i get source i
33+end
34+put lx_qn 0 len source
35+end
36+fn ft_mode source view uchar * expected view uchar * to bool
37+if ne len source len expected
38+ret false
39+end
40+for i ulong len source bound 131072
41+if ne get source i get expected i
42+ret false
43+end
44+end
45+ret true
46+end
47+text ft_reindex "--reindex"
48+text ft_find "--find"
49+text ft_ui "--ui"
50+text ft_activate "--activate"
51+text ft_default "find "
52+fn main to int
53+arg = new uchar 131072 0
54+cwd0 = new uchar 4096 0
55+cwd1 = new uchar 4096 0
56+n0 = cwd cwd0 0 len cwd0
57+if le n0 0
58+ret 9
59+end
60+if eq argcnt 1
61+ft_setquery ft_default
62+r = ff_query
63+if ne r 1
64+ret 4
65+end
66+r = ff_activate
67+k = write 1 lx_rows 0 get lx_rn 0
68+ret 0
69+end
70+n = argread 1 arg 0 len arg
71+if lt n 0
72+ret 2
73+end
74+if ft_mode part arg 0 ulong n ft_reindex
75+resultv = ff_cli 0
76+n1 = cwd cwd1 0 len cwd1
77+if ne n0 n1
78+ret 9
79+end
80+for i ulong ulong n0 bound 4096
81+if ne get cwd0 i get cwd1 i
82+ret 9
83+end
84+end
85+ret resultv
86+end
87+if ft_mode part arg 0 ulong n ft_find
88+ret ff_cli 1
89+end
90+ui = ft_mode part arg 0 ulong n ft_ui
91+activate = ft_mode part arg 0 ulong n ft_activate
92+if not or ui activate
93+ret 2
94+end
95+n = argread 2 arg 0 len arg
96+if lt n 0
97+ret 2
98+end
99+ft_setquery part arg 0 ulong n
100+if ne ff_query 1
101+ret 4
102+end
103+if activate
104+pick = ulong 0
105+if gt argcnt 3
106+n = argread 3 arg 0 len arg
107+if gt n 0
108+pick = ulong sub get arg 0 48
109+end
110+end
111+put lx_pick 0 pick
112+resultv = ff_activate
113+if ne resultv 1
114+ret 5
115+end
116+ret 0
117+end
118+k = write 1 lx_rows 0 get lx_rn 0
119+ret 0
120+end
121+"""
122+
123+
124+def compiled(omc: Path, apps: str, files: str, out: Path) -> None:
125+ source = HEADER + apps + (ROOT / "Linux/core.om").read_text() + files + MAIN
126+ result = subprocess.run([str(omc)], input=source.encode(), capture_output=True)
127+ if result.returncode:
128+ raise AssertionError(f"compile {result.returncode}: {result.stderr.decode()}")
129+ out.write_bytes(result.stdout)
130+ out.chmod(0o755)
131+
132+
133+def index_data(path: Path) -> tuple[dict[str, int], list[bytes]]:
134+ data = path.read_bytes()
135+ assert data[:8] == b"HOPFIND1" and len(data) >= 64
136+ records, partial, body_bytes, directories = struct.unpack("<4Q", data[8:40])
137+ assert data[40:64] == bytes(24)
138+ body = data[64:]
139+ assert len(body) == body_bytes
140+ paths = body.split(b"\0")[:-1] if body else []
141+ assert not body or body.endswith(b"\0")
142+ assert len(paths) == records and all(p.startswith(b"/") and len(p) < 4096 for p in paths)
143+ return dict(records=records, partial=partial, body_bytes=body_bytes, directories=directories), paths
144+
145+
146+def packed_index(paths: list[bytes], partial: int = 0) -> bytes:
147+ body = b"".join(p + b"\0" for p in paths)
148+ return b"HOPFIND1" + struct.pack("<4Q", len(paths), partial, len(body), 1) + bytes(24) + body
149+
150+
151+def main() -> None:
152+ parser = argparse.ArgumentParser()
153+ parser.add_argument("omc", type=Path)
154+ parser.add_argument("--evidence", type=Path)
155+ args = parser.parse_args()
156+ omc = args.omc.resolve()
157+ apps = (ROOT / "Linux/apps.om").read_text()
158+ files = (ROOT / "Linux/files.om").read_text()
159+ events: list[dict] = []
160+ checks: list[str] = []
161+
162+ def check(condition: bool, message: str) -> None:
163+ if not condition:
164+ raise AssertionError(message)
165+ checks.append(message)
166+ print("PASS", message, flush=True)
167+
168+ with tempfile.TemporaryDirectory(prefix="hop-file-check-") as folder:
169+ tmp = Path(folder)
170+ exe = tmp / "files"
171+ compiled(omc, apps, files, exe)
172+ home = tmp / "home"
173+ home.mkdir()
174+ cache = tmp / "cache"
175+ root = tmp / "root"
176+ root.mkdir()
177+ env = dict(PATH=os.defpath, HOME=str(home), XDG_CACHE_HOME=str(cache),
178+ HOP_INDEX_ALARM_ENTRIES="2", HOP_API_KEY="private-fixture-model-key",
179+ HOP_MODEL_URL="http://fixture.invalid/v1", DESKTOP_SESSION_TEST="preserve this variable")
180+
181+ def run(*argv: str, expected: int | None = 0, program: Path = exe,
182+ run_env: dict[str, str] | None = None, **kwargs) -> subprocess.CompletedProcess:
183+ result = subprocess.run([str(program), *map(str, argv)], env=run_env or env,
184+ capture_output=True, timeout=30, **kwargs)
185+ events.append(dict(args=list(map(str, argv)), exit=result.returncode,
186+ stdout_sha256=hashlib.sha256(result.stdout).hexdigest(),
187+ stderr=result.stderr.decode(errors="replace")))
188+ if expected is not None:
189+ assert result.returncode == expected, (argv, result.returncode, result.stderr)
190+ return result
191+
192+ def query(text: str = "", **kwargs) -> list[str]:
193+ return json.loads(run("--find", text, **kwargs).stdout)
194+
195+ # Missing state offers an action without touching the real home directory.
196+ result = run("--ui", "find notes")
197+ check(result.stdout == b"Build file list\n" and not cache.exists(),
198+ "missing index offers one build action without creating or scanning anything")
199+ run("--ui", "finder notes", expected=4)
200+ check(not cache.exists(), "unrelated query is left to the other screens")
201+
202+ (root / "sub").mkdir()
203+ (root / "Alpha notes.txt").write_text("one")
204+ newline = root / "sub/target\nfile.txt"
205+ newline.write_text("two")
206+ emoji = root / "sub/Café 😀.txt"
207+ emoji.write_text("three")
208+ long_file = root / ("l" * 240)
209+ long_file.touch()
210+ bad_name = os.fsencode(root / "sub") + b"/bad-\xff-\xc0\xaf"
211+ os.close(os.open(bad_name, os.O_CREAT | os.O_WRONLY, 0o600))
212+ outside = tmp / "outside"
213+ outside.mkdir()
214+ (outside / "never-index-this.txt").touch()
215+ (root / "outside-link").symlink_to(outside, target_is_directory=True)
216+ (root / "sub/cycle").symlink_to(root, target_is_directory=True)
217+ generated = [".git", ".hidden", "node_modules", "target", "build", "dist", "__pycache__",
218+ "venv", ".venv", "site-packages"]
219+ for name in generated:
220+ (root / name).mkdir()
221+ (root / name / "never-index-this.txt").touch()
222+ result = run("--reindex", root)
223+ index = cache / "hop/files.idx"
224+ meta, paths = index_data(index)
225+ wanted = {os.fsencode(p) for p in (root, root / "sub", root / "Alpha notes.txt", newline,
226+ emoji, long_file, root / "outside-link", root / "sub/cycle")} | {bad_name}
227+ check(set(paths) == wanted and len(paths) == len(wanted),
228+ "NUL format preserves exact names, skips generated and hidden directories, and never follows symlink cycles")
229+ check(meta["partial"] == 0 and meta["directories"] == 2,
230+ "header independently accounts for records, bytes, attempted directories and complete coverage")
231+ check(b"ALARM" in result.stderr and len(paths) > 2,
232+ "entry threshold raises an alarm and continues instead of capping results")
233+ decoded = query()
234+ check({os.fsencode(p) for p in decoded} == wanted,
235+ "CLI JSON round-trips newline, Unicode, supplementary Unicode and invalid filesystem bytes")
236+ check(query("SUB target") == [str(newline)], "Find matches every typed word with ASCII case folding")
237+ check(query("l" * 220) == [str(long_file)], "long search text is matched in full without an app-helper wire cap")
238+ result = run("--ui", "find target")
239+ check(result.stdout.splitlines() == [os.fsencode(newline).replace(b"\n", b"\\n")],
240+ "UI escapes newline filenames into one row while keeping the underlying pathname intact")
241+
242+ # Roots are directory identities, so aliases and overlapping explicit roots do not duplicate entries.
243+ run("--reindex", root, root / "sub", str(root) + "/./", str(root / "sub") + "/..", root)
244+ meta2, paths2 = index_data(index)
245+ check(set(paths2) == wanted and len(paths2) == len(wanted) and meta2["directories"] == 2,
246+ "duplicate and overlapping roots are traversed once")
247+ run("--reindex", "root/sub/..", cwd=tmp)
248+ check(set(index_data(index)[1]) == wanted, "relative roots normalize against the original working directory")
249+ run("--reindex", root / "node_modules")
250+ check(index_data(index)[0]["records"] == 0,
251+ "generated-directory exclusion also applies when that directory is supplied explicitly")
252+ run("--reindex", root, root / "outside-link")
253+ alias_meta, alias_paths = index_data(index)
254+ check(alias_meta["partial"] > 0 and set(alias_paths) == wanted,
255+ "explicit symlink root is not followed and its coverage warning preserves the readable root")
256+
257+ # Dynamic queue/hash table and multiple getdents chunks.
258+ bulk = tmp / "bulk"
259+ bulk.mkdir()
260+ for i in range(3000):
261+ (bulk / f"item-{i}.txt").touch()
262+ for i in range(160):
263+ (bulk / f"folder-{i}").mkdir()
264+ (bulk / f"folder-{i}/inside.txt").touch()
265+ run("--reindex", bulk)
266+ bulk_meta, bulk_paths = index_data(index)
267+ check(bulk_meta["records"] == 1 + 3000 + 160 + 160 and bulk_meta["directories"] == 161 and
268+ len(set(bulk_paths)) == bulk_meta["records"],
269+ "dynamic records, queue and directory identity hash grow across multiple directory reads")
270+
271+ # Known development scratch is skipped exactly; ordinary source directories remain searchable.
272+ (home / "work/hive").mkdir(parents=True)
273+ (home / "work/lanes").mkdir()
274+ (home / "work/source").mkdir()
275+ (home / "work/hive/skip.txt").touch()
276+ (home / "work/lanes/skip.txt").touch()
277+ (home / "work/source/keep.txt").touch()
278+ run("--reindex")
279+ default_paths = index_data(index)[1]
280+ check(os.fsencode(home / "work/source/keep.txt") in default_paths and
281+ not any(b"/work/hive" in p or b"/work/lanes" in p for p in default_paths),
282+ "default home scan excludes exact scratch subtrees and keeps ordinary source folders")
283+
284+ # Permissions are a partial scan, not a reason to throw away obtainable records.
285+ locked = root / "unreadable"
286+ locked.mkdir()
287+ (locked / "secret.txt").touch()
288+ locked.chmod(0)
289+ try:
290+ assert os.geteuid() != 0, "Run this permissions oracle as the ordinary workspace user"
291+ result = run("--reindex", root)
292+ partial_meta, partial_paths = index_data(index)
293+ check(partial_meta["partial"] > 0 and b"partial" in result.stderr and
294+ os.fsencode(root / "Alpha notes.txt") in partial_paths and
295+ os.fsencode(locked / "secret.txt") not in partial_paths,
296+ "unreadable folder retains obtainable results and visibly records partial coverage")
297+ result = run("--find", "Alpha")
298+ check(json.loads(result.stdout) == [str(root / "Alpha notes.txt")] and b"partial" in result.stderr,
299+ "partial results stay queryable with a visible warning")
300+ result = run("--ui", "find Alpha")
301+ check(len(result.stdout.splitlines()) == 2 and b"partial" in result.stdout.splitlines()[0],
302+ "UI marks partial coverage beside its results")
303+ partial_source = files.replace("if ok\nok = ff_publish\nend", "if ok\nif eq get ff_s 4 0\nok = ff_publish\nelse\nok = false\nend\nend")
304+ check(partial_source != files, "discard-partial-results negative control applied")
305+ mutant = tmp / "discard-partial"
306+ compiled(omc, apps, partial_source, mutant)
307+ before = index.read_bytes()
308+ result = run("--reindex", root, program=mutant, expected=1)
309+ check(index.read_bytes() == before,
310+ "negative control reproduces the lost-partial-list bug and fails the successful-rebuild contract")
311+ finally:
312+ locked.chmod(0o700)
313+
314+ # Keep the previous usable snapshot on real output errors.
315+ run("--reindex", root)
316+ before = index.read_bytes()
317+ lock = cache / "hop/files.lock"
318+ with lock.open("r+") as held:
319+ fcntl.flock(held, fcntl.LOCK_EX | fcntl.LOCK_NB)
320+ result = run("--reindex", bulk, expected=3)
321+ check(index.read_bytes() == before and b"already being built" in result.stderr,
322+ "nonblocking lock excludes another rebuild and preserves the current snapshot")
323+ (cache / "hop").chmod(0o500)
324+ try:
325+ result = run("--reindex", bulk, expected=1)
326+ check(index.read_bytes() == before and b"previous list has been kept" in result.stderr,
327+ "temporary-file creation failure preserves the previous usable index")
328+ finally:
329+ (cache / "hop").chmod(0o700)
330+
331+ def file_limit() -> None:
332+ signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
333+ resource.setrlimit(resource.RLIMIT_FSIZE, (80, 80))
334+
335+ result = run("--reindex", bulk, expected=1, preexec_fn=file_limit)
336+ check(index.read_bytes() == before and not list((cache / "hop").glob(".files.*.tmp")),
337+ "actual short-write/disk-limit failure keeps the old index and removes its unique temporary file")
338+ rename_source = files.replace("k = renames ff_rename 0 add add p 2 len ff_index 0",
339+ "k = renames ff_rename 0 add add p 2 len ff_index 1")
340+ check(rename_source != files, "rename-failure kernel fault injection applied")
341+ rename_exe = tmp / "rename-fails"
342+ compiled(omc, apps, rename_source, rename_exe)
343+ run("--reindex", bulk, expected=1, program=rename_exe)
344+ check(index.read_bytes() == before, "real rename EEXIST failure preserves the last good index")
345+
346+ # Using relative cache operations avoids a compiler packed-list limit on two absolute rename paths.
347+ deep = tmp / "deep"
348+ for i in range(23):
349+ deep = deep / ("c" * 95 + str(i))
350+ deep_env = dict(env, XDG_CACHE_HOME=str(deep))
351+ run("--reindex", root, run_env=deep_env)
352+ deep_index = deep / "hop/files.idx"
353+ check(len(os.fsencode(deep_index)) * 2 > 4096 and index_data(deep_index)[0]["partial"] == 0,
354+ "long cache paths publish atomically without imposing the compiler rename-packet bound")
355+ check(str(newline) in query("target", run_env=deep_env), "long-cache lookup uses the same known location")
356+
357+ # Corrupt format inputs never produce a plausible truncated result.
358+ saved = index.read_bytes()
359+ base = packed_index([os.fsencode(newline)])
360+ corruptions = [b"bad", b"BADMAGIC" + base[8:],
361+ base[:8] + struct.pack("<Q", 2) + base[16:],
362+ base[:24] + struct.pack("<Q", 1) + base[32:],
363+ base[:40] + b"x" + base[41:],
364+ packed_index([b"relative/path"]), packed_index([b""]),
365+ packed_index([b"/" + b"a" * 4096]),
366+ base[:-1], base + b"trailing"]
367+ for damaged in corruptions:
368+ index.write_bytes(damaged)
369+ result = run("--find", "", expected=1)
370+ assert b"damaged" in result.stderr and not result.stdout
371+ index.write_bytes(saved)
372+ check(True, "malformed header, counts, reserved bytes, path bounds and NUL framing are refused")
373+
374+ # A real child process records file-open arguments and only the permitted desktop environment.
375+ marker = tmp / "opened.json"
376+ fake_gio = tmp / "gio-oracle"
377+ fake_gio.write_text("#!/usr/bin/python3\nimport os,sys,json\n"
378+ "out={'args':sys.argv[1:],'env':dict(os.environ),"
379+ "'cmdline':open('/proc/self/cmdline','rb').read().decode()}\n"
380+ f"open({str(marker)!r},'w').write(json.dumps(out))\n")
381+ fake_gio.chmod(0o755)
382+ test_apps = apps.replace('text ha_gio "/usr/bin/gio"', f'text ha_gio "{fake_gio}"')
383+ check(test_apps != apps, "file-open platform oracle applied")
384+ opener = tmp / "opener"
385+ compiled(omc, test_apps, files, opener)
386+ run("--activate", "find target", "0", program=opener)
387+ opened = json.loads(marker.read_text())
388+ check(opened["args"] == ["open", str(newline)],
389+ "file activation preserves the selected actual pathname, including its newline")
390+ check(opened["env"]["DESKTOP_SESSION_TEST"] == env["DESKTOP_SESSION_TEST"] and
391+ not any(k.startswith("HOP_") for k in opened["env"]) and
392+ env["HOP_API_KEY"] not in opened["cmdline"] and
393+ env["HOP_API_KEY"] not in marker.read_text(),
394+ "file-open child receives desktop settings while private Hop settings reach neither environment nor command line")
395+
396+ # The missing-list action is tested with argc1, just as an ordinary graphical launch runs.
397+ fresh_env = dict(env, XDG_CACHE_HOME=str(tmp / "fresh-cache"))
398+ run(run_env=fresh_env)
399+ check((tmp / "fresh-cache/hop/files.idx").is_file(),
400+ "Build file list action actually creates and reloads the default-home index")
401+ check(not list((cache / "hop").glob(".files.*.tmp")), "normal rebuilds leave no temporary indexes")
402+
403+ receipt = dict(status="PASS", checks=len(checks), names=checks,
404+ compiler_sha256=hashlib.sha256(omc.read_bytes()).hexdigest(),
405+ sources={name: hashlib.sha256((ROOT / name).read_bytes()).hexdigest()
406+ for name in ("Linux/files.om", "Linux/apps.om", "Linux/tests/files_check.py")},
407+ runs=events)
408+ if args.evidence:
409+ args.evidence.mkdir(parents=True, exist_ok=False)
410+ (args.evidence / "RECEIPT.json").write_text(json.dumps(receipt, indent=2) + "\n")
411+ print(f"HOP-LINUX-FILES PASS checks={len(checks)}")
412+
413+
414+if __name__ == "__main__":
415+ main()

Linux/tests/install_check.py

new file mode 100644
@@ -0,0 +1,209 @@
1+#!/usr/bin/env python3
2+"""Installer checks in disposable HOME and Git stores; never installs the real app.
3+Python and shell fixtures are independent measuring instruments only.
4+"""
5+import argparse
6+import hashlib
7+import json
8+import os
9+from pathlib import Path
10+import subprocess
11+import tempfile
12+
13+
14+def cmd(*args, **kw):
15+ result = subprocess.run(list(args), capture_output=True, **kw)
16+ assert result.returncode == 0, (args, result.returncode, result.stdout, result.stderr)
17+ return result.stdout
18+
19+
20+def fixture(base):
21+ source = base / 'source'
22+ source.mkdir()
23+ (source / '.gitignore').write_text('build/\n')
24+ (source / 'LICENSE').write_text('Independent installer fixture.\n')
25+ cmd('git', 'init', '-q', '-b', 'main', str(source))
26+ cmd('git', '-C', str(source), 'add', '.')
27+ cmd('git', '-C', str(source), '-c', 'user.name=Installer test',
28+ '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture')
29+ store = base / 'store.git'
30+ cmd('git', 'clone', '--bare', '-q', str(source), str(store))
31+ build = source / 'build' / 'linux'
32+ build.mkdir(parents=True)
33+ for name in ('hop', 'hopcore'):
34+ executable = build / name
35+ executable.write_text('#!/bin/sh\nprintf "installer-fixture-ran\\n"\n')
36+ executable.chmod(0o755)
37+ (build / 'SOURCE_HEAD').write_bytes(cmd('git', '-C', str(source), 'rev-parse', 'HEAD'))
38+ toolchain = source / 'build/linux-toolchain'
39+ (toolchain / 'seed/out').mkdir(parents=True)
40+ compiler = toolchain / 'seed/out/omc'
41+ compiler.write_bytes(b'independent compiler fixture\n')
42+ compiler_head = hashlib.sha1(compiler.read_bytes()).hexdigest()
43+ (toolchain / 'source-commit').write_text(compiler_head + '\n')
44+ record = ['HOPBUILD1', (build / 'SOURCE_HEAD').read_text().strip(), compiler_head]
45+ record += [hashlib.sha256(p.read_bytes()).hexdigest()
46+ for p in (compiler, build / 'hop', build / 'hopcore')]
47+ (build / 'BUILD_RECORD').write_text('\n'.join(record) + '\n')
48+ return source, store
49+
50+
51+def main():
52+ parser = argparse.ArgumentParser()
53+ parser.add_argument('--compiler', required=True, type=Path)
54+ parser.add_argument('--evidence', type=Path)
55+ args = parser.parse_args()
56+ root = Path(__file__).resolve().parents[2]
57+ with tempfile.TemporaryDirectory(prefix='hop-install-check-') as raw:
58+ base = Path(raw)
59+ executable = base / 'installer'
60+ build = subprocess.run([str(args.compiler.resolve())],
61+ input=(root / 'Linux/install.om').read_bytes(), capture_output=True)
62+ assert build.returncode == 0, build.stderr
63+ executable.write_bytes(build.stdout)
64+ executable.chmod(0o755)
65+ source, store = fixture(base)
66+ checks = []
67+ home = base / 'A home 50% "dollar$ back` slash\\'
68+ home.mkdir()
69+ data = base / 'custom data'
70+ env = dict(os.environ, HOME=str(home), XDG_DATA_HOME=str(data), HOP_GIT_STORE=str(store))
71+
72+ def install(**updates):
73+ return subprocess.run([str(executable), str(source)],
74+ env=dict(env, **updates), capture_output=True)
75+
76+ def refused(result, word):
77+ assert result.returncode == 1 and word in result.stderr, result
78+
79+ (source / 'LICENSE').write_text('uncommitted\n')
80+ refused(install(), b'clean checkout')
81+ assert not (home / '.local').exists() and not data.exists()
82+ cmd('git', '-C', str(source), 'checkout', '--', 'LICENSE')
83+ checks.append('dirty source refused before installation')
84+ (source / 'new-source').write_text('unpublished\n')
85+ cmd('git', '-C', str(source), 'add', 'new-source')
86+ cmd('git', '-C', str(source), '-c', 'user.name=Installer test',
87+ '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'unpublished')
88+ refused(install(), b'clean checkout')
89+ assert not (home / '.local').exists() and not data.exists()
90+ cmd('git', '-C', str(source), 'reset', '--hard', 'HEAD~1')
91+ checks.append('unpublished commit refused before installation')
92+ stamp = source / 'build/linux/SOURCE_HEAD'
93+ saved_stamp = stamp.read_bytes()
94+ stamp.write_text('stale build\n')
95+ refused(install(), b'Rebuild')
96+ assert not (home / '.local').exists()
97+ stamp.write_bytes(saved_stamp)
98+ checks.append('stale build source stamp refused')
99+
100+ for name in ('hop', 'hopcore'):
101+ artifact = source / 'build/linux' / name
102+ saved = artifact.read_bytes()
103+ artifact.write_bytes(b'#!/bin/sh\nprintf "UNBOUND-REPLACEMENT\\n"\n')
104+ refused(install(), b'Rebuild')
105+ assert not (home / '.local').exists() and not data.exists()
106+ artifact.write_bytes(saved)
107+ checks.append(f'replaced {name} refused with unchanged source stamp and build record')
108+ record = source / 'build/linux/BUILD_RECORD'
109+ saved_record = record.read_bytes()
110+ for invalid in (b'', saved_record[:-1], saved_record + b'extra\n'):
111+ record.write_bytes(invalid)
112+ refused(install(), b'Rebuild')
113+ assert not (home / '.local').exists()
114+ record.write_bytes(saved_record)
115+ checks.append('missing, incomplete and extended build proofs refused')
116+ compiler = source / 'build/linux-toolchain/seed/out/omc'
117+ compiler_saved = compiler.read_bytes()
118+ compiler.write_bytes(b'changed compiler\n')
119+ refused(install(), b'Rebuild')
120+ assert not (home / '.local').exists()
121+ compiler.write_bytes(compiler_saved)
122+ checks.append('changed compiler refused against successful-build proof')
123+
124+ bindir = home / '.local/bin'
125+ bindir.mkdir(parents=True)
126+ collision = bindir / 'hop'
127+ collision.write_text('another program\n')
128+ refused(install(), b'belongs to something else')
129+ assert collision.read_text() == 'another program\n' and not data.exists()
130+ collision.unlink()
131+ collision.symlink_to('/somewhere/else/hop')
132+ refused(install(), b'belongs to something else')
133+ assert os.readlink(collision) == '/somewhere/else/hop'
134+ collision.unlink()
135+ collision.symlink_to(str(home / '.local/lib/hop/../../else/hop'))
136+ refused(install(), b'belongs to something else')
137+ assert os.readlink(collision).endswith('/hop/../../else/hop')
138+ collision.unlink()
139+ checks.append('unrelated regular launcher, symlink and traversal target left untouched')
140+
141+ applications = data / 'applications'
142+ applications.mkdir(parents=True)
143+ desktop = applications / 'hop.desktop'
144+ desktop.write_text('[Desktop Entry]\nName=Someone else\n')
145+ refused(install(), b'belongs to something else')
146+ assert desktop.read_text().endswith('Someone else\n')
147+ desktop.unlink()
148+ checks.append('unrelated desktop entry left untouched')
149+
150+ result = install()
151+ assert result.returncode == 0, result.stderr
152+ first_version = collision.resolve().parent
153+ first_desktop = desktop.read_bytes()
154+ assert cmd(str(collision)) == b'installer-fixture-ran\n'
155+ assert (first_version / 'hopcore').read_bytes() == (source / 'build/linux/hopcore').read_bytes()
156+ assert (first_version / 'LICENSE').read_bytes() == (source / 'LICENSE').read_bytes()
157+ assert (first_version / 'SOURCE_HEAD').read_bytes() == saved_stamp
158+ assert (first_version / 'BUILD_RECORD').read_bytes() == saved_record
159+ assert not (home / '.local/share/applications/hop.desktop').exists()
160+ cmd('desktop-file-validate', str(desktop))
161+ # GLib is an independent implementation of Desktop Entry parsing and Exec expansion.
162+ assert cmd('gio', 'launch', str(desktop), env=env).endswith(b'installer-fixture-ran\n')
163+ checks.append('main installs executable copies, license and a valid application entry in XDG_DATA_HOME')
164+ checks.append('desktop launches correctly with spaces, percent, quotes, dollar, backtick and backslash in HOME')
165+
166+ result = install()
167+ assert result.returncode == 0, result.stderr
168+ second_version = collision.resolve().parent
169+ assert second_version != first_version and first_version.exists()
170+ links = list(bindir.glob('hop.backup.*'))
171+ desktops = list(applications.glob('hop.desktop.backup.*'))
172+ assert len(links) == 1 and links[0].resolve().parent == first_version
173+ assert len(desktops) == 1 and desktops[0].read_bytes() == first_desktop
174+ assert cmd(str(collision)) == b'installer-fixture-ran\n'
175+ checks.append('repeat install preserves old executable version and exact launcher/desktop backups')
176+
177+ second_desktop = desktop.read_bytes()
178+ for name in ('hop', 'hopcore'):
179+ artifact = source / 'build/linux' / name
180+ saved = artifact.read_bytes()
181+ artifact.write_bytes(b'#!/bin/sh\nexit 0\n')
182+ refused(install(), b'Rebuild')
183+ assert collision.resolve().parent == second_version
184+ assert desktop.read_bytes() == second_desktop
185+ artifact.write_bytes(saved)
186+ checks.append('tampered update preserves the previously published launcher and desktop')
187+
188+ # Default data path and canonical-store location are also exercised in another disposable HOME.
189+ normal = base / 'default-home'
190+ normal.mkdir()
191+ (normal / 'git').mkdir()
192+ cmd('git', 'clone', '--bare', '-q', str(store), str(normal / 'git/hop.git'))
193+ default_env = {k: v for k, v in dict(env, HOME=str(normal)).items()
194+ if k not in ('HOP_GIT_STORE', 'XDG_DATA_HOME')}
195+ result = subprocess.run([str(executable), str(source)], env=default_env, capture_output=True)
196+ assert result.returncode == 0, result.stderr
197+ assert (normal / '.local/share/applications/hop.desktop').exists()
198+ checks.append('default HOME/git/hop.git source check and HOME/.local/share application path work')
199+ report = {'status': 'PASS', 'checks': checks,
200+ 'scope': 'disposable fixtures only; no real Hop installation performed'}
201+ if args.evidence:
202+ args.evidence.mkdir(parents=True, exist_ok=True)
203+ (args.evidence / 'result.json').write_text(json.dumps(report, indent=2) + '\n')
204+ (args.evidence / 'desktop-entry.txt').write_bytes(desktop.read_bytes())
205+ print(json.dumps(report))
206+
207+
208+if __name__ == '__main__':
209+ main()

Linux/tests/window_check.py

new file mode 100644
@@ -0,0 +1,209 @@
1+#!/usr/bin/env python3
2+"""Independent Linux UI probe: Xvfb + real X11 keyboard and pointer events.
3+
4+Python is a measuring tool only. It is never installed with Hop or linked into it.
5+Pass --compiler and optionally --evidence to retain source, logs and an XWD image.
6+"""
7+import argparse
8+import json
9+import os
10+from pathlib import Path
11+import secrets
12+import socket
13+import struct
14+import subprocess
15+import tempfile
16+import time
17+
18+STUB = r'''
19+text wt_rows "First result\nSecond result\nThird result\n"
20+text wt_query "QUERY "
21+text wt_action "ACT "
22+text wt_nl "\n"
23+global wt_byte uchar 1
24+fn hop_query to void
25+r = enlarge lx_rows len wt_rows
26+for i ulong len wt_rows bound 256
27+put lx_rows i get wt_rows i
28+end
29+put lx_rn 0 len wt_rows
30+k = write 1 wt_query 0 len wt_query
31+k = write 1 lx_query 0 get lx_qn 0
32+k = write 1 wt_nl 0 1
33+end
34+fn hop_activate to int
35+k = write 1 wt_action 0 len wt_action
36+put wt_byte 0 uchar add get lx_pick 0 48
37+k = write 1 wt_byte 0 1
38+k = write 1 wt_nl 0 1
39+ret 0
40+end
41+fn main to int
42+ret lx_main
43+end
44+'''
45+
46+
47+def authority(display, cookie, hostname=None, family=256):
48+ address = socket.gethostname().encode() if hostname is None else hostname
49+ fields = [address, str(display).encode(),
50+ b"MIT-MAGIC-COOKIE-1", cookie]
51+ return struct.pack('>H', family) + b''.join(struct.pack('>H', len(v)) + v for v in fields)
52+
53+
54+def checked(cmd, env=None):
55+ return subprocess.run(cmd, env=env, capture_output=True, check=True).stdout
56+
57+
58+def run(compiler, evidence, source_path=None):
59+ root = Path(__file__).resolve().parents[2]
60+ evidence.mkdir(parents=True, exist_ok=True)
61+ source = (source_path or root / 'Linux/window.om').read_bytes() + STUB.encode()
62+ (evidence / 'window-test.om').write_bytes(source)
63+ exe = evidence / 'window-test'
64+ built = subprocess.run([str(compiler)], input=source, capture_output=True)
65+ (evidence / 'compile.log').write_bytes(built.stderr)
66+ assert built.returncode == 0, built.stderr.decode()
67+ exe.write_bytes(built.stdout)
68+ exe.chmod(0o755)
69+ checks = []
70+ display = 171
71+ assert not Path(f'/tmp/.X11-unix/X{display}').exists(), 'test display is already occupied'
72+ auth = evidence / 'Xauthority'
73+ server_auth = evidence / 'server-Xauthority'
74+ cookie = secrets.token_bytes(16)
75+ other_host = b'hop-test-other-machine.invalid'
76+ assert other_host != socket.gethostname().encode()
77+ server_auth.write_bytes(authority(display, cookie))
78+ server_auth.chmod(0o600)
79+ # The server trusts only its actual cookie. The client also carries another machine's
80+ # same-display credential, ahead of the valid one, as a shared or moved HOME can.
81+ auth.write_bytes(authority(display + 1, secrets.token_bytes(16)) +
82+ authority(display, secrets.token_bytes(16), other_host) +
83+ authority(display, cookie))
84+ auth.chmod(0o600)
85+ server_log = open(evidence / 'xvfb.log', 'wb')
86+ server = subprocess.Popen(['Xvfb', f':{display}', '-screen', '0', '1024x768x24',
87+ '-nolisten', 'tcp', '-auth', str(server_auth)],
88+ stdout=server_log, stderr=server_log)
89+ proc = None
90+ try:
91+ for _ in range(100):
92+ if server.poll() is not None:
93+ raise AssertionError((evidence / 'xvfb.log').read_text())
94+ if Path(f'/tmp/.X11-unix/X{display}').exists():
95+ break
96+ time.sleep(.02)
97+ env = dict(os.environ, DISPLAY=f':{display}.0', XAUTHORITY=str(auth))
98+ checked(['xdpyinfo'], env)
99+ proc = subprocess.Popen([str(exe)], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
100+ window = None
101+ for _ in range(100):
102+ found = subprocess.run(['xdotool', 'search', '--name', '^Hop$'], env=env, capture_output=True)
103+ if found.returncode == 0 and found.stdout.strip():
104+ window = found.stdout.splitlines()[0].decode()
105+ break
106+ if proc.poll() is not None:
107+ break
108+ time.sleep(.02)
109+ assert window, 'Hop did not create its window: ' + repr(proc.communicate(timeout=1))
110+ checks.append('same-display credentials for another hostname are skipped, matching xdpyinfo; screen suffix accepted')
111+ checked(['xdotool', 'type', '--clearmodifiers', 'hello'], env)
112+ checked(['xdotool', 'key', 'BackSpace', 'Shift_L+a'], env)
113+ checked(['xdotool', 'key', 'Down', 'Return'], env)
114+ checked(['xdotool', 'mousemove', '--window', window, '40', '174', 'click', '1'], env)
115+ checked(['xdotool', 'key', 'ctrl+u'], env)
116+ checked(['xdotool', 'type', '--clearmodifiers', 'world'], env)
117+ checked(['xwd', '-silent', '-id', window, '-out', str(evidence / 'window.xwd')], env)
118+ checked(['xdotool', 'key', 'Escape'], env)
119+ out, err = proc.communicate(timeout=5)
120+ (evidence / 'window.stdout').write_bytes(out)
121+ (evidence / 'window.stderr').write_bytes(err)
122+ assert proc.returncode == 0 and not err, (proc.returncode, err)
123+ assert b'QUERY hello\n' in out, out
124+ assert b'QUERY hellA\n' in out, out
125+ checks.append('real typing, backspace and Shift reach the query')
126+ assert b'ACT 1\n' in out and b'ACT 2\n' in out, out
127+ checks.append('Down + Enter and a pointer click activate the selected rows')
128+ assert b'QUERY world\n' in out, out
129+ checks.append('Control+U clears and Escape closes cleanly')
130+ wrong = evidence / 'wrong-Xauthority'
131+ wrong.write_bytes(authority(display, secrets.token_bytes(16)))
132+ rejected = subprocess.run([str(exe)], env=dict(env, XAUTHORITY=str(wrong)), capture_output=True, timeout=5)
133+ assert rejected.returncode == 1 and b'refused' in rejected.stderr, rejected
134+ standard_rejected = subprocess.run(['xdpyinfo'], env=dict(env, XAUTHORITY=str(wrong)),
135+ capture_output=True, timeout=5)
136+ assert standard_rejected.returncode != 0, standard_rejected
137+ checks.append('wrong display cookie is refused visibly by Hop and xdpyinfo')
138+ wrong.write_bytes(authority(display, cookie, other_host))
139+ standard_rejected = subprocess.run(['xdpyinfo'], env=dict(env, XAUTHORITY=str(wrong)),
140+ capture_output=True, timeout=5)
141+ assert standard_rejected.returncode != 0, standard_rejected
142+ rejected = subprocess.run([str(exe)], env=dict(env, XAUTHORITY=str(wrong)), capture_output=True, timeout=5)
143+ assert rejected.returncode == 1 and b'refused' in rejected.stderr, rejected
144+ checks.append('a different host record alone is refused even when its cookie is valid, matching xdpyinfo')
145+ wild = evidence / 'wild-Xauthority'
146+ wild.write_bytes(authority(display, cookie, other_host, family=65535))
147+ wild.chmod(0o600)
148+ wild_env = dict(env, XAUTHORITY=str(wild))
149+ checked(['xdpyinfo'], wild_env)
150+ proc = subprocess.Popen([str(exe)], env=wild_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
151+ wild_window = None
152+ for _ in range(100):
153+ found = subprocess.run(['xdotool', 'search', '--name', '^Hop$'], env=wild_env, capture_output=True)
154+ if found.returncode == 0 and found.stdout.strip():
155+ wild_window = found.stdout.splitlines()[0].decode()
156+ break
157+ if proc.poll() is not None:
158+ break
159+ time.sleep(.02)
160+ assert wild_window, 'Hop did not accept the explicit FamilyWild credential'
161+ checked(['xdotool', 'key', 'Escape'], wild_env)
162+ out, err = proc.communicate(timeout=5)
163+ assert proc.returncode == 0 and not err, (proc.returncode, err)
164+ checks.append('explicit FamilyWild still accepts its deliberate address wildcard, matching xdpyinfo')
165+ missing = subprocess.run([str(exe)], env={k: v for k, v in env.items() if k != 'DISPLAY'}, capture_output=True, timeout=5)
166+ assert missing.returncode == 1 and b'DISPLAY' in missing.stderr, missing
167+ remote = subprocess.run([str(exe)], env=dict(env, DISPLAY='remote.example:0'), capture_output=True, timeout=5)
168+ assert remote.returncode == 1 and b'local X11' in remote.stderr, remote
169+ checks.append('missing desktop and remote display are refused visibly')
170+ home = evidence / 'home'
171+ home.mkdir(exist_ok=True)
172+ (home / '.Xauthority').write_bytes(auth.read_bytes())
173+ default_env = {k: v for k, v in dict(env, HOME=str(home)).items() if k != 'XAUTHORITY'}
174+ proc = subprocess.Popen([str(exe)], env=default_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
175+ time.sleep(.2)
176+ assert proc.poll() is None
177+ checked(['xdotool', 'key', 'Escape'], env)
178+ out, err = proc.communicate(timeout=5)
179+ assert proc.returncode == 0 and not err, (proc.returncode, err)
180+ checks.append('default HOME/.Xauthority works')
181+ result = {'status': 'PASS', 'checks': checks, 'not_run': ['native Wayland', 'XWayland', 'non-Latin rendering']}
182+ (evidence / 'result.json').write_text(json.dumps(result, indent=2) + '\n')
183+ print(json.dumps(result))
184+ finally:
185+ if proc is not None and proc.poll() is None:
186+ proc.terminate()
187+ proc.wait(timeout=5)
188+ server.terminate()
189+ server.wait(timeout=5)
190+ server_log.close()
191+ # Cookies grant access to a now-terminated, test-only X server, but are not retained.
192+ auth.unlink(missing_ok=True)
193+ server_auth.unlink(missing_ok=True)
194+ (evidence / 'wild-Xauthority').unlink(missing_ok=True)
195+ (evidence / 'wrong-Xauthority').unlink(missing_ok=True)
196+ (evidence / 'home' / '.Xauthority').unlink(missing_ok=True)
197+
198+
199+if __name__ == '__main__':
200+ parser = argparse.ArgumentParser()
201+ parser.add_argument('--compiler', required=True, type=Path)
202+ parser.add_argument('--evidence', type=Path)
203+ parser.add_argument('--source', type=Path, help='independent wrong-version or mutation control')
204+ args = parser.parse_args()
205+ if args.evidence:
206+ run(args.compiler.resolve(), args.evidence.resolve(), args.source)
207+ else:
208+ with tempfile.TemporaryDirectory(prefix='hop-window-check-') as directory:
209+ run(args.compiler.resolve(), Path(directory), args.source)

Linux/window.om

new file mode 100644
@@ -0,0 +1,948 @@
1+om2
2+note Hop Linux desktop boundary. X11 requests are emitted directly from Omega; no UI host library.
3+note X Consortium X11 protocol release 7.7, chapters 8/9/11 and Appendix B.
4+note X11 core fonts render Latin-1. Unicode input is retained as UTF-8; unrenderable glyphs show ?. Native Wayland is not implied.
5+note Color names below map to aienos-brand/reference/tokens.json dark theme. No display polling service is installed.
6+const lx_bg ulong 0x0a0a0f
7+const lx_card ulong 0x14141f
8+const lx_ink ulong 0xffffff
9+const lx_accent ulong 0x2563eb
10+const lx_muted ulong 0x88888b
11+global lx_query uchar *
12+global lx_rows uchar *
13+global lx_qn ulong 1
14+global lx_rn ulong 1
15+global lx_pick ulong 1
16+global lx_fd long 1
17+global lx_s ulong 32
18+global lx_buf uchar *
19+global lx_auth uchar *
20+global lx_keys uchar *
21+global lx_host uchar *
22+global lx_hn ulong 2
23+global lx_req uchar 512
24+global lx_env uchar 4096
25+global lx_path uchar 4096
26+global lx_addr uchar 110
27+global lx_piece uchar 256
28+text lx_display "DISPLAY="
29+text lx_xauth "XAUTHORITY="
30+text lx_home "HOME="
31+text lx_local "/tmp/.X11-unix/X"
32+text lx_dotauth "/.Xauthority"
33+text lx_cookie "MIT-MAGIC-COOKIE-1"
34+text lx_hostname "/proc/sys/kernel/hostname"
35+text lx_name "Hop"
36+text lx_font "fixed"
37+text lx_wmp "WM_PROTOCOLS"
38+text lx_wmd "WM_DELETE_WINDOW"
39+text lx_hint "Type to find an app, a file, or ask a question"
40+text lx_help "Up / Down choose Enter opens Escape closes"
41+text lx_errdisp "Hop: open it from a Linux desktop (DISPLAY is missing or is not a local X11 display).\n"
42+text lx_errsock "Hop: cannot connect to the desktop display.\n"
43+text lx_errauth "Hop: the desktop refused its X11 login. Check DISPLAY and XAUTHORITY.\n"
44+text lx_errwire "Hop: the desktop connection ended or returned an invalid response.\n"
45+text lx_errmem "Hop: the system could not allocate memory for the desktop.\n"
46+
47+fn lx_bad to void
48+k = write 2 lx_errwire 0 len lx_errwire
49+exit 1
50+end
51+fn lx_grow n ulong to void
52+r = enlarge lx_buf n
53+if lt r 0
54+k = write 2 lx_errmem 0 len lx_errmem
55+exit 1
56+end
57+end
58+fn lx_u16 o ulong to ulong
59+ret or ulong get lx_buf o shl ulong get lx_buf add o 1 8
60+end
61+fn lx_u32 o ulong to ulong
62+ret or lx_u16 o shl lx_u16 add o 2 16
63+end
64+fn lx_a16 o ulong to ulong
65+ret or shl ulong get lx_auth o 8 ulong get lx_auth add o 1
66+end
67+fn lx_p16 o ulong v ulong to void
68+put lx_req o uchar and v 255
69+put lx_req add o 1 uchar and shr v 8 255
70+end
71+fn lx_p32 o ulong v ulong to void
72+lx_p16 o v
73+lx_p16 add o 2 shr v 16
74+end
75+fn lx_request op uchar n ulong to void
76+for i ulong n bound 512
77+put lx_req i 0
78+end
79+put lx_req 0 op
80+lx_p16 2 div n 4
81+end
82+fn lx_send n ulong to void
83+p = ulong 0
84+while lt p n bound 9223372036854775807
85+k = send int get lx_fd 0 lx_req p sub n p 0
86+if eq k -4
87+continue
88+end
89+if le k 0
90+lx_bad
91+end
92+p = add p ulong k
93+end
94+end
95+fn lx_read off ulong n ulong to void
96+lx_grow add off n
97+p = ulong 0
98+while lt p n bound 9223372036854775807
99+k = read int get lx_fd 0 lx_buf add off p sub n p
100+if eq k -4
101+continue
102+end
103+if le k 0
104+lx_bad
105+end
106+p = add p ulong k
107+end
108+end
109+fn lx_reply to void
110+while true bound 9223372036854775807
111+lx_read 0 32
112+kind = and get lx_buf 0 127
113+if eq kind 0
114+lx_bad
115+end
116+if eq kind 1
117+n = mul lx_u32 4 4
118+lx_read 32 n
119+ret
120+end
121+end
122+end
123+fn lx_envget key view uchar * to ulong
124+for i ulong ulong envcnt bound 9223372036854775807
125+n = envread i lx_env 0 len lx_env
126+if ge n long len key
127+ok = true
128+for j ulong len key bound 4096
129+if ne get key j get lx_env j
130+ok = false
131+end
132+end
133+if ok
134+count = sub ulong n len key
135+for j ulong count bound 4096
136+put lx_path j get lx_env add len key j
137+end
138+ret count
139+end
140+end
141+end
142+ret 0
143+end
144+fn lx_number n ulong to ulong
145+v = ulong 0
146+i = ulong 0
147+if and ge n 5 eq get lx_path 0 117
148+note unix: and unix/: are local display spellings
149+if and eq get lx_path 1 110 eq get lx_path 2 105
150+if eq get lx_path 3 120
151+i = 4
152+if eq get lx_path 4 47
153+i = 5
154+end
155+end
156+end
157+end
158+if ge i n
159+ret 0
160+end
161+if ne get lx_path i 58
162+ret 0
163+end
164+i = add i 1
165+start = i
166+while lt i n bound 4096
167+c = get lx_path i
168+if eq c 46
169+break
170+end
171+if or lt c 48 gt c 57
172+ret 0
173+end
174+if gt v 999999
175+ret 0
176+end
177+v = add mul v 10 ulong sub c 48
178+i = add i 1
179+end
180+if eq start i
181+ret 0
182+end
183+put lx_s 24 v
184+put lx_s 25 sub i start
185+for j ulong sub i start bound 4096
186+put lx_piece j get lx_path add start j
187+end
188+screen = ulong 0
189+if lt i n
190+i = add i 1
191+if eq i n
192+ret 0
193+end
194+while lt i n bound 4096
195+c = get lx_path i
196+if or lt c 48 gt c 57
197+ret 0
198+end
199+if gt screen 999999
200+ret 0
201+end
202+screen = add mul screen 10 ulong sub c 48
203+i = add i 1
204+end
205+end
206+put lx_s 26 screen
207+ret 1
208+end
209+note FamilyLocal credentials name this machine, not merely a display number. The kernel hostname is read once per authority scan.
210+note FamilyWild explicitly bypasses the address match, as before; display and authentication-scheme checks remain in force.
211+fn lx_loadhost to void
212+put lx_hn 0 0
213+put lx_hn 1 0
214+fd = fopen lx_hostname 0 len lx_hostname 0 0
215+if lt fd 0
216+ret
217+end
218+used = ulong 0
219+while true bound 9223372036854775807
220+r = enlarge lx_host add used 256
221+if lt r 0
222+k = fclose int fd
223+ret
224+end
225+k = read int fd lx_host used 256
226+if eq k -4
227+continue
228+end
229+if lt k 0
230+k = fclose int fd
231+ret
232+end
233+if eq k 0
234+break
235+end
236+used = add used ulong k
237+end
238+k = fclose int fd
239+note proc appends exactly one line feed; remove that delimiter, preserving any line feed in the hostname itself.
240+if gt used 0
241+if eq get lx_host sub used 1 10
242+used = sub used 1
243+end
244+end
245+put lx_hn 0 used
246+put lx_hn 1 1
247+end
248+fn lx_hostmatch offset ulong size ulong to bool
249+if eq get lx_hn 1 0
250+ret false
251+end
252+if ne size get lx_hn 0
253+ret false
254+end
255+for i ulong size bound 65536
256+if ne get lx_auth add offset i get lx_host i
257+ret false
258+end
259+end
260+ret true
261+end
262+fn lx_findauth n ulong to ulong
263+lx_loadhost
264+p = ulong 0
265+while lt p n bound 9223372036854775807
266+if gt add p 2 n
267+ret 0
268+end
269+family = lx_a16 p
270+p = add p 2
271+ok = or eq family 256 eq family 65535
272+for fld ulong 4 bound 4
273+if gt add p 2 n
274+ret 0
275+end
276+size = lx_a16 p
277+p = add p 2
278+if gt add p size n
279+ret 0
280+end
281+if and eq fld 0 eq family 256
282+if not lx_hostmatch p size
283+ok = false
284+end
285+end
286+if eq fld 1
287+if ne size get lx_s 25
288+ok = false
289+else
290+for j ulong size bound 65536
291+if ne get lx_auth add p j get lx_piece j
292+ok = false
293+end
294+end
295+end
296+end
297+if eq fld 2
298+if ne size len lx_cookie
299+ok = false
300+else
301+for j ulong size bound 65536
302+if ne get lx_auth add p j get lx_cookie j
303+ok = false
304+end
305+end
306+end
307+end
308+if eq fld 3
309+if and ok eq size 16
310+put lx_s 27 p
311+ret size
312+end
313+end
314+p = add p size
315+end
316+end
317+ret 0
318+end
319+fn lx_authload to ulong
320+n = lx_envget lx_xauth
321+if eq n 0
322+n = lx_envget lx_home
323+if eq n 0
324+ret 0
325+end
326+if gt add n len lx_dotauth 4095
327+ret 0
328+end
329+for i ulong len lx_dotauth bound 32
330+put lx_path add n i get lx_dotauth i
331+end
332+n = add n len lx_dotauth
333+end
334+fd = fopen lx_path 0 n 0 0
335+if lt fd 0
336+ret 0
337+end
338+used = ulong 0
339+while true bound 9223372036854775807
340+r = enlarge lx_auth add used 4096
341+if lt r 0
342+k = fclose int fd
343+ret 0
344+end
345+k = read int fd lx_auth used 4096
346+if eq k -4
347+continue
348+end
349+if le k 0
350+break
351+end
352+used = add used ulong k
353+end
354+k = fclose int fd
355+ret lx_findauth used
356+end
357+fn lx_setup to int
358+n = lx_envget lx_display
359+if eq n 0
360+k = write 2 lx_errdisp 0 len lx_errdisp
361+ret 1
362+end
363+if eq lx_number n 0
364+k = write 2 lx_errdisp 0 len lx_errdisp
365+ret 1
366+end
367+for i ulong len lx_local bound 32
368+put lx_addr add i 2 get lx_local i
369+end
370+for i ulong get lx_s 25 bound 16
371+put lx_addr add add 2 len lx_local i get lx_piece i
372+end
373+put lx_addr 0 1
374+n = add add 3 len lx_local get lx_s 25
375+fd = socknew 1 1 0
376+if lt fd 0
377+k = write 2 lx_errsock 0 len lx_errsock
378+ret 1
379+end
380+put lx_fd 0 fd
381+r = connect int fd lx_addr 0 n
382+if lt r 0
383+k = write 2 lx_errsock 0 len lx_errsock
384+k = fclose int fd
385+ret 1
386+end
387+an = lx_authload
388+lx_request 108 48
389+lx_p16 2 11
390+lx_p16 4 0
391+if gt an 0
392+lx_p16 6 len lx_cookie
393+lx_p16 8 an
394+for i ulong len lx_cookie bound 32
395+put lx_req add 12 i get lx_cookie i
396+end
397+for i ulong an bound 32
398+put lx_req add 32 i get lx_auth add get lx_s 27 i
399+end
400+lx_send 48
401+else
402+lx_send 12
403+end
404+lx_read 0 8
405+if ne get lx_buf 0 1
406+k = write 2 lx_errauth 0 len lx_errauth
407+k = fclose int fd
408+ret 1
409+end
410+n = mul lx_u16 6 4
411+lx_read 0 n
412+ret lx_screen n
413+end
414+fn lx_screen n ulong to int
415+if lt n 32
416+lx_bad
417+end
418+put lx_s 7 lx_u32 4
419+put lx_s 8 lx_u32 8
420+put lx_s 13 ulong get lx_buf 26
421+put lx_s 14 ulong get lx_buf 27
422+roots = ulong get lx_buf 20
423+if ge get lx_s 26 roots
424+lx_bad
425+end
426+p = add 32 mul div add lx_u16 16 3 4 4
427+p = add p mul ulong get lx_buf 21 8
428+for screen ulong add get lx_s 26 1 bound 65536
429+if gt add p 40 n
430+lx_bad
431+end
432+if eq screen get lx_s 26
433+put lx_s 4 lx_u32 p
434+put lx_s 16 lx_u16 add p 20
435+put lx_s 17 lx_u16 add p 22
436+ret 0
437+end
438+depths = ulong get lx_buf add p 39
439+p = add p 40
440+for j ulong depths bound 256
441+if gt add p 8 n
442+lx_bad
443+end
444+p = add add p 8 mul lx_u16 add p 2 24
445+end
446+end
447+ret 1
448+end
449+fn lx_id k ulong to ulong
450+v = get lx_s 7
451+mask = get lx_s 8
452+bit = ulong 1
453+for i ulong 32 bound 32
454+if ne and mask shl ulong 1 i 0
455+if ne and k bit 0
456+v = or v shl ulong 1 i
457+end
458+bit = shl bit 1
459+end
460+end
461+ret v
462+end
463+fn lx_atom name view uchar * to ulong
464+n = mul div add add 8 len name 3 4 4
465+lx_request 16 n
466+lx_p16 4 len name
467+for i ulong len name bound 256
468+put lx_req add 8 i get name i
469+end
470+lx_send n
471+lx_reply
472+ret lx_u32 8
473+end
474+fn lx_property atom ulong ty ulong fmt uchar data ulong n ulong to void
475+lx_request 18 28
476+lx_p32 4 get lx_s 1
477+lx_p32 8 atom
478+lx_p32 12 ty
479+put lx_req 16 fmt
480+lx_p32 20 n
481+lx_p32 24 data
482+lx_send 28
483+end
484+fn lx_color fg ulong bg ulong to void
485+lx_request 56 20
486+lx_p32 4 get lx_s 2
487+lx_p32 8 12
488+lx_p32 12 fg
489+lx_p32 16 bg
490+lx_send 20
491+end
492+fn lx_fill x ulong y ulong w ulong h ulong color ulong to void
493+lx_color color lx_bg
494+lx_request 70 20
495+lx_p32 4 get lx_s 1
496+lx_p32 8 get lx_s 2
497+lx_p16 12 x
498+lx_p16 14 y
499+lx_p16 16 w
500+lx_p16 18 h
501+lx_send 20
502+end
503+fn lx_text x ulong y ulong count ulong to void
504+note ImageText8 has an 8-bit glyph count. Split long strings in caller at the visible edge.
505+n = mul div add add 16 count 3 4 4
506+lx_request 76 n
507+put lx_req 1 uchar count
508+lx_p32 4 get lx_s 1
509+lx_p32 8 get lx_s 2
510+lx_p16 12 x
511+lx_p16 14 y
512+for i ulong count bound 256
513+put lx_req add 16 i get lx_piece i
514+end
515+lx_send n
516+end
517+fn lx_label textv view uchar * x ulong y ulong to void
518+n = len textv
519+if gt n 100
520+n = 100
521+end
522+for i ulong n bound 256
523+put lx_piece i get textv i
524+end
525+lx_text x y n
526+end
527+fn lx_querytext to void
528+n = get lx_qn 0
529+start = ulong 0
530+if gt n 90
531+start = sub n 90
532+while lt start n bound 9223372036854775807
533+c = get lx_query start
534+if ne and c 192 128
535+break
536+end
537+start = add start 1
538+end
539+end
540+count = ulong 0
541+i = start
542+while and lt i n lt count 100 bound 9223372036854775807
543+c = get lx_query i
544+if lt c 128
545+put lx_piece count c
546+count = add count 1
547+else
548+if ne and c 192 128
549+put lx_piece count 63
550+count = add count 1
551+end
552+end
553+i = add i 1
554+end
555+lx_text 24 78 count
556+end
557+fn lx_rowtext start ulong last ulong y ulong to void
558+count = ulong 0
559+i = start
560+while and lt i last lt count 92 bound 9223372036854775807
561+c = get lx_rows i
562+if lt c 128
563+if ge c 32
564+put lx_piece count c
565+count = add count 1
566+end
567+else
568+if ne and c 192 128
569+put lx_piece count 63
570+count = add count 1
571+end
572+end
573+i = add i 1
574+end
575+lx_text 32 y count
576+end
577+fn lx_rowcount to ulong
578+n = get lx_rn 0
579+count = ulong 0
580+for i ulong n bound 9223372036854775807
581+if eq get lx_rows i 10
582+count = add count 1
583+end
584+end
585+if gt n 0
586+if ne get lx_rows sub n 1 10
587+count = add count 1
588+end
589+end
590+ret count
591+end
592+fn lx_draw to void
593+put lx_s 19 lx_rowcount
594+if ge get lx_pick 0 get lx_s 19
595+put lx_pick 0 0
596+end
597+visible = div sub get lx_s 12 150 30
598+if lt get lx_pick 0 get lx_s 20
599+put lx_s 20 get lx_pick 0
600+end
601+if ge get lx_pick 0 add get lx_s 20 visible
602+put lx_s 20 add sub get lx_pick 0 visible 1
603+end
604+lx_request 61 16
605+lx_p32 4 get lx_s 1
606+lx_send 16
607+lx_color lx_ink lx_bg
608+lx_label lx_name 24 32
609+lx_color lx_muted lx_bg
610+if eq get lx_qn 0 0
611+lx_label lx_hint 24 78
612+else
613+lx_color lx_ink lx_bg
614+lx_querytext
615+end
616+lx_fill 24 96 sub get lx_s 11 48 1 lx_card
617+start = ulong 0
618+row = ulong 0
619+n = get lx_rn 0
620+i = ulong 0
621+while le i n bound 9223372036854775807
622+last = eq i n
623+if lt i n
624+last = eq get lx_rows i 10
625+end
626+if last
627+if and ge row get lx_s 20 lt row add get lx_s 20 visible
628+if gt i start
629+y = add 126 mul sub row get lx_s 20 30
630+if eq row get lx_pick 0
631+lx_fill 24 sub y 18 sub get lx_s 11 48 28 lx_accent
632+lx_color lx_ink lx_accent
633+else
634+lx_color lx_ink lx_bg
635+end
636+lx_rowtext start i y
637+end
638+end
639+row = add row 1
640+start = add i 1
641+end
642+i = add i 1
643+end
644+lx_color lx_muted lx_bg
645+lx_label lx_help 24 sub get lx_s 12 20
646+end
647+fn lx_makewin to void
648+put lx_s 1 lx_id 1
649+put lx_s 2 lx_id 2
650+put lx_s 3 lx_id 3
651+put lx_s 11 640
652+put lx_s 12 440
653+lx_request 1 40
654+lx_p32 4 get lx_s 1
655+lx_p32 8 get lx_s 4
656+x = ulong 0
657+y = ulong 0
658+if gt get lx_s 16 640
659+x = div sub get lx_s 16 640 2
660+end
661+if gt get lx_s 17 440
662+y = div sub get lx_s 17 440 2
663+end
664+lx_p16 12 x
665+lx_p16 14 y
666+lx_p16 16 640
667+lx_p16 18 440
668+lx_p16 22 1
669+lx_p32 28 2050
670+lx_p32 32 lx_bg
671+lx_p32 36 or or ulong 1 4 or ulong 32768 131072
672+lx_send 40
673+put lx_s 9 lx_atom lx_wmp
674+put lx_s 10 lx_atom lx_wmd
675+lx_property get lx_s 9 4 32 get lx_s 10 1
676+lx_request 18 28
677+lx_p32 4 get lx_s 1
678+lx_p32 8 39
679+lx_p32 12 31
680+put lx_req 16 8
681+lx_p32 20 len lx_name
682+for i ulong len lx_name bound 16
683+put lx_req add 24 i get lx_name i
684+end
685+lx_send 28
686+lx_request 45 20
687+lx_p32 4 get lx_s 3
688+lx_p16 8 len lx_font
689+for i ulong len lx_font bound 16
690+put lx_req add 12 i get lx_font i
691+end
692+lx_send 20
693+lx_request 55 28
694+lx_p32 4 get lx_s 2
695+lx_p32 8 get lx_s 1
696+lx_p32 12 16396
697+lx_p32 16 lx_ink
698+lx_p32 20 lx_bg
699+lx_p32 24 get lx_s 3
700+lx_send 28
701+lx_request 101 8
702+put lx_req 4 uchar get lx_s 13
703+put lx_req 5 uchar add sub get lx_s 14 get lx_s 13 1
704+lx_send 8
705+lx_reply
706+put lx_s 15 ulong get lx_buf 1
707+n = mul lx_u32 4 4
708+r = enlarge lx_keys n
709+if lt r 0
710+lx_bad
711+end
712+for i ulong n bound 9223372036854775807
713+put lx_keys i get lx_buf add 32 i
714+end
715+lx_request 8 8
716+lx_p32 4 get lx_s 1
717+lx_send 8
718+note SetInputFocus follows MapWindow; the window manager may override placement and focus according to user policy.
719+lx_request 42 12
720+put lx_req 1 1
721+lx_p32 4 get lx_s 1
722+lx_send 12
723+end
724+fn lx_keyvalue code ulong column ulong to ulong
725+if or lt code get lx_s 13 gt code get lx_s 14
726+ret 0
727+end
728+if ge column get lx_s 15
729+ret 0
730+end
731+p = mul add mul sub code get lx_s 13 get lx_s 15 column 4
732+if gt add p 4 len lx_keys
733+ret 0
734+end
735+v = ulong 0
736+for i ulong 4 bound 4
737+v = or v shl ulong get lx_keys add p i mul i 8
738+end
739+ret v
740+end
741+fn lx_append cp ulong to void
742+n = get lx_qn 0
743+r = enlarge lx_query add n 4
744+if lt r 0
745+lx_bad
746+end
747+if lt cp 128
748+put lx_query n uchar cp
749+n = add n 1
750+else
751+if lt cp 2048
752+put lx_query n uchar or 192 shr cp 6
753+put lx_query add n 1 uchar or 128 and cp 63
754+n = add n 2
755+else
756+if lt cp 65536
757+put lx_query n uchar or 224 shr cp 12
758+put lx_query add n 1 uchar or 128 and shr cp 6 63
759+put lx_query add n 2 uchar or 128 and cp 63
760+n = add n 3
761+else
762+put lx_query n uchar or 240 shr cp 18
763+put lx_query add n 1 uchar or 128 and shr cp 12 63
764+put lx_query add n 2 uchar or 128 and shr cp 6 63
765+put lx_query add n 3 uchar or 128 and cp 63
766+n = add n 4
767+end
768+end
769+end
770+put lx_qn 0 n
771+end
772+fn lx_changed to void
773+put lx_pick 0 0
774+put lx_s 20 0
775+hop_query
776+lx_draw
777+end
778+fn lx_key to void
779+code = ulong get lx_buf 1
780+state = lx_u16 28
781+key = lx_keyvalue code 0
782+if ne and state 1 0
783+other = lx_keyvalue code 1
784+if ne other 0
785+key = other
786+end
787+end
788+if ne and state 2 0
789+if and ge key 97 le key 122
790+key = sub key 32
791+else
792+if and ge key 65 le key 90
793+key = add key 32
794+end
795+end
796+end
797+if eq key 65307
798+put lx_s 18 1
799+ret
800+end
801+if eq key 65293
802+if eq hop_activate 1
803+put lx_s 18 1
804+else
805+lx_draw
806+end
807+ret
808+end
809+if eq key 65362
810+if gt get lx_pick 0 0
811+put lx_pick 0 sub get lx_pick 0 1
812+end
813+lx_draw
814+ret
815+end
816+if eq key 65364
817+if lt add get lx_pick 0 1 get lx_s 19
818+put lx_pick 0 add get lx_pick 0 1
819+end
820+lx_draw
821+ret
822+end
823+if eq key 65288
824+n = get lx_qn 0
825+if gt n 0
826+n = sub n 1
827+while gt n 0 bound 9223372036854775807
828+if ne and get lx_query n 192 128
829+break
830+end
831+n = sub n 1
832+end
833+put lx_qn 0 n
834+lx_changed
835+end
836+ret
837+end
838+if eq key 65289
839+ret
840+end
841+if ne and state 4 0
842+if or eq key 117 eq key 85
843+put lx_qn 0 0
844+lx_changed
845+end
846+ret
847+end
848+if ne and state 72 0
849+ret
850+end
851+if and ge key 32 lt key 256
852+lx_append key
853+lx_changed
854+ret
855+end
856+if and ge key 16777248 le key 17891327
857+cp = sub key 16777216
858+if or lt cp 55296 gt cp 57343
859+lx_append cp
860+lx_changed
861+end
862+end
863+end
864+fn lx_click to void
865+button = get lx_buf 1
866+if eq button 4
867+if gt get lx_pick 0 0
868+put lx_pick 0 sub get lx_pick 0 1
869+end
870+lx_draw
871+ret
872+end
873+if eq button 5
874+if lt add get lx_pick 0 1 get lx_s 19
875+put lx_pick 0 add get lx_pick 0 1
876+end
877+lx_draw
878+ret
879+end
880+if ne button 1
881+ret
882+end
883+y = lx_u16 26
884+if lt y 108
885+ret
886+end
887+offset = div sub y 108 30
888+if ge offset div sub get lx_s 12 150 30
889+ret
890+end
891+row = add get lx_s 20 offset
892+if ge row get lx_s 19
893+ret
894+end
895+put lx_pick 0 row
896+if eq hop_activate 1
897+put lx_s 18 1
898+else
899+lx_draw
900+end
901+end
902+fn lx_main to int
903+if ne lx_setup 0
904+ret 1
905+end
906+lx_makewin
907+lx_changed
908+while eq get lx_s 18 0 bound 9223372036854775807
909+lx_read 0 32
910+kind = and get lx_buf 0 127
911+if eq kind 0
912+lx_bad
913+end
914+if eq kind 1
915+lx_read 32 mul lx_u32 4 4
916+end
917+if eq kind 2
918+lx_key
919+end
920+if eq kind 4
921+lx_click
922+end
923+if eq kind 12
924+lx_draw
925+end
926+if eq kind 17
927+put lx_s 18 1
928+end
929+if eq kind 22
930+w = lx_u16 20
931+h = lx_u16 22
932+if and ge w 200 ge h 200
933+put lx_s 11 w
934+put lx_s 12 h
935+lx_draw
936+end
937+end
938+if eq kind 33
939+if eq lx_u32 8 get lx_s 9
940+if eq lx_u32 12 get lx_s 10
941+put lx_s 18 1
942+end
943+end
944+end
945+end
946+k = fclose int get lx_fd 0
947+ret 0
948+end

README.md

@@ -2,6 +2,8 @@
22
33 Hop is a small native macOS launcher. One shortcut opens one box.
44
5+A [Linux desktop edition for the Spark](Linux/README.md) is in development. It finds and opens applications and indexed files, and supports Ask with a model you configure. The other features described below are currently available in the Mac edition only. Linux build, installation checks and remaining gaps are in the linked guide.
6+
57 **The box works before you type.** When it opens there is no list: a night sky, one point of light, and at most three cards with Hop's best guesses for the moment, most likely first. The guesses are what you just copied (Enter pastes it; a copied web address is offered to open), the app you were in a moment ago, the apps you usually open from the app you are in or at this time of day, and the apps that are open. Enter does the highlighted card; Up and Down choose another. Under the cards is a small button for each screen.
68
79 **Typing brings the list.** An app's name (or part of it, its initials, or a slip of the finger) opens or switches to the app. A file or folder name finds it. Words from something you copied find it to paste. A web address is offered to open. A question goes to Ask, and so does text that matches nothing else: Ask is then the first line, and Enter sends the text where Ask sends it (see "What stays on your Mac"). A screen's name ("accounts", "voice") shows that screen, and "settings" opens the settings file. There is nothing to pick first: no tabs, no prefixes, no screen shortcut.

build.sh

@@ -3,6 +3,18 @@
33 # HOP_SIGN=adhoc signs without any local identity (this is what a public release uses).
44 set -e
55 cd "$(dirname "$0")"
6+if [ "$(uname -s)" = Linux ]; then
7+ mkdir -p build/linux-toolchain
8+ OMEGA_STORE=${OMEGA_STORE:-"$HOME/git/omega-mv.git"}
9+ OMEGA_HEAD=$(git --git-dir="$OMEGA_STORE" rev-parse refs/heads/main)
10+ git --git-dir="$OMEGA_STORE" archive --output=build/linux-toolchain.tar "$OMEGA_HEAD" seed/ng seed/out
11+ tar -xf build/linux-toolchain.tar -C build/linux-toolchain
12+ git --git-dir="$OMEGA_STORE" rev-parse "$OMEGA_HEAD" > build/linux-toolchain/source-commit
13+ (cd build/linux-toolchain && sha256sum -c seed/out/omc.sha256)
14+ build/linux-toolchain/seed/out/omc < Linux/build.om > build/linux-build
15+ chmod +x build/linux-build
16+ exec build/linux-build "$PWD/build/linux-toolchain" "$@"
17+fi
618 export LC_ALL=C # the same source file order on every Mac
719 if [ "${1:-}" = "install" ] && pgrep -u "$(id -u)" -x Hop >/dev/null; then
820 echo "Quit Hop before installing. Running chats are not silently terminated." >&2