claude-scope 0.3.2 → 0.4.0
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.
- package/dist/claude-scope.cjs +285 -0
- package/package.json +1 -1
package/dist/claude-scope.cjs
CHANGED
|
@@ -440,6 +440,7 @@ function colorize(text, color) {
|
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
// src/ui/utils/colors.ts
|
|
443
|
+
var red = "\x1B[31m";
|
|
443
444
|
var gray = "\x1B[90m";
|
|
444
445
|
|
|
445
446
|
// src/ui/theme/default-theme.ts
|
|
@@ -823,6 +824,289 @@ var ConfigCountWidget = class {
|
|
|
823
824
|
}
|
|
824
825
|
};
|
|
825
826
|
|
|
827
|
+
// src/widgets/poker/deck.ts
|
|
828
|
+
var import_node_crypto = require("node:crypto");
|
|
829
|
+
|
|
830
|
+
// src/widgets/poker/types.ts
|
|
831
|
+
var Suit = {
|
|
832
|
+
Spades: "spades",
|
|
833
|
+
Hearts: "hearts",
|
|
834
|
+
Diamonds: "diamonds",
|
|
835
|
+
Clubs: "clubs"
|
|
836
|
+
};
|
|
837
|
+
var SUIT_SYMBOLS = {
|
|
838
|
+
spades: "\u2660",
|
|
839
|
+
hearts: "\u2665",
|
|
840
|
+
diamonds: "\u2666",
|
|
841
|
+
clubs: "\u2663"
|
|
842
|
+
};
|
|
843
|
+
function isRedSuit(suit) {
|
|
844
|
+
return suit === "hearts" || suit === "diamonds";
|
|
845
|
+
}
|
|
846
|
+
var Rank = {
|
|
847
|
+
Two: "2",
|
|
848
|
+
Three: "3",
|
|
849
|
+
Four: "4",
|
|
850
|
+
Five: "5",
|
|
851
|
+
Six: "6",
|
|
852
|
+
Seven: "7",
|
|
853
|
+
Eight: "8",
|
|
854
|
+
Nine: "9",
|
|
855
|
+
Ten: "10",
|
|
856
|
+
Jack: "J",
|
|
857
|
+
Queen: "Q",
|
|
858
|
+
King: "K",
|
|
859
|
+
Ace: "A"
|
|
860
|
+
};
|
|
861
|
+
function getRankValue(rank) {
|
|
862
|
+
const values = {
|
|
863
|
+
"2": 2,
|
|
864
|
+
"3": 3,
|
|
865
|
+
"4": 4,
|
|
866
|
+
"5": 5,
|
|
867
|
+
"6": 6,
|
|
868
|
+
"7": 7,
|
|
869
|
+
"8": 8,
|
|
870
|
+
"9": 9,
|
|
871
|
+
"10": 10,
|
|
872
|
+
"J": 11,
|
|
873
|
+
"Q": 12,
|
|
874
|
+
"K": 13,
|
|
875
|
+
"A": 14
|
|
876
|
+
};
|
|
877
|
+
return values[rank];
|
|
878
|
+
}
|
|
879
|
+
function formatCard(card) {
|
|
880
|
+
return `${card.rank}${SUIT_SYMBOLS[card.suit]}`;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/widgets/poker/deck.ts
|
|
884
|
+
var ALL_SUITS = [Suit.Spades, Suit.Hearts, Suit.Diamonds, Suit.Clubs];
|
|
885
|
+
var ALL_RANKS = [
|
|
886
|
+
Rank.Two,
|
|
887
|
+
Rank.Three,
|
|
888
|
+
Rank.Four,
|
|
889
|
+
Rank.Five,
|
|
890
|
+
Rank.Six,
|
|
891
|
+
Rank.Seven,
|
|
892
|
+
Rank.Eight,
|
|
893
|
+
Rank.Nine,
|
|
894
|
+
Rank.Ten,
|
|
895
|
+
Rank.Jack,
|
|
896
|
+
Rank.Queen,
|
|
897
|
+
Rank.King,
|
|
898
|
+
Rank.Ace
|
|
899
|
+
];
|
|
900
|
+
var Deck = class {
|
|
901
|
+
cards = [];
|
|
902
|
+
constructor() {
|
|
903
|
+
this.initialize();
|
|
904
|
+
this.shuffle();
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Create a standard 52-card deck
|
|
908
|
+
*/
|
|
909
|
+
initialize() {
|
|
910
|
+
this.cards = [];
|
|
911
|
+
for (const suit of ALL_SUITS) {
|
|
912
|
+
for (const rank of ALL_RANKS) {
|
|
913
|
+
this.cards.push({ rank, suit });
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Shuffle deck using Fisher-Yates algorithm with crypto.random
|
|
919
|
+
*/
|
|
920
|
+
shuffle() {
|
|
921
|
+
for (let i = this.cards.length - 1; i > 0; i--) {
|
|
922
|
+
const j = (0, import_node_crypto.randomInt)(0, i + 1);
|
|
923
|
+
[this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]];
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Deal one card from the top of the deck
|
|
928
|
+
* @throws Error if deck is empty
|
|
929
|
+
*/
|
|
930
|
+
deal() {
|
|
931
|
+
if (this.cards.length === 0) {
|
|
932
|
+
throw new Error("Deck is empty");
|
|
933
|
+
}
|
|
934
|
+
return this.cards.pop();
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Get number of remaining cards in deck
|
|
938
|
+
*/
|
|
939
|
+
remaining() {
|
|
940
|
+
return this.cards.length;
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
// src/widgets/poker/hand-evaluator.ts
|
|
945
|
+
var HAND_DISPLAY = {
|
|
946
|
+
[10 /* RoyalFlush */]: { name: "Royal Flush", emoji: "\u{1F3C6}" },
|
|
947
|
+
[9 /* StraightFlush */]: { name: "Straight Flush", emoji: "\u{1F525}" },
|
|
948
|
+
[8 /* FourOfAKind */]: { name: "Four of a Kind", emoji: "\u{1F48E}" },
|
|
949
|
+
[7 /* FullHouse */]: { name: "Full House", emoji: "\u{1F3E0}" },
|
|
950
|
+
[6 /* Flush */]: { name: "Flush", emoji: "\u{1F4A7}" },
|
|
951
|
+
[5 /* Straight */]: { name: "Straight", emoji: "\u{1F4C8}" },
|
|
952
|
+
[4 /* ThreeOfAKind */]: { name: "Three of a Kind", emoji: "\u{1F3AF}" },
|
|
953
|
+
[3 /* TwoPair */]: { name: "Two Pair", emoji: "\u270C\uFE0F" },
|
|
954
|
+
[2 /* OnePair */]: { name: "One Pair", emoji: "\u{1F44D}" },
|
|
955
|
+
[1 /* HighCard */]: { name: "High Card", emoji: "\u{1F0CF}" }
|
|
956
|
+
};
|
|
957
|
+
function countRanks(cards) {
|
|
958
|
+
const counts = /* @__PURE__ */ new Map();
|
|
959
|
+
for (const card of cards) {
|
|
960
|
+
const value = getRankValue(card.rank);
|
|
961
|
+
counts.set(value, (counts.get(value) || 0) + 1);
|
|
962
|
+
}
|
|
963
|
+
return counts;
|
|
964
|
+
}
|
|
965
|
+
function countSuits(cards) {
|
|
966
|
+
const counts = /* @__PURE__ */ new Map();
|
|
967
|
+
for (const card of cards) {
|
|
968
|
+
counts.set(card.suit, (counts.get(card.suit) || 0) + 1);
|
|
969
|
+
}
|
|
970
|
+
return counts;
|
|
971
|
+
}
|
|
972
|
+
function isFlush(cards) {
|
|
973
|
+
const suitCounts = countSuits(cards);
|
|
974
|
+
for (const count of suitCounts.values()) {
|
|
975
|
+
if (count >= 5) return true;
|
|
976
|
+
}
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
function getStraightHighCard(cards) {
|
|
980
|
+
const uniqueValues = /* @__PURE__ */ new Set();
|
|
981
|
+
for (const card of cards) {
|
|
982
|
+
uniqueValues.add(getRankValue(card.rank));
|
|
983
|
+
}
|
|
984
|
+
const sortedValues = Array.from(uniqueValues).sort((a, b) => b - a);
|
|
985
|
+
if (sortedValues.includes(14)) {
|
|
986
|
+
sortedValues.push(1);
|
|
987
|
+
}
|
|
988
|
+
for (let i = 0; i <= sortedValues.length - 5; i++) {
|
|
989
|
+
const current = sortedValues[i];
|
|
990
|
+
const next1 = sortedValues[i + 1];
|
|
991
|
+
const next2 = sortedValues[i + 2];
|
|
992
|
+
const next3 = sortedValues[i + 3];
|
|
993
|
+
const next4 = sortedValues[i + 4];
|
|
994
|
+
if (current - next1 === 1 && current - next2 === 2 && current - next3 === 3 && current - next4 === 4) {
|
|
995
|
+
return current;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
function getMaxCount(cards) {
|
|
1001
|
+
const rankCounts = countRanks(cards);
|
|
1002
|
+
let maxCount = 0;
|
|
1003
|
+
for (const count of rankCounts.values()) {
|
|
1004
|
+
if (count > maxCount) {
|
|
1005
|
+
maxCount = count;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return maxCount;
|
|
1009
|
+
}
|
|
1010
|
+
function getPairCount(cards) {
|
|
1011
|
+
const rankCounts = countRanks(cards);
|
|
1012
|
+
let pairCount = 0;
|
|
1013
|
+
for (const count of rankCounts.values()) {
|
|
1014
|
+
if (count === 2) {
|
|
1015
|
+
pairCount++;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return pairCount;
|
|
1019
|
+
}
|
|
1020
|
+
function evaluateHand(hole, board) {
|
|
1021
|
+
const allCards = [...hole, ...board];
|
|
1022
|
+
const flush = isFlush(allCards);
|
|
1023
|
+
const straightHighCard = getStraightHighCard(allCards);
|
|
1024
|
+
const maxCount = getMaxCount(allCards);
|
|
1025
|
+
const pairCount = getPairCount(allCards);
|
|
1026
|
+
if (flush && straightHighCard === 14) {
|
|
1027
|
+
return { rank: 10 /* RoyalFlush */, ...HAND_DISPLAY[10 /* RoyalFlush */] };
|
|
1028
|
+
}
|
|
1029
|
+
if (flush && straightHighCard !== null) {
|
|
1030
|
+
return { rank: 9 /* StraightFlush */, ...HAND_DISPLAY[9 /* StraightFlush */] };
|
|
1031
|
+
}
|
|
1032
|
+
if (maxCount === 4) {
|
|
1033
|
+
return { rank: 8 /* FourOfAKind */, ...HAND_DISPLAY[8 /* FourOfAKind */] };
|
|
1034
|
+
}
|
|
1035
|
+
if (maxCount === 3 && pairCount >= 1) {
|
|
1036
|
+
return { rank: 7 /* FullHouse */, ...HAND_DISPLAY[7 /* FullHouse */] };
|
|
1037
|
+
}
|
|
1038
|
+
if (flush) {
|
|
1039
|
+
return { rank: 6 /* Flush */, ...HAND_DISPLAY[6 /* Flush */] };
|
|
1040
|
+
}
|
|
1041
|
+
if (straightHighCard !== null) {
|
|
1042
|
+
return { rank: 5 /* Straight */, ...HAND_DISPLAY[5 /* Straight */] };
|
|
1043
|
+
}
|
|
1044
|
+
if (maxCount === 3) {
|
|
1045
|
+
return { rank: 4 /* ThreeOfAKind */, ...HAND_DISPLAY[4 /* ThreeOfAKind */] };
|
|
1046
|
+
}
|
|
1047
|
+
if (pairCount >= 2) {
|
|
1048
|
+
return { rank: 3 /* TwoPair */, ...HAND_DISPLAY[3 /* TwoPair */] };
|
|
1049
|
+
}
|
|
1050
|
+
if (pairCount === 1) {
|
|
1051
|
+
return { rank: 2 /* OnePair */, ...HAND_DISPLAY[2 /* OnePair */] };
|
|
1052
|
+
}
|
|
1053
|
+
return { rank: 1 /* HighCard */, ...HAND_DISPLAY[1 /* HighCard */] };
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// src/widgets/poker-widget.ts
|
|
1057
|
+
var PokerWidget = class extends StdinDataWidget {
|
|
1058
|
+
id = "poker";
|
|
1059
|
+
metadata = createWidgetMetadata(
|
|
1060
|
+
"Poker",
|
|
1061
|
+
"Displays random Texas Hold'em hands for entertainment",
|
|
1062
|
+
"1.0.0",
|
|
1063
|
+
"claude-scope",
|
|
1064
|
+
2
|
|
1065
|
+
// Third line (0-indexed)
|
|
1066
|
+
);
|
|
1067
|
+
deck = null;
|
|
1068
|
+
holeCards = [];
|
|
1069
|
+
boardCards = [];
|
|
1070
|
+
handResult = "";
|
|
1071
|
+
constructor() {
|
|
1072
|
+
super();
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Generate new poker hand on each update
|
|
1076
|
+
*/
|
|
1077
|
+
async update(data) {
|
|
1078
|
+
await super.update(data);
|
|
1079
|
+
this.deck = new Deck();
|
|
1080
|
+
const hole = [
|
|
1081
|
+
this.deck.deal(),
|
|
1082
|
+
this.deck.deal()
|
|
1083
|
+
];
|
|
1084
|
+
const board = [
|
|
1085
|
+
this.deck.deal(),
|
|
1086
|
+
this.deck.deal(),
|
|
1087
|
+
this.deck.deal(),
|
|
1088
|
+
this.deck.deal(),
|
|
1089
|
+
this.deck.deal()
|
|
1090
|
+
];
|
|
1091
|
+
const result = evaluateHand(hole, board);
|
|
1092
|
+
this.holeCards = hole.map((card) => this.formatCardColor(card));
|
|
1093
|
+
this.boardCards = board.map((card) => this.formatCardColor(card));
|
|
1094
|
+
this.handResult = `${result.name}! ${result.emoji}`;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Format card with appropriate color (red for ♥♦, gray for ♠♣)
|
|
1098
|
+
*/
|
|
1099
|
+
formatCardColor(card) {
|
|
1100
|
+
const color = isRedSuit(card.suit) ? red : gray;
|
|
1101
|
+
return colorize(`[${formatCard(card)}]`, color);
|
|
1102
|
+
}
|
|
1103
|
+
renderWithData(_data, _context) {
|
|
1104
|
+
const handStr = this.holeCards.join(" ");
|
|
1105
|
+
const boardStr = this.boardCards.join(" ");
|
|
1106
|
+
return `Hand: ${handStr} | Board: ${boardStr} \u2192 ${this.handResult}`;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
|
|
826
1110
|
// src/validation/result.ts
|
|
827
1111
|
function success(data) {
|
|
828
1112
|
return { success: true, data };
|
|
@@ -1026,6 +1310,7 @@ async function main() {
|
|
|
1026
1310
|
await registry.register(new GitWidget());
|
|
1027
1311
|
await registry.register(new GitChangesWidget());
|
|
1028
1312
|
await registry.register(new ConfigCountWidget());
|
|
1313
|
+
await registry.register(new PokerWidget());
|
|
1029
1314
|
const renderer = new Renderer({
|
|
1030
1315
|
separator: " \u2502 ",
|
|
1031
1316
|
onError: (error, widget) => {
|