modscode EN

modscode / 図鑑 / visible-compact

visible-compact

Shows the conversation before and after /compact side by side in a pane; /show-last-compact reopens it

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

何をするか

  • 欄・トーストを描く
  • session.compact・session.end・session.startにフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • ネットワークに出ない
  • プロセスを起こさない
  • TypeScript で書かれている
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like visible-compact by Sravan (pane, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/nvsravank-visible-compact/
// 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: "Your compaction history" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Button, Text, Markdown } = $.ui.resolve(e)
    const tokens = '…'
    const tokens2 = '…'
    const durationMs = '…'
    const messages = '…'
    const total = '…'
    const at = '…'
    const pageCount = '…'
    const role = '…'
    const m = '…'
    const i = '…'
    const n = '…'
    const text = '…'
    const role2 = '…'
    const role3 = '…'
    const pageCount2 = '…'
    const messages2 = '…'
    const total2 = '…'
    const pageCount3 = '…'
    const role4 = '…'
    const role5 = '…'
    const role6 = '…'
    const pageCount4 = '…'
    return (
      <Box flexDirection="column">
        <Box justifyContent="space-between">
          <Box flexDirection="column">
            <Button plain />
            <Button plain />
            <Button plain />
          </Box>
          <Box gap={1}>
            <Box />
            <Box />
            <Box />
            <Button plain>
              ☾
            </Button>
          </Box>
        </Box>
        <Box justifyContent="space-between">
          <Text>
            <Text dimColor>
              {"Tokens reduced to "}
            </Text>
            <Text bold>
              {tokens}
            </Text>
            <Text dimColor>
              {" from "}
            </Text>
            <Text bold>
              {tokens2}
            </Text>
          </Text>
          <Text dimColor>
            {"Took: "}
            {durationMs}
            s
          </Text>
        </Box>
        <Box marginTop={1}>
          <Text wrap="wrap">
            <Text bold>
              {"Instructions: "}
            </Text>
            <Text dimColor>
              none typed after /compact (the default summary prompt only)
            </Text>
          </Text>
        </Box>
        <Box flexDirection="row">
          <Box flexDirection="column" paddingRight={1}>
            <Box justifyContent="space-between">
              <Text bold underline>
                After
                {" ("}
                {messages}
                {" msgs, "}
                {total}
                {" chunks)"}
              </Text>
              <Box gap={1}>
                <Button plain>
                  {`‹ Previous`}
                </Button>
                <Text dimColor>
                  {`${at}1`}
                  /
                  {pageCount}
                </Text>
                <Button plain>
                  Next ›
                </Button>
              </Box>
            </Box>
            <Text dimColor>
              (empty)
            </Text>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role2}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role3}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box marginTop={1} justifyContent="flex-end">
              <Box gap={1}>
                <Button plain>
                  {`‹ Previous`}
                </Button>
                <Text dimColor>
                  {`${at}1`}
                  /
                  {pageCount2}
                </Text>
                <Button plain>
                  Next ›
                </Button>
              </Box>
            </Box>
          </Box>
          <Box flexDirection="column" paddingRight={1} marginTop="1">
            <Box justifyContent="space-between">
              <Text bold underline>
                After
                {" ("}
                {messages2}
                {" msgs, "}
                {total2}
                {" chunks)"}
              </Text>
              <Box gap={1}>
                <Button plain>
                  {`‹ Previous`}
                </Button>
                <Text dimColor>
                  {`${at}1`}
                  /
                  {pageCount3}
                </Text>
                <Button plain>
                  Next ›
                </Button>
              </Box>
            </Box>
            <Text dimColor>
              (empty)
            </Text>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role4}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role5}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold>
                  {role6}
                </Text>
                {" "}
                {"· msg "}
                {`${m}1`}
                {` · part ${i}1/${n}`}
              </Text>
              <Markdown text={`${text}`} />
            </Box>
            <Box marginTop={1} justifyContent="flex-end">
              <Box gap={1}>
                <Button plain>
                  {`‹ Previous`}
                </Button>
                <Text dimColor>
                  {`${at}1`}
                  /
                  {pageCount4}
                </Text>
                <Button plain>
                  Next ›
                </Button>
              </Box>
            </Box>
          </Box>
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const error = '…'
    await $.ui.toast(`visible-compact: could not save the compaction (${error})`)
    return next(e)
  })
}

Mod 自身のコード

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

hooks/register.tsx 214〜373 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const ui = $.ui.resolve(e)
    const { Box, Text, Button, Markdown } = ui
    const all = await read($, index)
    if (all.length === 0) return <Text dimColor>No compaction recorded for this session yet.</Text>

    const pick = await read($, selected)
    const meta = all.find(m => m.id === pick) ?? all[all.length - 1]!
    const mode = await read($, view)
    const page = await read($, pages)
    const columns = e.props.bodyColumns
    const colorTheme = await read($, theme)
    const colors = PALETTES[colorTheme]

    const setView = (next: ViewMode) => () => void update($, view, () => next)
    // Laid out as the columns are: after on the left, before on the right.
    // A Button's label is one plain string, so the selected mode is drawn as bold
    // text in its column's color instead; pressing it would change nothing anyway.
    const modes = [
      { mode: 'after' as const, label: '◧ After', selected: <Text bold color={colors.after}>◧ After</Text> },
      {
        mode: 'both' as const,
        label: '◫ Both',
        selected: (
          <Text>
            <Text bold color={colors.after}>◫ Bo</Text>
            <Text bold color={colors.before}>th</Text>
          </Text>
        ),
      },
      { mode: 'before' as const, label: '◨ Before', selected: <Text bold color={colors.before}>◨ Before</Text> },
    ]
    const toggle = (
      <Box gap={1}>
        {modes.map(m =>
          m.mode === mode ? (
            <Box key={m.mode}>{m.selected}</Box>
          ) : (
            <Button key={m.mode} plain dimColor onPress={setView(m.mode)}>
              {m.label}
            </Button>
          ),
        )}
        {/* Shows the mode a press switches to: ☾ while light, ☀ while dark. */}
        <Button plain onPress={() => void toggleTheme($)}>
          {colorTheme === 'light' ? '☾' : '☀'}
        </Button>
      </Box>
    )

    const newestFirst = [...all].reverse()
    const options = newestFirst.map((m, i) => ({
      value: m.id,
      label: `${i === 0 ? '(latest) ' : ''}${optionLabel(m)}`,
    }))
    const pickId = (id: string) => void show($, id === newestFirst[0]?.id ? null : id)
    // Mobile draws no Select: there the latest few are buttons instead.
    const picker =
      'Select' in ui ? (
        <ui.Select key="compaction" label="Compaction: " value={meta.id} options={options} onSelect={pickId} />
      ) : (
        <Box flexDirection="column">
          {options.slice(0, 5).map(o => (
            <Button key={o.value} plain dimColor={o.value !== meta.id} onPress={() => pickId(o.value)}>
              {o.label}
            </Button>
          ))}
        </Box>
      )

    // When, who and what triggered it are in the picker; message counts head each column.
    const stats = (
      <Box justifyContent="space-between">
        {/* Only the words are dim, so the bold numbers don't inherit it. */}
        <Text>
          <Text dimColor>Tokens reduced to </Text>
          <Text bold color={colors.after}>
            {tokens(meta.tokensAfter)}
          </Text>
          <Text dimColor> from </Text>
          <Text bold color={colors.before}>
            {tokens(meta.tokensBefore)}
          </Text>
        </Text>
        <Text dimColor>Took: {(meta.durationMs / 1000).toFixed(1)}s</Text>
      </Box>
    )

    // `gap` is the blank rows above the column, so a stacked Before stands apart from After's end.
    const column = async (side: Side, width: number, gap = 1) => {
      const total = meta.chunks[side]
      const pageCount = Math.max(1, Math.ceil(total / PAGE_CHUNKS))
      const at = Math.min(page[side], pageCount - 1)
      const chunks = await readChunks($, meta.id, side, at * PAGE_CHUNKS, PAGE_CHUNKS)
      const turn = (by: number) => () =>
        void update($, pages, p => ({ ...p, [side]: Math.max(0, Math.min(pageCount - 1, at + by)) }))

      const pager = pageCount > 1 && (
        <Box gap={1}>
          <Button plain dimColor={at === 0} onPress={turn(-1)}>
            ‹ Previous
          </Button>
          <Text dimColor>
            {at + 1}/{pageCount}
          </Text>
          <Button plain dimColor={at === pageCount - 1} onPress={turn(1)}>
            Next ›
          </Button>
        </Box>
      )

      return (
        <Box flexDirection="column" width={width} paddingRight={1} marginTop={gap}>
          <Box justifyContent="space-between">
            <Text bold underline color={colors[side]}>
              {side === 'after' ? 'After' : 'Before'} ({meta.messages[side]} msgs, {total} chunks)
            </Text>
            {pager}
          </Box>
          {chunks.length === 0 && <Text dimColor>(empty)</Text>}
          {chunks.map((chunk: Chunk) => (
            <Box flexDirection="column" marginTop={1}>
              <Text dimColor>
                <Text bold color={chunk.role === 'user' ? colors.user : colors.assistant}>
                  {chunk.role}
                </Text>{' '}
                · msg {chunk.m + 1}
                {chunk.n > 1 ? ` · part ${chunk.i + 1}/${chunk.n}` : ''}
              </Text>
              <Markdown text={chunk.text} />
            </Box>
          ))}
          {pager && (
            <Box marginTop={1} justifyContent="flex-end">
              {pager}
            </Box>
          )}
        </Box>
      )
    }

    const isSideBySide = mode === 'both' && columns >= SIDE_BY_SIDE_MIN
    const half = isSideBySide ? Math.floor(columns / 2) : columns
    const body =
      mode === 'after' ? (
        await column('after', columns)
      ) : mode === 'before' ? (
        await column('before', columns)
      ) : (
        <Box flexDirection={isSideBySide ? 'row' : 'column'}>
          {await column('after', half)}
          {await column('before', half, isSideBySide ? 1 : 3)}
        </Box>
      )

    return (
      <Box flexDirection="column">
        <Box justifyContent="space-between">
          {picker}
          {toggle}
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 nvsravank

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.

コードが呼ぶもの

ファイル書き込み環境変数Claude を動かす保存

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

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

コードから読めること

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。2 ファイルを解析
コードが 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 .)、触るものを見て、読んだコミットを入れてください。

リポジトリの .claude-plugin/marketplace.json にこの Mod が載っていないため、入れる手順は出せません。コードとして読むか、作者の README に従ってください。

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン