modscode EN

modscode / 図鑑 / hop

hop

Hop: a hop game to play while Claude works, with an AI coding tip on every block / 蹦一蹦:等 Claude 干活时玩的跳一跳,每块方块带一张 AI 编程知识卡片

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

何をするか

  • プロンプトの上の帯・欄・トーストを描く
  • /hop を足す
  • ツールの呼び出しを見張る
  • classic.Notification・classic.PermissionRequest・session.append・session.start ほか 2 個にフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う
  • 複数の言語で話す

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like hop by AGI Hunt (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/agihunt-hop/
// 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 band above the prompt; what else goes there is drawn under it
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" gap={1} alignItems="center">
          <Text dimColor>
            Claude is still working
          </Text>
          <Button label="Play Hop" variant="primary" />
          <Button label="Not this session" plain dimColor />
        </Box>
        {await next(e)}
      </Box>
    )
  })

  // the pane: open it with $.ui.open({ id: 'my-pane', title: "蹦一蹦" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Svg, Input } = $.ui.resolve(e)
    const svg = '…'
    const hint = '…'
    const lbTabs = '…'
    const lbTabs2 = '…'
    const lbTabs3 = '…'
    const rank = '…'
    const nickname = '…'
    const score = '…'
    const score2 = '…'
    const score3 = '…'
    const lbMe = '…'
    const status = '…'
    const scoreLine = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" justifyContent="space-between" alignItems="center">
          <Text bold color="#E63946">
            Claude needs you
          </Text>
          <Button label="Back to Claude" plain />
        </Box>
        <Svg source={`${svg}`} alt="蹦一蹦,当前 0 分" />
        <Box flexDirection="row" gap={1} alignItems="center">
          <Box width={34}>
            <Input value="" placeholder="Click, hold Space" autoFocus />
          </Box>
          <Text dimColor>
            {hint}
          </Text>
        </Box>
        <Box flexDirection="column" borderStyle="round" borderDimColor paddingX={1}>
          <Box flexDirection="column">
            <Box flexDirection="row" justifyContent="space-between" alignItems="center">
              <Box flexDirection="row" gap={2} alignItems="center">
                <Text bold color="#D97757">
                  {lbTabs}
                </Text>
                <Text bold color="#D97757">
                  {lbTabs2}
                </Text>
                <Text bold color="#D97757">
                  {lbTabs3}
                </Text>
              </Box>
              <Text dimColor>
                Slow network, still loading…
              </Text>
            </Box>
            <Box flexDirection="column" width={32}>
              <Box flexDirection="row" justifyContent="space-between">
                <Text color="#D97757">
                  {`${rank}  ${nickname}`}
                </Text>
                <Text color="#D97757">
                  {score}
                </Text>
              </Box>
              <Box flexDirection="row" justifyContent="space-between">
                <Text color="#D97757">
                  {`${rank}  ${nickname}`}
                </Text>
                <Text color="#D97757">
                  {score2}
                </Text>
              </Box>
              <Box flexDirection="row" justifyContent="space-between">
                <Text color="#D97757">
                  {`${rank}  ${nickname}`}
                </Text>
                <Text color="#D97757">
                  {score3}
                </Text>
              </Box>
            </Box>
            <Box flexDirection="row" justifyContent="space-between">
              <Text dimColor>
                {`${lbMe}`}
              </Text>
              <Button label="Leave leaderboard" plain dimColor />
            </Box>
          </Box>
          <Box flexDirection="row" gap={2} alignItems="center">
            <Text color="#E76F51">
              {`${status}. Showing the last results`}
            </Text>
            <Button label="Retry" plain />
          </Box>
        </Box>
        <Box flexDirection="row" justifyContent="space-between" alignItems="center">
          <Text dimColor>
            {`${scoreLine}`}
          </Text>
          <Button label="♪" plain dimColor={false} />
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    await $.ui.toast(`Claude needs you`)
    await $.ui.toast(`Claude is done. Come take a look`)
    return next(e)
  })
}

Mod 自身のコード

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

