modscode EN

modscode / 図鑑 / shot-view

shot-view

收集 Claude 截下或查看的 PNG,ctrl+x s 在侧边面板里看图;n/p 翻页,按住 o 在终端里放大、松开收起,轻按 o 用快速查看打开;看过的按 r 标为已读就不再出现(u 撤销)

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

何をするか

  • プロンプトの上の帯・欄を描く
  • /shots を足す
  • ツールの呼び出しを見張る
  • session.startにフックする
  • プロセスを起こす

良いところ

  • ネットワークに出ない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • ファイルを書かない

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like shot-view by Bearisbug (pane, band), as modscode read it from the mod's code:
// https://modscode.com/gallery/bearisbug-shot-view/
// 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 } = $.ui.resolve(e)
    const head = '…'
    const tail = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" gap={1}>
          <Box flexShrink={0}>
            <Text color="ide" bold>
              ▍截图
            </Text>
          </Box>
          <Text wrap="truncate-end">
            {head}
          </Text>
          <Text dimColor wrap="truncate-end">
            {tail}
          </Text>
        </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 } = $.ui.resolve(e)
    const basename = '…'
    const at = '…'
    const length = '…'
    const readCount = '…'
    const via = '…'
    const width = '…'
    const height = '…'
    const path = '…'
    const gone = '…'
    const alt = '…'
    return (
      <Box flexDirection="column" paddingX={1}>
        <Box flexDirection="row" gap={1}>
          <Text bold>
            {basename}
          </Text>
          <Text color="suggestion">
            {"未读 "}
            {`${at}1`}
            /
            {length}
          </Text>
          <Text dimColor>
            {"已读 "}
            {readCount}
          </Text>
          <Text dimColor>
            刚刚
            {" · "}
            {via}
            {" · "}
            {width}
            ×
            {height}
          </Text>
        </Box>
        <Text dimColor wrap="wrap">
          {path}
        </Text>
        <Text dimColor>
          {"另有 "}
          {gone}
          {" 张截图的文件已不在(被删除或移走),不再显示"}
        </Text>
        <Text dimColor>
          {alt}
        </Text>
        <Box flexDirection="row" gap={2}>
          <Button plain hotkey="n">
            下一张
          </Button>
          <Button plain hotkey="p">
            上一张
          </Button>
          <Button plain hotkey="r">
            标为已读
          </Button>
          <Button plain hotkey="u">
            撤销已读
          </Button>
        </Box>
        <Box flexDirection="row" gap={2}>
          <Button plain hotkey="o">
            按住放大 · 轻按快速查看
          </Button>
          <Button plain hotkey="f">
            Finder
          </Button>
          <Button plain hotkey="y">
            复制路径
          </Button>
        </Box>
        <Text dimColor>
          从最新一张开始,n 往后看更早的;看过、不需要再看了就按 r,它不会再出现,只是翻过不算已读
        </Text>
        <Text dimColor>
          Esc 或 ctrl+x s 关闭(面板开着时 Esc 只关面板,不会中断 Claude)
        </Text>
      </Box>
    )
  })
}

Mod 自身のコード

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

shot-view/hooks/register.tsx 283〜312 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const below = await next(e)
    if (!hint) return below
    const unread = unreadOf(await read($, shots))
    const live = await present($, unread)
    drawn = keyOf(live)
    // 提示的那张不在了就换成还在的最新一张;一张都不在了就不再提示
    if (!live.has(hint)) hint = unread.find(s => live.has(s.path))?.path ?? null
    if (!hint || e.props.hasSurvey) return below
    const { Box, Text } = $.ui.resolve(e)
    const line = bandLine(basename(hint), live.size, e.props.bodyColumns)
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" gap={1}>
          <Box flexShrink={0}>
            <Text color="ide" bold>
              {BAND_LABEL}
            </Text>
          </Box>
          <Text wrap="truncate-end">{line.head}</Text>
          {line.tail !== '' && (
            <Text dimColor wrap="truncate-end">
              {line.tail}
            </Text>
          )}
        </Box>
        {below}
      </Box>
    )
  })
