lycheedev 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ local MAX_UNACKNOWLEDGED_RESULTS = 3
28
28
 
29
29
  local activeContext
30
30
  local awaitingNotice
31
+ local identityReceiptNonce
31
32
  local unacknowledgedResults = 0
32
33
  local executedRequests = {}
33
34
 
@@ -637,14 +638,94 @@ end
637
638
  function Controller.Stop()
638
639
  ns.AutomationOverlay.HideNotice()
639
640
  ns.AutomationOverlay.HideStatus()
641
+ ns.AutomationOverlay.HideIdentity()
640
642
  Print(L.AUTO_STOPPED)
641
643
  end
642
644
 
645
+ function Controller.StopIdentify(nonce)
646
+ if nonce and nonce ~= identityReceiptNonce then
647
+ return
648
+ end
649
+ identityReceiptNonce = nil
650
+ ns.AutomationOverlay.HideIdentity()
651
+ Print(L.AUTO_IDENTITY_HIDDEN)
652
+ end
653
+
654
+ -- Identity marker for host-side window discovery.
655
+ --
656
+ -- The host can capture several game windows but cannot tell which character is
657
+ -- behind each one; nothing observable from outside the game says so. This shows
658
+ -- a tiny QR code carrying the character identity and build, so a host can map
659
+ -- every running window to a name and let the user choose. It appears only on
660
+ -- explicit request because it shares the top-left corner with the completion
661
+ -- notice and would otherwise sit on screen permanently.
662
+ function Controller.Identify()
663
+ if not EnsureReady() then
664
+ return
665
+ end
666
+
667
+ local character, realm
668
+ local succeeded, name = pcall(UnitName, "player")
669
+ if succeeded and type(name) == "string" and name ~= ""
670
+ and not (issecretvalue and issecretvalue(name)) then
671
+ character = name
672
+ end
673
+ succeeded, name = pcall(GetRealmName)
674
+ if succeeded and type(name) == "string" and name ~= ""
675
+ and not (issecretvalue and issecretvalue(name)) then
676
+ realm = name
677
+ end
678
+
679
+ if not character then
680
+ Print(L.AUTO_IDENTITY_UNAVAILABLE)
681
+ return
682
+ end
683
+
684
+ -- The marker and the completion notice share one corner. Replacing a notice
685
+ -- would take away the only on-screen reference to its Ticket, so refuse
686
+ -- instead of hiding evidence the user may still need.
687
+ if awaitingNotice then
688
+ Print(L.AUTO_IDENTITY_NOTICE_SHOWN)
689
+ return
690
+ end
691
+
692
+ local version = GetBuildInfo and select(1, GetBuildInfo()) or nil
693
+ if issecretvalue and issecretvalue(version) then
694
+ version = nil
695
+ end
696
+
697
+ -- Character names and realm names are plain text, so escape them before
698
+ -- embedding rather than assuming they are JSON-safe.
699
+ local function EscapeJson(value)
700
+ value = tostring(value or "")
701
+ value = value:gsub("\\", "\\\\"):gsub('"', '\\"'):gsub("[%c]", " ")
702
+ return value
703
+ end
704
+
705
+ local json = string.format('{"v":1,"id":"%s","realm":"%s","client":"%s","build":"%s"}',
706
+ EscapeJson(character),
707
+ EscapeJson(realm or ""),
708
+ EscapeJson(ns.Client and ns.Client.id or ""),
709
+ EscapeJson(version or ""))
710
+
711
+ if #json > MAX_NOTICE_BYTES then
712
+ Print(L.AUTO_IDENTITY_UNAVAILABLE)
713
+ return
714
+ end
715
+
716
+ identityReceiptNonce = nil
717
+ if ns.AutomationOverlay.ShowIdentity(json) then
718
+ Print(L.AUTO_IDENTITY_SHOWN:format(character, realm or "-"))
719
+ else
720
+ Print(L.AUTO_IDENTITY_UNAVAILABLE)
721
+ end
722
+ end
723
+
643
724
  -- The plugin cannot observe whether the host read a result, so the host reports
