Repository navigation
feat(bin): add Firstmate commands to the Rex command palette - #5
Conversation
Add a Firstmate group to Rex's command palette: Show Fleet, This Worker, Peek Worker, Go to Waiting Worker, Show or Hide Away Pane, Answer Decision, Tell Firstmate, and Request Merge. - bin/fm-rex-palette.sh installs, removes, checks, and reports one marked block at the top of this machine's Rex init.lua: it refuses unbalanced markers, a failing config check, and a remote server, backs the file up, keeps its mode, edits a symlink's target, and uninstalls byte for byte. No key is bound. - bin/backends/rex-palette.lua defines the actions; each asks bin/fm-rex-popup.sh plan what to do, opens a floating popup, and moves the view only for a key or palette use. - bin/fm-rex-popup.sh resolves the focused pane to a task, or a pane on another host to its remote second mate, shows popups on this machine, ranks waiting workers for goto, and shows or hides the away daemon's detached block. The acting popups only file captain inbox notes; nothing steers a worker or merges. - Tests: a fake-rex unit suite and a token-free lab-server smoke, mapped to the rex family; docs and dated verification evidence.
… surface Go to Waiting Worker shows this machine's fm-local session for a remote second mate instead of selecting another host's session id. The away command is a plain toggle, the installer keeps only install and uninstall, an unchanged install still reloads, and This Worker shows its fallback for a task with no status line.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d34eba6217
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| snapshot | jq -r --arg t "${1:-}" ' | ||
| [ ((.tasks // [])[] | select($t == "" or .id == $t) | . as $r | ||
| | ($r.hints.open_decisions // [])[] | [$r.id, (.key // ""), (.summary // "")]), | ||
| ((.backlog.records // [])[] | select(.captain_actionable == true) | select($t == "" or .id == $t) | ||
| | [.id, "", (.hold_reason // .title // "")]) ] | ||
| | .[] | map(gsub("[\t\n\r]"; " ")) | @tsv' |
There was a problem hiding this comment.
Include remote secondmate decisions in Answer Decision
Captain, when the focused worker is managed by a remote secondmate, its open decisions are exposed by the fleet snapshot under secondmate_current.records[].decisions_open, but this query only reads local .tasks[].hints.open_decisions and .backlog.records[].captain_actionable. As a result, Answer Decision reports no pending decision (or omits it from the list) and cannot file an answer for remote secondmate workers.
Useful? React with 👍 / 👎.
| first_waiting() { | ||
| local meta id kind rank best='' best_rank=9 | ||
| for meta in "$STATE"/*.meta; do | ||
| [ -f "$meta" ] && [ ! -L "$meta" ] || continue | ||
| id=${meta##*/} | ||
| id=${id%.meta} | ||
| task_ok "$id" || continue | ||
| [ "$(fm_meta_get "$meta" backend)" = rex ] || [ "$(fm_meta_get "$meta" remote_backend)" = rex ] || continue | ||
| kind=$(fm_meta_get "$meta" kind) | ||
| rank=$(waiting_rank "$id" "${kind:-ship}") | ||
| [ -n "$rank" ] && [ "$rank" -lt "$best_rank" ] || continue | ||
| best=$id | ||
| best_rank=$rank | ||
| done |
There was a problem hiding this comment.
Rank remote secondmate child waits in Go to Waiting Worker
When a child of a remote secondmate is waiting on the captain, Go to Waiting Worker does not see it: first_waiting ranks only the parent home's state/<id>.status for each metadata record, while remote child decisions and holds are published in secondmate_current.records[].decisions_open and holds. This can select a lower-priority local task or report that nobody is waiting even though a remote worker has an actionable decision.
Useful? React with 👍 / 👎.
| body_merge() { | ||
| local task=${1:-} rows url t confirm | ||
| rows=$(snapshot | jq -r --arg t "$task" \ | ||
| '(.tasks // [])[] | select($t == "" or .id == $t) | select((.pr.url // "") != "") | [.id, "", .pr.url] | @tsv') | ||
| if [ -z "$rows" ] && [ -n "$task" ]; then | ||
| printf 'No pull request is recorded for %s; showing every recorded one.\n\n' "$task" | ||
| rows=$(snapshot | jq -r '(.tasks // [])[] | select((.pr.url // "") != "") | [.id, "", .pr.url] | @tsv') | ||
| fi |
There was a problem hiding this comment.
Include remote child pull requests in Request Merge
For a pull request belonging to a worker under a remote secondmate, the fleet snapshot exposes that worker through the secondmate summary rather than as a local .tasks[] row, but this query only scans (.tasks // [])[] for .pr.url. The Request Merge popup therefore reports no pull request (or only lists local workers) and cannot file a merge request for remote secondmate work.
Useful? React with 👍 / 👎.
| out=$(FM_BACKEND_REX_SERVER=$(fm_meta_get "$meta" rex_server) fm_backend_rex_block_inspect "$(fm_meta_get "$meta" window)") \ | ||
| && out=$(printf '%s' "$out" | jq -r '.block.window_id // empty' 2>/dev/null) \ | ||
| && [ -n "$out" ] && G_WINDOW=$out | ||
| return 0 |
There was a problem hiding this comment.
Fail Go to Waiting Worker when its tab is stale
If a local worker's recorded Rex session or block has been deleted or its server is unreachable, fm_backend_rex_block_inspect fails, but this && chain is ignored and goto_target still returns success with the stale metadata window. fm_goto then emits a selection for a nonexistent tab instead of reporting that the worker no longer has a live Rex target.
Useful? React with 👍 / 👎.
| file_note() { # <text> | ||
| local text=$1 rid out rc | ||
| rid="rex-palette-$(date +%s)-$$-$RANDOM" | ||
| out=$("$SCRIPT_DIR/fm-inbox.sh" note --request-id "$rid" -- "$text" 2>&1) | ||
| rc=$? | ||
| case "$rc" in | ||
| 0) printf '\nFiled for Firstmate:\n %s\n' "$text" ;; | ||
| 3) printf '\nSaved for Firstmate, but its wake could not be queued; Firstmate sees it at its next inbox read:\n %s\n' "$text" ;; | ||
| *) printf '\nCould not file the note (%s): %s\n' "$rc" "$out" ;; | ||
| esac |
There was a problem hiding this comment.
Propagate inbox write failures from acting popups
When fm-inbox.sh note fails with any status other than 0 or 3, file_note prints an error but then returns the success status of printf; the answer, note, and merge popup bodies therefore exit successfully even though the requested captain inbox action was not saved. Rex callers and automation cannot distinguish a completed action from a failed write.
Useful? React with 👍 / 👎.
Summary
Part of Rex Phase 4: Firstmate commands in the Rex command palette (A1, A2, D, E from the Phase 4 pick).
bin/fm-rex-palette.sh install|uninstallowns one marked block at the top of the Rexinit.lua. The new file must passrex config checkbefore it replaces the old one, and a backup is kept. Uninstall restores the file byte for byte. When Firstmate's module fails to load, the rest of the config still loads.bin/fm-inbox.sh. They never steer a worker or merge, so merges always go through Firstmate.fm-localsession.bin/backends/rex-palette.luadefines the actions, andbin/fm-rex-popup.shplans each action and runs the popup bodies.docs/rex-backend.md"Command palette" owns the public contract.Validation
tests/fm-rex-palette.test.sh(fake rex) passes 14 of 14 checks: installer placement, idempotence, reload, refusals, symlinks, pane resolution (local and remote), goto ranking and remote selection, the away toggle, and the inbox-only acting popups.tests/fm-rex-palette-smoke.test.shpasses 7 of 7 on a private lab Rex server. The lab's live-server tripwire was clean.bin/fm-lint.shandbin/fm-doc-audience-check.share clean.