shot-view/hooks/register.tsx 314〜434 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const list = await read($, shots)
    const unreadAll = unreadOf(list)
    const live = await present($, unreadAll)
    drawn = keyOf(live)
    const unread = unreadAll.filter(s => live.has(s.path))
    const gone = unreadAll.length - unread.length
    const readCount = list.length - unreadAll.length
    const at = Math.min(await read($, index), Math.max(0, unread.length - 1))
    const shot = unread[at]
    const undo = (
      <Button key="undo" plain hotkey="u" onPress={() => void undoRead($)}>
        撤销已读
      </Button>
    )
    const closeHint = <Text dimColor>Esc 或 ctrl+x s 关闭(面板开着时 Esc 只关面板,不会中断 Claude)</Text>
    const goneNote = gone > 0 && <Text dimColor>另有 {gone} 张截图的文件已不在(被删除或移走),不再显示</Text>
    if (list.length === 0) {
      return (
        <Box paddingX={1}>
          <Text dimColor>还没有截图。Claude 截图或查看 PNG 后会出现在这里。</Text>
        </Box>
      )
    }
    if (!shot) {
      return (
        <Box flexDirection="column" paddingX={1}>
          <Box flexDirection="row" gap={1}>
            <Text color="success">✓</Text>
            <Text bold>{readCount === 0 ? '没有可看的截图' : '截图都看完了'}</Text>
            {readCount > 0 && <Text dimColor>已读 {readCount} 张</Text>}
          </Box>
          {goneNote}
          {readCount > 0 && undo}
          {closeHint}
        </Box>
      )
    }

    const visibleRows = Math.min(e.props.scroll.bodyRows, e.viewport?.rows ?? e.props.scroll.bodyRows)
    const alt = `${basename(shot.path)}(终端没有开启图片显示,轻按 o 用快速查看打开)`
    const pictureOf = (size: { columns: number; rows: number }) =>
      e.surface === 'terminal' ? (
        (() => {
          const { Image } = $.ui.resolve(e)
          return (
            <Image
              key="shot"
              source={{ file: shot.path, format: 'png', generation: live.get(shot.path) ?? 0 }}
              columns={size.columns}
              rows={size.rows}
              alt={alt}
            />
          )
        })()
      ) : (
        <Text dimColor>{alt}</Text>
      )

    // 按住 o 的放大视图:只留图和一行提示,图铺满面板。
    // 提示行本身就是绑着 o 的按键:按住时终端补发的重复按键要有地方接,否则会被当成已经松开
    if (isPeeking) {
      return (
        <Box flexDirection="column">
          {pictureOf(fit(shot, Math.max(10, e.props.bodyColumns), Math.max(4, visibleRows - 1)))}
          <Button key="peek" plain hotkey="o" dimColor onPress={() => void pressPeek($, shot.path)}>
            {`放大查看 ${basename(shot.path)} · 松开 o 回到列表`}
          </Button>
        </Box>
      )
    }

    // 普通视图按面板真正能显示的高度缩图:标题、路径、两排按键和两行说明约占 8 行,图片太高会把按键挤出去
    const picture = pictureOf(fit(shot, Math.max(10, e.props.bodyColumns - 2), Math.max(4, visibleRows - 8 - (gone > 0 ? 1 : 0))))

    return (
      <Box flexDirection="column" paddingX={1}>
        <Box flexDirection="row" gap={1}>
          <Text bold>{basename(shot.path)}</Text>
          <Text color="suggestion">
            未读 {at + 1}/{unread.length}
          </Text>
          {readCount > 0 && <Text dimColor>已读 {readCount}</Text>}
          <Text dimColor>
            {ago(shot.at)} · {shot.via} · {shot.width}×{shot.height}
          </Text>
        </Box>
        <Text dimColor wrap="wrap">
          {shot.path}
        </Text>
        {goneNote}
        {picture}
        <Box flexDirection="row" gap={2}>
          <Button key="next" plain hotkey="n" onPress={() => void update($, index, n => Math.min(n + 1, unread.length - 1))}>
            下一张
          </Button>
          <Button key="prev" plain hotkey="p" onPress={() => void update($, index, n => Math.max(n - 1, 0))}>
            上一张
          </Button>
          <Button key="read" plain hotkey="r" onPress={() => void markRead($, shot.path)}>
            标为已读
          </Button>
          {readCount > 0 && undo}
        </Box>
        <Box flexDirection="row" gap={2}>
          <Button key="peek" plain hotkey="o" onPress={() => void pressPeek($, shot.path)}>
            按住放大 · 轻按快速查看
          </Button>
          <Button key="reveal" plain hotkey="f" onPress={() => void $.process.run(['open', '-R', shot.path])}>
            Finder
          </Button>
          <Button key="copy" plain hotkey="y" onPress={press => void $.ui.copy({ text: shot.path, surface: press.surface })}>
            复制路径
          </Button>
        </Box>
        <Text dimColor>从最新一张开始,n 往后看更早的;看过、不需要再看了就按 r,它不会再出现,只是翻过不算已读</Text>
        {closeHint}
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Bearisbug

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。shot-view/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。1 ファイルを解析
コードが 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/… などは無い)。shot-view/hooks/register.tsx:423 open(Windows にない)
通信fetch の送り先(https のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。sips, qlmanage, open(通信する)
読んで送るファイルや環境変数を読み、かつ通信するか。reads environment variables and files and reaches the network
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

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

入れる

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

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

/plugin marketplace add Bearisbug/cc-mods
/plugin install shot-view@cc-mods

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン