modscode EN

modscode / 図鑑 / blackjack

blackjack

A blackjack table in a side pane to play while Claude works

確かめやすいコードターミナル+デスクトップペインバンドトーストBoxButtonSvgText

何をするか

  • 欄・トーストを描く
  • /blackjack を足す
  • classic.SessionStart・session.start・turn.complete・turn.start ほか 1 個にフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • ネットワークに出ない
  • プロセスを起こさない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある

作り始めるためのコード

2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。

雛形(register.tsx)

register.tsx
import type { Register } from 'claude-code'

// Drawn like blackjack by michaeldavodovski (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/michaeldavodovski-blackjack/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
  // the pane: open it with $.ui.open({ id: 'my-pane', title: "Blackjack" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Svg, Button } = $.ui.resolve(e)
    const run = '…'
    const run2 = '…'
    const run3 = '…'
    const run4 = '…'
    const run5 = '…'
    const run6 = '…'
    const run7 = '…'
    const run8 = '…'
    const run9 = '…'
    const bankroll = '…'
    const wagerOf = '…'
    const ruleSvg = '…'
    const RESULT = '…'
    const row = '…'
    const row2 = '…'
    const row3 = '…'
    const source = '…'
    const hotkey = '…'
    const centered = '…'
    const text = '…'
    const betFor = '…'
    const keysHint = '…'
    const label = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="column" alignItems="center" marginBottom={1}>
          <Box flexDirection="column">
            <Box flexDirection="row">
              <Text bold>
                {run}
              </Text>
              <Text bold>
                {run2}
              </Text>
              <Text bold>
                {run3}
              </Text>
            </Box>
            <Box flexDirection="row">
              <Text bold>
                {run4}
              </Text>
              <Text bold>
                {run5}
              </Text>
              <Text bold>
                {run6}
              </Text>
            </Box>
            <Box flexDirection="row">
              <Text bold>
                {run7}
              </Text>
              <Text bold>
                {run8}
              </Text>
              <Text bold>
                {run9}
              </Text>
            </Box>
          </Box>
          <Text bold>
            CCC
          </Text>
          <Text dimColor>
            Claude Code Casino
          </Text>
        </Box>
        <Box flexDirection="row" justifyContent="space-between">
          <Text bold>
            {"Bank "}
            {bankroll}
          </Text>
          <Text>
            Bet
            {" "}
            {wagerOf}
          </Text>
        </Box>
        <Box marginTop={1}>
          <Svg source={`${ruleSvg}`} alt="Divider" height={1} />
        </Box>
        <Box flexDirection="column" marginY={1}>
          <Box flexDirection="row" justifyContent="space-between">
            <Text dimColor>
              {"Dealer "}
              soft 0
            </Text>
            <Text dimColor>
              {"stands on "}
              17
            </Text>
          </Box>
          <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
            <Text>
              {" ?? "}
            </Text>
            <Text>
              {" ?? "}
            </Text>
            <Text>
              {" ?? "}
            </Text>
          </Box>
          <Box marginTop={1}>
            <Text dimColor>
              {"You "}
              soft 0
            </Text>
          </Box>
          <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
            <Text>
              {" ?? "}
            </Text>
            <Text>
              {" ?? "}
            </Text>
            <Text>
              {" ?? "}
            </Text>
          </Box>
        </Box>
        <Box flexDirection="column" marginBottom={1}>
          <Box height={1} justifyContent="center">
            <Text dimColor>
              Dealer plays...
            </Text>
            <Text bold color="success">
              {RESULT}
            </Text>
          </Box>
          <Box flexDirection="column" alignItems="center" height={3}>
            <Text bold>
              {row}
            </Text>
            <Text bold>
              {row2}
            </Text>
            <Text bold>
              {row3}
            </Text>
            <Svg source={`${source}`} alt="A rain cloud" />
          </Box>
        </Box>
        <Box flexDirection="column" rowGap={1}>
          <Box flexDirection="column">
            <Button plain label="        " />
            <Button hotkey={`${hotkey}`} label={`${centered}`} variant="primary" autoFocus />
            <Button plain label="        " />
          </Box>
          <Box flexDirection="column">
            <Button plain label="        " />
            <Button hotkey={`${hotkey}`} label={`${centered}`} variant="primary" autoFocus />
            <Button plain label="        " />
          </Box>
          <Box flexDirection="column">
            <Button plain label="        " />
            <Button hotkey={`${hotkey}`} label={`${centered}`} variant="primary" autoFocus />
            <Button plain label="        " />
          </Box>
        </Box>
        <Box flexDirection="column" rowGap={1}>
          <Text>
            Out of chips.
          </Text>
          <Box flexDirection="column">
            <Button plain label="        " />
            <Button hotkey={`${hotkey}`} label={`${centered}`} variant="primary" autoFocus />
            <Button plain label="        " />
          </Box>
        </Box>
        <Box flexDirection="column" rowGap={1}>
          <Box flexDirection="row" alignItems="center" columnGap={1}>
            <Box>
              <Button plain label={` ${text} `} />
            </Box>
            <Box>
              <Button plain label={` ${text} `} />
            </Box>
            <Box flexDirection="column" justifyContent="center" alignItems="center" paddingX={2}>
              <Text bold>
                {betFor}
              </Text>
            </Box>
            <Box>
              <Button plain label={` ${text} `} />
            </Box>
            <Box>
              <Button plain label={` ${text} `} />
            </Box>
          </Box>
          <Box flexDirection="column">
            <Text dimColor>
              Bet change step
            </Text>
            <Box flexDirection="row" justifyContent="space-between">
              <Box>
                <Button plain label={` ${text} `} />
              </Box>
              <Box>
                <Button plain label={` ${text} `} />
              </Box>
              <Box>
                <Button plain label={` ${text} `} />
              </Box>
            </Box>
          </Box>
          <Box flexDirection="column">
            <Button plain label="        " />
            <Button hotkey={`${hotkey}`} label={`${centered}`} variant="primary" autoFocus />
            <Button plain label="        " />
          </Box>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Box flexDirection="column" height={2}>
            <Text dimColor>
              Claude is working...
            </Text>
            <Text color="success">
              Claude is done.
            </Text>
            <Text bold>
              Get back to work!
            </Text>
          </Box>
          <Text dimColor>
            {keysHint}
          </Text>
          <Box flexDirection="row" columnGap={2}>
            <Button plain hotkey="1" label="Min" autoFocus />
            <Button plain hotkey="2" label={`${label}`} autoFocus />
            <Button plain hotkey="3" label={`${label}`} autoFocus />
            <Button plain hotkey="4" label="Max" autoFocus />
          </Box>
          <Box flexDirection="row" columnGap={2}>
            <Button plain hotkey="5" label="smaller step" autoFocus />
            <Button plain hotkey="6" label="bigger step" autoFocus />
          </Box>
          <Text dimColor>
            ctrl+x tab to use keys
          </Text>
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    await $.ui.toast(`Blackjack: could not save the bank`)
    await $.ui.toast(`Blackjack: run /blackjack to open the table`)
    return next(e)
  })
}

Mod 自身のコード

Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。

hooks/register.tsx 399〜558 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    isFullscreen = e.viewport?.isFullscreen ?? isFullscreen

    const { Box, Button, Text } = $.ui.resolve(e)
    const table = await read($, game)
    const status = await read($, claude)
    const net = netOf(table)
    // Minus and plus carry the amount they move the bet by, so the row that
    // picks it explains itself.
    const less = `-${stepOf(table)}`
    const more = `+${stepOf(table)}`

    // The dealer's cards start turning before anything is saved, so a save
    // that fails cannot leave the table waiting on them. A move that stakes
    // or restores chips (`isFresh`) first takes up the bank as saved.
    const play = (move: (table: Game) => Game, isFresh = false) => async () => {
      if (isFresh) {
        await refresh($)
      }

      let before = table
      const after = await update($, game, now => {
        before = now

        return move(now)
      })
      if (isRevealing(after)) {
        reveal($)
      } else if (isFxRunning(after)) {
        animate($)
      }
      await save($, before, after)
    }

    // While the dealer's cards turn, the table shows the hand as it stood:
    // no result yet, and the bank as it was before it.
    const isTurning = isRevealing(table)
    const isBetting = !table.isPlaying && !isBroke(table) && !isTurning
    const faceUp = table.isPlaying ? 1 : table.dealerShown
    const dealerUp = table.dealer.slice(0, faceUp)
    const isHoleDown = faceUp === 1 && table.dealer.length > 1
    const frame =
      table.outcome !== null && !isTurning
        ? frameOf(table.outcome, table.fx)
        : null

    const hand = (cards: readonly number[], isHoleHidden: boolean) => (
      <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
        {cards.map((card, i) =>
          isHoleHidden && i === 1 ? (
            <Text backgroundColor={theme.back} color={theme.backInk}>
              {' ?? '}
            </Text>
          ) : (
            <Text
              backgroundColor={theme.card}
              color={isRed(card) ? theme.redInk : theme.ink}
              bold
            >
              {` ${rankOf(card)}${suitOf(card)} `}
            </Text>
          ),
        )}
      </Box>
    )

    const columns = e.props.bodyColumns
    const isDocked = e.props.placement === 'dock'
    const isTerminal = e.surface === 'terminal'
    // The bet row: Min and minus on one side of the bet, plus and Max on
    // the other, each a chip two cells wider than its label.
    // Minus and plus are as wide as their longest label (`-100`), so the
    // row does not shift when the step changes.
    const stepCells = String(Math.max(...STEPS)).length + 1
    const betColumns = Math.max(
      4,
      columns - 5 - (stepCells + 2) - (stepCells + 2) - 5 - 4,
    )

    // A chip is a one-row filled Button with nothing but its label drawn: a
    // terminal Button that has a hotkey draws brackets or the key too, so
    // the chips' keys are the row of `1: Min` Buttons under the table.
    // Art made of characters, for a surface whose font is not fixed-width:
    // one image set in a fixed-width font. The terminal draws the rows as text.
    const picture = (rows: readonly (readonly Run[])[], alt: string) => {
      if (e.surface === 'terminal') {
        return null
      }

      const { Svg } = $.ui.resolve(e)
      const image = asciiSvg(rows)

      return (
        <Svg
          source={image.source}
          alt={alt}
          width={image.width}
          height={image.height}
        />
      )
    }

    // A thin rule across the pane, where the surface can draw one.
    const divider = () => {
      if (e.surface === 'terminal') {
        return null
      }

      const { Svg } = $.ui.resolve(e)

      return (
        <Box marginTop={1}>
          <Svg source={ruleSvg(IMAGE_INK)} alt="Divider" height={1} />
        </Box>
      )
    }

    const chip = (
      key: string,
      label: string,
      tone: { fill: string; lit: string },
      move: (table: Game) => Game,
      cells?: number,
    ) => {
      if (isTerminal) {
        const text = cells === undefined ? label : centered(label, cells)

        return (
          <Box
            key={`${key}-fill`}
            backgroundColor={tone.fill}
            hover={{ backgroundColor: tone.lit }}
          >
            <Button key={key} plain label={` ${text} `} onPress={play(move)} />
          </Box>
        )
      }

      // Off the terminal a button is as wide as its label, so one whose
      // label changes sits in a slot that fits its longest.
      const button = (
        <Button
          key={key}
          label={label}
          variant={tone === theme.chosen ? 'primary' : 'secondary'}
          onPress={play(move)}
        />
      )

      return cells === undefined ? (
        button
      ) : (
        <Box key={`${key}-slot`} minWidth={cells + 2} justifyContent="center">
          {button}
        </Box>
      )
    }

    // One entry of the key legend, which is also what the key presses: a
    // plain Button draws as `1: Min`, its hotkey in the accent color.
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 michaeldavodovski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