plugins/hop/hooks/register.tsx 439〜468 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const { value: c = IDLE } = await $.state.get(CLAUDE)
    if (!c.hint || c.needsYou || !c.busy || hintMuted || e.props.hasSurvey) return next(e)
    const panes = await $.ui.panes().catch(() => [])
    if (panes.some(p => p.id === PANE && p.isPlaced)) return next(e)
    const { Box, Text, Button } = $.ui.resolve(e)
    return (
      <Box flexDirection="row" gap={1} alignItems="center">
        <Text dimColor>{tr().bandBusy}</Text>
        <Button
          key="hop-open"
          label={tr().bandPlay}
          variant="primary"
          onPress={() =>
            void $.ui.open({ id: PANE, title: TITLE, focus: true }).then(() => $.state.set(CLAUDE, { ...c, hint: false }))
          }
        />
        <Button
          key="hop-mute"
          label={tr().bandMute}
          plain
          dimColor
          onPress={() => {
            hintMuted = true
            void $.state.set(CLAUDE, { ...c, hint: false })
          }}
        />
      </Box>
    )
  })
plugins/hop/hooks/register.tsx 470〜629 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    // 画面板出了错就把原因直接画出来,免得桌面端只显示一句「Nothing to show yet」
    try {
    const t = $.ui.resolve(e)
    const { Box, Text, Button } = t
    paneFocused = e.props.isFocused
    // 画布跟着面板大小走:面板越大,场景越大、看得越远;方块和小人保持原大小(不是把图片拉伸)
    // 面板只告诉插件格数,按一格约 7.5 像素、一行约 20 像素估算
    const { value: peek = EMPTY } = await $.state.get(VIEW)
    const { value: lbPeek = NO_BOARD } = await $.state.get(BOARD)
    // 画面下面的控件要占几行:状态行、输入框、分数行,结束时再加排行榜
    const controlRows = 6 + (peek.game?.isOver ? (lbPeek.joined ? 17 : 7) : 0)
    const canvasW = Math.min(1400, (e.props.bodyColumns || 60) * 7.5 - 24)
    const roomH = e.viewport?.rows ? (e.viewport.rows - controlRows) * 20 : 360
    // 不要竖着拉长:高度最多是宽度的 0.82 倍(原画面的比例)
    const canvasH = Math.min(canvasW * 0.82, roomH, 900)
    setCanvas(canvasW, canvasH)
    const sceneW = Math.max(440, Math.round(canvasW))
    const sceneH = Math.max(360, Math.round(canvasH))
    const { value: view = EMPTY } = await $.state.get(VIEW)
    const { value: board = NO_BOARD } = await $.state.get(BOARD)
    const { value: claude = IDLE } = await $.state.get(CLAUDE)
    const game = view.game

    if (!game) return <Text dimColor>{tr().loading}</Text>
    await $.state.get(TICK)
    const now = await $.clock.now()
    const svg =
      view.phase === 'charge'
        ? chargeFrame(game, now - view.chargeAt)
        : view.phase === 'jump' && view.before && view.jump && now - view.jumpAt < ANIM_MS
          ? jumpFrame(view.before, game, view.jump, now - view.jumpAt, now)
          : stillFrame(game, now)
    if (e.surface === 'terminal' || !('Svg' in t) || !('Input' in t)) {
      return <Text dimColor>{tr().desktopOnly}</Text>
    }

    // 输入框里每多一个空格(按住时系统会不停地打)都会走到这里
    const press = () =>
      void $.clock.now().then(async now => {
        if (holdStart === 0) {
          const { value: v = EMPTY } = await $.state.get(VIEW)
          if (!v.game || v.game.isOver) return
          holdStart = now
          lastPress = now
          presses = 1
          await $.state.set(VIEW, { ...v, phase: 'charge', chargeAt: now, startedAt: v.startedAt || now })
          if (!muted) {
            const s = $.process.spawn({ argv: ['afplay', '-v', VOLUME, `${$.plugin.root}/sounds/charge.wav`] })
            chargeSound = s
            void (async () => {
              try {
                for await (const _ of s) {
                  // 只是让它响着;松手时 return() 结束循环,afplay 随之退出
                }
              } catch {
                // 播不了就算了
              }
            })()
          }
          return
        }
        lastPress = now
        presses += 1
      })

    const restart = () =>
      void $.clock.now().then(async now => {
        isOverNow = false
        const seed = Math.floor(now % 2147483647)
        const seen = ((await $.store.get('seen')) ?? []) as string[]
        const best = Math.max(game.best, Number((await $.store.get('best')) ?? 0))
        await $.state.set(VIEW, {
          ...EMPTY,
          game: newGame(seed, best, queueFor(seen, seed).slice(0, QUEUE)),
          pad: view.pad + 1,
        })
        await $.state.get(BOARD).then(({ value: b = NO_BOARD }) => $.state.set(BOARD, { ...b, status: '' }))
      })

    return (
      <Box flexDirection="column" gap={1}>
        {(claude.needsYou || claude.done) && (
          <Box flexDirection="row" justifyContent="space-between" alignItems="center">
            <Text bold color={claude.needsYou ? '#E63946' : '#2A9D8F'}>
              {claude.needsYou ? tr().needsYou : tr().doneNow}
            </Text>
            <Button
              key="back"
              label={tr().backToClaude}
              plain
              onPress={() =>
                void $.state
                  .set(CLAUDE, { ...claude, done: false })
                  .then(() => $.ui.close({ id: PANE }))
                  .catch(() => undefined)
              }
            />
          </Box>
        )}
        {/* 不加 isInteractive:当普通图片显示,换图不闪 */}
        <t.Svg source={svg} alt={`蹦一蹦,当前 ${game.score} 分`} width={sceneW} height={sceneH} />
        <Box flexDirection="row" gap={1} alignItems="center">
          {game.isOver ? (
             <Button key="restart" label={tr().restart} hotkey={board.joined ? 'r' : undefined} variant="primary" autoFocus onPress={restart} />
          ) : (
            // 只有输入框收得到按住空格时的连续输入;宽度固定,空格攒多了也不会把框撑长
            <Box width={34}>
              <t.Input
                key={`pad-${view.pad}`}
                value=""
                placeholder={tr().placeholder}
                autoFocus
                onInput={() => press()}
                onSubmit={() => undefined}
              />
            </Box>
          )}
          <Text dimColor>{view.hint}</Text>
        </Box>
        {game.isOver && (
          <Box flexDirection="column" borderStyle="round" borderDimColor paddingX={1}>
            {board.joined ? (
              <Box flexDirection="column">
                {/* 当前榜单用醒目的字,其余两个是可点的按钮;右边是加载状态 */}
                <Box flexDirection="row" justifyContent="space-between" alignItems="center">
                  <Box flexDirection="row" gap={2} alignItems="center">
                    {(['today', 'week', 'all'] as const).map(tab =>
                      board.tab === tab ? (
                        <Text key={`tab-${tab}`} bold color="#D97757">
                          {tr().lbTabs[tab]}
                        </Text>
                      ) : (
                        <Button
                          key={`tab-${tab}`}
                          label={tr().lbTabs[tab]}
                          plain
                          dimColor
                          onPress={() => void lb?.refresh(tab)}
                        />
                      ),
                    )}
                  </Box>
                  {board.busy && <Text dimColor>{board.slow ? tr().lbSlow : tr().lbBusy}</Text>}
                </Box>
                {board.entries.length === 0 ? (
                  <Text dimColor>{board.busy ? tr().lbLoading : board.status !== '' ? '' : tr().lbEmpty}</Text>
                ) : (
                  <Box flexDirection="column" width={32}>
                    {board.entries.map(en => (
                      <Box key={`row-${en.rank}-${en.nickname}`} flexDirection="row" justifyContent="space-between">
                        <Text bold={en.isMe} color={en.isMe ? '#D97757' : undefined} dimColor={board.busy && !en.isMe}>
                          {`${String(en.rank).padStart(2, ' ')}  ${en.nickname}`}
                        </Text>
                        <Text bold={en.isMe} color={en.isMe ? '#D97757' : undefined} dimColor={board.busy && !en.isMe}>
                          {String(en.score)}
                        </Text>
                      </Box>
                    ))}
                  </Box>
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 AGI Hunt

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 に読んだコミット 2acd59d46f2f のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。plugins/hop/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。5 ファイルを解析
コードが 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/… などは無い)。plugins/hop/hooks/register.tsx:86 defaults(Windows にない); plugins/hop/hooks/register.tsx:94 defaults(Windows にない); plugins/hop/hooks/register.tsx:352 afplay(Windows にない); plugins/hop/hooks/register.tsx:363 afplay(Windows にない); plugins/hop/hooks/register.tsx:518 afplay(Windows にない)
通信fetch の送り先(https のホスト)がコードに書いてあるか。plugins/hop/hooks/register.tsx:112 fetch(`${LB_BASE}${path}`)
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。defaults, afplay
読んで送るファイルや環境変数を読み、かつ通信するか。読んだうえで通信する
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

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

入れる

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

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

/plugin marketplace add AGIHunt/cc-mods
/plugin install hop@agihunt

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン