Skip to content

feat: negative message IDs as reverse inbox indices#7

Merged
markmnl merged 3 commits intomainfrom
copilot/allow-negative-numbers-for-last-message
May 6, 2026
Merged

feat: negative message IDs as reverse inbox indices#7
markmnl merged 3 commits intomainfrom
copilot/allow-negative-numbers-for-last-message

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Commands accepting <message-id> required knowing the exact ID. Users now pass negative indices (-1, -2, …) to reference recent messages by position.

How it works

  • -1 → most recent inbox message, -2 → second most recent, resolved via GET /fmsg (ID desc) with offset -N - 1
  • fmsg get -1, fmsg del -1, fmsg get-data -2, etc. all work naturally

Changes

  • cmd/msgid.goresolveMessageID(client, arg): positive IDs pass through; negative values hit GET /fmsg?limit=1&offset=<N-1> to resolve the actual ID
  • cmd/root.goinjectDashDash() prepended to Execute(): scans os.Args and inserts -- before the first -\d+ argument so pflag doesn't swallow it as a shorthand flag — users type fmsg get -1 with no special syntax required
  • All 9 message-ID commands (get, del, update, add-to, attach, get-data, get-attach, rm-attach, draft send) updated to call resolveMessageID
  • cmd/msgid_test.go — unit tests for resolution logic and injectDashDash (positive, -1/-2/-3, out-of-range, zero, invalid, flags-before-index)
  • README.md — documents the feature with index table and examples
fmsg get -1            # most recent received message
fmsg get-data -2       # body of second most recent
fmsg update --topic "hello" -1   # flags must precede the negative ID

Copilot AI linked an issue May 6, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 6, 2026 11:37
- Add cmd/msgid.go with resolveMessageID() helper that resolves -1 to
  the most recent inbox message, -2 to the second most recent, etc.
  via GET /fmsg (ordered by ID desc)
- Add injectDashDash() in root.go to auto-insert '--' before any -N
  argument so pflag doesn't treat negative numbers as shorthand flags
- Update get, del, update, add-to, attach, get-data, get-attach,
  rm-attach, and draft-send commands to use resolveMessageID()
- Add unit tests for resolveMessageID() and injectDashDash()
- Document the feature in README.md

Agent-Logs-Url: https://github.com/markmnl/fmsg-cli/sessions/629c298b-2dde-4aa7-9b9f-258b118bfb3a

Co-authored-by: markmnl <2630321+markmnl@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for negative numbers in message ID commands feat: negative message IDs as reverse inbox indices May 6, 2026
Copilot finished work on behalf of markmnl May 6, 2026 11:39
Copilot AI requested a review from markmnl May 6, 2026 11:39
@markmnl markmnl marked this pull request as ready for review May 6, 2026 11:44
@markmnl markmnl merged commit 98eba7f into main May 6, 2026
@markmnl markmnl deleted the copilot/allow-negative-numbers-for-last-message branch May 6, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow negative numbers for last message for user

2 participants