コードが呼ぶもの

保存

コードから読み取ったデザイン

読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。

コードから読めること

2026-10-06 に読んだコミット 954b6bdb6551 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。3 ファイルを解析
コードが Mod の中で完結import は Mod 自身のファイルかエンジンのモジュールだけ。パッケージも require もない。コードはすべて Mod の中
読める圧縮した行・eval・new Function・計算した道の import()・符号化した塊がない。圧縮・eval・符号化した塊なし
呼び出しが見える通信とプログラム起動はその場で $.http.fetch・$.process.run と書き、他へ渡さない。外への呼び出しはすべてその場の $ で
入れる前に自分で判断する材料
描く場所コードから読んだ、描く先。ターミナル・デスクトップアプリ・両方・何も描かない(フックだけ: 見張りやプロンプトの書き換え)のどれか。出すだけで、外す理由にはしない。ターミナルとデスクトップアプリに同じように描く
入れる手順リポジトリ自身の .claude-plugin/marketplace.json にこの Mod が載っていて、ページに書いた手順でそのマーケットプレイスから入れられるか。リポジトリの .claude-plugin/marketplace.json に載っており、そこから入れられる
Windows のプログラム$.process で起動するプログラムが Windows にあるか(tail・date・open・osascript・/usr/… などは無い)。Windows にないプログラムを使わない
通信fetch の送り先(https のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない
読んで送るファイルや環境変数を読み、かつ通信するか。通信しない
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件

入れる

入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。

リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。

/plugin marketplace add michaeldavodovski/claude-code-blackjack
/plugin install blackjack@claude-code-blackjack

入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(954b6bdb6551)と違うことがあります。入れる前に見比べてください。

Claude に聞く

modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:

modscode のデザイン「michaeldavodovski-blackjack」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン