interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / hop / Omega / ui / hoppanel.om

8126 lines · 211350 bytes Raw Blame History
1target macos
2om2
3note hoppanel: the first cut of Hop's launcher panel as one Omega program, with no Swift. A window with a search
4note field and a list. Before anything is typed the list offers up to six apps by Hop's own rule (fn swsuggest): the
5note ones you usually open from the app in front or around this hour (habits.json, through fn swlifts), the ones
6note you use most (recents.json), the ones that are running and the one you were just in, each with the reason. What is opened is remembered in those two files as Hop remembers it (fn urecordapp, fn urecent).
7note The apps are the names in /Applications and /System/Applications. Typing narrows the
8note list by Hop's own rules: the matcher (hopfuzz), the test for a web address (weba) and the order of the rows
9note (swrank) are the functions of Omega/hopcore.om, which Omega/gen-ui.sh puts between the two marker notes, so
10note the panel and the one box cannot drift apart. Typed text shows the eight best apps, a row that opens the text when
11note it is a web address, and up to twelve files and folders from Hop's file index (file-index.bin in Hop's folder,
12note which Hop builds: the panel reads it, lower-cases a copy and searches it by the rule of Hop's file search).
13note The Ask row sends the typed text to a model and shows the answer as it arrives, in place of the list: the
14note model is the default one of Hop's settings (config.json) when it is an HTTP one, else the
15note first such; the request is Hop's (POST base/chat/completions, the model, one user message, stream true) and
16note the answer's pieces are read from the server's "data:" lines. The session's delegate methods are Omega code
17note (callback entries 7 and 8), called on the main queue. A model whose key is a saved account is asked with that key. The first row is selected; the down and up arrows move the selection, Enter
18note opens the selected row. Like Hop it then stays: Enter and Escape hide the panel and give the app before it the
19note keyboard back, and a global key (Option Space; Hop itself has Command Space), a click on its Dock icon or opening it again brings it
20note back. It has a small menu (Quit, and Edit with cut, copy, paste, select all) and runs in AppKit's own event
21note loop. The global key is a Carbon hot key whose handler is callback entry 5.
22note The field's two delegate methods, the list's two data-source methods and the field's action are Omega code, reached
23note through the callback entries (libback; omega-mv seed/ng/a64/DESIGN.md s14).
24note With HOPCHECK set in the environment it checks itself instead: it stays in the background and, after half a
25note second, puts "sa" into its field through the field's own editor (so AppKit, not the program, tells the
26note delegate that the text changed), sends that editor arrow down, Enter and Escape as commands, prints
27note "hoppanel apps N shown H first NAME selected R enter APP" and ends after six seconds. Enter reaches the field's
28note action with the field as sender, as a real Enter does, but opens nothing. Status then: 1 when apps were found,
29note the typed text narrowed them, the first one was read back from the list's own data source, the arrow moved the
30note list's selection, Enter chose the selected app, Escape hid the panel, a hot key could be registered (a spare
31note one: Control Option Shift Command F19) and its handler showed the panel again; 2 to 9 name a failed step.
32note The line then ends " key K hid H back B" (K 0 when the key was registered).
33note With HOPCHECK=type:TEXT it types TEXT instead and sends Enter (no arrow), still opening nothing: status 1 when
34note Enter chose a row. With HOPCHECK=open:TEXT it does the same and does open the row: the line ends " opened 1"
35note when the workspace took it, and the status is 1 then. With HOPCHECK=ask:TEXT it types TEXT, sends Enter on the
36note Ask row (first for a question) and does ask the model: the line ends " answer TEXT" and the status is 1 when an
37note answer came. With HOPCHECK=idle it types nothing and sends Enter on the first offer; HOPFRONT=ID then stands for
38note the app in front. With HOPRECORD set as well, a check that opens nothing still remembers what Enter chose,
39note and puts a chosen copied thing on a board of its own (the line then ends " pasted " and what is on it).
40note A check reaches no other machine but through HOPSSH and HOPSCP, its stand-ins for ssh and scp (HOPSSH is
41note also what a check starts in place of ssh for a forwarded port), and HOPLATE sends Enter late, when
42note they have answered. With HOPCHECK=agent:TEXT a check sends TEXT to the agent of the settings and waits for it to end; with
43note HOPAGENTS it first says each agent's command as it would be run.
44note HOPASK2 is a second question a check asks in the same conversation once the first is answered; with
45note HOPASKNEW it starts a new chat first.
46note HOPSCREEN (clipboard or accounts) starts a check in that screen, and HOPCLIPDO (pin or delete) does that to
47note the selected copied thing before Enter. With HOPCLIPREC a check first records what is on its own board into the history, as the program that stays
48note does for the real clipboard. HOPCLIPKEY is the clipboard key for a check, in base64, or "tool:" and the name of a Keychain item of the
49note security tool to read it from (the repository's checks use an item of their own, made and deleted there). HOPROW is the row Enter is sent on.
50note Without HOPCHECK it runs until it is quit.
51text s_appkit "/System/Library/Frameworks/AppKit.framework/AppKit"
52text s_gc "objc_getClass"
53text s_sr "sel_registerName"
54text s_ms "objc_msgSend"
55text s_wr "write"
56text s_acp "objc_allocateClassPair"
57text s_cam "class_addMethod"
58text s_rcp "objc_registerClassPair"
59text s_strlen "strlen"
60text s_memcpy "memcpy"
61text s_getenv "getenv"
62text c_pool "NSAutoreleasePool"
63text c_app "NSApplication"
64text c_win "NSWindow"
65text c_str "NSString"
66text c_field "NSTextField"
67text c_scroll "NSScrollView"
68text c_table "NSTableView"
69text c_col "NSTableColumn"
70text c_fm "NSFileManager"
71text c_obj "NSObject"
72text c_date "NSDate"
73text c_mine "OmegaHopPanel"
74text c_url "NSURL"
75text c_ws "NSWorkspace"
76text m_alloc "alloc"
77text m_init "init"
78text m_shared "sharedApplication"
79text m_policy "setActivationPolicy:"
80text m_initwi "initWithContentRect:styleMask:backing:defer:"
81text m_utf "stringWithUTF8String:"
82text m_cstr "UTF8String"
83text m_title "setTitle:"
84text m_conten "contentView"
85text m_addsub "addSubview:"
86text m_initfr "initWithFrame:"
87text m_label "labelWithString:"
88text m_setfra "setFrame:"
89text m_placeh "setPlaceholderString:"
90text m_setdel "setDelegate:"
91text m_settar "setTarget:"
92text m_setact "setAction:"
93text m_initid "initWithIdentifier:"
94text m_setwid "setWidth:"
95text m_addcol "addTableColumn:"
96text m_header "setHeaderView:"
97text m_dataso "setDataSource:"
98text m_docvie "setDocumentView:"
99text m_scroll "setHasVerticalScroller:"
100text m_reload "reloadData"
101text m_strval "stringValue"
102text m_setstr "setStringValue:"
103text m_defaul "defaultManager"
104text m_conte1 "contentsOfDirectoryAtPath:error:"
105text m_count "count"
106text m_at "objectAtIndex:"
107text m_finish "finishLaunching"
108text m_front "orderFrontRegardless"
109text m_visibl "isVisible"
110text m_close "close"
111text m_since "dateWithTimeIntervalSinceNow:"
112text m_next "nextEventMatchingMask:untilDate:inMode:dequeue:"
113text m_send "sendEvent:"
114text m_change "controlTextDidChange:"
115text m_rows "numberOfRowsInTableView:"
116text m_value "tableView:objectValueForTableColumn:row:"
117text m_go "go:"
118text m_furl "fileURLWithPath:"
119text m_shws "sharedWorkspace"
120text m_open "openURL:"
121text m_activ "activateIgnoringOtherApps:"
122text m_key "makeKeyAndOrderFront:"
123text m_firstr "makeFirstResponder:"
124text m_down "moveDown:"
125text m_up "moveUp:"
126text m_cancel "cancelOperation:"
127text m_selrow "selectRowIndexes:byExtendingSelection:"
128text m_ixwith "indexSetWithIndex:"
129text m_scrrow "scrollRowToVisible:"
130text m_cmd "control:textView:doCommandBySelector:"
131text m_selrd "selectedRow"
132text c_ixset "NSIndexSet"
133text t_b "B@:@@:"
134text m_curred "currentEditor"
135text m_instxt "insertText:"
136text m_docmd "doCommandBySelector:"
137text m_newln "insertNewline:"
138text t_v "v@:@"
139text t_q "q@:@"
140text t_o "@@:@@q"
141text x_title "Hop (Omega)"
142text x_hint "Type to find an app"
143text x_dir1 "/Applications"
144text x_dir2 "/System/Applications"
145text x_mode "kCFRunLoopDefaultMode"
146text x_name "name"
147text x_typed "sa"
148text x_out1 "hoppanel apps "
149text x_out2 " shown "
150text x_out3 " first "
151text x_out4 " selected "
152text x_out5 " enter "
153text x_out6 " opened "
154text x_https "https://"
155text x_open "Open "
156text m_urlstr "URLWithString:"
157text m_host "host"
158text s_carbon "/System/Library/Frameworks/Carbon.framework/Carbon"
159text s_event_target "GetApplicationEventTarget"
160text s_install_handler "InstallEventHandler"
161text s_register_key "RegisterEventHotKey"
162text m_order_out "orderOut:"
163text m_hide_app "hide:"
164text m_released "setReleasedWhenClosed:"
165text m_set_app_delegate "setDelegate:"
166text m_reopen "applicationShouldHandleReopen:hasVisibleWindows:"
167text m_run "run"
168text m_terminate "terminate:"
169text m_set_menu "setMainMenu:"
170text m_add_item "addItem:"
171text m_set_submenu "setSubmenu:"
172text m_init_title "initWithTitle:"
173text m_init_item "initWithTitle:action:keyEquivalent:"
174text m_cut "cut:"
175text m_copy "copy:"
176text m_paste "paste:"
177text m_select_all "selectAll:"
178text c_menu "NSMenu"
179text c_menu_item "NSMenuItem"
180text t_reopen "B@:@B"
181text t_handler "i^v^v^v"
182text x_quit "Quit Hop Omega"
183text x_edit "Edit"
184text x_cut "Cut"
185text x_copy "Copy"
186text x_paste "Paste"
187text x_select_all "Select All"
188text x_key_q "q"
189text x_key_x "x"
190text x_key_c "c"
191text x_key_v "v"
192text x_key_a "a"
193text x_app "Hop Omega"
194text x_out7 " key "
195text x_out8 " hid "
196text x_out9 " back "
197text s_malloc "malloc"
198text s_memmem "memmem"
199text s_memchr "memchr"
200text s_memrchr "memrchr"
201text c_data "NSData"
202text m_data_file "dataWithContentsOfFile:"
203text m_retain "retain"
204text m_bytes "bytes"
205text m_length "length"
206text x_env_dir "HOP_CONFIG_DIR"
207text x_env_home "HOME"
208text x_support "/Library/Application Support/Hop"
209text x_index "/file-index.bin"
210text x_gap " - "
211text x_dotapp_low ".app"
212text x_dir1_low "/applications/"
213text x_dir2_low "/system/applications/"
214text x_config "/config.json"
215text c_json "NSJSONSerialization"
216text c_dict "NSDictionary"
217text c_array "NSArray"
218text c_number "NSNumber"
219text c_mutable_dict "NSMutableDictionary"
220text c_mutable_string "NSMutableString"
221text c_request "NSMutableURLRequest"
222text c_session "NSURLSession"
223text c_session_config "NSURLSessionConfiguration"
224text c_queue "NSOperationQueue"
225text c_text_view "NSTextView"
226text m_json_object "JSONObjectWithData:options:error:"
227text m_json_data "dataWithJSONObject:options:error:"
228text m_object_for_key "objectForKey:"
229text m_is_kind "isKindOfClass:"
230text m_equal_string "isEqualToString:"
231text m_has_suffix "hasSuffix:"
232text m_substring_to "substringToIndex:"
233text m_append_string "stringByAppendingString:"
234text m_append "appendString:"
235text m_set_string "setString:"
236text m_string "string"
237text m_dictionary "dictionary"
238text m_set_object "setObject:forKey:"
239text m_array_with "arrayWithObject:"
240text m_number_bool "numberWithBool:"
241text m_request_url "requestWithURL:"
242text m_set_method "setHTTPMethod:"
243text m_set_header "setValue:forHTTPHeaderField:"
244text m_set_body "setHTTPBody:"
245text m_set_timeout "setTimeoutInterval:"
246text m_ephemeral "ephemeralSessionConfiguration"
247text m_main_queue "mainQueue"
248text m_session_with "sessionWithConfiguration:delegate:delegateQueue:"
249text m_data_task "dataTaskWithRequest:"
250text m_resume "resume"
251text m_cancel_task "cancel"
252text m_data_bytes "dataWithBytes:length:"
253text m_set_editable "setEditable:"
254text m_set_hidden "setHidden:"
255text m_description "localizedDescription"
256text m_response "response"
257text m_status_code "statusCode"
258text m_did_data "URLSession:dataTask:didReceiveData:"
259text m_did_complete "URLSession:task:didCompleteWithError:"
260text t_session "v@:@@@"
261text k_models "models"
262text k_default "defaultModel"
263text k_name "name"
264text k_base "baseURL"
265text k_model "model"
266text k_kind "kind"
267text k_key "keychainKey"
268text k_messages "messages"
269text k_stream "stream"
270text k_role "role"
271text k_content "content"
272text k_choices "choices"
273text k_delta "delta"
274text k_message "message"
275text x_openai "openai"
276text x_user "user"
277text x_post "POST"
278text x_json_type "application/json"
279text x_content_type "Content-Type"
280text x_slash_text "/"
281text x_completions "/chat/completions"
282text x_ask "Ask "
283text x_colon ": "
284text x_ask_none "Ask: no model in Hop's settings that can be asked from here"
285text x_asking "Asking ..."
286text x_no_answer "[no answer]"
287text x_http "[HTTP "
288text x_busy "The model is busy right now. Try again in a moment. "
289text x_bracket "]"
290text x_out10 " answer "
291text s_pow "pow"
292text s_log2 "log2"
293text c_calendar "NSCalendar"
294text c_running_app "NSRunningApplication"
295text m_current_calendar "currentCalendar"
296text m_component "component:fromDate:"
297text m_date_now "date"
298text m_current_app "currentApplication"
299text m_frontmost "frontmostApplication"
300text m_running_apps "runningApplications"
301text m_policy_of "activationPolicy"
302text m_bundle_id "bundleIdentifier"
303text m_bundle_url "bundleURL"
304text m_path "path"
305text m_localized_name "localizedName"
306text m_integer_value "integerValue"
307text m_double_value "doubleValue"
308text m_number_integer "numberWithInteger:"
309text m_reference_now "timeIntervalSinceReferenceDate"
310text x_habits "/habits.json"
311text x_recents "/recents.json"
312text x_mac_key "Mac:"
313text x_env_front "HOPFRONT"
314text k_app "app"
315text k_from "from"
316text k_hour "hour"
317text k_count "count"
318text k_last "last"
319text x_why4 "You often open this from "
320text x_here "here"
321text x_why5 "You were just here"
322text x_why6 "You often open this around now"
323text x_why7 "One of your most used"
324text x_why8 "Running now"
325text s_chmod "chmod"
326text c_mutable_array "NSMutableArray"
327text m_array "array"
328text m_add_object "addObject:"
329text m_remove_range "removeObjectsInRange:"
330text m_remove_key "removeObjectForKey:"
331text m_all_keys "allKeys"
332text m_number_double "numberWithDouble:"
333text m_write_file "writeToFile:atomically:"
334text k_at_key "at"
335text k_path "path"
336text x_env_record "HOPRECORD"
337text s_memset "memset"
338text s_trusted "AXIsProcessTrusted"
339text s_key_event "CGEventCreateKeyboardEvent"
340text s_event_flags "CGEventSetFlags"
341text s_event_post "CGEventPost"
342text s_cf_release "CFRelease"
343text x_security "/usr/bin/security"
344text x_find "find-generic-password"
345text x_dash_s "-s"
346text x_clip_service "com.aienos.hop.clipboard"
347text x_dash_a "-a"
348text x_clip_account "storage-key-v2"
349text x_dash_w "-w"
350text x_clipboard_file "/clipboard.bin"
351text x_clip_images "/clip-images/"
352text x_env_clipkey "HOPCLIPKEY"
353text x_env_row "HOPROW"
354text x_env_vault "HOPVAULT"
355text x_env_cliprec "HOPCLIPREC"
356text x_real_ssh "/usr/bin/ssh"
357text x_nc "/usr/bin/nc"
358text x_nc_args "-z|-G|2|127.0.0.1"
359text m_probe_done "probeDone:"
360text m_all_keys_for "allKeysForObject:"
361text m_remove_for_key "removeObjectForKey:"
362text m_note_object "object"
363text m_is_equal_number "isEqualToNumber:"
364text s_cf_true "kCFBooleanTrue"
365text s_cf_false "kCFBooleanFalse"
366text x_out16 " links "
367text x_tunnel_args "-N|-o|ControlMaster=no|-o|ControlPath=none|-o|BatchMode=yes|-o|ExitOnForwardFailure=yes|-o|ServerAliveInterval=15|-o|ServerAliveCountMax=3|-o|ConnectTimeout=8|-L"
368text x_loopback "127.0.0.1:"
369text k_tunnels "tunnels"
370text k_local_port "localPort"
371text k_remote_port "remotePort"
372text k_ssh_host "sshHost"
373text k_cortex "cortex"
374text k_enabled "enabled"
375text k_url "url"
376text k_host "host"
377text m_url_port "port"
378text m_is_executable "isExecutableFileAtPath:"
379text m_all_values "allValues"
380text s_will_terminate "NSApplicationWillTerminateNotification"
381text m_app_quit "appQuit:"
382text x_env_menu "HOPMENU"
383text x_status_symbol "bolt.horizontal.circle"
384text x_status_open "Open Hop Omega (Option Space)"
385text x_status_index "Rebuild file index"
386text x_status_paste "Allow paste into apps ..."
387text x_status_login "Open at login"
388text x_status_settings "Settings (edit config file) ..."
389text x_status_clear "Clear clipboard history"
390text x_key_comma ","
391text x_menu_word "menu "
392text c_status_bar "NSStatusBar"
393text m_system_status_bar "systemStatusBar"
394text m_status_item_length "statusItemWithLength:"
395text m_button "button"
396text m_set_image "setImage:"
397text m_symbol_image "imageWithSystemSymbolName:accessibilityDescription:"
398text m_set_target "setTarget:"
399text m_set_state "setState:"
400text m_separator "separatorItem"
401text m_set_item_menu "setMenu:"
402text m_item_array "itemArray"
403text m_item_title "title"
404text m_menu_open "menuOpen:"
405text m_menu_index "menuIndex:"
406text m_menu_paste "menuPaste:"
407text m_menu_login "menuLogin:"
408text m_menu_settings "menuSettings:"
409text m_menu_clear "menuClear:"
410text s_trusted_options "AXIsProcessTrustedWithOptions"
411text s_trusted_prompt "kAXTrustedCheckOptionPrompt"
412text x_sm_path "/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement"
413text c_sm_service "SMAppService"
414text m_main_app "mainAppService"
415text m_status "status"
416text m_register "registerAndReturnError:"
417text m_unregister "unregisterAndReturnError:"
418text x_login_failed "Couldn't change Open at login"
419text x_textedit "/System/Applications/TextEdit.app"
420text c_open_config "NSWorkspaceOpenConfiguration"
421text m_configuration "configuration"
422text m_open_urls_with "openURLs:withApplicationAtURL:configuration:completionHandler:"
423text x_empty_settings "{}"
424text x_env_ssh "HOPSSH"
425text x_env_scp "HOPSCP"
426text x_env_late "HOPLATE"
427text x_ssh_word "ssh"
428text x_scp_word "scp"
429text x_ssh_options " -o BatchMode=yes -o ConnectTimeout=8 "
430text x_scp_options " -q -o BatchMode=yes "
431text x_remote_a "d=~/.cache/hop/shards; [ -f $d/s00 ] || { echo HOP-NO-INDEX; exit 0; }; t=$(mktemp -d /dev/shm/hop.XXXXXX 2>/dev/null || mktemp -d); for s in $d/s*; do ( "
432text x_remote_grep "LC_ALL=C grep -F -i -- "
433text x_remote_shard " %%$s%%"
434text x_remote_pipe " | "
435text x_remote_b " | head -300 > %%$t/${s##*/}%% ) & done; wait; cat %%$t%%/*; rm -rf %%$t%%"
436text x_local_a "( "
437text x_local_b "; [ $? = 255 ] && echo HOP-UNREACHABLE ) 2>/dev/null | sed 's/^/"
438text x_local_c ":/' &"
439text x_wait_word "wait"
440text x_build_a "cd ~/.cache/hop && find "
441text x_build_b " -xdev ^^( -path '*/.*' -o "
442text x_build_c " ^^) -prune -o -type d -printf '%p/^^n' -o -printf '%p^^n' > index.tmp 2>/dev/null && rm -rf shards.new && mkdir shards.new && split -n l/20 -d -a 2 index.tmp shards.new/s && rm -f index.tmp index.txt && rm -rf shards.old && { [ ! -d shards ] || mv shards shards.old; } && mv shards.new shards && rm -rf shards.old; rm -f index.tmp; rmdir ~/.cache/hop/building"
443text x_name_flag "-name "
444text x_or_flag " -o "
445text x_fresh_a "mkdir -p ~/.cache/hop; f=~/.cache/hop/shards/s00"
446text x_fresh_b "if [ -d ~/.cache/hop/building ] && [ -n %%$(find ~/.cache/hop/building -maxdepth 0 -mmin +180 2>/dev/null)%% ]; then rmdir ~/.cache/hop/building; fi"
447text x_fresh_c "if [ ! -f $f ] || [ -n %%$(find $f -mmin +30 2>/dev/null)%% ]; then if mkdir ~/.cache/hop/building 2>/dev/null; then nohup nice -n 19 ionice -c3 sh -c "
448text x_fresh_d " >/dev/null 2>&1 & fi; fi"
449text x_fresh_e "echo ok"
450text x_percents "%%"
451text x_carets "^^"
452text x_fetch_a "sz=$("
453text x_fetch_stat "stat -c %s -- "
454text x_fetch_b ") && [ %%$sz%% -le 2000000000 ] && mkdir -p "
455text x_fetch_c " && "
456text x_fetch_d " && echo HOP-FETCHED"
457text x_fetched "HOP-FETCHED"
458text x_no_index "HOP-NO-INDEX"
459text x_unreachable "HOP-UNREACHABLE"
460text x_remote_cache "/Library/Caches/Hop/remote/"
461text x_check_cache "/remote/"
462text x_on " on "
463text x_note_unreachable " is unreachable right now"
464text x_note_building " is building its file list ..."
465text x_note_bringing "Bringing it over from "
466text x_note_copied "Copied the path on the clipboard: "
467text x_note_failed "Could not bring it over; its path is on the clipboard: "
468text x_out13 " fetched "
469text x_out14 " machine "
470text x_out15 " says "
471text k_roots_m "roots"
472text k_skip_m "skip"
473text m_remote_go "remoteGo:"
474text m_remote_done "remoteDone:"
475text m_fetch_done "fetchDone:"
476text m_read_to_end "readToEndOfFileInBackgroundAndNotify"
477text s_read_to_end_done "NSFileHandleReadToEndOfFileCompletionNotification"
478text m_cancel_previous "cancelPreviousPerformRequestsWithTarget:selector:object:"
479text m_dir_of "stringByDeletingLastPathComponent"
480text x_mskip0 ".git"
481text x_mskip1 "node_modules"
482text x_mskip2 "target"
483text x_mskip3 "__pycache__"
484text x_mskip4 "venv"
485text x_mskip5 ".venv"
486text x_mskip6 "site-packages"
487text x_mskip7 "build"
488text x_mskip8 "dist"
489text x_mskip9 "proc"
490text x_engine0 "Claude Code"
491text x_engine0_command "claude|-p|{prompt}|--output-format|stream-json|--verbose"
492text x_engine1 "Codex"
493text x_engine1_command "codex|exec|--skip-git-repo-check|{prompt}"
494text x_engine2 "Grok"
495text x_engine2_command "grok|-p|{prompt}"
496text x_engine3 "Gemini"
497text x_engine3_command "gemini|-p|{prompt}"
498text x_engine4 "OpenCode"
499text x_engine4_command "opencode|run|{prompt}"
500text x_engine5 "Cursor"
501text x_engine5_command "cursor-agent|-p|--output-format|text|{prompt}"
502text x_engine6 "Hermes"
503text x_engine6_command "hermes|-z|{prompt}"
504text x_old0_command "codex|exec|--skip-git-repo-check|--dangerously-bypass-approvals-and-sandbox|{prompt}"
505text x_old1_command "grok|--always-approve|-p|{prompt}"
506text x_old2_command "gemini|-y|-p|{prompt}"
507text x_old3_command "cursor-agent|-p|-f|--output-format|text|{prompt}"
508text x_old4_command "hermes|--yolo|-z|{prompt}"
509text x_path0 ".local/bin"
510text x_path1 ".claude/local"
511text x_path2 "/opt/homebrew/bin"
512text x_path3 "/usr/local/bin"
513text x_path4 ".bun/bin"
514text x_path5 ".npm-global/bin"
515text x_path6 ".cargo/bin"
516text x_path7 ".opencode/bin"
517text x_path8 ".volta/bin"
518text x_path9 ".asdf/shims"
519text x_path10 ".local/share/mise/shims"
520text x_path11 "bin"
521text x_custom_command "Custom command"
522text x_legacy_mark "HOP-LEGACY-COMMAND"
523text x_zsh "/bin/zsh"
524text x_dash_lc "-lc"
525text x_wrapper "[ -n ~$HOP_EXTRA_PATH~ ] && PATH=~$PATH:$HOP_EXTRA_PATH~; unset HOP_EXTRA_PATH; exec ~$@~"
526text x_tilde "~"
527text x_hop_word "hop"
528text x_sh "sh"
529text x_dash_c "-c"
530text x_probe_a "command -v "
531text x_probe_b " >/dev/null 2>&1 && echo "
532text x_true_word "true"
533text x_term "TERM"
534text x_dumb "dumb"
535text x_no_color "NO_COLOR"
536text x_one "1"
537text x_extra_path "HOP_EXTRA_PATH"
538text x_colon_only ":"
539text x_nvm "/.nvm/versions/node"
540text x_herd "/Library/Application Support/Herd/config/nvm/versions/node"
541text x_slash_bin "/bin"
542text x_prompt_mark "{prompt}"
543text x_claude "claude"
544text x_append_system "--append-system-prompt"
545text x_resume "--resume"
546text x_request "Request: "
547text x_the_user "the user"
548text x_brief_a "'s agent."
549text x_brief_b " All machines = one box; never ask which. Mac = here. "
550text x_brief_c " (auto-routed). Find files anywhere: hop find <words>."
551text x_brief_d " Factory: "
552text x_brief_e " Never delete agent files. Back up before destructive changes. Reply short, plain words."
553text x_ssh_a ": ssh "
554text x_ssh_b " '<cmd>'"
555text x_semi_space "; "
556text x_period "."
557text x_agent_row "Agent fixes it: "
558text x_brace "{"
559text x_bang "! "
560text x_tool_word "tool"
561text x_tool_mark "> "
562text x_agent_error "agent error"
563text x_agent_none_a "No coding agent was found on this Mac. Install one of these, sign in to it, then open Hop Omega again: "
564text x_agent_none_b "No coding agent was found on this Mac. Add an agent command to Hop's settings."
565text x_agent_missing_a " is set as your agent but is not installed on this Mac. Installed here: "
566text x_agent_missing_b ". Name one of them as agentEngine in Hop's settings. Nothing was run."
567text x_agent_stopped_a "Agent stopped (exit "
568text x_agent_stopped_b ")."
569text x_agent_working "The agent is working ..."
570text x_agent_busy "The agent is still working on the last request. Nothing new was run."
571text x_agent_ask "Let the agent work on this Mac?"
572text x_agent_ask_more "It can read and change files on this Mac, with the command of Hop's settings. Hop Omega asks this once each time it is started, until Hop itself has been told yes."
573text x_agent_yes "Run the agent"
574text x_agent_no "Cancel"
575text x_comma_space ", "
576text x_paren_a " ("
577text x_paren_b ")"
578text x_screen2 "Agent"
579text x_screen2_about "what the agent said"
580text x_word_agent "agent"
581text x_stop_item "Stop the Agent"
582text x_key_period "."
583text x_agent_menu "Agent"
584text c_alert "NSAlert"
585text m_set_message "setMessageText:"
586text m_set_informative "setInformativeText:"
587text m_add_button "addButtonWithTitle:"
588text m_run_modal "runModal"
589text c_center "NSNotificationCenter"
590text m_default_center "defaultCenter"
591text m_add_observer "addObserver:selector:name:object:"
592text m_remove_all_observer "removeObserver:name:object:"
593text s_read_done "NSFileHandleReadCompletionNotification"
594text s_data_item "NSFileHandleNotificationDataItem"
595text s_task_ended "NSTaskDidTerminateNotification"
596text m_read_background "readInBackgroundAndNotify"
597text m_user_info "userInfo"
598text m_set_cwd "setCurrentDirectoryPath:"
599text m_set_environment "setEnvironment:"
600text m_set_input "setStandardInput:"
601text m_environment "environment"
602text m_mutable_copy "mutableCopy"
603text m_terminate_task "terminate"
604text m_is_equal_array "isEqualToArray:"
605text m_range_of_data "rangeOfData:options:range:"
606text m_subdata "subdataWithRange:"
607text m_replace_bytes "replaceBytesInRange:withBytes:length:"
608text m_append_data "appendData:"
609text m_joined "componentsJoinedByString:"
610text m_uppercase "uppercaseString"
611text m_substring_from "substringFromIndex:"
612text m_contents_of_dir "contentsOfDirectoryAtPath:error:"
613text m_standard_compare "localizedStandardCompare:"
614text m_newline_set "newlineCharacterSet"
615text m_agent_out "agentOut:"
616text m_agent_err "agentErr:"
617text m_agent_end "agentEnd:"
618text m_agent_stop "stopAgent:"
619text k_engines "agentEngines"
620text k_engine "agentEngine"
621text k_agent_command "agentCommand"
622text k_agent_folder "agentWorkingDirectory"
623text k_enter_agent "enterSendsToAgent"
624text k_agent_confirmed "agentConfirmed"
625text k_keep_flags "keepAgentFlags"
626text k_command "command"
627text k_owner "ownerName"
628text k_machines "machines"
629text k_ssh "ssh"
630text k_factory_url "factoryURL"
631text k_type "type"
632text k_parts_text "text"
633text k_tool_use "tool_use"
634text k_result "result"
635text k_is_error "is_error"
636text k_session_id "session_id"
637text x_env_ask2 "HOPASK2"
638text x_env_agents "HOPAGENTS"
639text x_engine_word "engine "
640text x_env_asknew "HOPASKNEW"
641text m_array_adding "arrayByAddingObject:"
642text m_remove_last "removeLastObject"
643text x_assistant "assistant"
644text x_you "You: "
645text x_command3 "New chat"
646text x_word_new_chat "new chat"
647text x_word_clear_chat "clear chat"
648text s_free "free"
649text s_iopolicy "setiopolicy_np"
650text s_home_directory "NSHomeDirectory"
651text s_key_directory "NSURLIsDirectoryKey"
652text s_key_package "NSURLIsPackageKey"
653text s_key_link "NSURLIsSymbolicLinkKey"
654text s_modified "NSFileModificationDate"
655text c_process_info "NSProcessInfo"
656text m_process_info "processInfo"
657text m_arguments "arguments"
658text c_bundle "NSBundle"
659text m_main_bundle "mainBundle"
660text m_executable_path "executablePath"
661text m_drain "drain"
662text c_set "NSSet"
663text m_set_with_array "setWithArray:"
664text m_enumerator "enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:"
665text m_next_object "nextObject"
666text m_get_resource "getResourceValue:forKey:error:"
667text m_last_component "lastPathComponent"
668text m_skip_descendants "skipDescendants"
669text m_is_running "isRunning"
670text m_attributes_of "attributesOfItemAtPath:error:"
671text m_since_now "timeIntervalSinceNow"
672text k_roots "indexRoots"
673text k_skip_names "indexSkipNames"
674text x_index_word "index"
675text x_applications "/Applications"
676text x_system_applications "/System/Applications"
677text x_indexed "indexed "
678text x_items " items"
679text x_indexing " (indexing files ...)"
680text x_command2 "Rebuild file index"
681text x_word_rebuild "rebuild file index"
682text x_word_reindex "reindex"
683text x_word_index_files "index files"
684text x_skipname0 "Library"
685text x_skipname1 "node_modules"
686text x_skipname2 ".git"
687text x_skipname3 "target"
688text x_skipname4 "build"
689text x_skipname5 "dist"
690text x_skipname6 "DerivedData"
691text x_skipname7 "__pycache__"
692text x_skipname8 "venv"
693text x_skipname9 ".venv"
694text x_skipname10 ".cache"
695text x_skipname11 "Caches"
696text x_skipname12 ".Trash"
697text x_skipname13 "site-packages"
698text x_skipname14 ".build"
699text x_skipname15 "Pods"
700text x_word0 "clipboard"
701text x_word1 "copied"
702text x_word2 "clipboard history"
703text x_word3 "accounts"
704text x_word4 "keys"
705text x_word5 "api keys"
706text x_word6 "passwords"
707text x_word7 "logins"
708text x_word8 "settings"
709text x_word9 "preferences"
710text x_word10 "config"
711text x_word11 "hop settings"
712text x_word12 "quit hop"
713text x_screen0 "Clipboard"
714text x_screen0_about "your copied things"
715text x_screen1 "Accounts"
716text x_screen1_about "your saved keys and logins"
717text x_command0 "Settings"
718text x_command0_about "opens Hop's settings file"
719text x_command1 "Quit Hop Omega"
720text x_copied_things " copied things"
721text x_accounts_word " accounts"
722text x_pinned "pinned"
723text x_env_screen "HOPSCREEN"
724text x_env_clipdo "HOPCLIPDO"
725text x_clip_menu "Clipboard"
726text x_pin_item "Pin or Unpin"
727text x_delete_item "Delete from History"
728text x_key_p "p"
729text x_key_d "d"
730text m_pin_clip "pinClip:"
731text m_delete_clip "deleteClip:"
732text x_out12 " screen "
733text s_random "arc4random_buf"
734text c_uuid "NSUUID"
735text m_uuid "UUID"
736text m_uuid_string "UUIDString"
737text c_timer "NSTimer"
738text m_timer "scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:"
739text m_clip_tick "clipTick:"
740text m_change_count "changeCount"
741text m_types "types"
742text m_contains_object "containsObject:"
743text c_image "NSImage"
744text m_init_pasteboard "initWithPasteboard:"
745text m_tiff "TIFFRepresentation"
746text c_bitmap "NSBitmapImageRep"
747text m_rep_with_data "imageRepWithData:"
748text m_rep_using "representationUsingType:properties:"
749text m_running_with "runningApplicationsWithBundleIdentifier:"
750text x_hop_id "com.aienos.hop"
751text k_id "id"
752text k_source "sourceApp"
753text k_limit "clipboardLimit"
754text m_insert_at "insertObject:atIndex:"
755text m_remove_at "removeObjectAtIndex:"
756text m_byte_length "lengthOfBytesUsingEncoding:"
757text c_mutable_data "NSMutableData"
758text m_data "data"
759text m_append_bytes "appendBytes:length:"
760text c_file_manager "NSFileManager"
761text m_default_manager "defaultManager"
762text m_file_exists "fileExistsAtPath:"
763text m_remove_item "removeItemAtPath:error:"
764text m_create_dir "createDirectoryAtPath:withIntermediateDirectories:attributes:error:"
765text x_clip_backup "/clipboard.before-hop-omega.bin"
766text x_dot_bin ".bin"
767text x_skip0 "org.nspasteboard.ConcealedType"
768text x_skip1 "org.nspasteboard.TransientType"
769text x_skip2 "org.nspasteboard.AutoGeneratedType"
770text x_skip3 "com.agilebits.onepassword"
771text x_skip4 "com.typeit4me.clipping"
772text x_skip5 "de.petermaurer.TransientPasteboardType"
773text x_env_vault_add "HOPVAULTADD"
774text s_item_add "SecItemAdd"
775text s_item_delete "SecItemDelete"
776text s_interaction "SecKeychainSetUserInteractionAllowed"
777text s_value_data "kSecValueData"
778text s_accessible "kSecAttrAccessible"
779text s_accessible_unlocked "kSecAttrAccessibleWhenUnlockedThisDeviceOnly"
780text m_data_using "dataUsingEncoding:"
781text x_semicolon ";"
782text x_bar "|"
783text x_vault_service "com.aienos.hop.vault"
784text s_item_copy "SecItemCopyMatching"
785text s_class "kSecClass"
786text s_class_generic "kSecClassGenericPassword"
787text s_attr_service "kSecAttrService"
788text s_attr_account "kSecAttrAccount"
789text s_attr_description "kSecAttrDescription"
790text s_attr_comment "kSecAttrComment"
791text s_match_limit "kSecMatchLimit"
792text s_limit_all "kSecMatchLimitAll"
793text s_limit_one "kSecMatchLimitOne"
794text s_return_attributes "kSecReturnAttributes"
795text s_return_data "kSecReturnData"
796text s_true "kCFBooleanTrue"
797text m_sorted "sortedArrayUsingSelector:"
798text m_compare "compare:"
799text m_has_prefix "hasPrefix:"
800text m_declare_types "declareTypes:owner:"
801text x_type_concealed "org.nspasteboard.ConcealedType"
802text x_bearer "Bearer "
803text x_authorization "Authorization"
804text x_no_key "[The key of this model could not be read from the Keychain]"
805text x_check_board "com.aienos.hop.omega.check"
806text c_task "NSTask"
807text c_pipe "NSPipe"
808text c_file_handle "NSFileHandle"
809text c_pasteboard "NSPasteboard"
810text c_charset "NSCharacterSet"
811text m_set_launch "setLaunchPath:"
812text m_set_arguments "setArguments:"
813text m_pipe "pipe"
814text m_set_output "setStandardOutput:"
815text m_set_error "setStandardError:"
816text m_null_device "fileHandleWithNullDevice"
817text m_launch "launch"
818text m_reading "fileHandleForReading"
819text m_read_end "readDataToEndOfFile"
820text m_wait "waitUntilExit"
821text m_termination "terminationStatus"
822text m_init_data_encoding "initWithData:encoding:"
823text m_trim "stringByTrimmingCharactersInSet:"
824text m_whitespace "whitespaceAndNewlineCharacterSet"
825text m_init_base64 "initWithBase64EncodedString:options:"
826text m_general_pasteboard "generalPasteboard"
827text m_board_named "pasteboardWithName:"
828text m_clear "clearContents"
829text m_set_string_type "setString:forType:"
830text m_set_data_type "setData:forType:"
831text m_string_for_type "stringForType:"
832text m_data_for_type "dataForType:"
833text m_lowercase "lowercaseString"
834text m_contains "containsString:"
835text m_components "componentsSeparatedByString:"
836text m_replace "stringByReplacingOccurrencesOfString:withString:"
837text m_composed_at "rangeOfComposedCharacterSequenceAtIndex:"
838text m_bool_value "boolValue"
839text m_release "release"
840text m_perform_after "performSelector:withObject:afterDelay:"
841text m_paste_now "pasteNow:"
842text x_type_string "public.utf8-plain-text"
843text x_type_png "public.png"
844text k_text "text"
845text k_image "imageFile"
846text k_pinned "pinned"
847text k_date "date"
848text x_image "Image"
849text x_image_low "image"
850text x_space " "
851text x_paste_row "Paste: "
852text x_why1 "You just copied this"
853text x_why2 "The last thing you copied"
854text x_why3 "You copied a web address"
855text x_out11 " pasted "
856text x_png_word "png "
857text x_browser0 "com.apple.Safari"
858text x_browser1 "com.google.Chrome"
859text x_browser2 "com.brave.Browser"
860text x_browser3 "org.mozilla.firefox"
861text x_browser4 "company.thebrowser.Browser"
862text x_browser5 "com.microsoft.edgemac"
863text x_browser6 "com.operasoftware.Opera"
864text x_browser7 "com.vivaldi.Vivaldi"
865text x_browser8 "app.zen-browser.zen"
866text x_of " of "
867text x_apps " apps"
868text x_slash "/"
869text x_dotapp ".app"
870text x_env "HOPCHECK"
871
872note g_f: library functions. 0 objc_getClass 1 sel_registerName 2 objc_msgSend 3 write 4 objc_allocateClassPair
873note 5 class_addMethod 6 objc_registerClassPair 7 strlen 8 memcpy 9 getenv 10 malloc 11 memmem 12 memchr 13 memrchr
874note 14 pow 15 log2 16 chmod 17 memset 18 AXIsProcessTrusted 19 CGEventCreateKeyboardEvent 20 CGEventSetFlags
875note 21 CGEventPost 22 CFRelease 23 SecItemCopyMatching 24 SecItemAdd 25 SecItemDelete
876note 26 SecKeychainSetUserInteractionAllowed 27 arc4random_buf 28 free 29 setiopolicy_np 30 NSHomeDirectory
877global g_f ulong 32
878note g_o: objects and selectors the callbacks need. 0 field 1 table 2 status line 3 NSString 4 stringWithUTF8String:
879note 5 UTF8String 6 stringValue 7 reloadData 8 setStringValue: 9 moveDown: 10 moveUp: 11 cancelOperation:
880note 12 selectRowIndexes:byExtendingSelection: 13 NSIndexSet 14 indexSetWithIndex: 15 scrollRowToVisible:
881note 16 NSURL 17 URLWithString: 18 host 19 the window 20 orderOut: 21 the application 22 hide:
882note 23 activateIgnoringOtherApps: 24 makeKeyAndOrderFront: 25 makeFirstResponder: 26 orderFrontRegardless
883note 27 the object whose methods are the callbacks 28 the list's scroll view 29 the answer's scroll view
884note 30 the answer's text view
885global g_o ulong 32
886note g_n: 0 apps 1 shown 2 bytes of names 3 times the action ran 4 length of the typed text 5 1 to end the program
887note 6 the selected row 7 1 when Enter may open the row 8 the row Enter chose, plus 1 9 what the workspace answered
888note 10 the typed text as a web address (0 it is none, 1 written with its scheme, 2 a bare address) 12 where the
889note typed text starts once blanks are trimmed 13 its length then 14 1 when the program stays (no HOPCHECK)
890note 15 what registering the hot key gave (0 it is registered) 16 the words of the typed text 17 the files found
891note 18 1 when a file has exactly the typed text as its name 19 bytes of the answer waiting in g_net
892note 20 1 when an answer is on show 21 1 when the model's answer has ended 22 1 when a piece of it came
893note 23 1 when the check asks for what is chosen to be remembered without being opened 24 the count of copied
894note things 25 the bytes of the newest one's text when it may be a web address 26 its address kind 27 the count
895note of other copied things offered 28 the count of copied things that match the typed text 29 what the check
896note pasted (1 text, 2 a picture) 30 the row the check chooses before Enter (0: the first) 31 the count of
897note saved accounts 32 the place plus 1 of the app that was in front before the one in front now
898note 33 1 once the history was set aside before this run's first change to it 34 how many unpinned copied
899note things are kept 35 the clipboard's change count last seen 36 the screen the list shows (0 everything,
900note 1 the copied things, 2 the saved accounts) 37 what a check does to the selected copied thing (1 pin or
901note unpin, 2 delete) 38 half seconds since the file index was last looked at
902note 39 1 when the answer on show belongs to a turn that has ended 40 1 when that turn failed 41 1 when the
903note typed text reads as a question 42 1 when Hop's settings send a sentence to the agent on Enter 43 1 while
904note the agent runs 44 1 once the person said yes to the agent 45 1 once the agents on this Mac were looked
905note for 46 1 when a check sends what it types to the agent 47 what of the agent's run has ended (1 its
906note output, 2 the program) 48 the turn at which a check sends Enter 49 the count of files found on other
907note machines 50 the bytes of what the machines answered 51 what to say about a machine (1 unreachable, 2 building
908note its list, 3 a file is on its way, 4 a path was copied, 5 a file could not be brought) 52 which machine
909note 53 the bytes of the text the machines were asked for 54 the count of machines 55 1 when a check's file
910note arrived 56 the machine and 57 the found file that is on its way 58 1 when a file found on a machine has exactly the typed name
911note 59 1 when other machines may be reached 60 half seconds since the forwarded ports were last looked at
912note 61 how many links this program has started 62 how many forwarded ports the settings name
913global g_n ulong 64
914note g_t: the text HOPCHECK=open:TEXT asks to type
915global g_t uchar 64
916global g_rg uchar 128
917global g_nm uchar 1024
918global g_pool uchar 65536
919global g_off ulong 2048
920global g_ln ulong 2048
921global g_hit ulong 2048
922note g_hit: the app of each row; g_rk: the kind of each row (1 an app, 2 the web address); g_dir: the folder each
923note app is in (0 /Applications, 1 /System/Applications); g_mk and g_ms: the apps hopfuzz matched and their scores
924global g_rk uchar 2048
925global g_dir uchar 2048
926global g_mk ulong 2048
927global g_ms ulong 2048
928global g_q uchar 256
929note g_x: the first row's text, kept for the check's line
930global g_x uchar 256
931note g_ev: the hot key's event type (class 'keyb', kind 5 pressed) and, from byte 8, the reference Carbon gives back
932global g_ev uchar 16
933note The file index. g_fb: 0 where its bytes are (paths, a line each), 1 where the lower-case copy is, 2 how many
934note bytes, 3 1 when it is loaded, 4 the object that holds the bytes. g_chunk: a piece of it on its way to lower case. g_line: one path, lower case.
935note g_lq: the typed text, lower case; g_to and g_tl: where each of its words starts and how long it is.
936note g_fs, g_fo, g_fl: the best 40 files, best first: score plus 100000, where the path starts, how long it is
937global g_fb ulong 8
938note The model. g_m: 0 its id, 1 the address to post to, 2 its name (three NSStrings), 3 1 when there is one,
939note 4 the answer so far (an NSMutableString), 5 the session, 6 the running task, 7 NSDictionary, 8 NSArray,
940note 9 NSString (the classes, to tell what a JSON value is), 10 each app's path and its place (a dictionary),
941note 11 the id of the app in front when the panel was last shown, 12 its name, 13 its place among the apps plus 1,
942note 14 the copied things (an array, newest first), 15 the text each one is shown by, 16 objectAtIndex:,
943note 18 the names of the saved accounts in order, 19 what each is (its kind and note), 20 the Keychain service
944note they are under, 21 the name of the account that holds the model's key (nothing: it needs none), 22 the
945note accounts a check made for itself (an array of their names), to be deleted when it ends, 23 the program
946note that is building the file index now (nothing: none), 24 the conversation with the model (an array of
947note messages, each a role and a content), 25 what was said before the answer on show (a text), 26 the agent's
948note program while it runs, 27 where its output is read, 28 the agents of Hop's settings (each a name and a
949note command), 29 the name of the one to use, 30 the folder it works in, 31 the older single command, 32 its
950note output not yet a whole line, 33 the id of its last run (to carry on from), 34 the settings (for the
951note agent's standing instructions), 35 the agents found on this Mac, 36 when the agent last worked (a number
952note object), 37 where its errors are read, 38 to 41 the selectors agentOut: agentErr: agentEnd: stopAgent:,
953note 42 the ssh names of the machines (an array), 43 the program asking the machines, 44 where its answer is
954note read, 45 the program bringing a file over, 46 to 48 the selectors remoteGo: remoteDone: fetchDone:,
955note 49 where the fetch's answer is read, 50 where the file that is on its way lands (a path), 51 its
956note machine's ssh name and path, for the clipboard, 52 the icon in the menu bar, 53 its Open at login item,
957note 54 to 59 the selectors menuOpen: menuIndex: menuPaste: menuLogin: menuSettings: menuClear:,
958note 60 the forwarded ports to keep open (each: this Mac's port, the far port, the ssh name), 61 the programs
959note that hold them open (by this Mac's port), 62 the selector appQuit:, 63 the programs asking whether a port
960note is served (by the port), 64 the selector probeDone:.
961note g_net: bytes from the server not yet read as lines
962global g_m ulong 80
963global g_net uchar 262144
964note What is offered before anything is typed. g_so: the apps in the order of their paths; g_lf, g_lh: each app's
965note lift from the app in front and from the hour; g_us: how much it is used; g_rn: 1 when it is running;
966note g_fr: the apps that were in front when the panel was shown, newest first (place plus 1); g_why: why each
967note row is offered
968global g_so ulong 2048
969global g_lf ulong 2048
970global g_lh ulong 2048
971global g_us ulong 2048
972global g_rn uchar 2048
973global g_fr ulong 12
974global g_why uchar 2048
975note Copied things. g_ci: all of them in the order they are searched (the pinned ones first); g_cp: 1 for a
976note pinned one; g_cr: the others offered before anything is typed; g_cm: the ones that match the typed text;
977note g_ca: the newest one's text, kept while it may be a web address
978global g_ci ulong 1024
979global g_cp uchar 1024
980global g_cr ulong 20
981global g_cm ulong 1024
982global g_ca uchar 256
983note eight bytes a library function writes a pointer into
984global g_t8 uchar 8
985note Files on other machines. g_rb: what the machines answered (lines "K:path", K the machine's number); g_rq:
986note the text they were asked for; g_ro, g_rl, g_rs, g_rw: the best 64 found, best first (where the path starts in
987note g_rb, its length, its score plus 100000, its machine); g_mn and g_ml: the machines' names
988global g_rb uchar 1048576
989global g_rq uchar 256
990global g_ro ulong 64
991global g_rl ulong 64
992global g_rs ulong 64
993global g_rw uchar 64
994global g_mn uchar 640
995global g_ml uchar 10
996note the byte that ends a line of the file index
997global g_nl uchar 1
998global g_chunk uchar 524288
999global g_line uchar 4096
1000global g_lq uchar 256
1001global g_to ulong 16
1002global g_tl ulong 16
1003global g_fs ulong 64
1004global g_fo ulong 64
1005global g_fl ulong 64
1006
1007note @hopcore
1008
1009fn upr o ulong v ulong to void
1010for i ulong 8
1011put g_rg add o i uchar and shr v mul i 8 255
1012end
1013end
1014
1015fn ugr o ulong to ulong
1016v = ulong 0
1017for i ulong 8
1018v = or v shl ulong get g_rg add o i mul i 8
1019end
1020ret v
1021end
1022
1023note the text into g_nm with a zero byte after it; its length
1024fn ucs t view uchar * to ulong
1025n = len t
1026for i ulong n
1027put g_nm i get t i
1028end
1029put g_nm n 0
1030ret n
1031end
1032
1033note library function k of g_f on the register file; x0 as it came back (an object may have its top bit set)
1034fn ucall k ulong to ulong
1035lr = libcall get g_f k g_rg 0 128
1036ret ugr 0
1037end
1038
1039fn usym t view uchar * to ulong
1040n = ucs t
1041upr 0 18446744073709551614
1042upr 8 ulong libptr g_nm 0 1024
1043lr = libcall ulong libfn 1 g_rg 0 128
1044ret ugr 0
1045end
1046
1047fn ucl t view uchar * to ulong
1048n = ucs t
1049upr 0 ulong libptr g_nm 0 1024
1050ret ucall 0
1051end
1052
1053fn usl t view uchar * to ulong
1054n = ucs t
1055upr 0 ulong libptr g_nm 0 1024
1056ret ucall 1
1057end
1058
1059note [obj s a b c]
1060fn umsg obj ulong s ulong a ulong b ulong c ulong to ulong
1061upr 0 obj
1062upr 8 s
1063upr 16 a
1064upr 24 b
1065upr 32 c
1066ret ucall 2
1067end
1068
1069note an NSString of the zero-ended bytes in g_nm
1070fn unsb to ulong
1071ret umsg get g_o 3 get g_o 4 ulong libptr g_nm 0 1024 0 0
1072end
1073
1074fn uns t view uchar * to ulong
1075n = ucs t
1076ret unsb
1077end
1078
1079note a rectangle for the next message, in d0..d3
1080fn urect x f64 y f64 w f64 h f64 to void
1081upr 64 bitcast ulong x
1082upr 72 bitcast ulong y
1083upr 80 bitcast ulong w
1084upr 88 bitcast ulong h
1085end
1086
1087fn ulower c ulong to ulong
1088if and ge c 65 le c 90
1089ret add c 32
1090end
1091ret c
1092end
1093
1094note the zero-ended bytes at address p into g_nm (at most 1000); their count
1095fn ufetch p ulong to ulong
1096upr 0 p
1097n = ucall 7
1098if gt n 1000
1099n = 1000
1100end
1101upr 0 ulong libptr g_nm 0 1024
1102upr 8 p
1103upr 16 n
1104x = ucall 8
1105put g_nm n 0
1106ret n
1107end
1108
1109note the names in one folder that end in ".app", without that ending, into the pool
1110fn ufolder t view uchar * dn ulong to void
1111c = ucl c_fm
1112s = usl m_defaul
1113mgr = umsg c s 0 0 0
1114s = usl m_conte1
1115path = uns t
1116arr = umsg mgr s path 0 0
1117if eq arr 0
1118ret
1119end
1120s = usl m_count
1121cnt = umsg arr s 0 0 0
1122sat = usl m_at
1123for i ulong cnt bound 4096
1124item = umsg arr sat i 0 0
1125p = umsg item get g_o 5 0 0 0
1126n = ufetch p
1127k = get g_n 0
1128used = get g_n 2
1129if and and gt n 4 lt k 2048 lt add used n 65536
1130if and and eq get g_nm sub n 4 46 eq get g_nm sub n 3 97 and eq get g_nm sub n 2 112 eq get g_nm sub n 1 112
1131m = sub n 4
1132for j ulong m bound 1000
1133put g_pool add used j get g_nm j
1134end
1135put g_off k used
1136put g_ln k m
1137put g_dir k uchar dn
1138put g_n 0 add k 1
1139put g_n 2 add used m
1140end
1141end
1142end
1143end
1144
1145note the word hopfuzz reads for one byte: its lower-case value, bit 32 for a letter or digit (and for every byte of
1146note a longer character), bit 33 for a space or tab
1147fn ufword c ulong to ulong
1148l = ulower c
1149w = l
1150if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128
1151w = or w 4294967296
1152end
1153if or eq l 32 eq l 9
1154w = or w 8589934592
1155end
1156ret w
1157end
1158
1159note how well app k matches the typed text: hopfuzz's score plus 1, or 0 for no match (and for a text over 64 bytes
1160note or a name over 184, which hopfuzz refuses)
1161fn uscore k ulong to ulong
1162inp = new ulong 256 0
1163res = new ulong 256 0
1164ql = get g_n 4
1165nl = get g_ln k
1166o = get g_off k
1167if or gt ql 64 or gt nl 184 eq nl 0
1168ret 0
1169end
1170put inp 0 1212568922
1171put inp 1 1
1172put inp 2 ql
1173put inp 3 nl
1174for i ulong ql bound 64
1175put inp add 8 i ufword ulong get g_q i
1176end
1177for i ulong nl bound 184
1178put inp add 72 i ufword ulong get g_pool add o i
1179end
1180v = hopfuzz inp res
1181if ne v 1
1182ret 0
1183end
1184ret add get res 3 1
1185end
1186
1187note a number in decimal into g_nm from byte p; the byte after it
1188fn upnum p ulong v ulong to ulong
1189d = ulong 1
1190while ge div v d 10 bound 24
1191d = mul d 10
1192end
1193q = p
1194while gt d 0 bound 24
1195put g_nm q uchar add 48 rem div v d 10
1196q = add q 1
1197d = div d 10
1198end
1199ret q
1200end
1201
1202note the text into g_nm from byte p; the byte after it
1203fn uptxt p ulong t view uchar * to ulong
1204for i ulong len t
1205put g_nm add p i get t i
1206end
1207ret add p len t
1208end
1209
1210note name k into g_nm from byte p; the byte after it
1211fn upname p ulong k ulong to ulong
1212o = get g_off k
1213n = get g_ln k
1214for i ulong n bound 1000
1215put g_nm add p i get g_pool add o i
1216end
1217ret add p n
1218end
1219
1220note four bytes and eight bytes into a request for the core, and eight bytes out of its answer; numbers travel with
1221note 2^40 added (k_b), as in Omega/README.md kind 7
1222fn uw32 b edit uchar 1048576 o ulong v ulong to void
1223for i ulong 4
1224put b add o i uchar and shr v mul i 8 255
1225end
1226end
1227
1228fn upb b edit uchar 1048576 k ulong x ulong to void
1229o = add 8 mul k 8
1230for i ulong 8
1231put b add o i uchar and shr x mul i 8 255
1232end
1233end
1234
1235fn upn b edit uchar 1048576 k ulong v ulong to void
1236upb b k add v k_b
1237end
1238
1239fn uog ob view uchar 65544 k ulong to ulong
1240v = ulong 0
1241o = add 8 mul k 8
1242for i ulong 8
1243v = or v shl ulong get ob add o i mul i 8
1244end
1245ret v
1246end
1247
1248note the address the typed text stands for into g_nm from byte p (with "https://" before a bare one); the byte after
1249fn upaddr p ulong to ulong
1250q = p
1251if eq get g_n 10 2
1252q = uptxt p x_https
1253end
1254a = get g_n 12
1255n = get g_n 13
1256for i ulong n bound 256
1257put g_nm add q i get g_q add a i
1258end
1259ret add q n
1260end
1261
1262note is the typed text a web address? The shape is the core's decision (fn weba, text decisions op 3); that macOS
1263note can read it is asked of NSURL, as Hop does. The answer goes to g_n 10
1264fn udecide to void
1265tb = new uchar 1048576 0
1266a = get g_n 12
1267n = get g_n 13
1268put g_n 10 0
1269put g_n 41 0
1270if or eq n 0 gt n 255
1271ret
1272end
1273uw32 tb 0 3
1274uw32 tb 4 n
1275uw32 tb 8 n
1276for i ulong n bound 256
1277l = ulower ulong get g_q add a i
1278o = add 16 mul i 8
1279put tb o uchar l
1280f = ulong 0
1281if or or and ge l 97 le l 122 and ge l 48 le l 57 ge l 128
1282f = 1
1283end
1284if or eq l 32 eq l 9
1285f = 14
1286end
1287put tb add o 4 uchar f
1288end
1289put g_n 41 qlike tb n
1290k = weba tb n n
1291if eq k 0
1292ret
1293end
1294put g_n 10 k
1295p = upaddr 0
1296put g_nm p 0
1297str = unsb
1298u = umsg get g_o 16 get g_o 17 str 0 0
1299if eq u 0
1300put g_n 10 0
1301ret
1302end
1303if eq k 1
1304if eq umsg u get g_o 18 0 0 0 0
1305put g_n 10 0
1306end
1307end
1308end
1309
1310note ---- files: Hop's file index, searched by the rule of Hop's own file search (Sources/FileIndex.swift) ----
1311note read file-index.bin from Hop's folder (HOP_CONFIG_DIR, else the user's Application Support/Hop) and make the
1312note lower-case copy the search runs on. Without the file there are no file rows
1313fn uloadindex to void
1314if eq get g_fb 3 1
1315upr 0 get g_fb 1
1316x = ucall 28
1317x = umsg get g_fb 4 usl m_release 0 0 0
1318end
1319put g_fb 3 0
1320n = ucs x_env_dir
1321upr 0 ulong libptr g_nm 0 1024
1322dir_text = ucall 9
1323p = ulong 0
1324if ne dir_text 0
1325p = ufetch dir_text
1326end
1327if eq p 0
1328n = ucs x_env_home
1329upr 0 ulong libptr g_nm 0 1024
1330home_text = ucall 9
1331if eq home_text 0
1332ret
1333end
1334p = ufetch home_text
1335p = uptxt p x_support
1336end
1337p = uptxt p x_index
1338put g_nm p 0
1339path = unsb
1340c = ucl c_data
1341s = usl m_data_file
1342d = umsg c s path 0 0
1343if eq d 0
1344ret
1345end
1346s = usl m_retain
1347x = umsg d s 0 0 0
1348s = usl m_bytes
1349src = umsg d s 0 0 0
1350s = usl m_length
1351total = umsg d s 0 0 0
1352if or or eq src 0 eq total 0 gt total 536870912
1353ret
1354end
1355upr 0 total
1356dst = ucall 10
1357if eq dst 0
1358x = umsg d usl m_release 0 0 0
1359ret
1360end
1361done = ulong 0
1362while lt done total bound 2048
1363m = sub total done
1364if gt m 524288
1365m = 524288
1366end
1367upr 0 ulong libptr g_chunk 0 524288
1368upr 8 add src done
1369upr 16 m
1370x = ucall 8
1371for i ulong m bound 524288
1372cc = ulong get g_chunk i
1373if and ge cc 65 le cc 90
1374put g_chunk i uchar add cc 32
1375end
1376end
1377upr 0 add dst done
1378upr 8 ulong libptr g_chunk 0 524288
1379upr 16 m
1380x = ucall 8
1381done = add done m
1382end
1383put g_fb 0 src
1384put g_fb 1 dst
1385put g_fb 2 total
1386put g_fb 4 d
1387put g_fb 3 1
1388end
1389
1390note does g_line[ho .. ho+hl) hold word t of the typed text; md 1: does it start with it
1391fn uhas ho ulong hl ulong t ulong md ulong to bool
1392wo = get g_to t
1393wl = get g_tl t
1394if gt wl hl
1395ret false
1396end
1397last = sub hl wl
1398if eq md 1
1399last = 0
1400end
1401st = ulong 0
1402while le st last bound 4097
1403same_bytes = true
1404j = ulong 0
1405while and same_bytes lt j wl bound 257
1406if ne get g_line add add ho st j get g_lq add wo j
1407same_bytes = false
1408end
1409j = add j 1
1410end
1411if same_bytes
1412ret true
1413end
1414st = add st 1
1415end
1416ret false
1417end
1418
1419note the score of the path in g_line (ln bytes, lower case) plus 100000, or 0 when a word is in it nowhere: a
1420note word in the name counts 60 at its start and 30 elsewhere, a word only in the folders 5; a point less for
1421note every 20 bytes of path; 40 more when the name is exactly as long as the words; 25 more for an app
1422fn ufscore ln ulong to ulong
1423nt = get g_n 16
1424ns0 = ln
1425while gt ns0 0 bound 4097
1426if eq ulong get g_line sub ns0 1 47
1427break
1428end
1429ns0 = sub ns0 1
1430end
1431nl = sub ln ns0
1432sc = ulong 100000
1433words_len = ulong 0
1434for t ulong nt bound 16
1435words_len = add words_len get g_tl t
1436if uhas ns0 nl t 0
1437if uhas ns0 nl t 1
1438sc = add sc 60
1439else
1440sc = add sc 30
1441end
1442else
1443if uhas 0 ln t 0
1444sc = add sc 5
1445else
1446ret 0
1447end
1448end
1449end
1450sc = sub sc div ln 20
1451if eq nl words_len
1452sc = add sc 40
1453end
1454if ge ln 4
1455if and and eq ulong get g_line sub ln 4 46 eq ulong get g_line sub ln 3 97 and eq ulong get g_line sub ln 2 112 eq ulong get g_line sub ln 1 112
1456sc = add sc 25
1457end
1458end
1459ret sc
1460end
1461
1462note keep a found path among the best 40, best first; equal scores stay in the order they were found
1463fn ufkeep sc ulong o ulong ln ulong to void
1464k = get g_n 17
1465if and ge k 40 le sc get g_fs 39
1466ret
1467end
1468pos = k
1469if ge k 40
1470pos = 39
1471else
1472put g_n 17 add k 1
1473end
1474while gt pos 0 bound 64
1475if ge get g_fs sub pos 1 sc
1476break
1477end
1478put g_fs pos get g_fs sub pos 1
1479put g_fo pos get g_fo sub pos 1
1480put g_fl pos get g_fl sub pos 1
1481pos = sub pos 1
1482end
1483put g_fs pos sc
1484put g_fo pos o
1485put g_fl pos ln
1486end
1487
1488note path i of the best files into g_line, from the lower-case copy (lo 1) or as it is written (lo 0); its length
1489fn ufpath i ulong lo ulong to ulong
1490ln = get g_fl i
1491upr 0 ulong libptr g_line 0 4096
1492upr 8 add get g_fb lo get g_fo i
1493upr 16 ln
1494x = ucall 8
1495ret ln
1496end
1497
1498note the files for the typed text: every line of the index that holds the longest word is scored (at most
1499note 20000 lines, as Hop does), the best 40 are kept. Nothing under two characters
1500fn usearch to void
1501put g_n 17 0
1502put g_n 18 0
1503a = get g_n 12
1504n = get g_n 13
1505nt = ulong 0
1506i = ulong 0
1507while lt i n bound 257
1508c = ulower ulong get g_q add a i
1509put g_lq i uchar c
1510if or eq c 32 eq c 9
1511i = add i 1
1512continue
1513end
1514st = i
1515while lt i n bound 257
1516c = ulower ulong get g_q add a i
1517if or eq c 32 eq c 9
1518break
1519end
1520put g_lq i uchar c
1521i = add i 1
1522end
1523if lt nt 16
1524put g_to nt st
1525put g_tl nt sub i st
1526nt = add nt 1
1527end
1528end
1529put g_n 16 nt
1530if or or eq get g_fb 3 0 lt n 2 eq nt 0
1531ret
1532end
1533lead = ulong 0
1534for t ulong nt bound 16
1535if gt get g_tl t get g_tl lead
1536lead = t
1537end
1538end
1539low = get g_fb 1
1540total = get g_fb 2
1541pos = ulong 0
1542scanned = ulong 0
1543while and lt pos total lt scanned 20000 bound 20001
1544upr 0 add low pos
1545upr 8 sub total pos
1546upr 16 ulong libptr g_lq get g_to lead get g_tl lead
1547upr 24 get g_tl lead
1548m = ucall 11
1549if eq m 0
1550break
1551end
1552hit_at = sub m low
1553upr 0 low
1554upr 8 10
1555upr 16 hit_at
1556r = ucall 13
1557s = ulong 0
1558if ne r 0
1559s = add sub r low 1
1560end
1561upr 0 m
1562upr 8 10
1563upr 16 sub total hit_at
1564r = ucall 12
1565e = total
1566if ne r 0
1567e = sub r low
1568end
1569pos = add e 1
1570scanned = add scanned 1
1571ln = sub e s
1572if and gt ln 0 le ln 4000
1573upr 0 ulong libptr g_line 0 4096
1574upr 8 add low s
1575upr 16 ln
1576x = ucall 8
1577sc = ufscore ln
1578if ne sc 0
1579ufkeep sc s ln
1580end
1581end
1582end
1583note does one of them have exactly the typed text as its name (a folder's last "/" aside)
1584for f ulong get g_n 17 bound 64
1585ln = ufpath f 1
1586if gt ln 0
1587if eq ulong get g_line sub ln 1 47
1588ln = sub ln 1
1589end
1590end
1591ns0 = ln
1592while gt ns0 0 bound 4097
1593if eq ulong get g_line sub ns0 1 47
1594break
1595end
1596ns0 = sub ns0 1
1597end
1598if eq sub ln ns0 n
1599same_bytes = true
1600for j ulong n bound 256
1601if ne get g_line add ns0 j get g_lq j
1602same_bytes = false
1603end
1604end
1605if same_bytes
1606put g_n 18 1
1607end
1608end
1609end
1610end
1611
1612note is g_line[o .. o+n) the text t
1613fn ulineis o ulong n ulong t view uchar * to bool
1614if ne n len t
1615ret false
1616end
1617for i ulong n bound 64
1618if ne get g_line add o i get t i
1619ret false
1620end
1621end
1622ret true
1623end
1624
1625note is best file i one of the m matched apps (an app already listed is not shown again as a file)
1626fn uisapp i ulong m ulong to ulong
1627ln = ufpath i 1
1628if lt ln 6
1629ret 0
1630end
1631if not ulineis sub ln 4 4 x_dotapp_low
1632ret 0
1633end
1634o = ulong 0
1635if and ge ln 14 ulineis 0 14 x_dir1_low
1636o = 14
1637end
1638if and ge ln 21 ulineis 0 21 x_dir2_low
1639o = 21
1640end
1641if eq o 0
1642ret 0
1643end
1644nl = sub sub ln o 4
1645for j ulong m bound 2048
1646k = get g_mk j
1647if eq get g_ln k nl
1648same_bytes = true
1649for b ulong nl bound 1000
1650if ne ulower ulong get g_pool add get g_off k b ulong get g_line add o b
1651same_bytes = false
1652end
1653end
1654if same_bytes
1655ret 1
1656end
1657end
1658end
1659ret 0
1660end
1661
1662note the text of a file row into g_nm from byte p: its name, a gap, the folder it is in; the byte after it
1663fn ufilerow p ulong i ulong to ulong
1664ln = ufpath i 0
1665if gt ln 0
1666if eq ulong get g_line sub ln 1 47
1667ln = sub ln 1
1668end
1669end
1670ns0 = ln
1671while gt ns0 0 bound 4097
1672if eq ulong get g_line sub ns0 1 47
1673break
1674end
1675ns0 = sub ns0 1
1676end
1677q = p
1678nl = sub ln ns0
1679if gt nl 300
1680nl = 300
1681end
1682for j ulong nl bound 301
1683put g_nm add q j get g_line add ns0 j
1684end
1685q = add q nl
1686if and gt ns0 1 le ns0 600
1687q = uptxt q x_gap
1688for j ulong sub ns0 1 bound 601
1689put g_nm add q j get g_line j
1690end
1691q = add q sub ns0 1
1692end
1693ret q
1694end
1695
1696note the whole path of best file i into g_nm from byte p (nothing when it is over 900 bytes); the byte after it
1697fn ufilepath p ulong i ulong to ulong
1698ln = ufpath i 0
1699if gt ln 900
1700ret p
1701end
1702for j ulong ln bound 901
1703put g_nm add p j get g_line j
1704end
1705ret add p ln
1706end
1707
1708note open best file i with the app macOS has for it
1709fn uopenfile i ulong to void
1710p = ufilepath 0 i
1711if eq p 0
1712ret
1713end
1714put g_nm p 0
1715str = unsb
1716c = ucl c_url
1717s = usl m_furl
1718url = umsg c s str 0 0
1719c = ucl c_ws
1720s = usl m_shws
1721ws = umsg c s 0 0 0
1722s = usl m_open
1723put g_n 9 and umsg ws s url 0 0 255
1724end
1725
1726note ---- Ask: the model of Hop's settings, asked over HTTP as Hop asks it (Sources/Runners.swift) ----
1727note [obj objectForKey: the key named by t]
1728fn ukeyed obj ulong t view uchar * to ulong
1729key = uns t
1730ret umsg obj usl m_object_for_key key 0 0
1731end
1732
1733note is obj an object of class number w of g_m (7 a dictionary, 8 an array, 9 a string); nothing is not
1734fn uiskind obj ulong w ulong to bool
1735if eq obj 0
1736ret false
1737end
1738ret eq and umsg obj usl m_is_kind get g_m w 0 0 255 1
1739end
1740
1741note the path of the file at Hop's folder plus the text t (an NSString, its bytes left in g_nm; 0 when the
1742note folder is not known)
1743fn uhoppath t view uchar * to ulong
1744n = ucs x_env_dir
1745upr 0 ulong libptr g_nm 0 1024
1746dir_text = ucall 9
1747p = ulong 0
1748if ne dir_text 0
1749p = ufetch dir_text
1750end
1751if eq p 0
1752n = ucs x_env_home
1753upr 0 ulong libptr g_nm 0 1024
1754home_text = ucall 9
1755if eq home_text 0
1756ret 0
1757end
1758p = ufetch home_text
1759p = uptxt p x_support
1760end
1761p = uptxt p t
1762put g_nm p 0
1763ret unsb
1764end
1765
1766note the file at Hop's folder plus the text t, as NSData (0 when it is not there)
1767fn uhopfile t view uchar * to ulong
1768path = uhoppath t
1769if eq path 0
1770ret 0
1771end
1772ret umsg ucl c_data usl m_data_file path 0 0
1773end
1774
1775note ---- saved accounts: Hop's keys and logins in the login Keychain (Sources/Vault.swift) ----
1776note Each is a generic password under Hop's service: the account is its name, the description its kind, the comment
1777note its note. Listing them reads no secret. Enter on one reads its secret and puts it on the clipboard, marked
1778note concealed so that clipboard histories pass it over, as Hop does; macOS asks the person the first time this
1779note program reads an item Hop made. A check (HOPCHECK) reads only the service named by HOPVAULT, never Hop's,
1780note and tells the Keychain to put no dialog up for it: what it may not read without one, it does not read.
1781note It makes its accounts itself (HOPVAULTADD), since macOS lets a program read back what it saved, and
1782note deletes them when it ends.
1783note the eight bytes of g_t8 as a number
1784fn uread8 to ulong
1785v = ulong 0
1786for i ulong 8
1787v = or v shl ulong get g_t8 i mul i 8
1788end
1789ret v
1790end
1791
1792note the value of the library's constant named t (a pointer kept in a variable of that name); 0 when there is none
1793fn uconst t view uchar * to ulong
1794sym_at = usym t
1795if eq sym_at 0
1796ret 0
1797end
1798upr 0 ulong libptr g_t8 0 8
1799upr 8 sym_at
1800upr 16 8
1801x = ucall 8
1802ret uread8
1803end
1804
1805note ask the Keychain for what q describes; the answer (an object), or 0
1806fn ukeychain q ulong to ulong
1807for i ulong 8
1808put g_t8 i 0
1809end
1810upr 0 q
1811upr 8 ulong libptr g_t8 0 8
1812if ne and ucall 23 4294967295 0
1813ret 0
1814end
1815ret uread8
1816end
1817
1818note a question to the Keychain about Hop's items: the generic passwords under the service
1819fn uvaultquery to ulong
1820q = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
1821sset = usl m_set_object
1822x = umsg q sset uconst s_class_generic uconst s_class 0
1823x = umsg q sset get g_m 20 uconst s_attr_service 0
1824ret q
1825end
1826
1827note the saved accounts: their names in order (lower case decides), and what each is
1828fn uloadvault to void
1829put g_n 31 0
1830service = ulong 0
1831if eq get g_n 14 0
1832n = ucs x_env_vault
1833upr 0 ulong libptr g_nm 0 1024
1834vault_text = ucall 9
1835if eq vault_text 0
1836ret
1837end
1838n = ufetch vault_text
1839service = unsb
1840else
1841service = uns x_vault_service
1842end
1843if eq service 0
1844ret
1845end
1846sret = usl m_retain
1847if eq get g_m 20 0
1848put g_m 20 umsg service sret 0 0 0
1849if eq get g_n 14 0
1850uvaultcheckadd
1851end
1852end
1853q = uvaultquery
1854sset = usl m_set_object
1855x = umsg q sset uconst s_limit_all uconst s_match_limit 0
1856x = umsg q sset uconst s_true uconst s_return_attributes 0
1857items = ukeychain q
1858if not uiskind items 8
1859ret
1860end
1861key_account = uconst s_attr_account
1862key_kind = uconst s_attr_description
1863key_note = uconst s_attr_comment
1864sget = usl m_object_for_key
1865sat = usl m_at
1866slower = usl m_lowercase
1867sappend = usl m_append_string
1868slen = usl m_length
1869by_low = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
1870cnt = umsg items usl m_count 0 0 0
1871for i ulong cnt bound 4096
1872item = umsg items sat i 0 0
1873if uiskind item 7
1874name = umsg item sget key_account 0 0
1875if uiskind name 9
1876x = umsg by_low sset item umsg name slower 0 0 0 0
1877end
1878end
1879end
1880lows = umsg umsg by_low usl m_all_keys 0 0 0 usl m_sorted usl m_compare 0 0
1881acct_names = umsg ucl c_mutable_array usl m_array 0 0 0
1882acct_details = umsg ucl c_mutable_array usl m_array 0 0 0
1883sadd = usl m_add_object
1884put g_nm 0 32
1885put g_nm 1 194
1886put g_nm 2 183
1887put g_nm 3 32
1888put g_nm 4 0
1889dot = unsb
1890put g_nm 0 0
1891nothing = unsb
1892total = umsg lows usl m_count 0 0 0
1893if gt total 800
1894total = 800
1895end
1896for i ulong total bound 800
1897item = umsg by_low sget umsg lows sat i 0 0 0 0
1898x = umsg acct_names sadd umsg item sget key_account 0 0 0 0
1899detail = nothing
1900kind = umsg item sget key_kind 0 0
1901if uiskind kind 9
1902detail = kind
1903end
1904remark = umsg item sget key_note 0 0
1905if uiskind remark 9
1906if gt umsg remark slen 0 0 0 0
1907if gt umsg detail slen 0 0 0 0
1908detail = umsg detail sappend dot 0 0
1909end
1910detail = umsg detail sappend remark 0 0
1911end
1912end
1913x = umsg acct_details sadd detail 0 0
1914end
1915srel = usl m_release
1916if ne get g_m 18 0
1917x = umsg get g_m 18 srel 0 0 0
1918x = umsg get g_m 19 srel 0 0 0
1919end
1920put g_m 18 umsg acct_names sret 0 0 0
1921put g_m 19 umsg acct_details sret 0 0 0
1922put g_n 31 total
1923end
1924
1925note the secret of the account named name (an NSString), as text; 0 when it cannot be read
1926fn usecret name ulong to ulong
1927if or eq get g_m 20 0 eq name 0
1928ret 0
1929end
1930q = uvaultquery
1931sset = usl m_set_object
1932x = umsg q sset name uconst s_attr_account 0
1933x = umsg q sset uconst s_true uconst s_return_data 0
1934x = umsg q sset uconst s_limit_one uconst s_match_limit 0
1935d = ukeychain q
1936if eq d 0
1937ret 0
1938end
1939whole = umsg ucl c_str usl m_alloc 0 0 0
1940ret umsg whole usl m_init_data_encoding d 4 0
1941end
1942
1943note save an account as Hop does (Vault.save): any item of that name goes, then one is added with the secret as
1944note its data, the kind as its description and the note as its comment; 1 when it was added
1945fn uvaultsave name ulong secret_text ulong kind ulong remark ulong to ulong
1946if or eq get g_m 20 0 or eq name 0 eq secret_text 0
1947ret 0
1948end
1949q = uvaultquery
1950sset = usl m_set_object
1951x = umsg q sset name uconst s_attr_account 0
1952upr 0 q
1953x = ucall 25
1954data = umsg secret_text usl m_data_using 4 0 0
1955if eq data 0
1956ret 0
1957end
1958x = umsg q sset data uconst s_value_data 0
1959if ne kind 0
1960x = umsg q sset kind uconst s_attr_description 0
1961end
1962if ne remark 0
1963x = umsg q sset remark uconst s_attr_comment 0
1964end
1965x = umsg q sset uconst s_accessible_unlocked uconst s_accessible 0
1966upr 0 q
1967upr 8 0
1968if ne and ucall 24 4294967295 0
1969ret 0
1970end
1971ret 1
1972end
1973
1974note delete the account of that name (Vault.delete)
1975fn uvaultdelete name ulong to void
1976if or eq get g_m 20 0 eq name 0
1977ret
1978end
1979q = uvaultquery
1980x = umsg q usl m_set_object name uconst s_attr_account 0
1981upr 0 q
1982x = ucall 25
1983end
1984
1985note for a check: the accounts HOPVAULTADD describes ("name|kind|note|value", more after ";") are saved under the
1986note check's service by this very program, so that it may read them back without the person being asked
1987fn uvaultcheckadd to void
1988if eq get g_m 20 0
1989ret
1990end
1991n = ucs x_env_vault_add
1992upr 0 ulong libptr g_nm 0 1024
1993add_text = ucall 9
1994if eq add_text 0
1995ret
1996end
1997n = ufetch add_text
1998whole = unsb
1999if eq whole 0
2000ret
2001end
2002ssplit = usl m_components
2003sat = usl m_at
2004slen = usl m_length
2005made = umsg ucl c_mutable_array usl m_array 0 0 0
2006put g_m 22 umsg made usl m_retain 0 0 0
2007entries = umsg whole ssplit uns x_semicolon 0 0
2008entry_count = umsg entries usl m_count 0 0 0
2009for i ulong entry_count bound 16
2010fields = umsg umsg entries sat i 0 0 ssplit uns x_bar 0 0
2011if eq umsg fields usl m_count 0 0 0 4
2012name = umsg fields sat 0 0 0
2013kind = umsg fields sat 1 0 0
2014remark = umsg fields sat 2 0 0
2015value = umsg fields sat 3 0 0
2016if eq umsg kind slen 0 0 0 0
2017kind = 0
2018end
2019if eq umsg remark slen 0 0 0 0
2020remark = 0
2021end
2022if eq uvaultsave name value kind remark 1
2023x = umsg made usl m_add_object name 0 0
2024end
2025end
2026end
2027end
2028
2029note for a check: delete the accounts it made
2030fn uvaultcheckend to void
2031made = get g_m 22
2032if eq made 0
2033ret
2034end
2035cnt = umsg made usl m_count 0 0 0
2036for i ulong cnt bound 16
2037uvaultdelete umsg made get g_m 16 i 0 0
2038end
2039put g_m 22 0
2040end
2041
2042note string i of the array into g_nm from byte p; the byte after it
2043fn ustrat list_of ulong p ulong i ulong to ulong
2044if or eq list_of 0 ge p 900
2045ret p
2046end
2047entry_text = umsg list_of get g_m 16 i 0 0
2048src = umsg entry_text get g_o 5 0 0 0
2049if eq src 0
2050ret p
2051end
2052upr 0 src
2053n = ucall 7
2054if gt add p n 900
2055n = sub 900 p
2056end
2057if eq n 0
2058ret p
2059end
2060upr 0 ulong libptr g_nm p n
2061upr 8 src
2062upr 16 n
2063x = ucall 8
2064ret add p n
2065end
2066
2067note put the secret of saved account i on the clipboard, marked concealed. A check uses a board of its own
2068fn ucopysecret i ulong to void
2069if ge i get g_n 31
2070ret
2071end
2072name = umsg get g_m 18 get g_m 16 i 0 0
2073secret_text = usecret name
2074if eq secret_text 0
2075ret
2076end
2077pboard = ulong 0
2078if eq get g_n 14 1
2079pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
2080else
2081pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
2082end
2083x = umsg pboard usl m_clear 0 0 0
2084plain_type = uns x_type_string
2085concealed = uns x_type_concealed
2086types = umsg ucl c_mutable_array usl m_array 0 0 0
2087sadd = usl m_add_object
2088x = umsg types sadd plain_type 0 0
2089x = umsg types sadd concealed 0 0
2090x = umsg pboard usl m_declare_types types 0 0
2091sput = usl m_set_string_type
2092x = umsg pboard sput secret_text plain_type 0
2093put g_nm 0 0
2094nothing = unsb
2095x = umsg pboard sput nothing concealed 0
2096put g_n 29 1
2097end
2098
2099note is entry e of the models an HTTP model the panel can ask (one whose key is a saved account needs the
2100note accounts to be readable); when it is, keep it as the model to ask
2101fn utakemodel e ulong to bool
2102if not uiskind e 7
2103ret false
2104end
2105kind = ukeyed e k_kind
2106if uiskind kind 9
2107want = uns x_openai
2108if ne and umsg kind usl m_equal_string want 0 0 255 1
2109ret false
2110end
2111end
2112key_name = ukeyed e k_key
2113if uiskind key_name 9
2114if eq get g_m 20 0
2115ret false
2116end
2117else
2118key_name = 0
2119end
2120base = ukeyed e k_base
2121model = ukeyed e k_model
2122name = ukeyed e k_name
2123if or or not uiskind base 9 not uiskind model 9 not uiskind name 9
2124ret false
2125end
2126slash = uns x_slash_text
2127for i ulong 8
2128if eq and umsg base usl m_has_suffix slash 0 0 255 1
2129base = umsg base usl m_substring_to sub umsg base usl m_length 0 0 0 1 0 0
2130end
2131end
2132if eq umsg base usl m_length 0 0 0 0
2133ret false
2134end
2135tail = uns x_completions
2136address = umsg base usl m_append_string tail 0 0
2137sret = usl m_retain
2138put g_m 0 umsg model sret 0 0 0
2139put g_m 1 umsg address sret 0 0 0
2140put g_m 2 umsg name sret 0 0 0
2141put g_m 21 0
2142if ne key_name 0
2143put g_m 21 umsg key_name sret 0 0 0
2144end
2145put g_m 3 1
2146ret true
2147end
2148
2149note read Hop's settings and choose the model: the default one when it will do, else the first that will
2150fn uloadconfig to void
2151put g_m 3 0
2152put g_m 7 ucl c_dict
2153put g_m 8 ucl c_array
2154put g_m 9 ucl c_str
2155d = uhopfile x_config
2156if eq d 0
2157uagentconfig 0
2158ret
2159end
2160config = umsg ucl c_json usl m_json_object d 0 0
2161if not uiskind config 7
2162uagentconfig 0
2163ret
2164end
2165uagentconfig config
2166umachines config
2167utunnelsload config
2168put g_n 34 500
2169limit_number = ukeyed config k_limit
2170if ne limit_number 0
2171limit_value = ujsonint limit_number
2172if and gt limit_value 0 lt limit_value 1000000
2173put g_n 34 limit_value
2174end
2175end
2176models = ukeyed config k_models
2177if not uiskind models 8
2178ret
2179end
2180default_name = ukeyed config k_default
2181count = umsg models usl m_count 0 0 0
2182sat = usl m_at
2183if uiskind default_name 9
2184for i ulong count bound 256
2185e = umsg models sat i 0 0
2186if uiskind e 7
2187name = ukeyed e k_name
2188if uiskind name 9
2189if eq and umsg name usl m_equal_string default_name 0 0 255 1
2190if utakemodel e
2191ret
2192end
2193end
2194end
2195end
2196end
2197end
2198for i ulong count bound 256
2199e = umsg models sat i 0 0
2200if utakemodel e
2201ret
2202end
2203end
2204end
2205
2206note show the answer in place of the list (on 1), or the list again (on 0)
2207fn uanswerview on ulong to void
2208s = usl m_set_hidden
2209x = umsg get g_o 28 s on 0 0
2210x = umsg get g_o 29 s sub 1 on 0 0
2211put g_n 20 on
2212end
2213
2214note put the answer so far on show
2215fn uanswershow to void
2216whole_talk = get g_m 4
2217if ne get g_m 25 0
2218whole_talk = umsg get g_m 25 usl m_append_string get g_m 4 0 0
2219end
2220x = umsg get g_o 30 usl m_set_string whole_talk 0 0
2221end
2222
2223note stop asking: the running task is cancelled and the list is back
2224fn uaskstop to void
2225if ne get g_m 6 0
2226x = umsg get g_m 6 usl m_cancel_task 0 0 0
2227put g_m 6 0
2228if ne get g_m 24 0
2229x = umsg get g_m 24 usl m_remove_last 0 0 0
2230end
2231put g_n 39 1
2232end
2233if eq get g_n 20 1
2234uanswerview 0
2235end
2236end
2237
2238note ask the model the typed text. The body is made by Foundation, so the text is quoted as JSON wants it
2239fn uask to void
2240if eq get g_m 3 0
2241ret
2242end
2243a = get g_n 12
2244n = get g_n 13
2245for i ulong n bound 256
2246put g_nm i get g_q add a i
2247end
2248put g_nm n 0
2249question = unsb
2250sset = usl m_set_object
2251message = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
2252x = umsg message sset uns x_user uns k_role 0
2253x = umsg message sset question uns k_content 0
2254if eq get g_m 24 0
2255talk = umsg ucl c_mutable_array usl m_array 0 0 0
2256put g_m 24 umsg talk usl m_retain 0 0 0
2257told = umsg ucl c_mutable_string usl m_string 0 0 0
2258put g_m 25 umsg told usl m_retain 0 0 0
2259end
2260note a question asked while another is on its way takes its place
2261if ne get g_m 6 0
2262x = umsg get g_m 6 usl m_cancel_task 0 0 0
2263put g_m 6 0
2264x = umsg get g_m 24 usl m_remove_last 0 0 0
2265put g_n 39 1
2266end
2267messages = umsg get g_m 24 usl m_array_adding message 0 0
2268body = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
2269x = umsg body sset get g_m 0 uns k_model 0
2270x = umsg body sset messages uns k_messages 0
2271yes = umsg ucl c_number usl m_number_bool 1 0 0
2272x = umsg body sset yes uns k_stream 0
2273data = umsg ucl c_json usl m_json_data body 0 0
2274url = umsg get g_o 16 get g_o 17 get g_m 1 0 0
2275if or eq data 0 eq url 0
2276ret
2277end
2278req = umsg ucl c_request usl m_request_url url 0 0
2279x = umsg req usl m_set_method uns x_post 0 0
2280x = umsg req usl m_set_header uns x_json_type uns x_content_type 0
2281if ne get g_m 21 0
2282secret_text = usecret get g_m 21
2283if eq secret_text 0
2284if eq get g_m 4 0
2285fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
2286put g_m 4 umsg fresh_text usl m_retain 0 0 0
2287end
2288x = umsg get g_m 4 usl m_set_string uns x_no_key 0 0
2289put g_n 21 1
2290put g_n 22 1
2291uanswershow
2292uanswerview 1
2293ret
2294end
2295bearer = umsg uns x_bearer usl m_append_string secret_text 0 0
2296x = umsg req usl m_set_header bearer uns x_authorization 0
2297end
2298x = umsg req usl m_set_body data 0 0
2299s_timeout = usl m_set_timeout
2300upr 64 bitcast ulong 120.0f64
2301x = umsg req s_timeout 0 0 0
2302if eq get g_m 5 0
2303cfg = umsg ucl c_session_config usl m_ephemeral 0 0 0
2304queue = umsg ucl c_queue usl m_main_queue 0 0 0
2305session = umsg ucl c_session usl m_session_with cfg get g_o 27 queue
2306put g_m 5 umsg session usl m_retain 0 0 0
2307end
2308if eq get g_m 4 0
2309fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
2310put g_m 4 umsg fresh_text usl m_retain 0 0 0
2311end
2312note what was on show joins what was said before; then the question
2313put g_nm 0 10
2314put g_nm 1 10
2315put g_nm 2 0
2316blank_line = unsb
2317sappend_text = usl m_append
2318if eq get g_n 39 1
2319x = umsg get g_m 25 sappend_text get g_m 4 0 0
2320x = umsg get g_m 25 sappend_text blank_line 0 0
2321end
2322x = umsg get g_m 25 sappend_text uns x_you 0 0
2323x = umsg get g_m 25 sappend_text question 0 0
2324x = umsg get g_m 25 sappend_text blank_line 0 0
2325x = umsg get g_m 24 usl m_add_object message 0 0
2326x = umsg get g_m 4 usl m_set_string uns x_asking 0 0
2327put g_n 19 0
2328put g_n 21 0
2329put g_n 22 0
2330put g_n 39 0
2331put g_n 40 0
2332uanswershow
2333uanswerview 1
2334task = umsg get g_m 5 usl m_data_task req 0 0
2335put g_m 6 umsg task usl m_retain 0 0 0
2336x = umsg task usl m_resume 0 0 0
2337end
2338
2339note a turn has ended: an answer joins the conversation; without one the question leaves it again, so that the
2340note model is not sent a question it never answered
2341fn uturnend to void
2342put g_n 39 1
2343if eq get g_m 24 0
2344ret
2345end
2346if or eq get g_n 40 1 eq get g_n 22 0
2347x = umsg get g_m 24 usl m_remove_last 0 0 0
2348ret
2349end
2350sset = usl m_set_object
2351reply = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
2352x = umsg reply sset uns x_assistant uns k_role 0
2353said = umsg ucl c_str usl m_utf umsg get g_m 4 get g_o 5 0 0 0 0 0
2354if eq said 0
2355x = umsg get g_m 24 usl m_remove_last 0 0 0
2356ret
2357end
2358x = umsg reply sset said uns k_content 0
2359x = umsg get g_m 24 usl m_add_object reply 0 0
2360end
2361
2362note New chat: the conversation is forgotten
2363fn uchatnew to void
2364if ne get g_m 33 0
2365x = umsg get g_m 33 usl m_release 0 0 0
2366put g_m 33 0
2367end
2368if ne get g_m 6 0
2369x = umsg get g_m 6 usl m_cancel_task 0 0 0
2370put g_m 6 0
2371end
2372srel = usl m_release
2373if ne get g_m 24 0
2374x = umsg get g_m 24 srel 0 0 0
2375x = umsg get g_m 25 srel 0 0 0
2376put g_m 24 0
2377put g_m 25 0
2378end
2379put g_n 39 0
2380if ne get g_m 4 0
2381put g_nm 0 0
2382no_text = unsb
2383x = umsg get g_m 4 usl m_set_string no_text 0 0
2384end
2385if eq get g_n 20 1
2386uanswerview 0
2387end
2388end
2389
2390note for a check: when the first answer has come, ask the second question (HOPASK2) in the same conversation
2391fn uasksecond to void
2392n = ucs x_env_ask2
2393upr 0 ulong libptr g_nm 0 1024
2394second_text = ucall 9
2395if or eq second_text 0 eq get g_n 21 0
2396ret
2397end
2398n = ucs x_env_asknew
2399upr 0 ulong libptr g_nm 0 1024
2400if ne ucall 9 0
2401uchatnew
2402end
2403n = ufetch second_text
2404second = unsb
2405x = umsg get g_o 0 get g_o 8 second 0 0
2406utyped
2407if and gt get g_n 1 0 eq ulong get g_rk 0 8
2408uask
2409end
2410end
2411
2412note a piece of the answer: the first one takes the place of "Asking ..."
2413fn uanswerpiece piece ulong to void
2414if eq get g_n 22 0
2415put g_nm 0 0
2416empty_text = unsb
2417x = umsg get g_m 4 usl m_set_string empty_text 0 0
2418put g_n 22 1
2419end
2420x = umsg get g_m 4 usl m_append piece 0 0
2421uanswershow
2422end
2423
2424note the JSON in g_net[o .. o+n) as an object (0 when it is not JSON)
2425fn unetjson o ulong n ulong to ulong
2426if or eq n 0 gt add o n 262144
2427ret 0
2428end
2429d = umsg ucl c_data usl m_data_bytes ulong libptr g_net o n n 0
2430ret umsg ucl c_json usl m_json_object d 0 0
2431end
2432
2433note one line from the server: "data: {...}" carries a piece of the answer at choices[0].delta.content
2434note (an empty line may stand first in what came: a server's packet may begin with the line break that ends an
2435note event, so nothing before the line is looked at when it is empty; "and" looks at both its sides)
2436fn unetline o ulong n ulong to void
2437ln = n
2438if gt ln 0
2439if eq ulong get g_net sub add o ln 1 13
2440ln = sub ln 1
2441end
2442end
2443if lt ln 6
2444ret
2445end
2446if or or ne ulong get g_net o 100 ne ulong get g_net add o 1 97 or ne ulong get g_net add o 2 116 or ne ulong get g_net add o 3 97 ne ulong get g_net add o 4 58
2447ret
2448end
2449pay_o = add o 5
2450pay_l = sub ln 5
2451while and gt pay_l 0 eq ulong get g_net pay_o 32 bound 300000
2452pay_o = add pay_o 1
2453pay_l = sub pay_l 1
2454end
2455obj = unetjson pay_o pay_l
2456if not uiskind obj 7
2457ret
2458end
2459choices = ukeyed obj k_choices
2460if not uiskind choices 8
2461ret
2462end
2463if eq umsg choices usl m_count 0 0 0 0
2464ret
2465end
2466choice = umsg choices usl m_at 0 0 0
2467if not uiskind choice 7
2468ret
2469end
2470delta = ukeyed choice k_delta
2471if not uiskind delta 7
2472ret
2473end
2474content = ukeyed delta k_content
2475if uiskind content 9
2476if gt umsg content usl m_length 0 0 0 0
2477uanswerpiece content
2478end
2479end
2480end
2481
2482note bytes from the server: add them to g_net, read every whole line, keep the rest
2483fn unetdata data ulong to void
2484p = umsg data usl m_bytes 0 0 0
2485n = umsg data usl m_length 0 0 0
2486fill = get g_n 19
2487if or eq p 0 gt add fill n 262144
2488put g_n 19 0
2489ret
2490end
2491if eq n 0
2492ret
2493end
2494upr 0 ulong libptr g_net fill n
2495upr 8 p
2496upr 16 n
2497x = ucall 8
2498fill = add fill n
2499line_start = ulong 0
2500i = ulong 0
2501while lt i fill bound 300000
2502if eq ulong get g_net i 10
2503unetline line_start sub i line_start
2504line_start = add i 1
2505end
2506i = add i 1
2507end
2508rest = sub fill line_start
2509for j ulong rest bound 300000
2510put g_net j get g_net add line_start j
2511end
2512put g_n 19 rest
2513end
2514
2515note the answer has ended (problem: what went wrong, or nothing). A server that did not stream gave one JSON
2516note object: its text is at choices[0].message.content
2517fn unetdone task ulong problem ulong to void
2518put g_n 21 1
2519if ne task get g_m 6
2520ret
2521end
2522put g_m 6 0
2523if ne problem 0
2524uanswerpiece umsg problem usl m_description 0 0 0
2525put g_n 40 1
2526uturnend
2527ret
2528end
2529if eq get g_n 22 0
2530obj = unetjson 0 get g_n 19
2531if uiskind obj 7
2532choices = ukeyed obj k_choices
2533if uiskind choices 8
2534if gt umsg choices usl m_count 0 0 0 0
2535choice = umsg choices usl m_at 0 0 0
2536if uiskind choice 7
2537message = ukeyed choice k_message
2538if uiskind message 7
2539content = ukeyed message k_content
2540if uiskind content 9
2541uanswerpiece content
2542end
2543end
2544end
2545end
2546end
2547end
2548end
2549if eq get g_n 22 0
2550code = umsg umsg task usl m_response 0 0 0 usl m_status_code 0 0 0
2551if ge code 300
2552p = ulong 0
2553if or eq code 429 eq code 503
2554p = uptxt 0 x_busy
2555end
2556p = uptxt p x_http
2557p = upnum p code
2558p = uptxt p x_bracket
2559put g_nm p 0
2560uanswerpiece unsb
2561else
2562uanswerpiece uns x_no_answer
2563end
2564put g_n 40 1
2565end
2566uturnend
2567end
2568
2569note the rows for typed text, by the one box's rules (fn swrank): the request is what Sources/SmartRank.swift
2570note sends, with the m matched apps of g_mk, their hopfuzz scores, use and habits, the web address and the files found, and
2571note the copied things that match, the saved accounts, the two screens and the two commands the panel has. The Ask row and the agent's row come back too.
2572note one word of a screen or a command into the request: its length as number k, its bytes at bp; the byte after
2573fn uwordput tb edit uchar 1048576 k ulong bp ulong t view uchar * to ulong
2574n = ucs t
2575upn tb k n
2576for i ulong n bound 64
2577put tb add bp i get g_nm i
2578end
2579ret add bp n
2580end
2581
2582fn urankrows m ulong to void
2583tb = new uchar 1048576 0
2584ob = new uchar 65544 0
2585a = get g_n 12
2586n = get g_n 13
2587nf = get g_n 17
2588uclipmatch 8
2589ncl = get g_n 28
2590nacc = get g_n 31
2591nr = get g_n 49
2592nfa = add nf nr
2593c = add add add add add 13 mul m 4 mul nfa 3 mul nacc 2 ncl 26
2594upn tb 0 n
2595upn tb 1 n
2596upn tb 2 get g_n 10
2597upn tb 3 1
2598exact_name = get g_n 18
2599if eq get g_n 58 1
2600exact_name = 1
2601end
2602upn tb 4 exact_name
2603upn tb 5 get g_n 41
2604words_typed = ulong 0
2605in_word = false
2606for i ulong n bound 256
2607cw = ulong get g_q add a i
2608if or eq cw 32 eq cw 9
2609in_word = false
2610else
2611if not in_word
2612words_typed = add words_typed 1
2613end
2614in_word = true
2615end
2616end
2617send_agent = ulong 0
2618if and eq get g_n 42 1 ge words_typed 3
2619send_agent = 1
2620end
2621upn tb 6 send_agent
2622upn tb 7 m
2623upn tb 8 nfa
2624for i ulong nr bound 64
2625o = add add 13 mul m 4 mul add nf i 3
2626upb tb o sub add k_b get g_rs i 100000
2627upn tb add o 1 0
2628upn tb add o 2 0
2629end
2630for i ulong 4
2631upn tb add 9 i 0
2632end
2633upn tb 12 ncl
2634upn tb 11 nacc
2635pacc = add add 13 mul m 4 mul nfa 3
2636note the screens the panel has (the copied things, the accounts) and what it can do (settings, quit), each with
2637note the words that name it (and Rebuild file index): a count, then the length of each word; the words themselves follow the typed text
2638q = add add pacc mul nacc 2 ncl
2639word_start = add add 8 mul c 8 n
2640bp = word_start
2641upn tb add q 0 3
2642bp = uwordput tb add q 1 bp x_word0
2643bp = uwordput tb add q 2 bp x_word1
2644bp = uwordput tb add q 3 bp x_word2
2645upn tb add q 4 5
2646bp = uwordput tb add q 5 bp x_word3
2647bp = uwordput tb add q 6 bp x_word4
2648bp = uwordput tb add q 7 bp x_word5
2649bp = uwordput tb add q 8 bp x_word6
2650bp = uwordput tb add q 9 bp x_word7
2651upn tb add q 10 1
2652bp = uwordput tb add q 11 bp x_word_agent
2653upn tb add q 12 4
2654bp = uwordput tb add q 13 bp x_word8
2655bp = uwordput tb add q 14 bp x_word9
2656bp = uwordput tb add q 15 bp x_word10
2657bp = uwordput tb add q 16 bp x_word11
2658upn tb add q 17 1
2659bp = uwordput tb add q 18 bp x_word12
2660upn tb add q 19 3
2661bp = uwordput tb add q 20 bp x_word_rebuild
2662bp = uwordput tb add q 21 bp x_word_reindex
2663bp = uwordput tb add q 22 bp x_word_index_files
2664upn tb add q 23 2
2665bp = uwordput tb add q 24 bp x_word_new_chat
2666bp = uwordput tb add q 25 bp x_word_clear_chat
2667word_bytes = sub bp word_start
2668upn tb 9 3
2669upn tb 10 4
2670for i ulong ncl bound 8
2671upn tb add add pacc mul nacc 2 i ulong get g_cp get g_cm i
2672end
2673if gt nacc 0
2674for i ulong n bound 256
2675put g_nm i get g_q add a i
2676end
2677put g_nm n 0
2678typed = unsb
2679typed_low = ulong 0
2680if ne typed 0
2681typed_low = umsg typed usl m_lowercase 0 0 0
2682end
2683slower = usl m_lowercase
2684scontains = usl m_contains
2685sprefix = usl m_has_prefix
2686for i ulong nacc bound 800
2687has = ulong 0
2688starts = ulong 0
2689if ne typed_low 0
2690name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0
2691has = and umsg name_low scontains typed_low 0 0 255
2692starts = and umsg name_low sprefix typed_low 0 0 255
2693end
2694upn tb add pacc mul i 2 has
2695upn tb add add pacc mul i 2 1 starts
2696end
2697end
2698note an app's own use and habits count as in Hop: how much it is used, its lifts from the app in front and the
2699note hour, and whether it is the app that was in front before (all as they were when the panel was last shown)
2700for i ulong m bound 2048
2701o = add 13 mul i 4
2702k = get g_mk i
2703upn tb o get g_ms i
2704upn tb add o 1 get g_us k
2705upn tb add o 2 add get g_lf k get g_lh k
2706was_before = ulong 0
2707if eq add k 1 get g_n 32
2708was_before = 1
2709end
2710upn tb add o 3 was_before
2711end
2712note a file's score may be below zero: it goes in as 2^40 plus the score, written as it is
2713for i ulong nf bound 64
2714o = add add 13 mul m 4 mul i 3
2715upb tb o sub add k_b get g_fs i 100000
2716upn tb add o 1 0
2717upn tb add o 2 uisapp i m
2718end
2719lo = add 8 mul c 8
2720for i ulong n bound 256
2721put tb add lo i uchar ulower ulong get g_q add a i
2722end
2723k = swrank tb c add n word_bytes ob
2724h = ulong 0
2725if ne k 0
2726rws = sub uog ob 0 k_b
2727for i ulong rws bound 1024
2728knd = sub uog ob add 1 mul i 4 k_b
2729ix = sub uog ob add 2 mul i 4 k_b
2730if and eq knd 1 lt ix m
2731put g_rk h 1
2732put g_hit h get g_mk ix
2733h = add h 1
2734end
2735if eq knd 2
2736put g_rk h 2
2737put g_hit h 0
2738h = add h 1
2739end
2740if and eq knd 7 lt ix nf
2741put g_rk h 7
2742put g_hit h ix
2743h = add h 1
2744end
2745if and and eq knd 7 ge ix nf lt ix nfa
2746put g_rk h 10
2747put g_hit h sub ix nf
2748h = add h 1
2749end
2750if eq knd 8
2751put g_rk h 8
2752put g_hit h 0
2753h = add h 1
2754end
2755if eq knd 9
2756put g_rk h 9
2757put g_hit h 0
2758h = add h 1
2759end
2760if and eq knd 6 lt ix ncl
2761put g_rk h 6
2762put g_hit h get g_cm ix
2763h = add h 1
2764end
2765if and eq knd 5 lt ix nacc
2766put g_rk h 5
2767put g_hit h ix
2768h = add h 1
2769end
2770if and eq knd 3 lt ix 3
2771put g_rk h 3
2772put g_hit h ix
2773h = add h 1
2774end
2775if and eq knd 4 lt ix 4
2776put g_rk h 4
2777put g_hit h ix
2778h = add h 1
2779end
2780end
2781end
2782put g_n 1 h
2783end
2784
2785note ---- before anything is typed: what to offer, by Hop's rule (fn swsuggest, fn swlifts) ----
2786note the path of app k into g_nm from byte p (its folder, "/", its name, ".app"); the byte after it
2787fn uapppath p ulong k ulong to ulong
2788q = p
2789if eq ulong get g_dir k 0
2790q = uptxt p x_dir1
2791else
2792q = uptxt p x_dir2
2793end
2794q = uptxt q x_slash
2795q = upname q k
2796ret uptxt q x_dotapp
2797end
2798
2799note byte j of app k's name with ".app" after it (0 past the end): what its path is ordered by within a folder
2800fn ukeybyte k ulong j ulong to ulong
2801n = get g_ln k
2802if lt j n
2803ret ulong get g_pool add get g_off k j
2804end
2805if lt j add n 4
2806ret ulong get x_dotapp sub j n
2807end
2808ret 0
2809end
2810
2811note does app a come before app b in the order of their paths
2812fn uappless a ulong b ulong to bool
2813da = ulong get g_dir a
2814db = ulong get g_dir b
2815if ne da db
2816ret lt da db
2817end
2818for j ulong 1100
2819ca = ukeybyte a j
2820cb = ukeybyte b j
2821if ne ca cb
2822ret lt ca cb
2823end
2824if eq ca 0
2825ret false
2826end
2827end
2828ret false
2829end
2830
2831note each app's path and place into a dictionary, and the apps into the order of their paths
2832fn ubuildmap to void
2833map = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
2834put g_m 10 umsg map usl m_retain 0 0 0
2835sset = usl m_set_object
2836snum = usl m_number_integer
2837cnum = ucl c_number
2838for k ulong get g_n 0 bound 2048
2839p = uapppath 0 k
2840put g_nm p 0
2841path = unsb
2842num = umsg cnum snum k 0 0
2843x = umsg map sset num path 0
2844pos = k
2845while gt pos 0 bound 4096
2846if not uappless k get g_so sub pos 1
2847break
2848end
2849put g_so pos get g_so sub pos 1
2850pos = sub pos 1
2851end
2852put g_so pos k
2853end
2854end
2855
2856note the place of the app at this path (an NSString), or the count of apps when it is not one of them
2857fn uplaceof path ulong to ulong
2858if or eq path 0 eq get g_m 10 0
2859ret get g_n 0
2860end
2861num = umsg get g_m 10 usl m_object_for_key path 0 0
2862if eq num 0
2863ret get g_n 0
2864end
2865ret umsg num usl m_integer_value 0 0 0
2866end
2867
2868note how much the user's own use lifts a path: 25 times the base-2 logarithm of 1 plus the count of openings, the
2869note count halved for every three days since the last, plus 10; 80 at most (Sources/Recents.swift)
2870fn uboost cnt ulong last_bits ulong now_bits ulong to ulong
2871age = sub bitcast f64 now_bits bitcast f64 last_bits
2872upr 64 bitcast ulong 0.5f64
2873upr 72 bitcast ulong div age 259200.0f64
2874x = ucall 14
2875weighed = mul f64 cnt bitcast f64 ugr 64
2876upr 64 bitcast ulong add 1.0f64 weighed
2877x = ucall 15
2878v = add mul 25.0f64 bitcast f64 ugr 64 10.0f64
2879if gt v 80.0f64
2880ret 80
2881end
2882if lt v 0.0f64
2883ret 0
2884end
2885ret ulong v
2886end
2887
2888note remember the app in front (not this program) before the panel takes its place
2889fn ufront to void
2890ws = umsg ucl c_ws usl m_shws 0 0 0
2891app_front = umsg ws usl m_frontmost 0 0 0
2892this_app = umsg ucl c_running_app usl m_current_app 0 0 0
2893if or eq app_front 0 eq app_front this_app
2894ret
2895end
2896sret = usl m_retain
2897id = umsg app_front usl m_bundle_id 0 0 0
2898put g_m 11 0
2899if ne id 0
2900put g_m 11 umsg id sret 0 0 0
2901end
2902name = umsg app_front usl m_localized_name 0 0 0
2903put g_m 12 0
2904if ne name 0
2905put g_m 12 umsg name sret 0 0 0
2906end
2907put g_m 13 0
2908url = umsg app_front usl m_bundle_url 0 0 0
2909if eq url 0
2910ret
2911end
2912k = uplaceof umsg url usl m_path 0 0 0
2913if ge k get g_n 0
2914ret
2915end
2916put g_m 13 add k 1
2917note newest first, each app once
2918found = ulong 11
2919for i ulong 12
2920if and eq get g_fr i add k 1 eq found 11
2921found = i
2922end
2923end
2924pos = found
2925while gt pos 0 bound 16
2926put g_fr pos get g_fr sub pos 1
2927pos = sub pos 1
2928end
2929put g_fr 0 add k 1
2930end
2931
2932note is the JSON value a number (a file a person may have edited can hold anything where a number belongs, and
2933note only a number can be asked for its value: a null, a list or a group asked so would stop the program)
2934fn uisnumber obj ulong to bool
2935if eq obj 0
2936ret false
2937end
2938ret eq and umsg obj usl m_is_kind ucl c_number 0 0 255 1
2939end
2940
2941note a whole number from a JSON value (0 when it is none); below zero comes back as a number of 2^63 and up
2942fn ujsonint obj ulong to ulong
2943if not uisnumber obj
2944ret 0
2945end
2946ret umsg obj usl m_integer_value 0 0 0
2947end
2948
2949note the rows before anything is typed: the lifts from habit, the use, what is running and what was in front go
2950note to the rule as numbers, in the order of the apps' paths; the app in front is never offered
2951fn usuggest to void
2952tb = new uchar 1048576 0
2953ob = new uchar 65544 0
2954na = get g_n 0
2955put g_n 1 0
2956if eq get g_m 10 0
2957ret
2958end
2959note the lifts from habit
2960for k ulong na bound 2048
2961put g_lf k 0
2962put g_lh k 0
2963put g_us k 0
2964put g_rn k 0
2965end
2966cal = umsg ucl c_calendar usl m_current_calendar 0 0 0
2967now_date = umsg ucl c_date usl m_date_now 0 0 0
2968hour = umsg cal usl m_component 32 now_date 0
2969front_id = get g_m 11
2970nl = ulong 0
2971habits = ulong 0
2972d = uhopfile x_habits
2973if ne d 0
2974habits = umsg ucl c_json usl m_json_object d 0 0
2975end
2976if uiskind habits 8
2977nl = umsg habits usl m_count 0 0 0
2978if gt nl 4096
2979nl = 4096
2980end
2981end
2982upn tb 0 hour
2983front_number = ulong 0
2984if ne front_id 0
2985front_number = 1
2986end
2987upn tb 1 front_number
2988upn tb 2 na
2989upn tb 3 nl
2990sat = usl m_at
2991for j ulong nl bound 4096
2992o = add 4 mul j 3
2993launch = umsg habits sat j 0 0
2994here = ulong 0
2995hr = ulong 0
2996place = na
2997if uiskind launch 7
2998from = ukeyed launch k_from
2999if and ne front_id 0 uiskind from 9
3000if eq and umsg from usl m_equal_string front_id 0 0 255 1
3001here = 1
3002end
3003end
3004hr = ujsonint ukeyed launch k_hour
3005opened = ukeyed launch k_app
3006if uiskind opened 9
3007place = uplaceof opened
3008end
3009end
3010upn tb o here
3011if ge hr 9223372036854775808
3012upb tb add o 1 sub k_b add xor hr 18446744073709551615 1
3013else
3014if gt hr 1000000
3015hr = 1000000
3016end
3017upn tb add o 1 hr
3018end
3019if lt place na
3020upn tb add o 2 place
3021else
3022upb tb add o 2 sub k_b 1
3023end
3024end
3025k1 = swlifts tb add 4 mul nl 3 ob
3026if ne k1 0
3027for k ulong na bound 2048
3028put g_lf k sub uog ob add 1 mul k 2 k_b
3029put g_lh k sub uog ob add 2 mul k 2 k_b
3030end
3031end
3032note how much each app is used
3033recents = ulong 0
3034d = uhopfile x_recents
3035if ne d 0
3036recents = umsg ucl c_json usl m_json_object d 0 0
3037end
3038if uiskind recents 7
3039x = umsg ucl c_date usl m_reference_now 0 0 0
3040now_bits = ugr 64
3041for k ulong na bound 2048
3042p = uptxt 0 x_mac_key
3043p = uapppath p k
3044put g_nm p 0
3045key = unsb
3046e = umsg recents usl m_object_for_key key 0 0
3047if uiskind e 7
3048cnt = ujsonint ukeyed e k_count
3049last = ukeyed e k_last
3050if and uisnumber last lt cnt 1000000000
3051x = umsg last usl m_double_value 0 0 0
3052put g_us k uboost cnt ugr 64 now_bits
3053end
3054end
3055end
3056end
3057note what is running (apps a person sees: the regular ones)
3058ws = umsg ucl c_ws usl m_shws 0 0 0
3059running = umsg ws usl m_running_apps 0 0 0
3060if ne running 0
3061nr = umsg running usl m_count 0 0 0
3062for j ulong nr bound 4096
3063r = umsg running sat j 0 0
3064if eq umsg r usl m_policy_of 0 0 0 0
3065url = umsg r usl m_bundle_url 0 0 0
3066if ne url 0
3067k = uplaceof umsg url usl m_path 0 0 0
3068if lt k na
3069put g_rn k 1
3070end
3071end
3072end
3073end
3074end
3075note the app in front before: the newest remembered one that is not in front now
3076front_place = get g_m 13
3077previous = ulong 0
3078for i ulong 12
3079if and and eq previous 0 ne get g_fr i 0 ne get g_fr i front_place
3080previous = get g_fr i
3081end
3082end
3083put g_n 32 previous
3084note the request of fn swsuggest: what was copied, then six numbers an app
3085for i ulong 6
3086upn tb i 0
3087end
3088ncl = get g_n 24
3089nrest = ulong 0
3090put g_n 25 0
3091put g_n 26 0
3092if gt ncl 0
3093upn tb 0 1
3094newest = umsg get g_m 14 get g_m 16 0 0 0
3095age = ulong 0
3096if uiskind newest 7
3097moment = ukeyed newest k_date
3098if uisnumber moment
3099x = umsg moment usl m_double_value 0 0 0
3100then_bits = ugr 64
3101x = umsg ucl c_date usl m_reference_now 0 0 0
3102gap = sub bitcast f64 ugr 64 bitcast f64 then_bits
3103if gt gap 0.0f64
3104age = 1000000000
3105if lt gap 1000000000.0f64
3106age = ulong gap
3107end
3108end
3109end
3110words = ukeyed newest k_text
3111if uiskind words 9
3112wb = umsg words get g_o 5 0 0 0
3113if ne wb 0
3114upr 0 wb
3115wn = ucall 7
3116if and ge wn 4 le wn 255
3117upr 0 ulong libptr g_ca 0 wn
3118upr 8 wb
3119upr 16 wn
3120x = ucall 8
3121if and and eq ulower ulong get g_ca 0 104 eq ulower ulong get g_ca 1 116 and eq ulower ulong get g_ca 2 116 eq ulower ulong get g_ca 3 112
3122put g_n 25 wn
3123uclipaddr 1
3124udecide
3125put g_n 26 get g_n 10
3126uclipaddr 0
3127end
3128end
3129end
3130end
3131end
3132upn tb 1 age
3133if ne get g_n 26 0
3134upn tb 2 1
3135end
3136upn tb 3 ufrontbrowser
3137for pos ulong ncl bound 1024
3138i = get g_ci pos
3139if and ne i 0 lt nrest 20
3140put g_cr nrest i
3141nrest = add nrest 1
3142end
3143end
3144upn tb 4 nrest
3145end
3146put g_n 27 nrest
3147upn tb 6 na
3148for pos ulong na bound 2048
3149k = get g_so pos
3150o = add 7 mul pos 6
3151if eq add k 1 front_place
3152for i ulong 6
3153upn tb add o i 0
3154end
3155else
3156upn tb o get g_lf k
3157upn tb add o 1 get g_lh k
3158upn tb add o 2 get g_us k
3159upn tb add o 3 ulong get g_rn k
3160was_before = ulong 0
3161if eq add k 1 previous
3162was_before = 1
3163end
3164upn tb add o 4 was_before
3165lately = ulong 0
3166for i ulong 5
3167if eq get g_fr i add k 1
3168lately = sub 10 mul 2 i
3169end
3170end
3171upn tb add o 5 lately
3172end
3173end
3174k2 = swsuggest tb add 7 mul na 6 ob
3175h = ulong 0
3176if ne k2 0
3177rws = sub uog ob 0 k_b
3178for i ulong rws bound 64
3179knd = sub uog ob add 1 mul i 4 k_b
3180ix = sub uog ob add 2 mul i 4 k_b
3181if and eq knd 1 lt ix na
3182put g_rk h 1
3183put g_hit h get g_so ix
3184put g_why h uchar sub uog ob add 4 mul i 4 k_b
3185h = add h 1
3186end
3187if and eq knd 6 le ix nrest
3188put g_rk h 6
3189if eq ix 0
3190put g_hit h 0
3191else
3192put g_hit h get g_cr sub ix 1
3193end
3194put g_why h uchar sub uog ob add 4 mul i 4 k_b
3195h = add h 1
3196end
3197if and eq knd 2 ne get g_n 26 0
3198put g_rk h 2
3199put g_hit h 0
3200put g_why h 3
3201h = add h 1
3202end
3203end
3204end
3205put g_n 1 h
3206end
3207
3208note ---- remembering what was opened, as Hop does (Habits.record in Sources/Smart.swift, Sources/Recents.swift) ----
3209note Both files are read again at that moment and written whole, all at once. A file that is there but is not
3210note what Hop writes is left alone. While Hop itself runs it keeps its own copy and writes that over the file the
3211note next time it remembers something, so what the panel added then is lost.
3212note write the JSON object obj as Hop's file named t; private: only the owner may read it; 1 when it was written
3213fn uhopwrite obj ulong t view uchar * private ulong to ulong
3214data = umsg ucl c_json usl m_json_data obj 0 0
3215if eq data 0
3216ret 0
3217end
3218s_write = usl m_write_file
3219path = uhoppath t
3220if eq path 0
3221ret 0
3222end
3223ok = and umsg data s_write path 1 0 255
3224if and eq ok 1 eq private 1
3225path = uhoppath t
3226upr 0 ulong libptr g_nm 0 1024
3227upr 8 384
3228x = ucall 16
3229end
3230ret ok
3231end
3232
3233note the weight of an entry of recents.json: its count of openings, halved for every three days since the last
3234fn urecentweight e ulong now_bits ulong to ulong
3235if not uiskind e 7
3236ret bitcast ulong 0.0f64
3237end
3238cnt = ujsonint ukeyed e k_count
3239if ge cnt 1000000000
3240cnt = 0
3241end
3242last = ukeyed e k_last
3243if not uisnumber last
3244ret bitcast ulong 0.0f64
3245end
3246x = umsg last usl m_double_value 0 0 0
3247last_bits = ugr 64
3248age = sub bitcast f64 now_bits bitcast f64 last_bits
3249upr 64 bitcast ulong 0.5f64
3250upr 72 bitcast ulong div age 259200.0f64
3251x = ucall 14
3252ret bitcast ulong mul f64 cnt bitcast f64 ugr 64
3253end
3254
3255note one more opening of path (an NSString) into recents.json: its count up by one, now as the last time; over 500
3256note entries the one that weighs least goes
3257fn urecent path ulong to void
3258recents = ulong 0
3259d = uhopfile x_recents
3260if ne d 0
3261recents = umsg ucl c_json usl m_json_object d 1 0
3262if not uiskind recents 7
3263ret
3264end
3265else
3266recents = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
3267end
3268prefix = uns x_mac_key
3269key = umsg prefix usl m_append_string path 0 0
3270sset = usl m_set_object
3271cnum = ucl c_number
3272e = umsg recents usl m_object_for_key key 0 0
3273cnt = ulong 0
3274if uiskind e 7
3275cnt = ujsonint ukeyed e k_count
3276if ge cnt 1000000000
3277cnt = 0
3278end
3279else
3280e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
3281key_path = uns k_path
3282x = umsg e sset path key_path 0
3283x = umsg recents sset e key 0
3284end
3285num = umsg cnum usl m_number_integer add cnt 1 0 0
3286key_count = uns k_count
3287x = umsg e sset num key_count 0
3288x = umsg ucl c_date usl m_reference_now 0 0 0
3289now_bits = ugr 64
3290s_double = usl m_number_double
3291upr 64 now_bits
3292last = umsg cnum s_double 0 0 0
3293key_last = uns k_last
3294x = umsg e sset last key_last 0
3295n = umsg recents usl m_count 0 0 0
3296if gt n 500
3297keys = umsg recents usl m_all_keys 0 0 0
3298sat = usl m_at
3299least = ulong 0
3300least_bits = ulong 0
3301for i ulong n bound 4096
3302k = umsg keys sat i 0 0
3303w = urecentweight umsg recents usl m_object_for_key k 0 0 now_bits
3304if or eq least 0 lt bitcast f64 w bitcast f64 least_bits
3305least = k
3306least_bits = w
3307end
3308end
3309if ne least 0
3310x = umsg recents usl m_remove_key least 0 0
3311end
3312end
3313x = uhopwrite recents x_recents 0
3314end
3315
3316note app k was opened: into recents.json, and into habits.json with the app that was in front and the hour (the
3317note newest 400 are kept)
3318fn urecordapp k ulong to void
3319p = uapppath 0 k
3320put g_nm p 0
3321path = unsb
3322urecent path
3323habits = ulong 0
3324d = uhopfile x_habits
3325if ne d 0
3326habits = umsg ucl c_json usl m_json_object d 1 0
3327if not uiskind habits 8
3328ret
3329end
3330else
3331habits = umsg ucl c_mutable_array usl m_array 0 0 0
3332end
3333cal = umsg ucl c_calendar usl m_current_calendar 0 0 0
3334now_date = umsg ucl c_date usl m_date_now 0 0 0
3335hour = umsg cal usl m_component 32 now_date 0
3336x = umsg ucl c_date usl m_reference_now 0 0 0
3337now_bits = ugr 64
3338cnum = ucl c_number
3339sset = usl m_set_object
3340launch = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
3341key_app = uns k_app
3342x = umsg launch sset path key_app 0
3343from_id = get g_m 11
3344if eq from_id 0
3345put g_nm 0 0
3346from_id = unsb
3347end
3348key_from = uns k_from
3349x = umsg launch sset from_id key_from 0
3350num = umsg cnum usl m_number_integer hour 0 0
3351key_hour = uns k_hour
3352x = umsg launch sset num key_hour 0
3353s_double = usl m_number_double
3354upr 64 now_bits
3355moment = umsg cnum s_double 0 0 0
3356key_moment = uns k_at_key
3357x = umsg launch sset moment key_moment 0
3358x = umsg habits usl m_add_object launch 0 0
3359n = umsg habits usl m_count 0 0 0
3360if gt n 400
3361x = umsg habits usl m_remove_range 0 sub n 400 0
3362end
3363x = uhopwrite habits x_habits 1
3364end
3365
3366note best file i was opened: into recents.json under its whole path
3367fn urecordfile i ulong to void
3368p = ufilepath 0 i
3369if eq p 0
3370ret
3371end
3372put g_nm p 0
3373path = unsb
3374urecent path
3375end
3376
3377note why an offered app is offered into g_nm from byte p (nothing for a typed row); the byte after it
3378fn uwhy p ulong r ulong to ulong
3379w = ulong get g_why r
3380if or ne get g_n 13 0 eq w 0
3381ret p
3382end
3383q = uptxt p x_gap
3384if eq w 1
3385ret uptxt q x_why1
3386end
3387if eq w 2
3388ret uptxt q x_why2
3389end
3390if eq w 3
3391ret uptxt q x_why3
3392end
3393if eq w 4
3394q = uptxt q x_why4
3395name = get g_m 12
3396if eq name 0
3397ret uptxt q x_here
3398end
3399name_bytes = umsg name get g_o 5 0 0 0
3400upr 0 name_bytes
3401n = ucall 7
3402if gt n 200
3403n = 200
3404end
3405upr 0 ulong libptr g_nm q n
3406upr 8 name_bytes
3407upr 16 n
3408x = ucall 8
3409ret add q n
3410end
3411if eq w 5
3412ret uptxt q x_why5
3413end
3414if eq w 6
3415ret uptxt q x_why6
3416end
3417if eq w 7
3418ret uptxt q x_why7
3419end
3420ret uptxt q x_why8
3421end
3422
3423note ---- building the file index, as Hop builds it (Sources/FileIndex.swift, rebuild) ----
3424note The program run with the one argument "index" walks the folders of Hop's settings (indexRoots; without
3425note settings the home folder, /Applications and /System/Applications) at throttled disk priority with the walker
3426note Hop uses (NSFileManager's, hidden things left out), and writes every path, a line each, as Hop's
3427note file-index.bin, all at once, for the owner only. A folder with one of the names to skip, or one that is a
3428note link, is left out with all in it; a package (an app, a document that is a folder) is one line. Three million
3429note lines at most. It is a program of its own run beside the panel, because the panel does one thing at a time.
3430note is the resource named key of the URL u set (a yes among its values)
3431fn uresource u ulong sget ulong key ulong to bool
3432for i ulong 8
3433put g_t8 i 0
3434end
3435x = umsg u sget ulong libptr g_t8 0 8 key 0
3436v = uread8
3437if eq v 0
3438ret false
3439end
3440ret eq and umsg v usl m_bool_value 0 0 0 255 1
3441end
3442
3443fn uindexbuild to ulong
3444upr 0 0
3445upr 8 0
3446upr 16 3
3447x = ucall 29
3448folder_roots = ulong 0
3449skip_names = ulong 0
3450d = uhopfile x_config
3451if ne d 0
3452config = umsg ucl c_json usl m_json_object d 0 0
3453if uiskind config 7
3454folder_roots = ukeyed config k_roots
3455if not uiskind folder_roots 8
3456folder_roots = 0
3457end
3458skip_names = ukeyed config k_skip_names
3459if not uiskind skip_names 8
3460skip_names = 0
3461end
3462end
3463end
3464sadd = usl m_add_object
3465if eq folder_roots 0
3466folder_roots = umsg ucl c_mutable_array usl m_array 0 0 0
3467x = ucall 30
3468home_folder = ugr 0
3469if ne home_folder 0
3470x = umsg folder_roots sadd home_folder 0 0
3471end
3472x = umsg folder_roots sadd uns x_applications 0 0
3473x = umsg folder_roots sadd uns x_system_applications 0 0
3474end
3475if eq skip_names 0
3476skip_names = umsg ucl c_mutable_array usl m_array 0 0 0
3477x = umsg skip_names sadd uns x_skipname0 0 0
3478x = umsg skip_names sadd uns x_skipname1 0 0
3479x = umsg skip_names sadd uns x_skipname2 0 0
3480x = umsg skip_names sadd uns x_skipname3 0 0
3481x = umsg skip_names sadd uns x_skipname4 0 0
3482x = umsg skip_names sadd uns x_skipname5 0 0
3483x = umsg skip_names sadd uns x_skipname6 0 0
3484x = umsg skip_names sadd uns x_skipname7 0 0
3485x = umsg skip_names sadd uns x_skipname8 0 0
3486x = umsg skip_names sadd uns x_skipname9 0 0
3487x = umsg skip_names sadd uns x_skipname10 0 0
3488x = umsg skip_names sadd uns x_skipname11 0 0
3489x = umsg skip_names sadd uns x_skipname12 0 0
3490x = umsg skip_names sadd uns x_skipname13 0 0
3491x = umsg skip_names sadd uns x_skipname14 0 0
3492x = umsg skip_names sadd uns x_skipname15 0 0
3493end
3494skip_set = umsg ucl c_set usl m_set_with_array skip_names 0 0
3495key_dir = uconst s_key_directory
3496key_pkg = uconst s_key_package
3497key_link = uconst s_key_link
3498wanted_keys = umsg ucl c_mutable_array usl m_array 0 0 0
3499x = umsg wanted_keys sadd key_dir 0 0
3500x = umsg wanted_keys sadd key_pkg 0 0
3501x = umsg wanted_keys sadd key_link 0 0
3502manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
3503index_lines = umsg ucl c_mutable_data usl m_data 0 0 0
3504sappend = usl m_append_bytes
3505snext = usl m_next_object
3506sget = usl m_get_resource
3507spath = usl m_path
3508slast = usl m_last_component
3509sskip = usl m_skip_descendants
3510shas = usl m_contains_object
3511s_enum = usl m_enumerator
3512sat = usl m_at
3513c_p = ucl c_pool
3514salloc = usl m_alloc
3515sinit = usl m_init
3516sdrain = usl m_drain
3517sfurl = usl m_furl
3518c_u = ucl c_url
3519put g_nl 0 10
3520listed = ulong 0
3521nroots = umsg folder_roots usl m_count 0 0 0
3522for ri ulong nroots bound 64
3523folder_root = umsg folder_roots sat ri 0 0
3524if uiskind folder_root 9
3525folder_url = umsg c_u sfurl folder_root 0 0
3526upr 40 0
3527en = umsg manager s_enum folder_url wanted_keys 4
3528if ne en 0
3529walking = true
3530for portion ulong 3001 bound 3001
3531if walking
3532walk_pool = umsg umsg c_p salloc 0 0 0 sinit 0 0 0
3533for turn ulong 1000 bound 1000
3534if and walking lt listed 3000000
3535u = umsg en snext 0 0 0
3536if eq u 0
3537walking = false
3538else
3539list_it = true
3540if uresource u sget key_dir
3541item_name = umsg u slast 0 0 0
3542skip_it = eq and umsg skip_set shas item_name 0 0 255 1
3543if not skip_it
3544skip_it = uresource u sget key_link
3545end
3546if skip_it
3547x = umsg en sskip 0 0 0
3548list_it = false
3549else
3550if uresource u sget key_pkg
3551x = umsg en sskip 0 0 0
3552end
3553end
3554end
3555if list_it
3556path_bytes = umsg umsg u spath 0 0 0 get g_o 5 0 0 0
3557if ne path_bytes 0
3558upr 0 path_bytes
3559pn = ucall 7
3560x = umsg index_lines sappend path_bytes pn 0
3561x = umsg index_lines sappend ulong libptr g_nl 0 1 1 0
3562listed = add listed 1
3563end
3564end
3565end
3566end
3567end
3568x = umsg walk_pool sdrain 0 0 0
3569if ge listed 3000000
3570walking = false
3571end
3572end
3573end
3574end
3575end
3576end
3577s_write = usl m_write_file
3578path = uhoppath x_index
3579if eq path 0
3580ret 1
3581end
3582ok = and umsg index_lines s_write path 1 0 255
3583path = uhoppath x_index
3584upr 0 ulong libptr g_nm 0 1024
3585upr 8 384
3586x = ucall 16
3587p = uptxt 0 x_indexed
3588p = upnum p listed
3589p = uptxt p x_items
3590put g_nm p 10
3591upr 0 1
3592upr 8 ulong libptr g_nm 0 1024
3593upr 16 add p 1
3594x = ucall 3
3595if eq ok 1
3596ret 0
3597end
3598ret 1
3599end
3600
3601note when the program was run with the one argument "index": build the index (0 done, 1 not written); else 2
3602fn uindexmode to ulong
3603run_arguments = umsg umsg ucl c_process_info usl m_process_info 0 0 0 usl m_arguments 0 0 0
3604if eq run_arguments 0
3605ret 2
3606end
3607if le umsg run_arguments usl m_count 0 0 0 1
3608ret 2
3609end
3610first_argument = umsg run_arguments get g_m 16 1 0 0
3611if ne and umsg first_argument usl m_equal_string uns x_index_word 0 0 255 1
3612ret 2
3613end
3614ret uindexbuild
3615end
3616
3617note start building the file index in a program of its own (this one, run with "index"); one at a time
3618fn uindexstart to void
3619if ne get g_m 23 0
3620ret
3621end
3622exe = umsg umsg ucl c_bundle usl m_main_bundle 0 0 0 usl m_executable_path 0 0 0
3623if eq exe 0
3624ret
3625end
3626task = umsg ucl c_task usl m_alloc 0 0 0
3627task = umsg task usl m_init 0 0 0
3628x = umsg task usl m_set_launch exe 0 0
3629arguments = umsg ucl c_mutable_array usl m_array 0 0 0
3630x = umsg arguments usl m_add_object uns x_index_word 0 0
3631x = umsg task usl m_set_arguments arguments 0 0
3632quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
3633x = umsg task usl m_set_output quiet 0 0
3634x = umsg task usl m_launch 0 0 0
3635put g_m 23 umsg task usl m_retain 0 0 0
3636ushowst
3637end
3638
3639note is the file index missing, or older than half an hour (Hop builds it anew that often)
3640fn uindexstale to bool
3641path = uhoppath x_index
3642if eq path 0
3643ret false
3644end
3645manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
3646attributes = umsg manager usl m_attributes_of path 0 0
3647if eq attributes 0
3648ret true
3649end
3650changed = umsg attributes usl m_object_for_key uconst s_modified 0 0
3651if eq changed 0
3652ret true
3653end
3654x = umsg changed usl m_since_now 0 0 0
3655age = sub 0.0f64 bitcast f64 ugr 64
3656ret gt age 1800.0f64
3657end
3658
3659note twice a second: when the program building the index has ended, read the new index and show the list anew;
3660note every half hour, and when the panel starts, build it anew when it is old and Hop is not there to do it
3661fn uindextick to void
3662if ne get g_m 23 0
3663if eq and umsg get g_m 23 usl m_is_running 0 0 0 255 0
3664x = umsg get g_m 23 usl m_release 0 0 0
3665put g_m 23 0
3666uloadindex
3667if ne get g_n 13 0
3668unarrow
3669x = umsg get g_o 1 get g_o 7 0 0 0
3670end
3671ushowst
3672end
3673ret
3674end
3675put g_n 38 add get g_n 38 1
3676if ge get g_n 38 3600
3677put g_n 38 0
3678if and not uhoprunning uindexstale
3679uindexstart
3680end
3681if not uhoprunning
3682uremoterefreshall
3683end
3684end
3685end
3686
3687note ---- the agent: the person's coding agent, run on this Mac for the typed text (Sources/Model.swift, runAgent) ----
3688note Hop's settings name the agents (each a name and a command, "{prompt}" standing for the request) and the one
3689note to use. Only that one is ever run, and only when it is installed: the look goes through the login shell
3690note with the usual tool folders added, as Hop's does. The command runs through the same wrapper as in Hop, in
3691note the folder of the settings; what it prints is shown as it comes (the lines of Claude Code's stream are read
3692note for their text and the tools they name). Hop's standing instructions ride along. Not here yet: what the
3693note knowledge base knows, and the count of tokens.
3694note an NSString of text t with every "~" turned into a double quote
3695fn uquoted t view uchar * to ulong
3696put g_nm 0 34
3697put g_nm 1 0
3698quote_mark = unsb
3699plain = uns t
3700ret umsg plain usl m_replace uns x_tilde quote_mark 0
3701end
3702
3703note the words of text t (separated by "|") as an array
3704fn uwords t view uchar * to ulong
3705whole = uns t
3706ret umsg whole usl m_components uns x_bar 0 0
3707end
3708
3709note an agent: a name and a command
3710fn uengine name ulong command ulong to ulong
3711e = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
3712sset = usl m_set_object
3713x = umsg e sset name uns k_name 0
3714x = umsg e sset command uns k_command 0
3715ret e
3716end
3717
3718note is the JSON value v a yes: JSON's own true and nothing else, as Hop reads its settings (a null, a number,
3719note a text, a list or a group is not)
3720fn uyes v ulong to bool
3721if eq v 0
3722ret false
3723end
3724ret eq v uconst s_cf_true
3725end
3726
3727note the agents Hop has out of the box (none of them switches a tool's own approval prompts or sandbox off)
3728fn uenginedefaults to ulong
3729all_engines = umsg ucl c_mutable_array usl m_array 0 0 0
3730sadd = usl m_add_object
3731x = umsg all_engines sadd uengine uns x_engine0 uwords x_engine0_command 0 0
3732x = umsg all_engines sadd uengine uns x_engine1 uwords x_engine1_command 0 0
3733x = umsg all_engines sadd uengine uns x_engine2 uwords x_engine2_command 0 0
3734x = umsg all_engines sadd uengine uns x_engine3 uwords x_engine3_command 0 0
3735x = umsg all_engines sadd uengine uns x_engine4 uwords x_engine4_command 0 0
3736x = umsg all_engines sadd uengine uns x_engine5 uwords x_engine5_command 0 0
3737x = umsg all_engines sadd uengine uns x_engine6 uwords x_engine6_command 0 0
3738ret all_engines
3739end
3740
3741note the zero-ended bytes at src into g_nm from byte p (900 bytes at most in all); the byte after them
3742fn ufetchat p ulong src ulong to ulong
3743if or eq src 0 ge p 900
3744ret p
3745end
3746upr 0 src
3747n = ucall 7
3748if gt add p n 900
3749n = sub 900 p
3750end
3751if eq n 0
3752ret p
3753end
3754upr 0 ulong libptr g_nm p n
3755upr 8 src
3756upr 16 n
3757x = ucall 8
3758ret add p n
3759end
3760
3761note what Hop's settings say about the agent (config: the settings, or 0 without any). A saved command that is
3762note exactly one of the old built-in ones that switched approval prompts or the sandbox off is brought to
3763note today's built-in one, unless keepAgentFlags says the commands are wanted as written (as Hop does on reading)
3764fn uagentconfig config ulong to void
3765engines = ulong 0
3766chosen = ulong 0
3767legacy = ulong 0
3768folder = ulong 0
3769keep_flags = false
3770put g_n 42 0
3771put g_n 44 0
3772put g_n 45 0
3773if ne config 0
3774engines = ukeyed config k_engines
3775chosen = ukeyed config k_engine
3776legacy = ukeyed config k_agent_command
3777folder = ukeyed config k_agent_folder
3778keep_flags = uyes ukeyed config k_keep_flags
3779if uyes ukeyed config k_enter_agent
3780put g_n 42 1
3781end
3782if uyes ukeyed config k_agent_confirmed
3783put g_n 44 1
3784end
3785end
3786defaults = uenginedefaults
3787sat = usl m_at
3788if not uiskind engines 8
3789engines = defaults
3790else
3791if not keep_flags
3792moved = umsg ucl c_mutable_array usl m_array 0 0 0
3793sadd = usl m_add_object
3794sequal = usl m_equal_string
3795ssame = usl m_is_equal_array
3796cnt = umsg engines usl m_count 0 0 0
3797for i ulong cnt bound 256
3798e = umsg engines sat i 0 0
3799if uiskind e 7
3800name = ukeyed e k_name
3801command = ukeyed e k_command
3802if and uiskind name 9 uiskind command 8
3803if and eq and umsg name sequal uns x_engine1 0 0 255 1 eq and umsg command ssame uwords x_old0_command 0 0 255 1
3804e = umsg defaults sat 1 0 0
3805end
3806if and eq and umsg name sequal uns x_engine2 0 0 255 1 eq and umsg command ssame uwords x_old1_command 0 0 255 1
3807e = umsg defaults sat 2 0 0
3808end
3809if and eq and umsg name sequal uns x_engine3 0 0 255 1 eq and umsg command ssame uwords x_old2_command 0 0 255 1
3810e = umsg defaults sat 3 0 0
3811end
3812if and eq and umsg name sequal uns x_engine5 0 0 255 1 eq and umsg command ssame uwords x_old3_command 0 0 255 1
3813e = umsg defaults sat 5 0 0
3814end
3815if and eq and umsg name sequal uns x_engine6 0 0 255 1 eq and umsg command ssame uwords x_old4_command 0 0 255 1
3816e = umsg defaults sat 6 0 0
3817end
3818end
3819end
3820x = umsg moved sadd e 0 0
3821end
3822engines = moved
3823end
3824end
3825if not uiskind chosen 9
3826chosen = uns x_engine0
3827end
3828if not uiskind legacy 8
3829legacy = uwords x_engine0_command
3830end
3831if not uiskind folder 9
3832x = ucall 30
3833folder = ugr 0
3834end
3835sret = usl m_retain
3836put g_m 28 umsg engines sret 0 0 0
3837put g_m 29 umsg chosen sret 0 0 0
3838put g_m 30 umsg folder sret 0 0 0
3839put g_m 31 umsg legacy sret 0 0 0
3840if ne config 0
3841put g_m 34 umsg config sret 0 0 0
3842end
3843note for a check (HOPAGENTS): say each agent's command as it would be run
3844if eq get g_n 14 0
3845n = ucs x_env_agents
3846upr 0 ulong libptr g_nm 0 1024
3847if ne ucall 9 0
3848cnt = umsg engines usl m_count 0 0 0
3849sjoin = usl m_joined
3850for i ulong cnt bound 256
3851e = umsg engines sat i 0 0
3852if uiskind e 7
3853name = ukeyed e k_name
3854command = ukeyed e k_command
3855if and uiskind name 9 uiskind command 8
3856said_words = umsg command sjoin uns x_space 0 0
3857name_bytes = umsg name get g_o 5 0 0 0
3858word_bytes = umsg said_words get g_o 5 0 0 0
3859p = uptxt 0 x_engine_word
3860p2 = ufetchat p name_bytes
3861p2 = uptxt p2 x_colon
3862p2 = ufetchat p2 word_bytes
3863put g_nm p2 10
3864upr 0 1
3865upr 8 ulong libptr g_nm 0 1024
3866upr 16 add p2 1
3867x = ucall 3
3868end
3869end
3870end
3871end
3872end
3873end
3874
3875note s between single quotes for a shell
3876fn ushellquote s ulong to ulong
3877put g_nm 0 39
3878put g_nm 1 0
3879tick = unsb
3880put g_nm 0 39
3881put g_nm 1 92
3882put g_nm 2 39
3883put g_nm 3 39
3884put g_nm 4 0
3885escaped = unsb
3886inner = umsg s usl m_replace tick escaped 0
3887sappend = usl m_append_string
3888ret umsg umsg tick sappend inner 0 0 sappend tick 0 0
3889end
3890
3891note the folders tools are commonly installed in, joined by ":" (searched after the login shell's own PATH)
3892fn uextrapath to ulong
3893x = ucall 30
3894home_folder = ugr 0
3895if eq home_folder 0
3896ret uns x_colon_only
3897end
3898dirs = umsg ucl c_mutable_array usl m_array 0 0 0
3899sadd = usl m_add_object
3900sappend = usl m_append_string
3901slash = uns x_slash_text
3902x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path0 0 0 0 0
3903x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path1 0 0 0 0
3904x = umsg dirs sadd uns x_path2 0 0
3905x = umsg dirs sadd uns x_path3 0 0
3906x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path4 0 0 0 0
3907x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path5 0 0 0 0
3908x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path6 0 0 0 0
3909x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path7 0 0 0 0
3910x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path8 0 0 0 0
3911x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path9 0 0 0 0
3912x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path10 0 0 0 0
3913x = umsg dirs sadd umsg umsg home_folder sappend slash 0 0 sappend uns x_path11 0 0 0 0
3914manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
3915sat = usl m_at
3916for which ulong 2
3917versions_root = umsg home_folder sappend uns x_nvm 0 0
3918if eq which 1
3919versions_root = umsg home_folder sappend uns x_herd 0 0
3920end
3921found_versions = umsg manager usl m_contents_of_dir versions_root 0 0
3922if ne found_versions 0
3923ordered = umsg found_versions usl m_sorted usl m_standard_compare 0 0
3924cnt = umsg ordered usl m_count 0 0 0
3925for back ulong cnt bound 512
3926v = umsg ordered sat sub sub cnt 1 back 0 0
3927one_dir = umsg umsg umsg versions_root sappend slash 0 0 sappend v 0 0 sappend uns x_slash_bin 0 0
3928if eq and umsg one_dir usl m_contains uns x_colon_only 0 0 255 0
3929x = umsg dirs sadd one_dir 0 0
3930end
3931end
3932end
3933end
3934ret umsg dirs usl m_joined uns x_colon_only 0 0
3935end
3936
3937note a program run through the login shell, as Hop runs every command: zsh -lc with the wrapper that adds the
3938note tool folders, then the words of argv; TERM is dumb and colours are off. Not started yet
3939fn ushellrun argv ulong folder ulong to ulong
3940task = umsg ucl c_task usl m_alloc 0 0 0
3941task = umsg task usl m_init 0 0 0
3942x = umsg task usl m_set_launch uns x_zsh 0 0
3943arguments = umsg ucl c_mutable_array usl m_array 0 0 0
3944sadd = usl m_add_object
3945x = umsg arguments sadd uns x_dash_lc 0 0
3946x = umsg arguments sadd uquoted x_wrapper 0 0
3947x = umsg arguments sadd uns x_hop_word 0 0
3948cnt = umsg argv usl m_count 0 0 0
3949sat = usl m_at
3950for i ulong cnt bound 256
3951x = umsg arguments sadd umsg argv sat i 0 0 0 0
3952end
3953x = umsg task usl m_set_arguments arguments 0 0
3954if ne folder 0
3955x = umsg task usl m_set_cwd folder 0 0
3956end
3957around = umsg umsg umsg ucl c_process_info usl m_process_info 0 0 0 usl m_environment 0 0 0 usl m_mutable_copy 0 0 0
3958sset = usl m_set_object
3959x = umsg around sset uns x_dumb uns x_term 0
3960x = umsg around sset uns x_one uns x_no_color 0
3961x = umsg around sset uextrapath uns x_extra_path 0
3962x = umsg task usl m_set_environment around 0 0
3963ret task
3964end
3965
3966note the agents of the settings that are installed on this Mac, looked for once (the login shell is asked for
3967note each tool); when none of them is and the older single command's tool is, that one, as "Custom command"
3968fn uagentsfound to ulong
3969if eq get g_n 45 1
3970ret get g_m 35
3971end
3972engines = get g_m 28
3973sat = usl m_at
3974sappend = usl m_append_string
3975put g_nm 0 10
3976put g_nm 1 0
3977line_end = unsb
3978script = umsg ucl c_mutable_string usl m_string 0 0 0
3979smore = usl m_append
3980cnt = umsg engines usl m_count 0 0 0
3981for i ulong cnt bound 256
3982e = umsg engines sat i 0 0
3983if uiskind e 7
3984name = ukeyed e k_name
3985command = ukeyed e k_command
3986if and uiskind name 9 uiskind command 8
3987if gt umsg command usl m_count 0 0 0 0
3988tool = umsg command sat 0 0 0
3989if uiskind tool 9
3990x = umsg script smore uns x_probe_a 0 0
3991x = umsg script smore ushellquote tool 0 0
3992x = umsg script smore uns x_probe_b 0 0
3993x = umsg script smore ushellquote name 0 0
3994x = umsg script smore line_end 0 0
3995end
3996end
3997end
3998end
3999end
4000legacy = get g_m 31
4001if gt umsg legacy usl m_count 0 0 0 0
4002tool = umsg legacy sat 0 0 0
4003if uiskind tool 9
4004if gt umsg tool usl m_length 0 0 0 0
4005x = umsg script smore uns x_probe_a 0 0
4006x = umsg script smore ushellquote tool 0 0
4007x = umsg script smore uns x_probe_b 0 0
4008x = umsg script smore uns x_legacy_mark 0 0
4009x = umsg script smore line_end 0 0
4010end
4011end
4012end
4013x = umsg script smore uns x_true_word 0 0
4014argv = umsg ucl c_mutable_array usl m_array 0 0 0
4015sadd = usl m_add_object
4016x = umsg argv sadd uns x_sh 0 0
4017x = umsg argv sadd uns x_dash_c 0 0
4018x = umsg argv sadd script 0 0
4019task = ushellrun argv 0
4020tube = umsg ucl c_pipe usl m_pipe 0 0 0
4021quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
4022x = umsg task usl m_set_output tube 0 0
4023x = umsg task usl m_set_error quiet 0 0
4024x = umsg task usl m_set_input quiet 0 0
4025x = umsg task usl m_launch 0 0 0
4026d = umsg umsg tube usl m_reading 0 0 0 usl m_read_end 0 0 0
4027x = umsg task usl m_wait 0 0 0
4028found = umsg ucl c_mutable_array usl m_array 0 0 0
4029if ne d 0
4030said = umsg ucl c_str usl m_alloc 0 0 0
4031said = umsg said usl m_init_data_encoding d 4 0
4032if ne said 0
4033names_said = umsg said usl m_components line_end 0 0
4034shas = usl m_contains_object
4035for i ulong cnt bound 256
4036e = umsg engines sat i 0 0
4037if uiskind e 7
4038name = ukeyed e k_name
4039if uiskind name 9
4040if eq and umsg names_said shas name 0 0 255 1
4041x = umsg found sadd e 0 0
4042end
4043end
4044end
4045end
4046if and eq umsg found usl m_count 0 0 0 0 eq and umsg names_said shas uns x_legacy_mark 0 0 255 1
4047x = umsg found sadd uengine uns x_custom_command legacy 0 0
4048end
4049end
4050end
4051put g_m 35 umsg found usl m_retain 0 0 0
4052put g_n 45 1
4053ret found
4054end
4055
4056note the agent to run: the one the settings name, when it is installed; never another in its place
4057fn uagentpicked to ulong
4058found = uagentsfound
4059cnt = umsg found usl m_count 0 0 0
4060sat = usl m_at
4061sequal = usl m_equal_string
4062for pass_no ulong 2
4063want = get g_m 29
4064if eq pass_no 1
4065want = uns x_custom_command
4066end
4067for i ulong cnt bound 256
4068e = umsg found sat i 0 0
4069if eq and umsg ukeyed e k_name sequal want 0 0 255 1
4070ret e
4071end
4072end
4073end
4074ret 0
4075end
4076
4077note why nothing was run, in plain words
4078fn uagentwhy to ulong
4079found = uagentsfound
4080sappend = usl m_append_string
4081sat = usl m_at
4082if eq umsg found usl m_count 0 0 0 0
4083engines = get g_m 28
4084cnt = umsg engines usl m_count 0 0 0
4085if eq cnt 0
4086ret uns x_agent_none_b
4087end
4088out_text = uns x_agent_none_a
4089for i ulong cnt bound 256
4090e = umsg engines sat i 0 0
4091if uiskind e 7
4092name = ukeyed e k_name
4093command = ukeyed e k_command
4094if and uiskind name 9 uiskind command 8
4095if gt i 0
4096out_text = umsg out_text sappend uns x_comma_space 0 0
4097end
4098out_text = umsg out_text sappend name 0 0
4099if gt umsg command usl m_count 0 0 0 0
4100out_text = umsg out_text sappend uns x_paren_a 0 0
4101out_text = umsg out_text sappend umsg command sat 0 0 0 0 0
4102out_text = umsg out_text sappend uns x_paren_b 0 0
4103end
4104end
4105end
4106end
4107ret umsg out_text sappend uns x_period 0 0
4108end
4109out_text = umsg get g_m 29 sappend uns x_agent_missing_a 0 0
4110cnt = umsg found usl m_count 0 0 0
4111for i ulong cnt bound 256
4112if gt i 0
4113out_text = umsg out_text sappend uns x_comma_space 0 0
4114end
4115out_text = umsg out_text sappend ukeyed umsg found sat i 0 0 k_name 0 0
4116end
4117ret umsg out_text sappend uns x_agent_missing_b 0 0
4118end
4119
4120note Hop's standing instructions for the agent (Sources/Machines.swift, agentBriefing): kept tiny on purpose
4121fn uagentbrief to ulong
4122sappend = usl m_append_string
4123config = get g_m 34
4124owner = uns x_the_user
4125if ne config 0
4126given = ukeyed config k_owner
4127if uiskind given 9
4128blanks = umsg ucl c_charset usl m_whitespace 0 0 0
4129given = umsg given usl m_trim blanks 0 0
4130if gt umsg given usl m_length 0 0 0 0
4131owner = given
4132end
4133end
4134end
4135head = umsg umsg owner usl m_substring_to 1 0 0 usl m_uppercase 0 0 0
4136brief = umsg umsg head sappend umsg owner usl m_substring_from 1 0 0 0 0 sappend uns x_brief_a 0 0
4137if ne config 0
4138machines = ukeyed config k_machines
4139if uiskind machines 8
4140cnt = umsg machines usl m_count 0 0 0
4141if gt cnt 0
4142sat = usl m_at
4143hosts = umsg ucl c_mutable_array usl m_array 0 0 0
4144for i ulong cnt bound 256
4145m = umsg machines sat i 0 0
4146if uiskind m 7
4147name = ukeyed m k_name
4148via = ukeyed m k_ssh
4149if and uiskind name 9 uiskind via 9
4150one_host = umsg umsg umsg name sappend uns x_ssh_a 0 0 sappend via 0 0 sappend uns x_ssh_b 0 0
4151x = umsg hosts usl m_add_object one_host 0 0
4152end
4153end
4154end
4155brief = umsg brief sappend uns x_brief_b 0 0
4156brief = umsg brief sappend umsg hosts usl m_joined uns x_semi_space 0 0 0 0
4157brief = umsg brief sappend uns x_brief_c 0 0
4158end
4159end
4160factory = ukeyed config k_factory_url
4161if uiskind factory 9
4162blanks = umsg ucl c_charset usl m_whitespace 0 0 0
4163if gt umsg umsg factory usl m_trim blanks 0 0 usl m_length 0 0 0 0
4164brief = umsg brief sappend uns x_brief_d 0 0
4165brief = umsg brief sappend factory 0 0
4166brief = umsg brief sappend uns x_period 0 0
4167end
4168end
4169end
4170ret umsg brief sappend uns x_brief_e 0 0
4171end
4172
4173note add a line to what the agent said, and show it
4174fn uagentsay line ulong to void
4175if eq line 0
4176ret
4177end
4178if eq get g_n 22 0
4179put g_nm 0 0
4180no_text = unsb
4181x = umsg get g_m 4 usl m_set_string no_text 0 0
4182put g_n 22 1
4183end
4184sappend_text = usl m_append
4185x = umsg get g_m 4 sappend_text line 0 0
4186put g_nm 0 10
4187put g_nm 1 0
4188x = umsg get g_m 4 sappend_text unsb 0 0
4189if eq get g_n 20 1
4190uanswershow
4191end
4192end
4193
4194note one line the agent printed, as Hop shows it (Sources/Runners.swift, AgentEvents): a line of Claude Code's
4195note stream gives its text and "> " and the name of each tool it uses, and its last line the id to carry on
4196note from (an error there is said); any other line is shown as it is. 0: nothing to show
4197fn uagentline line ulong to ulong
4198if eq and umsg line usl m_has_prefix uns x_brace 0 0 255 0
4199ret line
4200end
4201d = umsg line usl m_data_using 4 0 0
4202if eq d 0
4203ret line
4204end
4205obj = umsg ucl c_json usl m_json_object d 0 0
4206if not uiskind obj 7
4207ret line
4208end
4209kind = ukeyed obj k_type
4210if not uiskind kind 9
4211ret 0
4212end
4213sequal = usl m_equal_string
4214sappend = usl m_append_string
4215if eq and umsg kind sequal uns x_assistant 0 0 255 1
4216message = ukeyed obj k_message
4217if not uiskind message 7
4218ret 0
4219end
4220parts = ukeyed message k_content
4221if not uiskind parts 8
4222ret 0
4223end
4224put g_nm 0 10
4225put g_nm 1 0
4226line_end = unsb
4227put g_nm 0 0
4228shown_text = unsb
4229cnt = umsg parts usl m_count 0 0 0
4230sat = usl m_at
4231have = ulong 0
4232for i ulong cnt bound 1024
4233part_v = umsg parts sat i 0 0
4234if uiskind part_v 7
4235part_kind = ukeyed part_v k_type
4236piece = ulong 0
4237if uiskind part_kind 9
4238if eq and umsg part_kind sequal uns k_parts_text 0 0 255 1
4239piece = ukeyed part_v k_parts_text
4240if not uiskind piece 9
4241piece = 0
4242end
4243end
4244if eq and umsg part_kind sequal uns k_tool_use 0 0 255 1
4245tool_name = ukeyed part_v k_name
4246if not uiskind tool_name 9
4247tool_name = uns x_tool_word
4248end
4249piece = umsg uns x_tool_mark sappend tool_name 0 0
4250end
4251end
4252if ne piece 0
4253if eq have 1
4254shown_text = umsg shown_text sappend line_end 0 0
4255end
4256shown_text = umsg shown_text sappend piece 0 0
4257have = 1
4258end
4259end
4260end
4261if eq have 0
4262ret 0
4263end
4264ret shown_text
4265end
4266if eq and umsg kind sequal uns k_result 0 0 255 1
4267sid = ukeyed obj k_session_id
4268if uiskind sid 9
4269if ne get g_m 33 0
4270x = umsg get g_m 33 usl m_release 0 0 0
4271end
4272put g_m 33 umsg sid usl m_retain 0 0 0
4273end
4274if uyes ukeyed obj k_is_error
4275problem = ukeyed obj k_result
4276if not uiskind problem 9
4277problem = uns x_agent_error
4278end
4279ret umsg uns x_bang sappend problem 0 0
4280end
4281end
4282ret 0
4283end
4284
4285note output of the agent arrived (d; nothing left when it is empty): every whole line is shown
4286fn uagentout d ulong to void
4287buffer = get g_m 32
4288if eq buffer 0
4289ret
4290end
4291n = umsg d usl m_length 0 0 0
4292if gt n 0
4293x = umsg buffer usl m_append_data d 0 0
4294end
4295put g_nl 0 10
4296newline = umsg ucl c_data usl m_data_bytes ulong libptr g_nl 0 1 1 0
4297srange = usl m_range_of_data
4298ssub = usl m_subdata
4299scut = usl m_replace_bytes
4300slen = usl m_length
4301c_s = ucl c_str
4302salloc = usl m_alloc
4303sinit_data = usl m_init_data_encoding
4304more = true
4305for turn ulong 4096 bound 4096
4306if more
4307total = umsg buffer slen 0 0 0
4308if eq total 0
4309more = false
4310else
4311upr 40 total
4312found_at = umsg buffer srange newline 0 0
4313take = total
4314whole_line = false
4315if lt found_at total
4316take = found_at
4317whole_line = true
4318end
4319if and not whole_line ne n 0
4320more = false
4321else
4322piece = umsg buffer ssub 0 take 0
4323line = umsg c_s salloc 0 0 0
4324line = umsg line sinit_data piece 4 0
4325drop = take
4326if whole_line
4327drop = add take 1
4328end
4329upr 40 0
4330x = umsg buffer scut 0 drop 0
4331if ne line 0
4332uagentsay uagentline line
4333end
4334end
4335end
4336end
4337end
4338end
4339
4340note the agent's run has ended in one more way (1 its output, 2 the program); when both have, the turn is over
4341fn uagentended what ulong to void
4342put g_n 47 or get g_n 47 what
4343if eq get g_n 47 2
4344s_after = usl m_perform_after
4345upr 64 bitcast ulong 2.0f64
4346x = umsg get g_o 27 s_after get g_m 38 0 0
4347end
4348if ne get g_n 47 3
4349ret
4350end
4351task = get g_m 26
4352if eq task 0
4353ret
4354end
4355code = and umsg task usl m_termination 0 0 0 4294967295
4356if ne code 0
4357p = uptxt 0 x_agent_stopped_a
4358p = upnum p code
4359p = uptxt p x_agent_stopped_b
4360put g_nm p 0
4361uagentsay unsb
4362end
4363center = umsg ucl c_center usl m_default_center 0 0 0
4364s_forget = usl m_remove_all_observer
4365x = umsg center s_forget get g_o 27 0 get g_m 27
4366x = umsg center s_forget get g_o 27 0 get g_m 37
4367x = umsg center s_forget get g_o 27 0 task
4368srel = usl m_release
4369x = umsg task srel 0 0 0
4370put g_m 26 0
4371put g_n 43 0
4372put g_n 21 1
4373put g_n 39 1
4374x = umsg ucl c_date usl m_reference_now 0 0 0
4375now_bits = ugr 64
4376if ne get g_m 36 0
4377x = umsg get g_m 36 srel 0 0 0
4378end
4379s_double = usl m_number_double
4380cnum = ucl c_number
4381upr 64 now_bits
4382put g_m 36 umsg umsg cnum s_double 0 0 0 usl m_retain 0 0 0
4383end
4384
4385note what the agent's program tells this one: output (agentOut:), errors (agentErr:), its end (agentEnd:), and the
4386note menu's Stop the Agent (stopAgent:); which is the selector, about is what came with it
4387fn uagentevent which ulong about ulong to void
4388if ustatusevent which
4389ret
4390end
4391if eq which get g_m 64
4392uprobedone about
4393ret
4394end
4395if eq which get g_m 46
4396uremotestart
4397ret
4398end
4399if eq which get g_m 47
4400uremotedone about
4401ret
4402end
4403if eq which get g_m 48
4404ufetchdone about
4405ret
4406end
4407if eq which get g_m 41
4408if ne get g_m 26 0
4409x = umsg get g_m 26 usl m_terminate_task 0 0 0
4410end
4411ret
4412end
4413if eq which get g_m 40
4414uagentended 2
4415ret
4416end
4417if eq get g_m 26 0
4418ret
4419end
4420if eq about 0
4421if and eq which get g_m 38 eq and get g_n 47 1 0
4422uagentout umsg ucl c_data usl m_data 0 0 0
4423uagentended 1
4424end
4425ret
4426end
4427info = umsg about usl m_user_info 0 0 0
4428if eq info 0
4429ret
4430end
4431d = umsg info usl m_object_for_key uconst s_data_item 0 0
4432if eq d 0
4433ret
4434end
4435n = umsg d usl m_length 0 0 0
4436if eq which get g_m 38
4437uagentout d
4438if eq n 0
4439uagentended 1
4440else
4441x = umsg get g_m 27 usl m_read_background 0 0 0
4442end
4443ret
4444end
4445if gt n 0
4446said = umsg ucl c_str usl m_alloc 0 0 0
4447said = umsg said usl m_init_data_encoding d 4 0
4448if ne said 0
4449edge = umsg ucl c_charset usl m_newline_set 0 0 0
4450uagentsay umsg uns x_bang usl m_append_string umsg said usl m_trim edge 0 0 0 0
4451end
4452x = umsg get g_m 37 usl m_read_background 0 0 0
4453end
4454end
4455
4456note send the typed text to the agent
4457fn uagentrun to void
4458a = get g_n 12
4459n = get g_n 13
4460if or eq n 0 gt n 255
4461ret
4462end
4463for i ulong n bound 256
4464put g_nm i get g_q add a i
4465end
4466put g_nm n 0
4467request = unsb
4468if eq request 0
4469ret
4470end
4471note the talk on show: what was there joins what was said before, then the request
4472if eq get g_m 25 0
4473told = umsg ucl c_mutable_string usl m_string 0 0 0
4474put g_m 25 umsg told usl m_retain 0 0 0
4475end
4476if eq get g_m 4 0
4477fresh_text = umsg ucl c_mutable_string usl m_string 0 0 0
4478put g_m 4 umsg fresh_text usl m_retain 0 0 0
4479end
4480if eq get g_n 43 1
4481uanswershow
4482uanswerview 1
4483ret
4484end
4485put g_nm 0 10
4486put g_nm 1 10
4487put g_nm 2 0
4488blank_line = unsb
4489sappend_text = usl m_append
4490if eq get g_n 39 1
4491x = umsg get g_m 25 sappend_text get g_m 4 0 0
4492x = umsg get g_m 25 sappend_text blank_line 0 0
4493end
4494x = umsg get g_m 25 sappend_text uns x_you 0 0
4495x = umsg get g_m 25 sappend_text request 0 0
4496x = umsg get g_m 25 sappend_text blank_line 0 0
4497put g_n 39 0
4498put g_n 21 0
4499put g_n 22 0
4500engine = uagentpicked
4501if eq engine 0
4502uagentsay uagentwhy
4503put g_n 21 1
4504put g_n 39 1
4505uanswershow
4506uanswerview 1
4507ret
4508end
4509if eq get g_n 44 0
4510if eq get g_n 14 0
4511uagentsay uns x_agent_ask
4512put g_n 21 1
4513put g_n 39 1
4514uanswershow
4515uanswerview 1
4516ret
4517end
4518alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0
4519x = umsg alert usl m_set_message uns x_agent_ask 0 0
4520x = umsg alert usl m_set_informative uns x_agent_ask_more 0 0
4521x = umsg alert usl m_add_button uns x_agent_yes 0 0
4522x = umsg alert usl m_add_button uns x_agent_no 0 0
4523if ne umsg alert usl m_run_modal 0 0 0 1000
4524ret
4525end
4526put g_n 44 1
4527end
4528x = umsg get g_m 4 usl m_set_string uns x_agent_working 0 0
4529uanswershow
4530uanswerview 1
4531note the words to run: the request in place of "{prompt}", Hop's standing instructions before it, or for
4532note Claude Code as its system prompt; a follow-up within 15 minutes carries on from Claude Code's last run
4533brief = uagentbrief
4534command = ukeyed engine k_command
4535sat = usl m_at
4536sappend = usl m_append_string
4537sequal = usl m_equal_string
4538tool = umsg command sat 0 0 0
4539is_claude = eq and umsg tool sequal uns x_claude 0 0 255 1
4540prompt = request
4541if not is_claude
4542prompt = umsg umsg umsg brief sappend blank_line 0 0 sappend uns x_request 0 0 sappend request 0 0
4543end
4544argv = umsg ucl c_mutable_array usl m_array 0 0 0
4545sadd = usl m_add_object
4546mark = uns x_prompt_mark
4547cnt = umsg command usl m_count 0 0 0
4548for i ulong cnt bound 256
4549word = umsg command sat i 0 0
4550if uiskind word 9
4551x = umsg argv sadd umsg word usl m_replace mark prompt 0 0 0
4552end
4553end
4554if is_claude
4555shas = usl m_contains_object
4556if eq and umsg argv shas uns x_append_system 0 0 255 0
4557x = umsg argv sadd uns x_append_system 0 0
4558x = umsg argv sadd brief 0 0
4559end
4560if and ne get g_m 33 0 ne get g_m 36 0
4561if eq and umsg argv shas uns x_resume 0 0 255 0
4562x = umsg get g_m 36 usl m_double_value 0 0 0
4563last_bits = ugr 64
4564x = umsg ucl c_date usl m_reference_now 0 0 0
4565if lt sub bitcast f64 ugr 64 bitcast f64 last_bits 900.0f64
4566x = umsg argv sadd uns x_resume 0 0
4567x = umsg argv sadd get g_m 33 0 0
4568end
4569end
4570end
4571end
4572task = ushellrun argv get g_m 30
4573tube = umsg ucl c_pipe usl m_pipe 0 0 0
4574error_tube = umsg ucl c_pipe usl m_pipe 0 0 0
4575quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
4576x = umsg task usl m_set_output tube 0 0
4577x = umsg task usl m_set_error error_tube 0 0
4578x = umsg task usl m_set_input quiet 0 0
4579sret = usl m_retain
4580reader = umsg tube usl m_reading 0 0 0
4581error_reader = umsg error_tube usl m_reading 0 0 0
4582if ne get g_m 27 0
4583x = umsg get g_m 27 usl m_release 0 0 0
4584x = umsg get g_m 37 usl m_release 0 0 0
4585x = umsg get g_m 32 usl m_release 0 0 0
4586end
4587put g_m 27 umsg reader sret 0 0 0
4588put g_m 37 umsg error_reader sret 0 0 0
4589put g_m 32 umsg umsg ucl c_mutable_data usl m_data 0 0 0 sret 0 0 0
4590put g_m 26 umsg task sret 0 0 0
4591put g_n 47 0
4592center = umsg ucl c_center usl m_default_center 0 0 0
4593s_observe = usl m_add_observer
4594read_done = uconst s_read_done
4595ended = uconst s_task_ended
4596upr 40 reader
4597x = umsg center s_observe get g_o 27 get g_m 38 read_done
4598upr 40 error_reader
4599x = umsg center s_observe get g_o 27 get g_m 39 read_done
4600upr 40 task
4601x = umsg center s_observe get g_o 27 get g_m 40 ended
4602put g_n 43 1
4603x = umsg task usl m_launch 0 0 0
4604x = umsg reader usl m_read_background 0 0 0
4605x = umsg error_reader usl m_read_background 0 0 0
4606end
4607
4608note ---- files on other machines, as Hop finds them (Sources/Machines.swift, Sources/Model.swift searchFiles) ----
4609note Each machine of Hop's settings keeps its own list of files (20 pieces, built there by a command Hop sends
4610note when the list is missing or old); a search runs on the machine through ssh and the lines that hold every
4611note typed word come back, to be scored here by the rule the local files are scored by. The machines are asked
4612note a moment after typing pauses, all at once, by one program whose answer is read when it has ended. Enter on
4613note such a file brings it over (scp, into the cache folder) and opens it; a folder's path goes to the clipboard.
4614note an NSString of text t with every "%%" turned into a double quote and every "^^" into a backslash
4615fn uquoted2 t view uchar * to ulong
4616put g_nm 0 34
4617put g_nm 1 0
4618quote_mark = unsb
4619put g_nm 0 92
4620put g_nm 1 0
4621back_mark = unsb
4622plain = uns t
4623srep = usl m_replace
4624plain = umsg plain srep uns x_percents quote_mark 0
4625ret umsg plain srep uns x_carets back_mark 0
4626end
4627
4628note the machines of the settings: their names into g_mn (63 bytes each at most), their ssh names kept; 10 at most
4629fn umachines config ulong to void
4630put g_n 54 0
4631put g_n 59 0
4632if eq get g_n 14 1
4633put g_n 59 1
4634else
4635n = ucs x_env_ssh
4636upr 0 ulong libptr g_nm 0 1024
4637if ne ucall 9 0
4638put g_n 59 1
4639end
4640end
4641if eq config 0
4642ret
4643end
4644machines = ukeyed config k_machines
4645if not uiskind machines 8
4646ret
4647end
4648sat = usl m_at
4649aliases = umsg ucl c_mutable_array usl m_array 0 0 0
4650cnt = umsg machines usl m_count 0 0 0
4651have = ulong 0
4652for i ulong cnt bound 64
4653if lt have 10
4654m = umsg machines sat i 0 0
4655if uiskind m 7
4656name = ukeyed m k_name
4657via = ukeyed m k_ssh
4658if and uiskind name 9 uiskind via 9
4659src = umsg name get g_o 5 0 0 0
4660if ne src 0
4661upr 0 src
4662n = ucall 7
4663if gt n 63
4664n = 63
4665end
4666if gt n 0
4667upr 0 ulong libptr g_mn mul have 64 n
4668upr 8 src
4669upr 16 n
4670x = ucall 8
4671end
4672put g_ml have uchar n
4673x = umsg aliases usl m_add_object m 0 0
4674have = add have 1
4675end
4676end
4677end
4678end
4679end
4680if ne get g_m 42 0
4681x = umsg get g_m 42 usl m_release 0 0 0
4682end
4683put g_m 42 umsg aliases usl m_retain 0 0 0
4684put g_n 54 have
4685end
4686
4687note may other machines be reached: always when resident; a check reaches none but through its stand-in (HOPSSH)
4688note (looked up once, when the settings are read: 59 is 1 for yes)
4689fn uremoteok to bool
4690ret eq get g_n 59 1
4691end
4692
4693note the program to reach other machines with: ssh (scp when copy is 1), or for a check its stand-in
4694fn uremotetool copy ulong to ulong
4695if eq get g_n 14 0
4696n = ucs x_env_ssh
4697if eq copy 1
4698n = ucs x_env_scp
4699end
4700upr 0 ulong libptr g_nm 0 1024
4701given = ucall 9
4702if ne given 0
4703n = ufetch given
4704ret ushellquote unsb
4705end
4706end
4707if eq copy 1
4708ret uns x_scp_word
4709end
4710ret uns x_ssh_word
4711end
4712
4713note run a script through the login shell and read all it says when it has ended: done is the selector told then.
4714note The program (kept) and where its answer is read (kept) go to places prog and reader of g_m
4715fn uscriptrun script ulong done ulong prog ulong reader_at ulong to void
4716argv = umsg ucl c_mutable_array usl m_array 0 0 0
4717sadd = usl m_add_object
4718x = umsg argv sadd uns x_sh 0 0
4719x = umsg argv sadd uns x_dash_c 0 0
4720x = umsg argv sadd script 0 0
4721task = ushellrun argv 0
4722tube = umsg ucl c_pipe usl m_pipe 0 0 0
4723quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
4724x = umsg task usl m_set_output tube 0 0
4725x = umsg task usl m_set_error quiet 0 0
4726x = umsg task usl m_set_input quiet 0 0
4727reader = umsg tube usl m_reading 0 0 0
4728sret = usl m_retain
4729center = umsg ucl c_center usl m_default_center 0 0 0
4730whole_read = uconst s_read_to_end_done
4731if ne get g_m prog 0
4732x = umsg get g_m prog usl m_terminate_task 0 0 0
4733x = umsg center usl m_remove_all_observer get g_o 27 whole_read get g_m reader_at
4734x = umsg get g_m prog usl m_release 0 0 0
4735x = umsg get g_m reader_at usl m_release 0 0 0
4736end
4737put g_m prog umsg task sret 0 0 0
4738put g_m reader_at umsg reader sret 0 0 0
4739s_observe = usl m_add_observer
4740upr 40 reader
4741x = umsg center s_observe get g_o 27 done whole_read
4742x = umsg task usl m_launch 0 0 0
4743x = umsg reader usl m_read_to_end 0 0 0
4744end
4745
4746note the command that makes machine m (a settings entry) build its list of files when it has none or an old one
4747fn urefreshscript m ulong to ulong
4748sappend = usl m_append_string
4749sat = usl m_at
4750roots = ukeyed m k_roots_m
4751skips = ukeyed m k_skip_m
4752if not uiskind skips 8
4753skips = umsg ucl c_mutable_array usl m_array 0 0 0
4754sadd = usl m_add_object
4755x = umsg skips sadd uns x_mskip0 0 0
4756x = umsg skips sadd uns x_mskip1 0 0
4757x = umsg skips sadd uns x_mskip2 0 0
4758x = umsg skips sadd uns x_mskip3 0 0
4759x = umsg skips sadd uns x_mskip4 0 0
4760x = umsg skips sadd uns x_mskip5 0 0
4761x = umsg skips sadd uns x_mskip6 0 0
4762x = umsg skips sadd uns x_mskip7 0 0
4763x = umsg skips sadd uns x_mskip8 0 0
4764x = umsg skips sadd uns x_mskip9 0 0
4765end
4766prune = umsg ucl c_mutable_string usl m_string 0 0 0
4767smore = usl m_append
4768cnt = umsg skips usl m_count 0 0 0
4769for i ulong cnt bound 256
4770one_name = umsg skips sat i 0 0
4771if uiskind one_name 9
4772if gt umsg prune usl m_length 0 0 0 0
4773x = umsg prune smore uns x_or_flag 0 0
4774end
4775x = umsg prune smore uns x_name_flag 0 0
4776x = umsg prune smore ushellquote one_name 0 0
4777end
4778end
4779places = umsg ucl c_mutable_string usl m_string 0 0 0
4780if uiskind roots 8
4781cnt = umsg roots usl m_count 0 0 0
4782for i ulong cnt bound 256
4783one_root = umsg roots sat i 0 0
4784if uiskind one_root 9
4785if gt umsg places usl m_length 0 0 0 0
4786x = umsg places smore uns x_space 0 0
4787end
4788x = umsg places smore ushellquote one_root 0 0
4789end
4790end
4791end
4792build = umsg umsg umsg umsg uns x_build_a sappend places 0 0 sappend uquoted2 x_build_b 0 0 sappend prune 0 0 sappend uquoted2 x_build_c 0 0
4793put g_nm 0 10
4794put g_nm 1 0
4795line_end = unsb
4796script = umsg ucl c_mutable_string usl m_string 0 0 0
4797x = umsg script smore uns x_fresh_a 0 0
4798x = umsg script smore line_end 0 0
4799x = umsg script smore uquoted2 x_fresh_b 0 0
4800x = umsg script smore line_end 0 0
4801x = umsg script smore uquoted2 x_fresh_c 0 0
4802x = umsg script smore ushellquote build 0 0
4803x = umsg script smore uns x_fresh_d 0 0
4804x = umsg script smore line_end 0 0
4805x = umsg script smore uns x_fresh_e 0 0
4806ret script
4807end
4808
4809note ask machine k to build its list of files if it has none or an old one; nothing is waited for
4810fn uremoterefresh k ulong to void
4811if or or ge k get g_n 54 eq get g_m 42 0 not uremoteok
4812ret
4813end
4814m = umsg get g_m 42 get g_m 16 k 0 0
4815via = ukeyed m k_ssh
4816sappend = usl m_append_string
4817line = umsg umsg umsg uremotetool 0 sappend uns x_ssh_options 0 0 sappend ushellquote via 0 0 sappend uns x_space 0 0
4818line = umsg line sappend ushellquote urefreshscript m 0 0
4819argv = umsg ucl c_mutable_array usl m_array 0 0 0
4820sadd = usl m_add_object
4821x = umsg argv sadd uns x_sh 0 0
4822x = umsg argv sadd uns x_dash_c 0 0
4823x = umsg argv sadd line 0 0
4824task = ushellrun argv 0
4825quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
4826x = umsg task usl m_set_output quiet 0 0
4827x = umsg task usl m_set_error quiet 0 0
4828x = umsg task usl m_set_input quiet 0 0
4829x = umsg task usl m_launch 0 0 0
4830end
4831
4832note a moment after typing pauses the machines are asked; until then nothing found there is shown
4833fn uremotesoon to void
4834put g_n 49 0
4835put g_n 58 0
4836if le get g_n 51 2
4837put g_n 51 0
4838end
4839if eq get g_n 54 0
4840ret
4841end
4842if not uremoteok
4843ret
4844end
4845s_go = get g_m 46
4846x = umsg ucl c_obj usl m_cancel_previous get g_o 27 s_go 0
4847if or or lt get g_n 13 2 gt get g_n 13 255 ne get g_n 36 0
4848ret
4849end
4850s_after = usl m_perform_after
4851upr 64 bitcast ulong 0.22f64
4852x = umsg get g_o 27 s_after s_go 0 0
4853end
4854
4855note ask every machine for the files that hold every typed word (the longest first, as on the machine's side
4856note each further word narrows what the first found)
4857fn uremotestart to void
4858a = get g_n 12
4859n = get g_n 13
4860if or or lt n 2 gt n 255 eq get g_n 54 0
4861ret
4862end
4863for i ulong n bound 256
4864put g_rq i get g_q add a i
4865put g_nm i get g_q add a i
4866end
4867put g_n 53 n
4868put g_nm n 0
4869typed = unsb
4870if eq typed 0
4871ret
4872end
4873parts = umsg umsg typed usl m_lowercase 0 0 0 usl m_components uns x_space 0 0
4874sat = usl m_at
4875slen = usl m_length
4876cnt = umsg parts usl m_count 0 0 0
4877longest = ulong 0
4878longest_len = ulong 0
4879for i ulong cnt bound 64
4880one_word = umsg parts sat i 0 0
4881wl = umsg one_word slen 0 0 0
4882if ge wl longest_len
4883if gt wl 0
4884longest = one_word
4885longest_len = wl
4886end
4887end
4888end
4889if eq longest 0
4890ret
4891end
4892sappend = usl m_append_string
4893filter = umsg umsg uns x_remote_grep sappend ushellquote longest 0 0 sappend uquoted2 x_remote_shard 0 0
4894for i ulong cnt bound 64
4895one_word = umsg parts sat i 0 0
4896if and gt umsg one_word slen 0 0 0 0 eq and umsg one_word usl m_equal_string longest 0 0 255 0
4897filter = umsg umsg umsg filter sappend uns x_remote_pipe 0 0 sappend uns x_remote_grep 0 0 sappend ushellquote one_word 0 0
4898end
4899end
4900remote = umsg umsg uns x_remote_a sappend filter 0 0 sappend uquoted2 x_remote_b 0 0
4901remote_quoted = ushellquote remote
4902tool = uremotetool 0
4903put g_nm 0 10
4904put g_nm 1 0
4905line_end = unsb
4906script = umsg ucl c_mutable_string usl m_string 0 0 0
4907smore = usl m_append
4908for k ulong get g_n 54 bound 10
4909m = umsg get g_m 42 sat k 0 0
4910via = ukeyed m k_ssh
4911x = umsg script smore uns x_local_a 0 0
4912x = umsg script smore tool 0 0
4913x = umsg script smore uns x_ssh_options 0 0
4914x = umsg script smore ushellquote via 0 0
4915x = umsg script smore uns x_space 0 0
4916x = umsg script smore remote_quoted 0 0
4917x = umsg script smore uns x_local_b 0 0
4918put g_nm 0 uchar add 48 k
4919put g_nm 1 0
4920x = umsg script smore unsb 0 0
4921x = umsg script smore uns x_local_c 0 0
4922x = umsg script smore line_end 0 0
4923end
4924x = umsg script smore uns x_wait_word 0 0
4925uscriptrun script get g_m 47 43 44
4926end
4927
4928note keep a file found on a machine among the best 64, best first
4929fn uremotekeep sc ulong o ulong ln ulong k ulong to void
4930have = get g_n 49
4931if and ge have 64 le sc get g_rs 63
4932ret
4933end
4934pos = have
4935if ge have 64
4936pos = 63
4937else
4938put g_n 49 add have 1
4939end
4940while gt pos 0 bound 80
4941if ge get g_rs sub pos 1 sc
4942break
4943end
4944put g_rs pos get g_rs sub pos 1
4945put g_ro pos get g_ro sub pos 1
4946put g_rl pos get g_rl sub pos 1
4947put g_rw pos get g_rw sub pos 1
4948pos = sub pos 1
4949end
4950put g_rs pos sc
4951put g_ro pos o
4952put g_rl pos ln
4953put g_rw pos uchar k
4954end
4955
4956note does the line at o of g_rb (n bytes) read exactly as text t
4957fn uremoteis o ulong n ulong t view uchar * to bool
4958tl = len t
4959if ne n tl
4960ret false
4961end
4962for i ulong tl bound 64
4963if ne ulong get g_rb add o i ulong get t i
4964ret false
4965end
4966end
4967ret true
4968end
4969
4970note the machines have answered (about: the notice that carries what they said). When the typed text is still
4971note the one they were asked for, every line is scored and the list is made anew
4972fn uremotedone about ulong to void
4973if eq about 0
4974ret
4975end
4976info = umsg about usl m_user_info 0 0 0
4977if eq info 0
4978ret
4979end
4980d = umsg info usl m_object_for_key uconst s_data_item 0 0
4981if eq d 0
4982ret
4983end
4984a = get g_n 12
4985n = get g_n 13
4986if ne n get g_n 53
4987ret
4988end
4989for i ulong n bound 256
4990if ne ulong get g_q add a i ulong get g_rq i
4991ret
4992end
4993end
4994total = umsg d usl m_length 0 0 0
4995if gt total 1048575
4996total = 1048575
4997end
4998put g_n 49 0
4999put g_n 58 0
5000put g_n 50 total
5001if eq total 0
5002ret
5003end
5004src = umsg d usl m_bytes 0 0 0
5005base = ulong libptr g_rb 0 total
5006upr 0 base
5007upr 8 src
5008upr 16 total
5009x = ucall 8
5010pos = ulong 0
5011more = true
5012for turn ulong 20000 bound 20000
5013if more
5014if ge pos total
5015more = false
5016else
5017upr 0 add base pos
5018upr 8 10
5019upr 16 sub total pos
5020x = ucall 12
5021e = total
5022hit_at = ugr 0
5023if ne hit_at 0
5024e = sub hit_at base
5025end
5026ln = sub e pos
5027if and ge ln 3 eq ulong get g_rb add pos 1 58
5028k = sub ulong get g_rb pos 48
5029if lt k get g_n 54
5030o = add pos 2
5031bl = sub ln 2
5032if uremoteis o bl x_no_index
5033put g_n 51 2
5034put g_n 52 k
5035uremoterefresh k
5036else
5037if uremoteis o bl x_unreachable
5038put g_n 51 1
5039put g_n 52 k
5040else
5041pl = bl
5042if eq ulong get g_rb sub add o bl 1 47
5043pl = sub bl 1
5044end
5045if and gt pl 0 le pl 4000
5046for j ulong pl bound 4096
5047put g_line j uchar ulower ulong get g_rb add o j
5048end
5049sc = ufscore pl
5050if ne sc 0
5051uremotekeep sc o bl k
5052name_at = pl
5053while gt name_at 0 bound 4097
5054if eq ulong get g_line sub name_at 1 47
5055break
5056end
5057name_at = sub name_at 1
5058end
5059if eq sub pl name_at n
5060same_name = true
5061for j ulong n bound 256
5062if ne ulong get g_line add name_at j ulower ulong get g_rq j
5063same_name = false
5064end
5065end
5066if same_name
5067put g_n 58 1
5068end
5069end
5070end
5071end
5072end
5073end
5074end
5075end
5076pos = add e 1
5077end
5078end
5079end
5080keep_row = get g_n 6
5081unarrow
5082x = umsg get g_o 1 get g_o 7 0 0 0
5083if lt keep_row get g_n 1
5084uchoose keep_row
5085else
5086if gt get g_n 1 0
5087uchoose 0
5088end
5089end
5090ushowst
5091end
5092
5093note the text of a row for a file on another machine into g_nm from byte p: its name, the folder it is in,
5094note and the machine; the byte after it
5095fn uremoterow p ulong r ulong to ulong
5096if ge r get g_n 49
5097ret p
5098end
5099o = get g_ro r
5100ln = get g_rl r
5101if gt ln 0
5102if eq ulong get g_rb sub add o ln 1 47
5103ln = sub ln 1
5104end
5105end
5106ns0 = ln
5107while gt ns0 0 bound 4097
5108if eq ulong get g_rb sub add o ns0 1 47
5109break
5110end
5111ns0 = sub ns0 1
5112end
5113q = p
5114nl = sub ln ns0
5115if gt nl 300
5116nl = 300
5117end
5118for j ulong nl bound 301
5119put g_nm add q j get g_rb add add o ns0 j
5120end
5121q = add q nl
5122if and gt ns0 1 le ns0 400
5123q = uptxt q x_gap
5124for j ulong sub ns0 1 bound 401
5125put g_nm add q j get g_rb add o j
5126end
5127q = add q sub ns0 1
5128end
5129k = ulong get g_rw r
5130q = uptxt q x_on
5131ml = ulong get g_ml k
5132for j ulong ml bound 64
5133put g_nm add q j get g_mn add mul k 64 j
5134end
5135ret add q ml
5136end
5137
5138note the path of found file r, as it is written on its machine, as an NSString (without a folder's last "/")
5139fn uremotepath r ulong to ulong
5140o = get g_ro r
5141ln = get g_rl r
5142if gt ln 0
5143if eq ulong get g_rb sub add o ln 1 47
5144ln = sub ln 1
5145end
5146end
5147if or eq ln 0 gt ln 1000
5148ret 0
5149end
5150for j ulong ln bound 1001
5151put g_nm j get g_rb add o j
5152end
5153put g_nm ln 0
5154ret unsb
5155end
5156
5157note put text on the clipboard (a check uses a board of its own)
5158fn uclipput words ulong to void
5159pboard = ulong 0
5160if eq get g_n 14 1
5161pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
5162else
5163pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
5164end
5165x = umsg pboard usl m_clear 0 0 0
5166x = umsg pboard usl m_set_string_type words uns x_type_string 0
5167put g_n 29 1
5168if eq get g_n 14 1
5169uclipmine 0
5170end
5171end
5172
5173note Enter on a file of another machine: a folder's "ssh name:path" goes to the clipboard; a file is brought over
5174note (when it is under 2 GB) into the cache folder and opened when it has arrived
5175fn uremoteopen r ulong to void
5176if or or ge r get g_n 49 eq get g_m 42 0 not uremoteok
5177ret
5178end
5179k = ulong get g_rw r
5180o = get g_ro r
5181ln = get g_rl r
5182is_folder = false
5183if gt ln 0
5184is_folder = eq ulong get g_rb sub add o ln 1 47
5185end
5186path = uremotepath r
5187if eq path 0
5188ret
5189end
5190m = umsg get g_m 42 get g_m 16 k 0 0
5191via = ukeyed m k_ssh
5192name = ukeyed m k_name
5193sappend = usl m_append_string
5194there = umsg umsg via sappend uns x_colon_only 0 0 sappend path 0 0
5195sret = usl m_retain
5196if ne get g_m 51 0
5197x = umsg get g_m 51 usl m_release 0 0 0
5198end
5199put g_m 51 umsg there sret 0 0 0
5200put g_n 52 k
5201if is_folder
5202uclipput there
5203put g_n 51 4
5204ushowst
5205ret
5206end
5207dest = ulong 0
5208if eq get g_n 14 0
5209dest = uhoppath x_check_cache
5210else
5211x = ucall 30
5212dest = umsg ugr 0 sappend uns x_remote_cache 0 0
5213end
5214if eq dest 0
5215ret
5216end
5217dest = umsg umsg dest sappend name 0 0 sappend path 0 0
5218if ne get g_m 50 0
5219x = umsg get g_m 50 usl m_release 0 0 0
5220end
5221put g_m 50 umsg dest sret 0 0 0
5222folder = umsg dest usl m_dir_of 0 0 0
5223tool = uremotetool 0
5224script = umsg uns x_fetch_a sappend tool 0 0
5225script = umsg script sappend uns x_ssh_options 0 0
5226script = umsg script sappend ushellquote via 0 0
5227script = umsg script sappend uns x_space 0 0
5228script = umsg script sappend ushellquote umsg uns x_fetch_stat sappend ushellquote path 0 0 0 0
5229script = umsg script sappend uquoted2 x_fetch_b 0 0
5230script = umsg script sappend ushellquote folder 0 0
5231script = umsg script sappend uns x_fetch_c 0 0
5232script = umsg script sappend uremotetool 1 0 0
5233script = umsg script sappend uns x_scp_options 0 0
5234script = umsg script sappend ushellquote there 0 0
5235script = umsg script sappend uns x_space 0 0
5236script = umsg script sappend ushellquote dest 0 0
5237script = umsg script sappend uns x_fetch_d 0 0
5238put g_n 51 3
5239ushowst
5240uscriptrun script get g_m 48 45 49
5241end
5242
5243note the program bringing a file over has ended: when it says the file arrived it is opened, else the path goes
5244note to the clipboard and that is said
5245fn ufetchdone about ulong to void
5246if eq about 0
5247ret
5248end
5249info = umsg about usl m_user_info 0 0 0
5250if eq info 0
5251ret
5252end
5253d = umsg info usl m_object_for_key uconst s_data_item 0 0
5254arrived = false
5255if ne d 0
5256said = umsg ucl c_str usl m_alloc 0 0 0
5257said = umsg said usl m_init_data_encoding d 4 0
5258if ne said 0
5259arrived = eq and umsg said usl m_contains uns x_fetched 0 0 255 1
5260end
5261end
5262if arrived
5263put g_n 51 0
5264put g_n 55 1
5265if eq get g_n 7 1
5266url = umsg ucl c_url usl m_furl get g_m 50 0 0
5267ws = umsg ucl c_ws usl m_shws 0 0 0
5268put g_n 9 and umsg ws usl m_open url 0 0 255
5269end
5270else
5271if ne get g_m 51 0
5272uclipput get g_m 51
5273end
5274put g_n 51 5
5275end
5276ushowst
5277end
5278
5279note every half hour, and when the panel starts, each machine is asked to build its list if it is old
5280fn uremoterefreshall to void
5281for k ulong get g_n 54 bound 10
5282uremoterefresh k
5283end
5284end
5285
5286note what to say about a machine into g_nm from byte p; the byte after it
5287fn uremotenote p ulong to ulong
5288w = get g_n 51
5289k = get g_n 52
5290if or eq w 0 ge k get g_n 54
5291ret p
5292end
5293q = uptxt p x_gap
5294if eq w 3
5295q = uptxt q x_note_bringing
5296end
5297if eq w 4
5298q = uptxt q x_note_copied
5299end
5300if eq w 5
5301q = uptxt q x_note_failed
5302end
5303ml = ulong get g_ml k
5304for j ulong ml bound 64
5305put g_nm add q j get g_mn add mul k 64 j
5306end
5307q = add q ml
5308if eq w 1
5309q = uptxt q x_note_unreachable
5310end
5311if eq w 2
5312q = uptxt q x_note_building
5313end
5314ret q
5315end
5316
5317note for a check: HOPLATE sends Enter late, when the machines have had time to answer
5318fn uchecklate to void
5319put g_n 48 20
5320n = ucs x_env_late
5321upr 0 ulong libptr g_nm 0 1024
5322if ne ucall 9 0
5323put g_n 48 80
5324end
5325end
5326
5327note the three more things this program is told by selector (entry 13 hears them all)
5328fn umoremethods mine ulong to bool
5329ok = umethod mine m_remote_go 13 t_v
5330ok = and ok umethod mine m_remote_done 13 t_v
5331ok = and ok umethod mine m_fetch_done 13 t_v
5332put g_m 46 usl m_remote_go
5333put g_m 47 usl m_remote_done
5334put g_m 48 usl m_fetch_done
5335ret ok
5336end
5337
5338note ---- the icon in the menu bar and its menu, as Hop has them (Sources/main.swift) ----
5339note Open, Rebuild file index, Allow paste into apps, Open at login, Settings, Clear clipboard history, Quit.
5340note one item of that menu: title, what it tells this program (action_sel), its key (an NSString); the item
5341fn ustatusadd menu ulong title view uchar * action_sel ulong key_string ulong to ulong
5342item = umsg ucl c_menu_item usl m_alloc 0 0 0
5343title_string = uns title
5344item = umsg item usl m_init_item title_string action_sel key_string
5345x = umsg item usl m_set_target get g_o 27 0 0
5346x = umsg menu usl m_add_item item 0 0
5347ret item
5348end
5349
5350note macOS's keeper of what opens at login, for this app (0: there is none)
5351fn uloginservice to ulong
5352n = ucs x_sm_path
5353upr 0 ulong libptr g_nm 0 1024
5354upr 8 1
5355x = ucall 0
5356c = ucl c_sm_service
5357if eq c 0
5358ret 0
5359end
5360ret umsg c usl m_main_app 0 0 0
5361end
5362
5363note Open at login: on becomes off and off on; when macOS refuses, that is said
5364fn ulogintoggle to void
5365service = uloginservice
5366if eq service 0
5367ret
5368end
5369done = ulong 0
5370if eq umsg service usl m_status 0 0 0 1
5371done = and umsg service usl m_unregister 0 0 0 255
5372if eq done 1
5373x = umsg get g_m 53 usl m_set_state 0 0 0
5374end
5375else
5376done = and umsg service usl m_register 0 0 0 255
5377if eq done 1
5378x = umsg get g_m 53 usl m_set_state 1 0 0
5379end
5380end
5381if eq done 0
5382alert = umsg umsg ucl c_alert usl m_alloc 0 0 0 usl m_init 0 0 0
5383x = umsg alert usl m_set_message uns x_login_failed 0 0
5384x = umsg alert usl m_run_modal 0 0 0
5385end
5386end
5387
5388note Allow paste into apps: macOS is asked to show its own question about Accessibility for this app
5389fn upasteask to void
5390prompt_key = uconst s_trusted_prompt
5391if eq prompt_key 0
5392ret
5393end
5394yes_flag = umsg ucl c_number usl m_number_bool 1 0 0
5395options = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
5396x = umsg options usl m_set_object yes_flag prompt_key 0
5397f = usym s_trusted_options
5398if eq f 0
5399ret
5400end
5401upr 0 options
5402x = ucallf f
5403end
5404
5405note Clear clipboard history: every copied thing that is not pinned goes, a picture's sealed file with it. Like
5406note every change to the history it is this program's to do only while Hop is not running
5407fn uclipclear to void
5408if and eq get g_n 14 1 uhoprunning
5409ret
5410end
5411items = uclipsmutable
5412if eq items 0
5413ret
5414end
5415sat = usl m_at
5416sremove = usl m_remove_at
5417cnt = umsg items usl m_count 0 0 0
5418for back ulong cnt bound 100000
5419j = sub sub cnt 1 back
5420e = umsg items sat j 0 0
5421if uiskind e 7
5422if not uclippinned e
5423image_name = ukeyed e k_image
5424if uiskind image_name 9
5425if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
5426folder = uhoppath x_clip_images
5427if ne folder 0
5428gone = umsg folder usl m_append_string image_name 0 0
5429manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
5430x = umsg manager usl m_remove_item gone 0 0
5431end
5432end
5433end
5434x = umsg items sremove j 0 0
5435end
5436end
5437end
5438if eq uclipswrite items 1
5439uloadclips
5440urefresh
5441end
5442end
5443
5444note the menu of the icon in the menu bar
5445fn ustatusmenu to ulong
5446menu = umsg ucl c_menu usl m_alloc 0 0 0
5447menu = umsg menu usl m_init_title uns x_app 0 0
5448put g_nm 0 0
5449no_key = unsb
5450s_add = usl m_add_item
5451c_item = ucl c_menu_item
5452s_line = usl m_separator
5453x = ustatusadd menu x_status_open get g_m 54 no_key
5454x = umsg menu s_add umsg c_item s_line 0 0 0 0 0
5455x = ustatusadd menu x_status_index get g_m 55 no_key
5456x = ustatusadd menu x_status_paste get g_m 56 no_key
5457login_item = ustatusadd menu x_status_login get g_m 57 no_key
5458put g_m 53 login_item
5459if eq get g_n 14 1
5460service = uloginservice
5461if ne service 0
5462if eq umsg service usl m_status 0 0 0 1
5463x = umsg login_item usl m_set_state 1 0 0
5464end
5465end
5466end
5467comma_key = uns x_key_comma
5468x = ustatusadd menu x_status_settings get g_m 58 comma_key
5469x = ustatusadd menu x_status_clear get g_m 59 no_key
5470x = umsg menu s_add umsg c_item s_line 0 0 0 0 0
5471q_key = uns x_key_q
5472s_quit = usl m_terminate
5473quit_item = ustatusadd menu x_quit s_quit q_key
5474x = umsg quit_item usl m_set_target umsg ucl c_app usl m_shared 0 0 0 0 0
5475ret menu
5476end
5477
5478note put the icon in the menu bar (a check has none; with HOPMENU it says the menu's items instead)
5479fn ustatus to void
5480menu = ustatusmenu
5481if eq get g_n 14 0
5482n = ucs x_env_menu
5483upr 0 ulong libptr g_nm 0 1024
5484if eq ucall 9 0
5485ret
5486end
5487entries = umsg menu usl m_item_array 0 0 0
5488sat = usl m_at
5489s_title = usl m_item_title
5490cnt = umsg entries usl m_count 0 0 0
5491p = uptxt 0 x_menu_word
5492for i ulong cnt bound 32
5493title_bytes = umsg umsg umsg entries sat i 0 0 s_title 0 0 0 get g_o 5 0 0 0
5494if gt i 0
5495put g_nm p 124
5496p = add p 1
5497end
5498p = ufetchat p title_bytes
5499end
5500put g_nm p 10
5501upr 0 1
5502upr 8 ulong libptr g_nm 0 1024
5503upr 16 add p 1
5504x = ucall 3
5505ret
5506end
5507bar = umsg ucl c_status_bar usl m_system_status_bar 0 0 0
5508s_length = usl m_status_item_length
5509upr 64 13835058055282163712
5510item = umsg bar s_length 0 0 0
5511if eq item 0
5512ret
5513end
5514item = umsg item usl m_retain 0 0 0
5515put g_m 52 item
5516button = umsg item usl m_button 0 0 0
5517c_i = ucl c_image
5518s_symbol = usl m_symbol_image
5519symbol_name = uns x_status_symbol
5520said_name = uns x_app
5521image = umsg c_i s_symbol symbol_name said_name 0
5522if ne image 0
5523x = umsg button usl m_set_image image 0 0
5524end
5525x = umsg item usl m_set_item_menu menu 0 0
5526center = umsg ucl c_center usl m_default_center 0 0 0
5527s_observe = usl m_add_observer
5528quitting = uconst s_will_terminate
5529upr 40 0
5530x = umsg center s_observe get g_o 27 get g_m 62 quitting
5531end
5532
5533note what the menu of the icon tells this program (which: the selector); true when it was one of its
5534fn ustatusevent which ulong to bool
5535if eq which get g_m 62
5536utunnelstop
5537ret true
5538end
5539if eq which get g_m 54
5540ushow
5541ret true
5542end
5543if eq which get g_m 55
5544uindexstart
5545ret true
5546end
5547if eq which get g_m 56
5548upasteask
5549ret true
5550end
5551if eq which get g_m 57
5552ulogintoggle
5553ret true
5554end
5555if eq which get g_m 58
5556usettings
5557ret true
5558end
5559if eq which get g_m 59
5560uclipclear
5561ret true
5562end
5563ret false
5564end
5565
5566note the six more things this program is told by selector (entry 13 hears them all)
5567fn ustatusmethods mine ulong to bool
5568ok = umethod mine m_menu_open 13 t_v
5569ok = and ok umethod mine m_menu_index 13 t_v
5570ok = and ok umethod mine m_menu_paste 13 t_v
5571ok = and ok umethod mine m_menu_login 13 t_v
5572ok = and ok umethod mine m_menu_settings 13 t_v
5573ok = and ok umethod mine m_menu_clear 13 t_v
5574put g_m 54 usl m_menu_open
5575put g_m 55 usl m_menu_index
5576put g_m 56 usl m_menu_paste
5577put g_m 57 usl m_menu_login
5578put g_m 58 usl m_menu_settings
5579put g_m 59 usl m_menu_clear
5580ret ok
5581end
5582
5583note ---- forwarded ports: the ssh links Hop keeps open (Sources/Factory.swift, TunnelManager) ----
5584note Hop's settings name ports of other computers to have on this Mac (a model's server, the factory, the
5585note knowledge base). At the start and every 20 seconds each one whose link is not running is looked at: when
5586note nothing on this Mac serves its port (nc is asked, as a program of its own), ssh is started for it with Hop's own options (a link of its own, never
5587note the shared connection, so it ends cleanly). A port something else serves is left alone, and so Hop and this
5588note program do not fight over one. When this program quits it ends its links. Not here yet: dropping the links
5589note at once when the network changes (ssh notices by itself within 45 seconds, and the link is made anew).
5590note the whole number an object of the settings holds: 0 when it is not a number, is a yes or a no, or is not
5591note whole (8080.9 is no port, and Hop takes none of these either)
5592fn uwhole obj ulong to ulong
5593if not uisnumber obj
5594ret 0
5595end
5596yes_object = uconst s_cf_true
5597no_object = uconst s_cf_false
5598if or eq obj yes_object eq obj no_object
5599ret 0
5600end
5601v = umsg obj usl m_integer_value 0 0 0
5602same_v = umsg ucl c_number usl m_number_integer v 0 0
5603if eq and umsg obj usl m_is_equal_number same_v 0 0 255 0
5604ret 0
5605end
5606ret v
5607end
5608
5609note one forwarded port to keep: added to list when both ports are ports, the ssh name is there, and this Mac's
5610note port is not in the list already
5611fn utunneladd list ulong local ulong remote ulong host ulong to void
5612if or or eq local 0 gt local 65535 or eq remote 0 gt remote 65535
5613ret
5614end
5615if not uiskind host 9
5616ret
5617end
5618if eq umsg host usl m_length 0 0 0 0
5619ret
5620end
5621sat = usl m_at
5622s_whole = usl m_integer_value
5623cnt = umsg list usl m_count 0 0 0
5624for i ulong cnt bound 256
5625if eq umsg umsg umsg list sat i 0 0 sat 0 0 0 s_whole 0 0 0 local
5626ret
5627end
5628end
5629entry = umsg ucl c_mutable_array usl m_array 0 0 0
5630sadd = usl m_add_object
5631c_n_v = ucl c_number
5632s_number = usl m_number_integer
5633x = umsg entry sadd umsg c_n_v s_number local 0 0 0 0
5634x = umsg entry sadd umsg c_n_v s_number remote 0 0 0 0
5635x = umsg entry sadd host 0 0
5636x = umsg list sadd entry 0 0
5637end
5638
5639note the forwarded ports of the settings: the ones named there, and the one to the knowledge base when it runs
5640note on another computer
5641fn utunnelsload config ulong to void
5642links = umsg ucl c_mutable_array usl m_array 0 0 0
5643if ne config 0
5644named = ukeyed config k_tunnels
5645if uiskind named 8
5646sat = usl m_at
5647cnt = umsg named usl m_count 0 0 0
5648for i ulong cnt bound 256
5649t = umsg named sat i 0 0
5650if uiskind t 7
5651utunneladd links uwhole ukeyed t k_local_port uwhole ukeyed t k_remote_port ukeyed t k_ssh_host
5652end
5653end
5654end
5655cx = ukeyed config k_cortex
5656if uiskind cx 7
5657if uyes ukeyed cx k_enabled
5658address = ukeyed cx k_url
5659if uiskind address 9
5660url = umsg ucl c_url usl m_urlstr address 0 0
5661if ne url 0
5662utunneladd links uwhole umsg url usl m_url_port 0 0 0 uwhole ukeyed cx k_remote_port ukeyed cx k_host
5663end
5664end
5665end
5666end
5667end
5668if ne get g_m 60 0
5669x = umsg get g_m 60 usl m_release 0 0 0
5670end
5671put g_m 60 umsg links usl m_retain 0 0 0
5672put g_n 62 umsg links usl m_count 0 0 0
5673if eq get g_m 61 0
5674running = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
5675put g_m 61 umsg running usl m_retain 0 0 0
5676asking = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
5677put g_m 63 umsg asking usl m_retain 0 0 0
5678end
5679end
5680
5681note start the ssh link for one forwarded port (a check starts its stand-in, never ssh itself)
5682fn utunnelstart local ulong remote ulong host ulong to void
5683tool = uns x_real_ssh
5684if eq get g_n 14 0
5685n = ucs x_env_ssh
5686upr 0 ulong libptr g_nm 0 1024
5687given = ucall 9
5688if eq given 0
5689ret
5690end
5691n = ufetch given
5692tool = unsb
5693end
5694manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
5695if eq and umsg manager usl m_is_executable tool 0 0 255 0
5696ret
5697end
5698arguments = umsg uwords x_tunnel_args usl m_mutable_copy 0 0 0
5699p = uptxt 0 x_loopback
5700p = upnum p local
5701put g_nm p 58
5702p = uptxt add p 1 x_loopback
5703p = upnum p remote
5704put g_nm p 0
5705forward = unsb
5706sadd = usl m_add_object
5707x = umsg arguments sadd forward 0 0
5708x = umsg arguments sadd host 0 0
5709task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0
5710x = umsg task usl m_set_launch tool 0 0
5711x = umsg task usl m_set_arguments arguments 0 0
5712quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
5713x = umsg task usl m_set_output quiet 0 0
5714x = umsg task usl m_set_error quiet 0 0
5715x = umsg task usl m_set_input quiet 0 0
5716x = umsg task usl m_launch 0 0 0
5717put g_n 61 add get g_n 61 1
5718c_n_v = ucl c_number
5719s_number = usl m_number_integer
5720port_key = umsg c_n_v s_number local 0 0
5721x = umsg get g_m 61 usl m_set_object task port_key 0
5722note the list of this Mac's links keeps the program now, and the program its words
5723srel = usl m_release
5724x = umsg task srel 0 0 0
5725x = umsg arguments srel 0 0 0
5726end
5727
5728note is the link of this Mac's port running
5729fn utunnelalive port_key ulong to bool
5730task = umsg get g_m 61 usl m_object_for_key port_key 0 0
5731if eq task 0
5732ret false
5733end
5734ret eq and umsg task usl m_is_running 0 0 0 255 1
5735end
5736
5737note ask whether something on this Mac serves the port: nc tries it for two seconds at most, as a program of its
5738note own, so this program never waits on a port that does not answer (Hop asks with a two second limit too).
5739note probeDone: is told when it has ended
5740fn uprobestart local ulong port_key ulong to void
5741tool = uns x_nc
5742manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
5743if eq and umsg manager usl m_is_executable tool 0 0 255 0
5744ret
5745end
5746arguments = umsg uwords x_nc_args usl m_mutable_copy 0 0 0
5747p = upnum 0 local
5748put g_nm p 0
5749port_text = unsb
5750x = umsg arguments usl m_add_object port_text 0 0
5751task = umsg umsg ucl c_task usl m_alloc 0 0 0 usl m_init 0 0 0
5752x = umsg task usl m_set_launch tool 0 0
5753x = umsg task usl m_set_arguments arguments 0 0
5754quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
5755x = umsg task usl m_set_output quiet 0 0
5756x = umsg task usl m_set_error quiet 0 0
5757x = umsg task usl m_set_input quiet 0 0
5758center = umsg ucl c_center usl m_default_center 0 0 0
5759s_observe = usl m_add_observer
5760ended = uconst s_task_ended
5761upr 40 task
5762x = umsg center s_observe get g_o 27 get g_m 64 ended
5763x = umsg get g_m 63 usl m_set_object task port_key 0
5764x = umsg task usl m_launch 0 0 0
5765note the list of askers keeps the program now, and the program its words
5766srel = usl m_release
5767x = umsg task srel 0 0 0
5768x = umsg arguments srel 0 0 0
5769end
5770
5771note the asking has ended (about: the notice, whose object is the program that asked). A port nothing serves,
5772note whose link is still not running, gets its link
5773fn uprobedone about ulong to void
5774if or eq about 0 eq get g_m 63 0
5775ret
5776end
5777task = umsg about usl m_note_object 0 0 0
5778if eq task 0
5779ret
5780end
5781x = umsg task usl m_retain 0 0 0
5782center = umsg ucl c_center usl m_default_center 0 0 0
5783x = umsg center usl m_remove_all_observer get g_o 27 0 task
5784served = eq and umsg task usl m_termination 0 0 0 4294967295 0
5785port_keys = umsg get g_m 63 usl m_all_keys_for task 0 0
5786sat = usl m_at
5787s_whole = usl m_integer_value
5788s_drop = usl m_remove_for_key
5789links = get g_m 60
5790cnt = umsg port_keys usl m_count 0 0 0
5791for i ulong cnt bound 16
5792port_key = umsg port_keys sat i 0 0
5793local = umsg port_key s_whole 0 0 0
5794x = umsg get g_m 63 s_drop port_key 0 0
5795if and not served ne links 0
5796if not utunnelalive port_key
5797many = umsg links usl m_count 0 0 0
5798for j ulong many bound 256
5799entry = umsg links sat j 0 0
5800if eq umsg umsg entry sat 0 0 0 s_whole 0 0 0 local
5801utunnelstart local umsg umsg entry sat 1 0 0 s_whole 0 0 0 umsg entry sat 2 0 0
5802end
5803end
5804end
5805end
5806end
5807x = umsg task usl m_release 0 0 0
5808end
5809
5810note look at every forwarded port: for one whose link is not running, and that is not being asked about already,
5811note it is asked whether something serves the port
5812fn utunnelcheck to void
5813links = get g_m 60
5814if or or eq links 0 eq get g_m 61 0 eq get g_m 63 0
5815ret
5816end
5817if not uremoteok
5818ret
5819end
5820sat = usl m_at
5821s_whole = usl m_integer_value
5822s_keyed = usl m_object_for_key
5823c_n_v = ucl c_number
5824s_number = usl m_number_integer
5825cnt = umsg links usl m_count 0 0 0
5826for i ulong cnt bound 256
5827entry = umsg links sat i 0 0
5828local = umsg umsg entry sat 0 0 0 s_whole 0 0 0
5829port_key = umsg c_n_v s_number local 0 0
5830if not utunnelalive port_key
5831if eq umsg get g_m 63 s_keyed port_key 0 0 0
5832uprobestart local port_key
5833end
5834end
5835end
5836end
5837
5838note twice a second: every 20 seconds, and half a second after the start, the forwarded ports are looked at
5839fn utunneltick to void
5840ticks = get g_n 60
5841put g_n 60 add ticks 1
5842if eq sub ticks mul div ticks 40 40 0
5843utunnelcheck
5844end
5845end
5846
5847note this program is ending (quitting, or a check at its end): its links and its askers end with it
5848fn utunnelstop to void
5849sat = usl m_at
5850s_running = usl m_is_running
5851s_end = usl m_terminate_task
5852s_values = usl m_all_values
5853for which ulong 2
5854kept = get g_m 61
5855if eq which 1
5856kept = get g_m 63
5857end
5858if ne kept 0
5859tasks = umsg kept s_values 0 0 0
5860cnt = umsg tasks usl m_count 0 0 0
5861for i ulong cnt bound 256
5862task = umsg tasks sat i 0 0
5863if eq and umsg task s_running 0 0 0 255 1
5864x = umsg task s_end 0 0 0
5865end
5866end
5867end
5868end
5869end
5870
5871note hear when this program is about to quit (appQuit:) and when a port has been asked about (probeDone:)
5872fn uquitwatch mine ulong to bool
5873ok = umethod mine m_app_quit 13 t_v
5874ok = and ok umethod mine m_probe_done 13 t_v
5875put g_m 62 usl m_app_quit
5876put g_m 64 usl m_probe_done
5877ret ok
5878end
5879
5880note ---- screens: the list shows one kind of thing, and typing looks in it ----
5881note the copied things: all of them, pinned first, or the ones that have every typed word
5882fn uscreenclips to void
5883uclipmatch 1024
5884h = get g_n 28
5885for i ulong h bound 1024
5886put g_rk i 6
5887put g_hit i get g_cm i
5888put g_why i 0
5889end
5890put g_n 1 h
5891end
5892
5893note the saved accounts: all of them, or the ones whose name has the typed text
5894fn uscreenaccounts to void
5895nacc = get g_n 31
5896a = get g_n 12
5897n = get g_n 13
5898typed_low = ulong 0
5899if and gt n 0 le n 255
5900for i ulong n bound 256
5901put g_nm i get g_q add a i
5902end
5903put g_nm n 0
5904typed = unsb
5905if ne typed 0
5906typed_low = umsg typed usl m_lowercase 0 0 0
5907end
5908end
5909slower = usl m_lowercase
5910scontains = usl m_contains
5911h = ulong 0
5912for i ulong nacc bound 800
5913keep = true
5914if gt n 0
5915keep = false
5916if ne typed_low 0
5917name_low = umsg umsg get g_m 18 get g_m 16 i 0 0 slower 0 0 0
5918keep = eq and umsg name_low scontains typed_low 0 0 255 1
5919end
5920end
5921if keep
5922put g_rk h 5
5923put g_hit h i
5924put g_why h 0
5925h = add h 1
5926end
5927end
5928put g_n 1 h
5929end
5930
5931note show screen number which (0: everything again): the field is emptied and the list made anew
5932fn uscreen which ulong to void
5933put g_n 36 which
5934put g_nm 0 0
5935x = umsg get g_o 0 get g_o 8 unsb 0 0
5936utyped
5937end
5938
5939note make the list anew from what is known now, keeping the first row selected
5940fn urefresh to void
5941unarrow
5942x = umsg get g_o 1 get g_o 7 0 0 0
5943put g_n 6 0
5944if gt get g_n 1 0
5945uchoose 0
5946end
5947ushowst
5948end
5949
5950note pin or unpin (what 1) or delete (what 2) copied thing i in the history, then show the history as it is now.
5951note Like recording it is this program's to do only while Hop is not running
5952fn uclipedit i ulong what ulong to void
5953if ge i get g_n 24
5954ret
5955end
5956if and eq get g_n 14 1 uhoprunning
5957ret
5958end
5959shown_item = umsg get g_m 14 get g_m 16 i 0 0
5960if not uiskind shown_item 7
5961ret
5962end
5963id_text = ukeyed shown_item k_id
5964if not uiskind id_text 9
5965ret
5966end
5967items = uclipsmutable
5968if eq items 0
5969ret
5970end
5971sat = usl m_at
5972sequal = usl m_equal_string
5973cnt = umsg items usl m_count 0 0 0
5974found = cnt
5975for j ulong cnt bound 100000
5976if eq found cnt
5977e = umsg items sat j 0 0
5978if uiskind e 7
5979other_id = ukeyed e k_id
5980if uiskind other_id 9
5981if eq and umsg other_id sequal id_text 0 0 255 1
5982found = j
5983end
5984end
5985end
5986end
5987end
5988if eq found cnt
5989ret
5990end
5991e = umsg items sat found 0 0
5992if eq what 1
5993flip = ulong 1
5994if uclippinned e
5995flip = 0
5996end
5997flag = umsg ucl c_number usl m_number_bool flip 0 0
5998x = umsg e usl m_set_object flag uns k_pinned 0
5999else
6000image_name = ukeyed e k_image
6001if uiskind image_name 9
6002if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
6003folder = uhoppath x_clip_images
6004if ne folder 0
6005gone = umsg folder usl m_append_string image_name 0 0
6006manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
6007x = umsg manager usl m_remove_item gone 0 0
6008end
6009end
6010end
6011x = umsg items usl m_remove_at found 0 0
6012end
6013if eq uclipswrite items 1
6014uloadclips
6015urefresh
6016end
6017end
6018
6019note the menu's Pin or Unpin and Delete from History: on the selected row when it is a copied thing
6020fn uclipmenu what ulong to void
6021r = get g_n 6
6022if or ge r get g_n 1 ne ulong get g_rk r 6
6023ret
6024end
6025uclipedit get g_hit r what
6026end
6027
6028note open Hop's settings file in TextEdit, as Hop does (a check: with the program macOS has for it). When there
6029note is no settings file yet an empty one is made, which Hop reads as all its built-in settings
6030fn usettings to void
6031path = uhoppath x_config
6032if eq path 0
6033ret
6034end
6035url = umsg ucl c_url usl m_furl path 0 0
6036ws = umsg ucl c_ws usl m_shws 0 0 0
6037if eq get g_n 14 0
6038put g_n 9 and umsg ws usl m_open url 0 0 255
6039ret
6040end
6041manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
6042if eq and umsg manager usl m_file_exists path 0 0 255 0
6043d = umsg uns x_empty_settings usl m_data_using 4 0 0
6044x = umsg d usl m_write_file path 1 0
6045upr 0 umsg path get g_o 5 0 0 0
6046upr 8 384
6047x = ucall 16
6048end
6049urls = umsg ucl c_array usl m_array_with url 0 0
6050editor = umsg ucl c_url usl m_furl uns x_textedit 0 0
6051how = umsg ucl c_open_config usl m_configuration 0 0 0
6052s_open = usl m_open_urls_with
6053upr 40 0
6054x = umsg ws s_open urls editor how
6055put g_n 9 1
6056end
6057
6058note the rows to show: a screen's own, else what is offered when nothing is typed, else what the one box's
6059note rules give for the text
6060fn unarrow to void
6061if eq get g_n 36 1
6062uscreenclips
6063ret
6064end
6065if eq get g_n 36 2
6066uscreenaccounts
6067ret
6068end
6069if eq get g_n 13 0
6070usuggest
6071ret
6072end
6073m = ulong 0
6074for k ulong get g_n 0 bound 2048
6075s = uscore k
6076if gt s 0
6077put g_mk m k
6078put g_ms m sub s 1
6079m = add m 1
6080end
6081end
6082usearch
6083urankrows m
6084end
6085
6086note "H of N apps" into the status line
6087fn ushowst to void
6088p = upnum 0 get g_n 1
6089if eq get g_n 36 0
6090p = uptxt p x_of
6091p = upnum p get g_n 0
6092p = uptxt p x_apps
6093end
6094if eq get g_n 36 1
6095p = uptxt p x_copied_things
6096end
6097if eq get g_n 36 2
6098p = uptxt p x_accounts_word
6099end
6100if ne get g_m 23 0
6101p = uptxt p x_indexing
6102end
6103p = uremotenote p
6104put g_nm p 0
6105str = unsb
6106x = umsg get g_o 2 get g_o 8 str 0 0
6107end
6108
6109note select row r of the list and bring it into view
6110fn uchoose r ulong to void
6111put g_n 6 r
6112ix = umsg get g_o 13 get g_o 14 r 0 0
6113x = umsg get g_o 1 get g_o 12 ix 0 0
6114x = umsg get g_o 1 get g_o 15 r 0 0
6115end
6116
6117note what the list shows was typed into the field: read it, narrow, show
6118fn utyped to void
6119uaskstop
6120str = umsg get g_o 0 get g_o 6 0 0 0
6121p = umsg str get g_o 5 0 0 0
6122n = ufetch p
6123if gt n 255
6124n = 255
6125end
6126for i ulong n bound 256
6127put g_q i get g_nm i
6128end
6129put g_n 4 n
6130a = ulong 0
6131while lt a n bound 256
6132c = ulong get g_q a
6133if and ne c 32 ne c 9
6134break
6135end
6136a = add a 1
6137end
6138e = n
6139while gt e a bound 256
6140c = ulong get g_q sub e 1
6141if and ne c 32 ne c 9
6142break
6143end
6144e = sub e 1
6145end
6146put g_n 12 a
6147put g_n 13 sub e a
6148udecide
6149uremotesoon
6150unarrow
6151x = umsg get g_o 1 get g_o 7 0 0 0
6152put g_n 6 0
6153if gt get g_n 1 0
6154uchoose 0
6155end
6156ushowst
6157end
6158
6159note open app k: its folder, "/", its name and ".app" as a file address, handed to the workspace
6160fn ulaunch k ulong to void
6161p = ulong 0
6162if eq ulong get g_dir k 0
6163p = uptxt 0 x_dir1
6164else
6165p = uptxt 0 x_dir2
6166end
6167p = uptxt p x_slash
6168p = upname p k
6169p = uptxt p x_dotapp
6170put g_nm p 0
6171str = unsb
6172c = ucl c_url
6173s = usl m_furl
6174url = umsg c s str 0 0
6175c = ucl c_ws
6176s = usl m_shws
6177ws = umsg c s 0 0 0
6178s = usl m_open
6179put g_n 9 and umsg ws s url 0 0 255
6180end
6181
6182note open the web address the typed text stands for
6183fn uopenaddr to void
6184p = upaddr 0
6185put g_nm p 0
6186str = unsb
6187u = umsg get g_o 16 get g_o 17 str 0 0
6188c = ucl c_ws
6189s = usl m_shws
6190ws = umsg c s 0 0 0
6191s = usl m_open
6192put g_n 9 and umsg ws s u 0 0 255
6193end
6194
6195note ---- copied things: Hop's encrypted clipboard history (Sources/Clipboard.swift), read and never written ----
6196note The history is one file, sealed with AES-256-GCM (the core's fn gcunlock) under a key that Hop keeps in the
6197note login Keychain as an item of Apple's security tool and reads through that tool; the panel reads it the same
6198note way. The key and the unsealed bytes are wiped from the core's buffers as soon as they are used. The panel
6199note only reads the history: Hop, when it runs, is the one that keeps it, and it sees what the panel puts on
6200note the clipboard like anything else that is copied. A check (HOPCHECK) never asks the tool and never touches
6201note the real clipboard: it takes the key from HOPCLIPKEY and pastes into a board of its own.
6202note the clipboard key into the core's c_k; 1 when it is there
6203fn uclipkey to ulong
6204encoded = ulong 0
6205item_name = ulong 0
6206if eq get g_n 14 0
6207n = ucs x_env_clipkey
6208upr 0 ulong libptr g_nm 0 1024
6209key_text = ucall 9
6210if eq key_text 0
6211ret 0
6212end
6213n = ufetch key_text
6214if and and gt n 5 eq get g_nm 0 116 and eq get g_nm 3 108 eq get g_nm 4 58
6215for i ulong sub n 5 bound 1024
6216put g_nm i get g_nm add 5 i
6217end
6218put g_nm sub n 5 0
6219item_name = unsb
6220else
6221encoded = unsb
6222end
6223else
6224item_name = uns x_clip_service
6225end
6226if ne item_name 0
6227task = umsg ucl c_task usl m_alloc 0 0 0
6228task = umsg task usl m_init 0 0 0
6229x = umsg task usl m_set_launch uns x_security 0 0
6230arguments = umsg ucl c_mutable_array usl m_array 0 0 0
6231sadd = usl m_add_object
6232x = umsg arguments sadd uns x_find 0 0
6233x = umsg arguments sadd uns x_dash_s 0 0
6234x = umsg arguments sadd item_name 0 0
6235x = umsg arguments sadd uns x_dash_a 0 0
6236x = umsg arguments sadd uns x_clip_account 0 0
6237x = umsg arguments sadd uns x_dash_w 0 0
6238x = umsg task usl m_set_arguments arguments 0 0
6239tube = umsg ucl c_pipe usl m_pipe 0 0 0
6240x = umsg task usl m_set_output tube 0 0
6241quiet = umsg ucl c_file_handle usl m_null_device 0 0 0
6242x = umsg task usl m_set_error quiet 0 0
6243x = umsg task usl m_launch 0 0 0
6244reader = umsg tube usl m_reading 0 0 0
6245d = umsg reader usl m_read_end 0 0 0
6246x = umsg task usl m_wait 0 0 0
6247if ne and umsg task usl m_termination 0 0 0 4294967295 0
6248ret 0
6249end
6250if eq d 0
6251ret 0
6252end
6253whole = umsg ucl c_str usl m_alloc 0 0 0
6254whole = umsg whole usl m_init_data_encoding d 4 0
6255if eq whole 0
6256ret 0
6257end
6258blanks = umsg ucl c_charset usl m_whitespace 0 0 0
6259encoded = umsg whole usl m_trim blanks 0 0
6260end
6261if eq encoded 0
6262ret 0
6263end
6264kd = umsg ucl c_data usl m_alloc 0 0 0
6265kd = umsg kd usl m_init_base64 encoded 0 0
6266if eq kd 0
6267ret 0
6268end
6269if ne umsg kd usl m_length 0 0 0 32
6270ret 0
6271end
6272src = umsg kd usl m_bytes 0 0 0
6273upr 0 ulong libptr c_k 0 32
6274upr 8 src
6275upr 16 32
6276x = ucall 8
6277ret 1
6278end
6279
6280note wipe the first m unsealed bytes of the core's buffer
6281fn uforget m ulong to void
6282if eq m 0
6283ret
6284end
6285upr 0 ulong libptr c_d 0 m
6286upr 8 0
6287upr 16 m
6288x = ucall 17
6289end
6290
6291note the sealed bytes of d (an NSData: the nonce, the data, the tag) unsealed into the core's c_d with the
6292note clipboard key; the count of data bytes plus 1, or 0 when it cannot be done (no key, or not sealed by it)
6293fn uunseal d ulong to ulong
6294n = umsg d usl m_length 0 0 0
6295if or lt n 28 gt n 16777244
6296ret 0
6297end
6298src = umsg d usl m_bytes 0 0 0
6299if eq uclipkey 0
6300ret 0
6301end
6302m = sub n 28
6303upr 0 ulong libptr c_n 0 12
6304upr 8 src
6305upr 16 12
6306x = ucall 8
6307if gt m 0
6308upr 0 ulong libptr c_d 0 m
6309upr 8 add src 12
6310upr 16 m
6311x = ucall 8
6312end
6313upr 0 ulong libptr c_tg 0 16
6314upr 8 add src sub n 16
6315upr 16 16
6316x = ucall 8
6317good = gcunlock m
6318gcwipe
6319if eq good 0
6320ret 0
6321end
6322ret add m 1
6323end
6324
6325note the text a copied thing is shown by: its text without the blanks around it, a mark where a line ends, the
6326note first 80 characters; "Image" for a picture
6327fn uclippreview item ulong to ulong
6328if not uiskind item 7
6329ret uns x_image
6330end
6331words = ukeyed item k_text
6332if not uiskind words 9
6333ret uns x_image
6334end
6335blanks = umsg ucl c_charset usl m_whitespace 0 0 0
6336t = umsg words usl m_trim blanks 0 0
6337put g_nm 0 10
6338put g_nm 1 0
6339line_end = unsb
6340put g_nm 0 32
6341put g_nm 1 226
6342put g_nm 2 143
6343put g_nm 3 142
6344put g_nm 4 32
6345put g_nm 5 0
6346mark = unsb
6347t = umsg t usl m_replace line_end mark 0
6348if gt umsg t usl m_length 0 0 0 80
6349cut = umsg t usl m_composed_at 80 0 0
6350t = umsg t usl m_substring_to cut 0 0
6351end
6352ret t
6353end
6354
6355note read the history: the copied things, the text each is shown by, which are pinned, and the order they are
6356note searched in. Nothing is kept when the file is not there, the key is not to be had or the file is not Hop's
6357fn uloadclips to void
6358put g_n 24 0
6359d = uhopfile x_clipboard_file
6360if eq d 0
6361ret
6362end
6363r = uunseal d
6364if le r 1
6365ret
6366end
6367m = sub r 1
6368plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
6369uforget m
6370items = umsg ucl c_json usl m_json_object plain 0 0
6371if not uiskind items 8
6372ret
6373end
6374cnt = umsg items usl m_count 0 0 0
6375if gt cnt 1024
6376cnt = 1024
6377end
6378sret = usl m_retain
6379srel = usl m_release
6380if ne get g_m 14 0
6381x = umsg get g_m 14 srel 0 0 0
6382x = umsg get g_m 15 srel 0 0 0
6383end
6384put g_m 14 umsg items sret 0 0 0
6385shown_by = umsg ucl c_mutable_array usl m_array 0 0 0
6386put g_m 15 umsg shown_by sret 0 0 0
6387sat = usl m_at
6388put g_m 16 sat
6389sadd = usl m_add_object
6390for i ulong cnt bound 1024
6391item = umsg items sat i 0 0
6392pv = uclippreview item
6393x = umsg shown_by sadd pv 0 0
6394put g_cp i 0
6395if uiskind item 7
6396pin = ukeyed item k_pinned
6397if uisnumber pin
6398if eq and umsg pin usl m_bool_value 0 0 0 255 1
6399put g_cp i 1
6400end
6401end
6402end
6403end
6404pos = ulong 0
6405for i ulong cnt bound 1024
6406if eq ulong get g_cp i 1
6407put g_ci pos i
6408pos = add pos 1
6409end
6410end
6411for i ulong cnt bound 1024
6412if eq ulong get g_cp i 0
6413put g_ci pos i
6414pos = add pos 1
6415end
6416end
6417put g_n 24 cnt
6418end
6419
6420note the text copied thing i is shown by into g_nm from byte p; the byte after it
6421fn uclipname p ulong i ulong to ulong
6422if or ge i get g_n 24 ge p 900
6423ret p
6424end
6425pv = umsg get g_m 15 get g_m 16 i 0 0
6426src = umsg pv get g_o 5 0 0 0
6427if eq src 0
6428ret p
6429end
6430upr 0 src
6431n = ucall 7
6432if gt add p n 900
6433n = sub 900 p
6434end
6435if eq n 0
6436ret p
6437end
6438upr 0 ulong libptr g_nm p n
6439upr 8 src
6440upr 16 n
6441x = ucall 8
6442ret add p n
6443end
6444
6445note the newest copied thing's text takes the place of the typed text (on 1) so that the address helpers work on
6446note it, and gives it back (on 0). Only used while nothing is typed
6447fn uclipaddr on ulong to void
6448if eq on 1
6449n = get g_n 25
6450for i ulong n bound 256
6451put g_q i get g_ca i
6452end
6453put g_n 12 0
6454put g_n 13 n
6455put g_n 10 get g_n 26
6456else
6457put g_n 13 0
6458put g_n 10 0
6459end
6460end
6461
6462note the copied things that match the typed text, as Hop's search does: the pinned ones first, each in lower
6463note case has to contain every typed word (a picture counts as "image"); the first "most" of them into g_cm
6464note (for a whole screen with nothing typed: all of them)
6465fn uclipmatch most ulong to void
6466put g_n 28 0
6467cnt = get g_n 24
6468if eq cnt 0
6469ret
6470end
6471a = get g_n 12
6472n = get g_n 13
6473if and eq n 0 gt most 8
6474every = cnt
6475if gt every most
6476every = most
6477end
6478for pos ulong every bound 1024
6479put g_cm pos get g_ci pos
6480end
6481put g_n 28 every
6482ret
6483end
6484if or eq n 0 gt n 255
6485ret
6486end
6487for i ulong n bound 256
6488put g_nm i get g_q add a i
6489end
6490put g_nm n 0
6491typed = unsb
6492if eq typed 0
6493ret
6494end
6495slower = usl m_lowercase
6496typed_low = umsg typed slower 0 0 0
6497parts = umsg typed_low usl m_components uns x_space 0 0
6498nt = umsg parts usl m_count 0 0 0
6499scontains = usl m_contains
6500slen = usl m_length
6501sat = get g_m 16
6502image_low = uns x_image_low
6503found = ulong 0
6504for pos ulong cnt bound 1024
6505if lt found most
6506i = get g_ci pos
6507item = umsg get g_m 14 sat i 0 0
6508hay = image_low
6509if uiskind item 7
6510words = ukeyed item k_text
6511if uiskind words 9
6512hay = umsg words slower 0 0 0
6513end
6514end
6515okay = true
6516for j ulong nt bound 64
6517term = umsg parts sat j 0 0
6518if gt umsg term slen 0 0 0 0
6519if ne and umsg hay scontains term 0 0 255 1
6520okay = false
6521end
6522end
6523end
6524if okay
6525put g_cm found i
6526found = add found 1
6527end
6528end
6529end
6530put g_n 28 found
6531end
6532
6533note put copied thing i on the clipboard: its text, or its picture unsealed (as PNG data). A check uses a board
6534note of its own
6535fn upasteclip i ulong to void
6536if ge i get g_n 24
6537ret
6538end
6539item = umsg get g_m 14 get g_m 16 i 0 0
6540if not uiskind item 7
6541ret
6542end
6543pboard = ulong 0
6544if eq get g_n 14 1
6545pboard = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
6546else
6547pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
6548end
6549x = umsg pboard usl m_clear 0 0 0
6550words = ukeyed item k_text
6551if uiskind words 9
6552x = umsg pboard usl m_set_string_type words uns x_type_string 0
6553put g_n 29 1
6554ret
6555end
6556name = ukeyed item k_image
6557if not uiskind name 9
6558ret
6559end
6560if eq and umsg name usl m_contains uns x_slash_text 0 0 255 1
6561ret
6562end
6563folder = uhoppath x_clip_images
6564if eq folder 0
6565ret
6566end
6567path = umsg folder usl m_append_string name 0 0
6568d = umsg ucl c_data usl m_data_file path 0 0
6569if eq d 0
6570ret
6571end
6572r = uunseal d
6573if le r 1
6574ret
6575end
6576m = sub r 1
6577picture = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
6578uforget m
6579x = umsg pboard usl m_set_data_type picture uns x_type_png 0
6580put g_n 29 2
6581end
6582
6583note press Command V for the app that is in front again, as Hop does after it has put something on the clipboard
6584fn usendpaste to void
6585for half ulong 2
6586upr 0 0
6587upr 8 9
6588upr 16 sub 1 half
6589ev = ucall 19
6590if ne ev 0
6591upr 0 ev
6592upr 8 1048576
6593x = ucall 20
6594upr 0 0
6595upr 8 ev
6596x = ucall 21
6597upr 0 ev
6598x = ucall 22
6599end
6600end
6601end
6602
6603note a moment from now, press Command V; only when this program is allowed to control the Mac (Accessibility)
6604fn ulaterpaste to void
6605if eq and ucall 18 255 0
6606ret
6607end
6608s_after = usl m_perform_after
6609s_paste = usl m_paste_now
6610upr 64 bitcast ulong 0.15f64
6611x = umsg get g_o 27 s_after s_paste 0 0
6612end
6613
6614note ---- recording what is copied, as Hop does (Sources/Clipboard.swift, poll) ----
6615note Only while Hop itself is not running: two programs must not write the same history. The history is read
6616note again at that moment, changed and written whole, sealed under the same key with a fresh nonce (the core's fn
6617note gclock), for the owner only. Before this program's first change in a run the history as it was is set
6618note aside next to it (clipboard.before-hop-omega.bin). What is marked concealed or transient is never kept.
6619note seal the first m bytes of the core's c_d under the clipboard key; nonce, data and tag as NSData, or 0
6620fn useal m ulong to ulong
6621if or eq m 0 gt m 16777216
6622ret 0
6623end
6624if eq uclipkey 0
6625ret 0
6626end
6627upr 0 ulong libptr c_n 0 12
6628upr 8 12
6629x = ucall 27
6630gclock m
6631gcwipe
6632sealed = umsg ucl c_mutable_data usl m_data 0 0 0
6633sappend = usl m_append_bytes
6634x = umsg sealed sappend ulong libptr c_n 0 12 12 0
6635x = umsg sealed sappend ulong libptr c_d 0 m m 0
6636x = umsg sealed sappend ulong libptr c_tg 0 16 16 0
6637ret sealed
6638end
6639
6640note the history as it is on disk now, as a list that can be changed: an empty one when there is no file yet,
6641note 0 when there is no key or the file is not Hop's
6642fn uclipsmutable to ulong
6643path = uhoppath x_clipboard_file
6644if eq path 0
6645ret 0
6646end
6647manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
6648if eq and umsg manager usl m_file_exists path 0 0 255 0
6649if eq uclipkey 0
6650ret 0
6651end
6652gcwipe
6653ret umsg ucl c_mutable_array usl m_array 0 0 0
6654end
6655d = umsg ucl c_data usl m_data_file path 0 0
6656if eq d 0
6657ret 0
6658end
6659r = uunseal d
6660if le r 1
6661ret 0
6662end
6663m = sub r 1
6664plain = umsg ucl c_data usl m_data_bytes ulong libptr c_d 0 m m 0
6665uforget m
6666items = umsg ucl c_json usl m_json_object plain 1 0
6667if not uiskind items 8
6668ret 0
6669end
6670ret items
6671end
6672
6673note write the list as the history; 1 when it was written
6674fn uclipswrite items ulong to ulong
6675data = umsg ucl c_json usl m_json_data items 0 0
6676if eq data 0
6677ret 0
6678end
6679n = umsg data usl m_length 0 0 0
6680if or eq n 0 gt n 16777216
6681ret 0
6682end
6683s_write = usl m_write_file
6684if eq get g_n 33 0
6685before = uhopfile x_clipboard_file
6686if ne before 0
6687aside = uhoppath x_clip_backup
6688x = umsg before s_write aside 1 0
6689upr 0 ulong libptr g_nm 0 1024
6690upr 8 384
6691x = ucall 16
6692end
6693put g_n 33 1
6694end
6695src = umsg data usl m_bytes 0 0 0
6696upr 0 ulong libptr c_d 0 n
6697upr 8 src
6698upr 16 n
6699x = ucall 8
6700sealed = useal n
6701uforget n
6702if eq sealed 0
6703ret 0
6704end
6705path = uhoppath x_clipboard_file
6706if eq path 0
6707ret 0
6708end
6709ok = and umsg sealed s_write path 1 0 255
6710path = uhoppath x_clipboard_file
6711upr 0 ulong libptr g_nm 0 1024
6712upr 8 384
6713x = ucall 16
6714ret ok
6715end
6716
6717note is the copied thing e pinned
6718fn uclippinned e ulong to bool
6719if not uiskind e 7
6720ret false
6721end
6722pin = ukeyed e k_pinned
6723if not uisnumber pin
6724ret false
6725end
6726ret eq and umsg pin usl m_bool_value 0 0 0 255 1
6727end
6728
6729note what is on the pasteboard pb goes into the history as Hop puts it there: text that is already there moves
6730note to the front, new text or a picture (as PNG, sealed in a file of its own) is added in front with the app it
6731note came from; then the unpinned ones over the limit go, the oldest first
6732fn ucliprecord pb ulong to void
6733types = umsg pb usl m_types 0 0 0
6734if ne types 0
6735shas = usl m_contains_object
6736if eq and umsg types shas uns x_skip0 0 0 255 1
6737ret
6738end
6739if eq and umsg types shas uns x_skip1 0 0 255 1
6740ret
6741end
6742if eq and umsg types shas uns x_skip2 0 0 255 1
6743ret
6744end
6745if eq and umsg types shas uns x_skip3 0 0 255 1
6746ret
6747end
6748if eq and umsg types shas uns x_skip4 0 0 255 1
6749ret
6750end
6751if eq and umsg types shas uns x_skip5 0 0 255 1
6752ret
6753end
6754end
6755items = uclipsmutable
6756if eq items 0
6757ret
6758end
6759source = ulong 0
6760if eq get g_n 14 1
6761front_app = umsg umsg ucl c_ws usl m_shws 0 0 0 usl m_frontmost 0 0 0
6762if ne front_app 0
6763source = umsg front_app usl m_localized_name 0 0 0
6764end
6765end
6766cnum = ucl c_number
6767x = umsg ucl c_date usl m_reference_now 0 0 0
6768now_bits = ugr 64
6769s_double = usl m_number_double
6770upr 64 now_bits
6771moment = umsg cnum s_double 0 0 0
6772sset = usl m_set_object
6773sat = usl m_at
6774sins = usl m_insert_at
6775copied = umsg pb usl m_string_for_type uns x_type_string 0 0
6776has_text = false
6777if ne copied 0
6778if gt umsg copied usl m_length 0 0 0 0
6779has_text = true
6780end
6781end
6782fresh_item = ulong 0
6783if has_text
6784if gt umsg copied usl m_byte_length 4 0 0 512000
6785ret
6786end
6787cnt = umsg items usl m_count 0 0 0
6788found = cnt
6789sequal = usl m_equal_string
6790for i ulong cnt bound 100000
6791if eq found cnt
6792e = umsg items sat i 0 0
6793if uiskind e 7
6794words = ukeyed e k_text
6795if uiskind words 9
6796if eq and umsg words sequal copied 0 0 255 1
6797found = i
6798end
6799end
6800end
6801end
6802end
6803if lt found cnt
6804e = umsg items sat found 0 0
6805kept = umsg e usl m_retain 0 0 0
6806x = umsg e sset moment uns k_date 0
6807x = umsg items usl m_remove_at found 0 0
6808x = umsg items sins e 0 0
6809x = umsg e usl m_release 0 0 0
6810else
6811fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
6812x = umsg fresh_item sset copied uns k_text 0
6813end
6814else
6815picture = umsg ucl c_image usl m_alloc 0 0 0
6816picture = umsg picture usl m_init_pasteboard pb 0 0
6817if eq picture 0
6818ret
6819end
6820tiff = umsg picture usl m_tiff 0 0 0
6821if eq tiff 0
6822ret
6823end
6824bitmap = umsg ucl c_bitmap usl m_rep_with_data tiff 0 0
6825if eq bitmap 0
6826ret
6827end
6828no_properties = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
6829png = umsg bitmap usl m_rep_using 4 no_properties 0
6830if eq png 0
6831ret
6832end
6833pn = umsg png usl m_length 0 0 0
6834if or eq pn 0 gt pn 16777216
6835ret
6836end
6837src = umsg png usl m_bytes 0 0 0
6838upr 0 ulong libptr c_d 0 pn
6839upr 8 src
6840upr 16 pn
6841x = ucall 8
6842sealed = useal pn
6843uforget pn
6844if eq sealed 0
6845ret
6846end
6847folder = uhoppath x_clip_images
6848if eq folder 0
6849ret
6850end
6851manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
6852s_create = usl m_create_dir
6853upr 40 0
6854x = umsg manager s_create folder 1 0
6855file_name = umsg umsg umsg ucl c_uuid usl m_uuid 0 0 0 usl m_uuid_string 0 0 0 usl m_append_string uns x_dot_bin 0 0
6856file_path = umsg folder usl m_append_string file_name 0 0
6857if eq and umsg sealed usl m_write_file file_path 1 0 255 0
6858ret
6859end
6860fresh_item = umsg ucl c_mutable_dict usl m_dictionary 0 0 0
6861x = umsg fresh_item sset file_name uns k_image 0
6862end
6863if ne fresh_item 0
6864id_text = umsg umsg ucl c_uuid usl m_uuid 0 0 0 usl m_uuid_string 0 0 0
6865x = umsg fresh_item sset id_text uns k_id 0
6866x = umsg fresh_item sset moment uns k_date 0
6867if ne source 0
6868x = umsg fresh_item sset source uns k_source 0
6869end
6870no = umsg cnum usl m_number_bool 0 0 0
6871x = umsg fresh_item sset no uns k_pinned 0
6872x = umsg items sins fresh_item 0 0
6873end
6874note the unpinned ones over the limit go, from the end
6875limit = get g_n 34
6876if lt limit 50
6877limit = 50
6878end
6879cnt = umsg items usl m_count 0 0 0
6880loose = ulong 0
6881for i ulong cnt bound 100000
6882if not uclippinned umsg items sat i 0 0
6883loose = add loose 1
6884end
6885end
6886if gt loose limit
6887drop = sub loose limit
6888manager = umsg ucl c_file_manager usl m_default_manager 0 0 0
6889for back ulong cnt bound 100000
6890i = sub sub cnt 1 back
6891if gt drop 0
6892e = umsg items sat i 0 0
6893if not uclippinned e
6894if uiskind e 7
6895image_name = ukeyed e k_image
6896if uiskind image_name 9
6897if ne and umsg image_name usl m_contains uns x_slash_text 0 0 255 1
6898folder = uhoppath x_clip_images
6899if ne folder 0
6900gone = umsg folder usl m_append_string image_name 0 0
6901x = umsg manager usl m_remove_item gone 0 0
6902end
6903end
6904end
6905end
6906x = umsg items usl m_remove_at i 0 0
6907drop = sub drop 1
6908end
6909end
6910end
6911end
6912x = uclipswrite items
6913end
6914
6915note is Hop itself running
6916fn uhoprunning to bool
6917others = umsg ucl c_running_app usl m_running_with uns x_hop_id 0 0
6918if eq others 0
6919ret false
6920end
6921ret gt umsg others usl m_count 0 0 0 0
6922end
6923
6924note twice a second: when the clipboard has changed and Hop is not there to keep the history, this program does
6925fn ucliptick to void
6926uindextick
6927utunneltick
6928pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
6929cc = umsg pb usl m_change_count 0 0 0
6930if eq cc get g_n 35
6931ret
6932end
6933put g_n 35 cc
6934if uhoprunning
6935ret
6936end
6937ucliprecord pb
6938end
6939
6940note after this program put something on the clipboard itself: that change is not a new copied thing; a text that
6941note was pasted moves to the front of the history, as in Hop
6942fn uclipmine was_text ulong to void
6943pb = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
6944put g_n 35 umsg pb usl m_change_count 0 0 0
6945if and eq was_text 1 not uhoprunning
6946ucliprecord pb
6947end
6948end
6949
6950note is the app in front a browser, by Hop's list
6951fn ufrontbrowser to ulong
6952id = get g_m 11
6953if eq id 0
6954ret 0
6955end
6956sequal = usl m_equal_string
6957if eq and umsg id sequal uns x_browser0 0 0 255 1
6958ret 1
6959end
6960if eq and umsg id sequal uns x_browser1 0 0 255 1
6961ret 1
6962end
6963if eq and umsg id sequal uns x_browser2 0 0 255 1
6964ret 1
6965end
6966if eq and umsg id sequal uns x_browser3 0 0 255 1
6967ret 1
6968end
6969if eq and umsg id sequal uns x_browser4 0 0 255 1
6970ret 1
6971end
6972if eq and umsg id sequal uns x_browser5 0 0 255 1
6973ret 1
6974end
6975if eq and umsg id sequal uns x_browser6 0 0 255 1
6976ret 1
6977end
6978if eq and umsg id sequal uns x_browser7 0 0 255 1
6979ret 1
6980end
6981if eq and umsg id sequal uns x_browser8 0 0 255 1
6982ret 1
6983end
6984ret 0
6985end
6986
6987note the Ask row's text into g_nm from byte p: "Ask NAME: TEXT", or why it cannot ask; the byte after it
6988fn uaskrow p ulong to ulong
6989if eq get g_m 3 0
6990ret uptxt p x_ask_none
6991end
6992name_bytes = umsg get g_m 2 get g_o 5 0 0 0
6993q = uptxt p x_ask
6994upr 0 name_bytes
6995n = ucall 7
6996if gt n 200
6997n = 200
6998end
6999upr 0 ulong libptr g_nm q n
7000upr 8 name_bytes
7001upr 16 n
7002x = ucall 8
7003q = add q n
7004q = uptxt q x_colon
7005a = get g_n 12
7006n = get g_n 13
7007for i ulong n bound 256
7008put g_nm add q i get g_q add a i
7009end
7010ret add q n
7011end
7012
7013note the text of row r into g_nm from byte p (an app's name, the address, a file's whole path, or the Ask row); the byte after it
7014fn uprow p ulong r ulong to ulong
7015if eq ulong get g_rk r 8
7016ret uaskrow p
7017end
7018if eq ulong get g_rk r 10
7019ret uremoterow p get g_hit r
7020end
7021if eq ulong get g_rk r 9
7022q = uptxt p x_agent_row
7023a = get g_n 12
7024n = get g_n 13
7025for i ulong n bound 256
7026put g_nm add q i get g_q add a i
7027end
7028ret add q n
7029end
7030if eq ulong get g_rk r 6
7031ret uclipname p get g_hit r
7032end
7033if eq ulong get g_rk r 5
7034ret ustrat get g_m 18 p get g_hit r
7035end
7036if eq ulong get g_rk r 3
7037if eq get g_hit r 0
7038ret uptxt p x_screen0
7039end
7040if eq get g_hit r 2
7041ret uptxt p x_screen2
7042end
7043ret uptxt p x_screen1
7044end
7045if eq ulong get g_rk r 4
7046if eq get g_hit r 0
7047ret uptxt p x_command0
7048end
7049if eq get g_hit r 2
7050ret uptxt p x_command2
7051end
7052if eq get g_hit r 3
7053ret uptxt p x_command3
7054end
7055ret uptxt p x_command1
7056end
7057if and eq ulong get g_rk r 2 eq get g_n 13 0
7058uclipaddr 1
7059q = upaddr p
7060uclipaddr 0
7061ret q
7062end
7063if eq ulong get g_rk r 2
7064ret upaddr p
7065end
7066if eq ulong get g_rk r 7
7067ret ufilepath p get g_hit r
7068end
7069ret upname p get g_hit r
7070end
7071
7072note one turn of the event loop: wait for an event until date d and hand it to AppKit
7073fn utick app ulong sn ulong se ulong mode ulong d ulong to void
7074upr 0 app
7075upr 8 sn
7076upr 16 18446744073709551615
7077upr 24 d
7078upr 32 mode
7079upr 40 1
7080ev = ucall 2
7081if ne ev 0
7082x = umsg app se ev 0 0
7083end
7084end
7085
7086note put the panel away. A program that stays also empties the field, shows every app again and hides itself, so
7087note the app that was in front before has the keyboard back
7088fn uhide to void
7089uaskstop
7090put g_n 36 0
7091x = umsg get g_o 19 get g_o 20 0 0 0
7092if eq get g_n 14 1
7093put g_nm 0 0
7094x = umsg get g_o 0 get g_o 8 unsb 0 0
7095utyped
7096x = umsg get g_o 21 get g_o 22 0 0 0
7097end
7098end
7099
7100note bring the panel back: in front with the keyboard in the field for a program that stays, else just visible
7101fn ushow to void
7102if eq get g_n 14 1
7103ufront
7104uloadclips
7105uloadvault
7106if eq get g_m 3 0
7107uloadconfig
7108end
7109if eq get g_n 13 0
7110unarrow
7111x = umsg get g_o 1 get g_o 7 0 0 0
7112put g_n 6 0
7113if gt get g_n 1 0
7114uchoose 0
7115end
7116ushowst
7117end
7118x = umsg get g_o 21 get g_o 23 1 0 0
7119x = umsg get g_o 19 get g_o 24 0 0 0
7120x = umsg get g_o 19 get g_o 25 get g_o 0 0 0
7121else
7122x = umsg get g_o 19 get g_o 26 0 0 0
7123end
7124end
7125
7126note the library function at address f on the register file; x0 as it came back
7127fn ucallf f ulong to ulong
7128lr = libcall f g_rg 0 128
7129ret ugr 0
7130end
7131
7132note a global key: a Carbon hot key (key code, modifiers) whose handler is callback entry 5. 0 when both the
7133note handler and the key were taken; the hot key's id is 'HOPO' 1
7134fn ukey code ulong mods ulong to ulong
7135n = ucs s_carbon
7136upr 0 ulong libptr g_nm 0 1024
7137upr 8 2
7138lr = libcall ulong libfn 0 g_rg 0 128
7139target_fn = usym s_event_target
7140install_fn = usym s_install_handler
7141register_fn = usym s_register_key
7142if or or eq target_fn 0 eq install_fn 0 eq register_fn 0
7143ret 1
7144end
7145target = ucallf target_fn
7146put g_ev 0 98
7147put g_ev 1 121
7148put g_ev 2 101
7149put g_ev 3 107
7150put g_ev 4 5
7151upr 0 target
7152upr 8 ulong libfn 7
7153upr 16 1
7154upr 24 ulong libptr g_ev 0 16
7155upr 32 0
7156upr 40 0
7157installed = and ucallf install_fn 4294967295
7158upr 0 code
7159upr 8 mods
7160upr 16 5507124751
7161upr 24 target
7162upr 32 0
7163upr 40 ulong libptr g_ev 8 8
7164registered = and ucallf register_fn 4294967295
7165ret or installed registered
7166end
7167
7168note one menu item: title, action (a selector) and key. An unsized text takes two of a function's six places
7169fn uitem menu ulong title view uchar * action_sel ulong key view uchar * to void
7170c = ucl c_menu_item
7171s = usl m_alloc
7172item = umsg c s 0 0 0
7173title_string = uns title
7174key_string = uns key
7175s = usl m_init_item
7176item = umsg item s title_string action_sel key_string
7177s = usl m_add_item
7178x = umsg menu s item 0 0
7179end
7180
7181note a menu bar entry with an empty menu under it; the menu
7182fn usubmenu bar ulong title view uchar * to ulong
7183c = ucl c_menu_item
7184s = usl m_alloc
7185sinit = usl m_init
7186entry = umsg c s 0 0 0
7187entry = umsg entry sinit 0 0 0
7188s = usl m_add_item
7189x = umsg bar s entry 0 0
7190c = ucl c_menu
7191s = usl m_alloc
7192menu = umsg c s 0 0 0
7193title_string = uns title
7194s = usl m_init_title
7195menu = umsg menu s title_string 0 0
7196s = usl m_set_submenu
7197x = umsg entry s menu 0 0
7198ret menu
7199end
7200
7201note the menu: Quit, and Edit with the four commands the field's editor answers itself
7202fn umenu app ulong to void
7203c = ucl c_menu
7204s = usl m_alloc
7205sinit = usl m_init
7206bar = umsg c s 0 0 0
7207bar = umsg bar sinit 0 0 0
7208app_menu = usubmenu bar x_app
7209a = usl m_terminate
7210uitem app_menu x_quit a x_key_q
7211edit_menu = usubmenu bar x_edit
7212a = usl m_cut
7213uitem edit_menu x_cut a x_key_x
7214a = usl m_copy
7215uitem edit_menu x_copy a x_key_c
7216a = usl m_paste
7217uitem edit_menu x_paste a x_key_v
7218a = usl m_select_all
7219uitem edit_menu x_select_all a x_key_a
7220clip_menu = usubmenu bar x_clip_menu
7221a = usl m_pin_clip
7222uitem clip_menu x_pin_item a x_key_p
7223a = usl m_delete_clip
7224uitem clip_menu x_delete_item a x_key_d
7225agent_menu = usubmenu bar x_agent_menu
7226a = usl m_agent_stop
7227uitem agent_menu x_stop_item a x_key_period
7228s = usl m_set_menu
7229x = umsg app s bar 0 0
7230ustatus
7231end
7232
7233note the methods of OmegaHopPanel. 0 controlTextDidChange: 1 numberOfRowsInTableView:
7234note 2 tableView:objectValueForTableColumn:row: (e is the row) 3 go: (the field's action, Enter: c is the sender;
7235note it is remembered, and opened when g_n 7 allows) 4 control:textView:doCommandBySelector: (e is
7236note the command: the arrows move the selection, Escape puts the panel away; 1 says the key was handled)
7237note 5 the hot key's handler (a C function for Carbon: 0 says no error) 6 applicationShouldHandleReopen:
7238note hasVisibleWindows: (a click on the Dock icon, or the app opened again) 7 URLSession:dataTask:didReceiveData:
7239note (e is the data) 8 URLSession:task:didCompleteWithError: (d the task, e the problem or nothing)
7240note 9 pasteNow: (a moment after a copied thing was chosen) 10 clipTick: (twice a second, to see what was copied)
7241note 11 pinClip: 12 deleteClip: (the Clipboard menu, on the selected copied thing) 13 agentOut: agentErr:
7242note agentEnd: stopAgent: (what the agent's program tells, and the Agent menu; b is the selector, c what came)
7243fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong
7244if eq k 0
7245utyped
7246ret 0
7247end
7248if eq k 1
7249ret get g_n 1
7250end
7251if eq k 2
7252if ge e get g_n 1
7253ret 0
7254end
7255p = ulong 0
7256if eq ulong get g_rk e 7
7257p = ufilerow 0 get g_hit e
7258else
7259if eq ulong get g_rk e 2
7260p = uptxt 0 x_open
7261end
7262if eq ulong get g_rk e 6
7263p = uptxt 0 x_paste_row
7264end
7265p = uprow p e
7266if or or eq ulong get g_rk e 1 eq ulong get g_rk e 6 eq ulong get g_rk e 2
7267p = uwhy p e
7268end
7269if eq ulong get g_rk e 5
7270q = uptxt p x_gap
7271q2 = ustrat get g_m 19 q get g_hit e
7272if gt q2 q
7273p = q2
7274end
7275end
7276if and eq ulong get g_rk e 6 or ne get g_n 13 0 ne get g_n 36 0
7277if eq ulong get g_cp get g_hit e 1
7278p = uptxt p x_gap
7279p = uptxt p x_pinned
7280end
7281end
7282if eq ulong get g_rk e 3
7283p = uptxt p x_gap
7284if eq get g_hit e 0
7285p = uptxt p x_screen0_about
7286end
7287if eq get g_hit e 1
7288p = uptxt p x_screen1_about
7289end
7290if eq get g_hit e 2
7291p = uptxt p x_screen2_about
7292end
7293end
7294if and eq ulong get g_rk e 4 eq get g_hit e 0
7295p = uptxt p x_gap
7296p = uptxt p x_command0_about
7297end
7298end
7299put g_nm p 0
7300ret unsb
7301end
7302if eq k 3
7303put g_n 3 add get g_n 3 1
7304if and ne c 0 lt get g_n 6 get g_n 1
7305put g_n 8 add get g_n 6 1
7306if and eq ulong get g_rk get g_n 6 3 eq get g_hit get g_n 6 2
7307if ne get g_m 4 0
7308uanswershow
7309uanswerview 1
7310end
7311ret 0
7312end
7313if eq ulong get g_rk get g_n 6 3
7314uscreen add get g_hit get g_n 6 1
7315ret 0
7316end
7317if and eq ulong get g_rk get g_n 6 4 eq get g_hit get g_n 6 3
7318uchatnew
7319uscreen get g_n 36
7320ret 0
7321end
7322if eq get g_n 46 1
7323uagentrun
7324ret 0
7325end
7326if eq get g_n 7 1
7327rk = ulong get g_rk get g_n 6
7328if or eq rk 8 eq rk 9
7329if eq rk 8
7330uask
7331else
7332uagentrun
7333end
7334else
7335if eq rk 2
7336if eq get g_n 13 0
7337uclipaddr 1
7338uopenaddr
7339uclipaddr 0
7340else
7341uopenaddr
7342end
7343end
7344if eq rk 4
7345if eq get g_hit get g_n 6 0
7346usettings
7347end
7348if eq get g_hit get g_n 6 2
7349uindexstart
7350end
7351if eq get g_hit get g_n 6 1
7352if eq get g_n 14 1
7353x = umsg umsg ucl c_app usl m_shared 0 0 0 usl m_terminate 0 0 0
7354end
7355end
7356end
7357if eq rk 6
7358put g_n 29 0
7359upasteclip get g_hit get g_n 6
7360if eq get g_n 14 1
7361uclipmine get g_n 29
7362end
7363end
7364if eq rk 5
7365ucopysecret get g_hit get g_n 6
7366if eq get g_n 14 1
7367uclipmine 0
7368end
7369end
7370if eq rk 10
7371uremoteopen get g_hit get g_n 6
7372end
7373if eq rk 7
7374uopenfile get g_hit get g_n 6
7375urecordfile get g_hit get g_n 6
7376end
7377if eq rk 1
7378ulaunch get g_hit get g_n 6
7379urecordapp get g_hit get g_n 6
7380end
7381put g_n 5 1
7382if eq get g_n 14 1
7383uhide
7384if eq rk 6
7385ulaterpaste
7386end
7387end
7388end
7389end
7390if and eq get g_n 7 0 eq get g_n 23 1
7391rk = ulong get g_rk get g_n 6
7392if eq rk 6
7393upasteclip get g_hit get g_n 6
7394end
7395if eq rk 5
7396ucopysecret get g_hit get g_n 6
7397end
7398if eq rk 10
7399uremoteopen get g_hit get g_n 6
7400end
7401if eq rk 7
7402urecordfile get g_hit get g_n 6
7403end
7404if eq rk 1
7405urecordapp get g_hit get g_n 6
7406end
7407end
7408end
7409end
7410if eq k 4
7411if eq e get g_o 9
7412if lt add get g_n 6 1 get g_n 1
7413uchoose add get g_n 6 1
7414end
7415ret 1
7416end
7417if eq e get g_o 10
7418if gt get g_n 6 0
7419uchoose sub get g_n 6 1
7420end
7421ret 1
7422end
7423if eq e get g_o 11
7424if ne get g_n 36 0
7425uscreen 0
7426ret 1
7427end
7428put g_n 5 1
7429uhide
7430ret 1
7431end
7432end
7433if eq k 5
7434ushow
7435ret 0
7436end
7437if eq k 7
7438unetdata e
7439ret 0
7440end
7441if eq k 8
7442unetdone d e
7443ret 0
7444end
7445if eq k 9
7446usendpaste
7447ret 0
7448end
7449if eq k 10
7450ucliptick
7451ret 0
7452end
7453if eq k 11
7454uclipmenu 1
7455ret 0
7456end
7457if eq k 12
7458uclipmenu 2
7459ret 0
7460end
7461if eq k 13
7462uagentevent b c
7463ret 0
7464end
7465if eq k 6
7466ushow
7467ret 1
7468end
7469ret 0
7470end
7471
7472note one method of the class: selector text, callback entry, type text
7473fn umethod c ulong t view uchar * entry ulong ty view uchar * to bool
7474s = usl t
7475n = ucs ty
7476upr 0 c
7477upr 8 s
7478upr 16 ulong libfn int add 2 entry
7479upr 24 ulong libptr g_nm 0 1024
7480ret eq and ucall 5 255 1
7481end
7482
7483fn main to int
7484n = ucs s_appkit
7485upr 0 ulong libptr g_nm 0 1024
7486upr 8 2
7487lr = libcall ulong libfn 0 g_rg 0 128
7488if eq ugr 0 0
7489ret 2
7490end
7491put g_f 0 usym s_gc
7492put g_f 1 usym s_sr
7493put g_f 2 usym s_ms
7494put g_f 3 usym s_wr
7495put g_f 4 usym s_acp
7496put g_f 5 usym s_cam
7497put g_f 6 usym s_rcp
7498put g_f 7 usym s_strlen
7499put g_f 8 usym s_memcpy
7500put g_f 9 usym s_getenv
7501put g_f 10 usym s_malloc
7502put g_f 11 usym s_memmem
7503put g_f 12 usym s_memchr
7504put g_f 13 usym s_memrchr
7505put g_f 14 usym s_pow
7506put g_f 15 usym s_log2
7507put g_f 16 usym s_chmod
7508put g_f 17 usym s_memset
7509put g_f 18 usym s_trusted
7510put g_f 19 usym s_key_event
7511put g_f 20 usym s_event_flags
7512put g_f 21 usym s_event_post
7513put g_f 22 usym s_cf_release
7514put g_f 23 usym s_item_copy
7515put g_f 24 usym s_item_add
7516put g_f 25 usym s_item_delete
7517put g_f 26 usym s_interaction
7518put g_f 27 usym s_random
7519put g_f 28 usym s_free
7520put g_f 29 usym s_iopolicy
7521put g_f 30 usym s_home_directory
7522for i ulong 31
7523if eq get g_f i 0
7524ret 3
7525end
7526end
7527put g_o 3 ucl c_str
7528put g_o 4 usl m_utf
7529put g_o 5 usl m_cstr
7530put g_m 16 usl m_at
7531put g_m 7 ucl c_dict
7532put g_m 8 ucl c_array
7533put g_m 9 ucl c_str
7534x = uindexmode
7535if eq x 0
7536ret 0
7537end
7538if eq x 1
7539ret 1
7540end
7541put g_o 6 usl m_strval
7542put g_o 7 usl m_reload
7543put g_o 8 usl m_setstr
7544put g_o 9 usl m_down
7545put g_o 10 usl m_up
7546put g_o 11 usl m_cancel
7547put g_o 12 usl m_selrow
7548put g_o 13 ucl c_ixset
7549put g_o 14 usl m_ixwith
7550put g_o 15 usl m_scrrow
7551put g_o 16 ucl c_url
7552put g_o 17 usl m_urlstr
7553put g_o 18 usl m_host
7554c = ucl c_pool
7555s = usl m_alloc
7556pool = umsg c s 0 0 0
7557sinit = usl m_init
7558pool = umsg pool sinit 0 0 0
7559ufolder x_dir1 0
7560ufolder x_dir2 1
7561ubuildmap
7562n = ucs x_env_front
7563upr 0 ulong libptr g_nm 0 1024
7564front_text = ucall 9
7565if ne front_text 0
7566n = ufetch front_text
7567put g_m 11 umsg unsb usl m_retain 0 0 0
7568end
7569n = ucs x_env
7570upr 0 ulong libptr g_nm 0 1024
7571if eq ucall 9 0
7572put g_n 14 1
7573else
7574put g_n 14 0
7575upr 0 0
7576x = ucall 26
7577rn = ucs x_env_screen
7578upr 0 ulong libptr g_nm 0 1024
7579screen_text = ucall 9
7580if ne screen_text 0
7581rn = ufetch screen_text
7582if eq get g_nm 0 99
7583put g_n 36 1
7584end
7585if eq get g_nm 0 97
7586put g_n 36 2
7587end
7588end
7589rn = ucs x_env_clipdo
7590upr 0 ulong libptr g_nm 0 1024
7591do_text = ucall 9
7592if ne do_text 0
7593rn = ufetch do_text
7594if eq get g_nm 0 112
7595put g_n 37 1
7596end
7597if eq get g_nm 0 100
7598put g_n 37 2
7599end
7600if eq get g_nm 0 99
7601put g_n 37 3
7602end
7603end
7604end
7605uloadindex
7606uloadvault
7607uloadconfig
7608if eq get g_n 14 0
7609rn = ucs x_env_cliprec
7610upr 0 ulong libptr g_nm 0 1024
7611if ne ucall 9 0
7612ucliprecord umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
7613end
7614end
7615uloadclips
7616put g_n 4 0
7617put g_n 13 0
7618unarrow
7619if eq get g_n 0 0
7620ret 4
7621end
7622c = ucl c_app
7623s = usl m_shared
7624app = umsg c s 0 0 0
7625n = ucs x_env
7626upr 0 ulong libptr g_nm 0 1024
7627envp = ucall 9
7628chk = ne envp 0
7629opn = false
7630ovr = false
7631asking = false
7632idle = false
7633tl = ulong 0
7634pol = ulong 0
7635put g_n 7 1
7636if chk
7637pol = 1
7638put g_n 7 0
7639n = ufetch envp
7640skip = ulong 0
7641if and ge n 5 and or eq get g_nm 0 111 eq get g_nm 0 116 eq get g_nm 4 58
7642skip = 5
7643end
7644if and ge n 4 and eq get g_nm 0 97 eq get g_nm 3 58
7645skip = 4
7646asking = true
7647put g_n 7 1
7648end
7649if and eq n 4 and eq get g_nm 0 105 eq get g_nm 3 101
7650skip = 4
7651idle = true
7652end
7653if and ge n 6 and eq get g_nm 0 97 eq get g_nm 5 58
7654skip = 6
7655asking = true
7656put g_n 46 1
7657end
7658if gt skip 0
7659ovr = true
7660if eq get g_nm 0 111
7661opn = true
7662put g_n 7 1
7663end
7664tl = sub n skip
7665if gt tl 60
7666tl = 60
7667end
7668for i ulong tl bound 64
7669put g_t i get g_nm add skip i
7670end
7671end
7672rn = ucs x_env_record
7673upr 0 ulong libptr g_nm 0 1024
7674if ne ucall 9 0
7675put g_n 23 1
7676end
7677rn = ucs x_env_row
7678upr 0 ulong libptr g_nm 0 1024
7679row_text = ucall 9
7680if ne row_text 0
7681rn = ufetch row_text
7682row_pick = ulong 0
7683for i ulong rn bound 4
7684row_digit = ulong get g_nm i
7685if and ge row_digit 48 le row_digit 57
7686row_pick = add mul row_pick 10 sub row_digit 48
7687end
7688end
7689put g_n 30 row_pick
7690end
7691end
7692s = usl m_policy
7693x = umsg app s pol 0 0
7694note the class whose methods are the callback entries
7695c = ucl c_obj
7696n = ucs c_mine
7697upr 0 c
7698upr 8 ulong libptr g_nm 0 1024
7699upr 16 0
7700mine = ucall 4
7701if eq mine 0
7702ret 5
7703end
7704ok = umethod mine m_change 0 t_v
7705ok = and ok umethod mine m_rows 1 t_q
7706ok = and ok umethod mine m_value 2 t_o
7707ok = and ok umethod mine m_go 3 t_v
7708ok = and ok umethod mine m_cmd 4 t_b
7709ok = and ok umethod mine m_reopen 6 t_reopen
7710ok = and ok umethod mine m_did_data 7 t_session
7711ok = and ok umethod mine m_did_complete 8 t_session
7712ok = and ok umethod mine m_paste_now 9 t_v
7713ok = and ok umethod mine m_clip_tick 10 t_v
7714ok = and ok umethod mine m_pin_clip 11 t_v
7715ok = and ok umethod mine m_delete_clip 12 t_v
7716ok = and ok umethod mine m_agent_out 13 t_v
7717ok = and ok umethod mine m_agent_err 13 t_v
7718ok = and ok umethod mine m_agent_end 13 t_v
7719ok = and ok umethod mine m_agent_stop 13 t_v
7720put g_m 38 usl m_agent_out
7721put g_m 39 usl m_agent_err
7722put g_m 40 usl m_agent_end
7723put g_m 41 usl m_agent_stop
7724ok = and ok umoremethods mine
7725ok = and ok ustatusmethods mine
7726ok = and ok uquitwatch mine
7727uchecklate
7728if not ok
7729ret 6
7730end
7731upr 0 mine
7732x = ucall 6
7733s = usl m_alloc
7734me = umsg mine s 0 0 0
7735me = umsg me sinit 0 0 0
7736put g_o 27 me
7737note the window
7738c = ucl c_win
7739s = usl m_alloc
7740w = umsg c s 0 0 0
7741s = usl m_initwi
7742urect 240.0f64 260.0f64 520.0f64 360.0f64
7743w = umsg w s 3 2 0
7744if eq w 0
7745ret 7
7746end
7747str = uns x_title
7748s = usl m_title
7749x = umsg w s str 0 0
7750s = usl m_conten
7751cv = umsg w s 0 0 0
7752sadd = usl m_addsub
7753sframe = usl m_initfr
7754note the search field
7755c = ucl c_field
7756s = usl m_alloc
7757fld = umsg c s 0 0 0
7758urect 16.0f64 316.0f64 488.0f64 28.0f64
7759fld = umsg fld sframe 0 0 0
7760str = uns x_hint
7761s = usl m_placeh
7762x = umsg fld s str 0 0
7763s = usl m_setdel
7764x = umsg fld s me 0 0
7765s = usl m_settar
7766x = umsg fld s me 0 0
7767s = usl m_setact
7768sgo = usl m_go
7769x = umsg fld s sgo 0 0
7770x = umsg cv sadd fld 0 0
7771put g_o 0 fld
7772note the status line
7773str = uns x_hint
7774c = ucl c_field
7775s = usl m_label
7776lbl = umsg c s str 0 0
7777s = usl m_setfra
7778urect 16.0f64 8.0f64 488.0f64 20.0f64
7779x = umsg lbl s 0 0 0
7780x = umsg cv sadd lbl 0 0
7781put g_o 2 lbl
7782note the list
7783c = ucl c_scroll
7784s = usl m_alloc
7785sv = umsg c s 0 0 0
7786urect 16.0f64 36.0f64 488.0f64 272.0f64
7787sv = umsg sv sframe 0 0 0
7788c = ucl c_table
7789s = usl m_alloc
7790tv = umsg c s 0 0 0
7791urect 0.0f64 0.0f64 470.0f64 272.0f64
7792tv = umsg tv sframe 0 0 0
7793c = ucl c_col
7794s = usl m_alloc
7795col = umsg c s 0 0 0
7796str = uns x_name
7797s = usl m_initid
7798col = umsg col s str 0 0
7799s = usl m_setwid
7800upr 64 bitcast ulong 460.0f64
7801x = umsg col s 0 0 0
7802s = usl m_addcol
7803x = umsg tv s col 0 0
7804s = usl m_header
7805x = umsg tv s 0 0 0
7806s = usl m_dataso
7807x = umsg tv s me 0 0
7808s = usl m_docvie
7809x = umsg sv s tv 0 0
7810s = usl m_scroll
7811x = umsg sv s 1 0 0
7812x = umsg cv sadd sv 0 0
7813put g_o 1 tv
7814put g_o 28 sv
7815note the answer: a text view in the list's place, hidden until a question is asked
7816c = ucl c_scroll
7817s = usl m_alloc
7818answer_scroll = umsg c s 0 0 0
7819urect 16.0f64 36.0f64 488.0f64 272.0f64
7820answer_scroll = umsg answer_scroll sframe 0 0 0
7821c = ucl c_text_view
7822s = usl m_alloc
7823answer_text = umsg c s 0 0 0
7824urect 0.0f64 0.0f64 470.0f64 272.0f64
7825answer_text = umsg answer_text sframe 0 0 0
7826x = umsg answer_text usl m_set_editable 0 0 0
7827x = umsg answer_scroll usl m_docvie answer_text 0 0
7828x = umsg answer_scroll usl m_scroll 1 0 0
7829x = umsg answer_scroll usl m_set_hidden 1 0 0
7830x = umsg cv sadd answer_scroll 0 0
7831put g_o 29 answer_scroll
7832put g_o 30 answer_text
7833ushowst
7834s = usl m_finish
7835x = umsg app s 0 0 0
7836put g_o 19 w
7837put g_o 20 usl m_order_out
7838put g_o 21 app
7839put g_o 22 usl m_hide_app
7840put g_o 23 usl m_activ
7841put g_o 24 usl m_key
7842put g_o 25 usl m_firstr
7843put g_o 26 usl m_front
7844s = usl m_released
7845x = umsg w s 0 0 0
7846s = usl m_set_app_delegate
7847x = umsg app s me 0 0
7848if chk
7849put g_n 14 0
7850put g_n 15 ukey 80 6912
7851else
7852put g_n 14 1
7853put g_n 15 ukey 49 2048
7854umenu app
7855note keep the history of what is copied while Hop is not running: look twice a second
7856first_board = umsg ucl c_pasteboard usl m_general_pasteboard 0 0 0
7857put g_n 35 umsg first_board usl m_change_count 0 0 0
7858c_t = ucl c_timer
7859s_timer = usl m_timer
7860s_tick = usl m_clip_tick
7861upr 64 bitcast ulong 0.5f64
7862upr 40 1
7863x = umsg c_t s_timer get g_o 27 s_tick 0
7864if and not uhoprunning uindexstale
7865uindexstart
7866end
7867if not uhoprunning
7868uremoterefreshall
7869end
7870end
7871ushow
7872if gt get g_n 1 0
7873uchoose 0
7874end
7875svis = usl m_visibl
7876vis = and umsg w svis 0 0 0 255
7877mode = uns x_mode
7878cd = ucl c_date
7879sd = usl m_since
7880sn = usl m_next
7881se = usl m_send
7882schanged = usl m_change
7883total = get g_n 0
7884if not chk
7885note a person uses it: AppKit's own event loop, until the app is quit
7886s = usl m_run
7887x = umsg app s 0 0 0
7888ret 0
7889end
7890note the check: about six seconds. The text goes in through the field's editor; arrow down, Enter and Escape are
7891note commands sent to that editor, which asks the field, which asks its delegate and sends its action
7892sfr = usl m_firstr
7893sed = usl m_curred
7894sins = usl m_instxt
7895sdo = usl m_docmd
7896snl = usl m_newln
7897esc = ulong 0
7898hid = ulong 0
7899back = ulong 0
7900for i ulong 120
7901upr 64 bitcast ulong 0.05f64
7902d = umsg cd sd 0 0 0
7903utick app sn se mode d
7904if eq i 10
7905x = umsg w sfr fld 0 0
7906ed = umsg fld sed 0 0 0
7907if ovr
7908for j ulong tl bound 64
7909put g_nm j get g_t j
7910end
7911put g_nm tl 0
7912str = unsb
7913else
7914str = uns x_typed
7915end
7916if not idle
7917x = umsg ed sins str 0 0
7918end
7919end
7920if and eq i 15 not ovr
7921ed = umsg fld sed 0 0 0
7922x = umsg ed sdo get g_o 9 0 0
7923end
7924if and and eq i 15 ovr and gt get g_n 30 0 lt get g_n 30 get g_n 1
7925uchoose get g_n 30
7926end
7927if and and eq i 16 ovr ne get g_n 37 0
7928if eq get g_n 37 3
7929uclipclear
7930else
7931uclipmenu get g_n 37
7932end
7933end
7934if eq i 2
7935ustatus
7936utunnelcheck
7937end
7938if eq i get g_n 48
7939ed = umsg fld sed 0 0 0
7940x = umsg ed sdo snl 0 0
7941end
7942if eq i 60
7943uasksecond
7944end
7945if and and eq i 25 not asking eq get g_n 36 0
7946put g_n 5 0
7947x = umsg w sfr fld 0 0
7948ed = umsg fld sed 0 0 0
7949x = umsg ed sdo get g_o 11 0 0
7950esc = get g_n 5
7951put g_n 5 0
7952if eq and umsg w svis 0 0 0 255 0
7953hid = 1
7954end
7955end
7956if eq i 30
7957upr 0 0
7958upr 8 0
7959upr 16 0
7960x = ucallf ulong libfn 7
7961if eq and umsg w svis 0 0 0 255 1
7962back = 1
7963end
7964end
7965end
7966note the first row, asked of the list's own data source through Objective-C, and the list's own selection
7967shown = get g_n 1
7968row = umsg tv usl m_selrd 0 0 0
7969want = ulong 0
7970if and gt shown 1 not ovr
7971want = 1
7972end
7973first = umsg me usl m_value tv col 0
7974flen = ulong 0
7975if ne first 0
7976p = umsg first get g_o 5 0 0 0
7977flen = ufetch p
7978end
7979if gt flen 255
7980flen = 255
7981end
7982for i ulong flen bound 256
7983put g_x i get g_nm i
7984end
7985uvaultcheckend
7986utunnelstop
7987paste_text = ulong 0
7988paste_size = ulong 0
7989if ne get g_n 29 0
7990pboard = umsg ucl c_pasteboard usl m_board_named uns x_check_board 0 0
7991if eq get g_n 29 1
7992got = umsg pboard usl m_string_for_type uns x_type_string 0 0
7993if ne got 0
7994paste_text = umsg got get g_o 5 0 0 0
7995end
7996else
7997got = umsg pboard usl m_data_for_type uns x_type_png 0 0
7998if ne got 0
7999paste_size = umsg got usl m_length 0 0 0
8000end
8001end
8002x = umsg pboard usl m_clear 0 0 0
8003end
8004p = uptxt 0 x_out1
8005p = upnum p total
8006p = uptxt p x_out2
8007p = upnum p shown
8008p = uptxt p x_out3
8009for i ulong flen bound 256
8010put g_nm add p i get g_x i
8011end
8012p = add p flen
8013p = uptxt p x_out4
8014p = upnum p and row 255
8015p = uptxt p x_out5
8016if and gt get g_n 8 0 le get g_n 8 shown
8017p = uprow p sub get g_n 8 1
8018end
8019if opn
8020p = uptxt p x_out6
8021p = upnum p get g_n 9
8022end
8023if ne get g_n 29 0
8024p = uptxt p x_out11
8025if ne paste_text 0
8026upr 0 paste_text
8027pn = ucall 7
8028if gt pn 80
8029pn = 80
8030end
8031if gt pn 0
8032upr 0 ulong libptr g_nm p pn
8033upr 8 paste_text
8034upr 16 pn
8035x = ucall 8
8036for j ulong pn bound 81
8037if lt ulong get g_nm add p j 32
8038put g_nm add p j 32
8039end
8040end
8041p = add p pn
8042end
8043end
8044if eq get g_n 29 2
8045p = uptxt p x_png_word
8046p = upnum p paste_size
8047end
8048end
8049if ne get g_n 36 0
8050p = uptxt p x_out12
8051p = upnum p get g_n 36
8052end
8053if eq get g_n 55 1
8054p = uptxt p x_out13
8055p = upnum p 1
8056end
8057if gt get g_n 62 0
8058p = uptxt p x_out16
8059p = upnum p get g_n 61
8060end
8061if ne get g_n 51 0
8062p = uptxt p x_out14
8063p = upnum p get g_n 52
8064p = uptxt p x_out15
8065p = upnum p get g_n 51
8066end
8067answered = false
8068if asking
8069p = uptxt p x_out10
8070if ne get g_m 4 0
8071answer_bytes = umsg get g_m 4 get g_o 5 0 0 0
8072upr 0 answer_bytes
8073an = ucall 7
8074if gt an 120
8075an = 120
8076end
8077upr 0 ulong libptr g_nm p an
8078upr 8 answer_bytes
8079upr 16 an
8080x = ucall 8
8081for j ulong an bound 121
8082if lt ulong get g_nm add p j 32
8083put g_nm add p j 32
8084end
8085end
8086p = add p an
8087answered = and and gt an 0 eq get g_n 21 1 eq get g_n 22 1
8088end
8089end
8090if not ovr
8091p = uptxt p x_out7
8092p = upnum p get g_n 15
8093p = uptxt p x_out8
8094p = upnum p hid
8095p = uptxt p x_out9
8096p = upnum p back
8097end
8098put g_nm p 10
8099upr 0 1
8100upr 8 ulong libptr g_nm 0 1024
8101upr 16 add p 1
8102x = ucall 3
8103s = usl m_close
8104x = umsg w s 0 0 0
8105if ne vis 1
8106ret 8
8107end
8108if ovr
8109took = true
8110if opn
8111took = eq get g_n 9 1
8112end
8113if asking
8114took = answered
8115end
8116if and and gt shown 0 eq get g_n 3 1 and gt get g_n 8 0 took
8117ret 1
8118end
8119ret 9
8120end
8121picked = and eq get g_n 8 add want 1 eq ulong get g_rk 0 1
8122if and and and gt shown 0 lt shown total and gt flen 0 and eq get g_n 3 1 picked and and eq esc 1 eq row want and and eq hid 1 eq back 1 eq get g_n 15 0
8123ret 1
8124end
8125ret 9
8126end