hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
| 1 | #!/bin/sh |
| 2 | # Negative controls for the rows about who Hop picks to answer (Sources/PickChecks.swift). |
| 3 | # Usage: tools/check-pick.sh [mutant-name ...] (no names: all of them) |
| 4 | # |
| 5 | # First the rows must pass on this tree: a copy of it is built here and must print PICK PASS 31 (name "control" to |
| 6 | # run that alone). Then, for each mutant, a copy of the |
| 7 | # tree with ONE rule changed is built with ./build.sh (signed ad-hoc) and `Hop --selftest-pick` must exit non-zero |
| 8 | # with the named row reported FAIL. A mutant whose text is not found in the source is a failure of this script, |
| 9 | # not a pass. Every run uses a fresh HOP_CONFIG_DIR under the system's temporary folder; the rows talk only to stub |
| 10 | # servers on this Mac's loopback address and to one-line stand-in tools. Builds run one at a time under nice: this is |
| 11 | # one full build per mutant, so run it on a build machine, not on a laptop someone is using. Prints PICK-MUTANTS PASS n. |
| 12 | set -u |
| 13 | cd "$(dirname "$0")/.." |
| 14 | ROOT=$PWD |
| 15 | T=$(mktemp -d "${TMPDIR:-/tmp}/hop-pick.XXXXXX") |
| 16 | trap 'rm -rf "$T"' EXIT |
| 17 | fails=0 passes=0 |
| 18 | pass() { echo "PASS $*"; passes=$((passes + 1)); } |
| 19 | fail() { echo "FAIL $*"; fails=$((fails + 1)); } |
| 20 | |
| 21 | rows() { # rows APP LOG: run the rows alone with a throwaway settings folder; echoes the exit code (124: not done in 15 minutes) |
| 22 | d=$(mktemp -d "$T/cfg.XXXXXX") |
| 23 | HOP_CONFIG_DIR="$d" "$1/Contents/MacOS/Hop" --selftest-pick --no-global-hotkey > "$2" 2>&1 & |
| 24 | hop=$! n=0 |
| 25 | while kill -0 "$hop" 2>/dev/null && [ "$n" -lt 900 ]; do sleep 1; n=$((n + 1)); done |
| 26 | if kill -0 "$hop" 2>/dev/null; then kill -9 "$hop"; wait "$hop" 2>/dev/null; echo "TIMED OUT after 15 minutes" >> "$2"; echo 124; return; fi |
| 27 | wait "$hop"; echo $? |
| 28 | } |
| 29 | |
| 30 | # Control: the unchanged tree passes every row. It is built here, from a copy of this tree made the same way as |
| 31 | # the copies that are changed below, so the rows that pass are the rows of this source and of nothing else. |
| 32 | copy() { mkdir -p "$1"; (cd "$ROOT" && tar cf - --exclude ./build --exclude ./.git --exclude ./dist .) | (cd "$1" && tar xf -); } |
| 33 | if [ $# -eq 0 ] || [ "${1:-}" = control ]; then |
| 34 | copy "$T/control" |
| 35 | if ! (cd "$T/control" && HOP_SIGN=adhoc nice -n 15 ./build.sh > "$T/control.build.log" 2>&1); then |
| 36 | fail "control: the unchanged tree did not build"; tail -n 8 "$T/control.build.log" |
| 37 | else |
| 38 | rc=$(rows "$T/control/build/Hop.app" "$T/control.log") |
| 39 | if [ "$rc" = 0 ] && grep -q '^PICK PASS 31$' "$T/control.log"; then pass "control: unchanged tree, built here, $(tail -n 1 "$T/control.log")" |
| 40 | else fail "control: unchanged tree, Hop exit $rc"; cat "$T/control.log"; fi |
| 41 | fi |
| 42 | rm -rf "$T/control" |
| 43 | fi |
| 44 | |
| 45 | # name | file | text to find | replacement | row that must FAIL |
| 46 | MUTANTS='own-not-first|Sources/Fusion.swift|if [4, 5].contains(first.verdict) { first.ownFirst = true; return first }|first.ownFirst = false|Your own model answers first when it is there |
| 47 | busy-not-said|Sources/Fusion.swift|catch is ModelClient.Busy { busy.raise(); return nil }|catch is ModelClient.Busy { return nil }|Your own model busy or gone: the next mind answers |
| 48 | server-may-act|Sources/Fusion.swift|state: s.ready ? 1 : 3, caps: s.acts ? 3 : 1))|state: s.ready ? 1 : 3, caps: 3))|Work that changes things never goes to a model server |
| 49 | switch-ignored|Sources/Fusion.swift|(cfg.preferOwnModel ?? true |(true |Which model servers Hop may pick, and how strong they count |
| 50 | hop-picks-itself|Sources/Fusion.swift|let tools = installed.filter { !$0.isHopItself }|let tools = installed|Which agent tools Hop may pick: its table, your own words first, never Hop itself |
| 51 | stream-id-dropped|Sources/Runners.swift|if out.model == nil { out.model = AskRoute.reportedModel(j) }|_ = 0|Under an answer: the model the server named, and where it ran |
| 52 | configured-label-dropped|Sources/AskRoute.swift| (the configured name; \(teller) reported no model id)"|" + (teller.isEmpty ? "" : "")|No model id reported: the configured name, said to be that |
| 53 | session-dropped|Sources/Fusion.swift|if let sid = a.session { end.session = (s.seat.name, sid) }|_ = a.session|An agent tool'"'"'s own session, model and tokens are read; a follow-up carries on in its session |
| 54 | stronger-stays-put|Sources/Fusion.swift|r = r.map { row in var x = row; if x.tier <= above.tier { x.state = 3 }; return x }|_ = 0|The plan: your own model first unless the work changes things; Stronger goes a tier up, then fuses, then nothing |
| 55 | unsure-accepted|Sources/Fusion.swift|(r.fields["confidence"] ?? 0) >= 700_000|(r.fields["confidence"] ?? 0) >= 1|An unsure reply is handed on, and the record at a reply'"'"'s end is never shown |
| 56 | rest-ignored|Sources/Fusion.swift|if let why = resting[s.name] {|if let why = resting[s.name], why.isEmpty {|A mind that fails is passed over with the reason, and rests |
| 57 | stop-ignored|Sources/Fusion.swift|let hold = control.hold { run.stop() }|let hold = control.hold { }|Stop ends the tool that is working, what it started and a tool that will not end; nothing more starts |
| 58 | group-not-swept|Sources/Runners.swift| add(groupMembers(at.root, in: now))| _ = now.count|Stop ends the tool that is working, what it started and a tool that will not end; nothing more starts |
| 59 | prestopped-launches|Sources/Runners.swift| if stopAsked {| if stopAsked, started {|Stop ends the tool that is working, what it started and a tool that will not end; nothing more starts |
| 60 | consent-skipped|Sources/Fusion.swift|if consent == nil { consent = await mayAct(s.seat.name) }|if consent == nil { _ = await mayAct(s.seat.name); consent = true }|The yes to agent tools is asked once, before any command runs, whatever the settings call it; a no runs nothing |
| 61 | harmless-trusted|Sources/Fusion.swift|var needsYes: Bool { endpoint == nil && !seat.chatOnly }|var needsYes: Bool { endpoint == nil && seat.act && !seat.chatOnly }|The yes to agent tools is asked once, before any command runs, whatever the settings call it; a no runs nothing |
| 62 | earlier-reply-dropped|Sources/Fusion.swift|guard let above = ask.above, !above.reply.isEmpty else { return ask.text }|guard let above = ask.above, above.reply.isEmpty else { return ask.text }|Stronger asks the next mind up and shows it the earlier reply |
| 63 | fusion-not-formed|Sources/Fusion.swift|let most = min(max(cfg.fusionMaxSeats, 1), 8), escalations|let most = 1, escalations|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 64 | unagreed-carried-out|Sources/Fusion.swift|if t.kind == 3, !one, !agreed {|if t.kind == 3, !one, !agreed, one {|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 65 | sorter-ignored|Sources/Fusion.swift|(1...3).contains(k), (1...5).contains(d), (1...3).contains(st)|(1...3).contains(k), (9...9).contains(d), (1...3).contains(st)|A cheap mind sorts the request; without a usable sorting the words decide and say so; a busy sorter is not asked twice |
| 66 | record-shown|Sources/Fusion.swift|held = whole + "\n"; heldBefore = waiting; waiting = ""|show(whole + "\n")|A reply is shown as it arrives, without its record, however it is cut into pieces; what is on screen at the end is what is kept |
| 67 | shown-not-kept|Sources/Fusion.swift| else if let seen = a.shown, seen != r.body { say(.restart); say(.answer(r.body)) }| else { _ = a.shown }|A reply is shown as it arrives, without its record, however it is cut into pieces; what is on screen at the end is what is kept |
| 68 | builtins-not-added|Sources/Config.swift|agentEngines.append(b); addedEngines.append(b.name)|addedEngines.append(b.name)|Agents new in this Hop are added to older settings once; removed ones stay removed |
| 69 | left-out-in-silence|Sources/Fusion.swift|table.leftOut = order.dropFirst(mostSeats).map(\.seat.name)|_ = order|More minds than the chooser plans: the ready ones first, the rest named |
| 70 | stopped-run-blocks|Sources/Pick.swift|if let working = control, !working.isStopped {|if control != nil {|Stop and send at once: the new message is answered; a message sent while one is at work is told so |
| 71 | tool-answer-kept|Sources/Pick.swift|if !end.outcome.acted, let standing = end.standing, !end.reply.isEmpty {|if let standing = end.standing, !end.reply.isEmpty {|A repeated message is answered from memory; Stronger works on it; a tool'"'"'s answer is never kept; the yes is asked once |
| 72 | session-never-expires|Sources/Pick.swift|if let s = session, at.timeIntervalSince(s.at) < Self.sessionFor { ask.resume = [s.seat: s.id] }|if let s = session { ask.resume = [s.seat: s.id] }|A tool'"'"'s session is carried on by the next message, not after 15 minutes and not into a new conversation |
| 73 | rest-never-ends|Sources/Pick.swift|resting = resting.filter { $0.value.until > at }|_ = at|A mind that failed rests for ten minutes, then is asked again; one that showed it is ready is not asked the test question for as long |
| 74 | ready-forgotten|Sources/Pick.swift|proven: Set(proven.keys), previousKind|proven: [], previousKind|A mind that failed rests for ten minutes, then is asked again; one that showed it is ready is not asked the test question for as long |
| 75 | begun-work-handed-on|Sources/Fusion.swift|guard s.needsYes else { return false }|guard s.needsYes, false else { return false }|Work a tool has begun is not handed to a second tool; a tool that failed before it began is passed over |
| 76 | readiness-not-asked|Sources/Fusion.swift|guard s.askable, !ask.proven.contains(name), !end.proved.contains(name) else { return true }|guard s.askable, name.isEmpty else { return true }|A mind that fails is passed over with the reason, and rests |
| 77 | test-word-not-needed|Sources/Fusion.swift|if a.ok, saysReady(a.text) { end.proved.insert(name); return true }|if a.ok { end.proved.insert(name); return true }|A mind that fails is passed over with the reason, and rests |
| 78 | own-command-asked|Sources/Fusion.swift|needsYes && seat.command.contains { $0.contains("{prompt}") } && known[((seat.command.first ?? "") as NSString).lastPathComponent] != nil|needsYes && seat.command.contains { $0.contains("{prompt}") }|A mind that fails is passed over with the reason, and rests |
| 79 | late-word-taken|Sources/Fusion.swift|let ok = code == 0 && !timedOut.isUp && !left && |let ok = code == 0 && !left && |A tool that does not answer the test question in time is ended with what it started before the next is asked, and is not taken as ready |
| 80 | ended-tool-not-waited-for|Sources/Fusion.swift|left = !(await Control.gone([run], within: CommandRun.graceToEnd + 5) { control.isStopped })|left = false|A tool that does not answer the test question in time is ended with what it started before the next is asked, and is not taken as ready |
| 81 | record-only-fusion|Sources/Fusion.swift|guard a.ok, FusionRecord.parse(a.text).body.isEmpty else { return a }|guard a.ok, a.text.isEmpty else { return a }|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 82 | record-only-work|Sources/Fusion.swift|let e = heard(await Fusion.ask(doer,|let e = (await Fusion.ask(doer,|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 83 | failed-proposer-ignored|Sources/Fusion.swift|for x in got where !x.1.ok { if endsHere(x.0, end.failed[x.0.seat.name] ?? x.1.why, doing: "did not finish") { return close() } }|_ = got.count|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 84 | failed-merge-hidden|Sources/Fusion.swift|if endsHere(fuser, failed(fuser, m), doing: "could not put the changes in") { return close() }|_ = failed(fuser, m)|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 85 | fixed-command-fused|Sources/Fusion.swift|let fixed = Set(seats.filter(\.fixed).map(\.id))|let fixed = Set<Int>()|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 86 | tool-error-swallowed|Sources/Fusion.swift|errors.add(failure + "\n"); toolFailed.raise(); continue|errors.add(failure + "\n"); continue|Work a tool has begun is not handed to a second tool; a tool that failed before it began is passed over |
| 87 | error-told-by-its-look|Sources/Fusion.swift|if let failure = AgentEvents.failure(piece) {|if let failure = AgentEvents.failure(piece) ?? AgentEvents.render(piece).flatMap({ $0.hasPrefix("! ") ? $0 : nil }) {|Work a tool has begun is not handed to a second tool; a tool that failed before it began is passed over |
| 88 | sideways-after-unsure|Sources/Fusion.swift|unsure.map { s.seat.tier > $0.seat.seat.tier } ?? true|unsure.map { _ in true } ?? true|An unsure reply is handed on, and the record at a reply'"'"'s end is never shown |
| 89 | one-voice-unnamed|Sources/Fusion.swift|meta = one ? Fusion.meta(usable[0].0, usable[0].1) : |meta = one ? "answered by \(voices)" : |Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 90 | no-replacement-among-proposers|Sources/Fusion.swift|if let s = usable.map(\.0).first(where: { !down.contains($0.id) && (acting ? $0.acts : true) }) { return s }|_ = acting|Open-ended work is fused from several minds; an agreed plan is carried out once, one that was not agreed is not |
| 91 | claude-model-unnamed|Sources/Fusion.swift|else { command += ["--model", "opus"] }|else { command += [] }|Which agent tools Hop may pick: its table, your own words first, never Hop itself |
| 92 | old-claude-entry-dropped|Sources/Fusion.swift|for m in cfg.models where m.kind == "claude-cli" && m.rewrite {|for m in cfg.models where m.kind == "claude-cli" && m.rewrite && m.name.isEmpty {|Which model servers Hop may pick, and how strong they count |
| 93 | retry-keeps-usage|Sources/Runners.swift|return try await streamOnce(ep, history: history, usage: false, onDelta: onDelta)|return try await streamOnce(ep, history: history, usage: true, onDelta: onDelta)|Two requests at once to a server that refuses the usage option are both sent again without it and answered |
| 94 | goahead-ignored|Sources/Fusion.swift|guard !words.isEmpty, words.count <= 6 else { return false }|guard !words.isEmpty, words.count <= 0 else { return false }|A cheap mind sorts the request; without a usable sorting the words decide and say so; a busy sorter is not asked twice |
| 95 | command-sorts|Sources/Fusion.swift|$0.ready && !$0.acts && !$0.needsYes && maySort($0)|$0.ready && !$0.acts && maySort($0)|A cheap mind sorts the request; without a usable sorting the words decide and say so; a busy sorter is not asked twice |
| 96 | any-words-go-ahead|Sources/Fusion.swift|return words.allSatisfy(known.contains) && words.contains(where: yes.contains)|return words.contains(where: yes.contains)|A cheap mind sorts the request; without a usable sorting the words decide and say so; a busy sorter is not asked twice |
| 97 | own-top-tier-not-sorting|Sources/Fusion.swift|{ $0.own ? true : $0.seat.tier <= 3 }|{ $0.seat.tier <= 3 }|A cheap mind sorts the request; without a usable sorting the words decide and say so; a busy sorter is not asked twice |
| 98 | pieces-shown-twice|Sources/Fusion.swift|else if !inPieces.isUp { shown?.add(part + "\n") }|else { shown?.add(part + "\n") }|A reply that comes in small pieces from a tool is shown as it comes, once, with the tokens and the model it reports |
| 99 | stopped-tool-not-waited-for|Sources/Pick.swift| remember(control.leftRunning)| _ = control.leftRunning|After a Stop that ended a working tool, no command starts until the stopped tool and its children are gone |
| 100 | half-answer-kept|Sources/Model.swift|if let halfReply, let at = log.firstIndex(where: { $0.id == halfReply }), at > i { log.remove(at: at) }|_ = halfReply|A stronger try that gives no answer leaves the earlier answer, and no half answer, for the next mind' |
| 101 | |
| 102 | printf '%s\n' "$MUTANTS" > "$T/mutants" # not echo: it would turn the \n inside a mutant's text into a line break |
| 103 | # A name that is not "control" or one of the mutants is a mistake, not a run of nothing. |
| 104 | for want in "$@"; do |
| 105 | [ "$want" = control ] && continue |
| 106 | grep -q "^$want|" "$T/mutants" || fail "no mutant is called $want" |
| 107 | done |
| 108 | while IFS='|' read -r name file from to row; do |
| 109 | if [ $# -gt 0 ]; then case " $* " in *" $name "*) ;; *) continue ;; esac; fi |
| 110 | # A line of the list is five fields. A "|" inside a mutant's own text would shift them: that is a mistake in this list. |
| 111 | case "$row" in *"|"*|"") fail "mutant $name: its line in the list is not five fields"; continue ;; esac |
| 112 | M="$T/$name"; mkdir -p "$M" |
| 113 | (cd "$ROOT" && tar cf - --exclude ./build --exclude ./.git --exclude ./dist .) | (cd "$M" && tar xf -) |
| 114 | FROM="$from" TO="$to" perl -0pi -e '$n = s/\Q$ENV{FROM}\E/$ENV{TO}/g; END { exit($n == 1 ? 0 : 3) }' "$M/$file" |
| 115 | if [ $? -ne 0 ] || cmp -s "$ROOT/$file" "$M/$file"; then fail "mutant $name: the text to change was not found exactly once in $file"; continue; fi |
| 116 | if ! (cd "$M" && HOP_SIGN=adhoc nice -n 15 ./build.sh > "$T/$name.build.log" 2>&1); then |
| 117 | # A mutant may be caught by the build's Flow regression after compilation/signing. |
| 118 | # Still require the named chooser row below; neither a compiler error nor an |
| 119 | # unrelated build failure can count as a successful negative control. |
| 120 | if grep -qE '^[0-9]+ FLOW CHECKS FAILED$' "$T/$name.build.log" && |
| 121 | grep -q '^built build/Hop.app$' "$T/$name.build.log" && |
| 122 | codesign --verify --strict "$M/build/Hop.app" >/dev/null 2>&1; then |
| 123 | printf 'Mutant %s also failed the build-gated Flow checks:\n' "$name" |
| 124 | grep '^FAIL\|FLOW CHECKS FAILED$' "$T/$name.build.log" | sed 's/^/EXPECTED MUTANT FAILURE: /' |
| 125 | else |
| 126 | fail "mutant $name: did not build"; tail -n 8 "$T/$name.build.log"; rm -rf "$M"; continue |
| 127 | fi |
| 128 | fi |
| 129 | rc=$(rows "$M/build/Hop.app" "$T/$name.log") |
| 130 | if [ "$rc" != 0 ] && grep -qF "FAIL $row:" "$T/$name.log"; then |
| 131 | pass "negative control: $name is caught (Hop exit $rc, FAIL $row)" |
| 132 | else |
| 133 | fail "mutant $name was not caught (Hop exit $rc)"; cat "$T/$name.log" |
| 134 | fi |
| 135 | rm -rf "$M" |
| 136 | done < "$T/mutants" |
| 137 | |
| 138 | if [ "$fails" = 0 ] && [ "$passes" -gt 0 ]; then echo "PICK-MUTANTS PASS $passes"; exit 0; fi |
| 139 | [ "$passes" -gt 0 ] || echo "nothing was checked" |
| 140 | echo "PICK-MUTANTS FAIL $fails"; exit 1 |