644
725
  -- it back as a chat command: `/dev auto ack <ticket> <received|failed>`. That
645
726
  -- clears the pending-flush block immediately (no reload needed) and records the
646
727
  -- outcome so the page can show it and a later session keeps it.
647
- function Controller.Ack(ticket, outcome)
728
+ function Controller.Ack(ticket, outcome, nonce)
648
729
  if not EnsureReady() then
649
730
  return
650
731
  end
@@ -661,6 +742,16 @@ function Controller.Ack(ticket, outcome)
661
742
  Print(L.AUTO_ACK_TICKET_UNKNOWN:format(ticket))
662
743
  return
663
744
  end
745
+ if nonce then
746
+ if not IsValidRequestId(nonce) or #ticket > 64 then
747
+ Print(L.AUTO_USAGE)
748
+ return
749
+ end
750
+ if awaitingNotice and awaitingNotice.ticket ~= ticket then
751
+ Print(L.AUTO_IDENTITY_NOTICE_SHOWN)
752
+ return
753
+ end
754
+ end
664
755
  record.receivedAt = time()
665
756
  record.receivedStatus = outcome
666
757
  -- Only the first acknowledgement of a result frees a backlog slot; a repeat
@@ -675,6 +766,16 @@ function Controller.Ack(ticket, outcome)
675
766
  awaitingNotice = nil
676
767
  ns.AutomationOverlay.HideNotice()
677
768
  end
769
+ if nonce then
770
+ -- Echo only validated identifiers. A fresh nonce separates this receipt
771
+ -- from an older acknowledgement still visible on screen.
772
+ local receipt = string.format(
773
+ '{"v":1,"ticket":"%s","task":"ack","run":"%s","ts":%d,"status":"%s"}',
774
+ ticket, nonce, record.receivedAt, outcome)
775
+ if ns.AutomationOverlay.ShowIdentity(receipt) then
776
+ identityReceiptNonce = nonce
777
+ end
778
+ end
678
779
  Print(L.AUTO_ACK_DONE:format(ticket, outcome))
679
780
  end
680
781
 
@@ -725,13 +826,29 @@ function Controller.HandleCommand(text)
725
826
  return
726
827
  end
727
828
  Controller.Stop()
829
+ elseif action == "identify" then
830
+ if rest ~= "" then
831
+ Print(L.AUTO_USAGE)
832
+ return
833
+ end
834
+ Controller.Identify()
835
+ elseif action == "unidentify" then
836
+ local nonce = rest ~= "" and rest:match("^(%S+)$") or nil
837
+ if rest ~= "" and not IsValidRequestId(nonce) then
838
+ Print(L.AUTO_USAGE)
839
+ return
840
+ end
841
+ Controller.StopIdentify(nonce)
728
842
  elseif action == "ack" then
729
- local ticket, outcome = rest:match("^(%S+)%s+(%S+)$")
843
+ local ticket, outcome, nonce = rest:match("^(%S+)%s+(%S+)%s+(%S+)$")
844
+ if not ticket then
845
+ ticket, outcome = rest:match("^(%S+)%s+(%S+)$")
846
+ end
730
847
  if not ticket or not outcome then
731
848
  Print(L.AUTO_USAGE)
732
849
  return
733
850
  end
734
- Controller.Ack(ticket, outcome:lower())
851
+ Controller.Ack(ticket, outcome:lower(), nonce)
735
852
  else
736
853
  Print(L.AUTO_USAGE)
737
854
  end
@@ -755,3 +872,13 @@ end
755
872
  function Controller.GetAwaitingNotice()
756
873
  return awaitingNotice
757
874
  end
875
+
876
+ -- The identity marker is own UI and must not survive a combat lockout, matching
877
+ -- the notice and status blocks. The callback is constant time while the overlay
878
+ -- has never been built, so registering it costs nothing for users who never use
879
+ -- the automation page.
880
+ ns.RegisterCombatShutdown(function()
881
+ if ns.AutomationOverlay then
882
+ ns.AutomationOverlay.HideIdentity()
883
+ end
884
+ end)