modscode EN

modscode / 図鑑 / md

md

Read, write and review markdown with Claude in a pane inside Claude Code: drafts stream in, comments stay on their words, and Claude suggests edits you accept or reject.

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

何をするか

  • 欄・トーストを描く
  • /md を足す
  • mcp__md__view・mcp__md__reply・mcp__md__open・mcp__md__close の呼び出しを見張る
  • session.start・turn.step・ui.message・ui.scrollにフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • ネットワークに出ない
  • TypeScript で書かれている
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like md by Dave Kiss (pane, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/davekiss-md/
// 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: "Open markdown" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Client } = $.ui.resolve(e)
    const relative = '…'
    const excerpt = '…'
    const countWords = '…'
    const words = '…'
    const length = '…'
    const size = '…'
    const label = '…'
    const stale = '…'
    const value = '…'
    const alt = '…'
    const src = '…'
    const head = '…'
    const note = '…'
    const head2 = '…'
    const note2 = '…'
    const head3 = '…'
    const note3 = '…'
    const head4 = '…'
    const reply = '…'
    const head5 = '…'
    const reply2 = '…'
    const head6 = '…'
    const reply3 = '…'
    const draft = '…'
    const submit = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" columnGap={2}>
          <Text bold wrap="truncate-start">
            {relative}
          </Text>
          <Text dimColor>
            {`“${excerpt}” · ${countWords} of ${words} words`}
            {" ·"}
            {" "}
            {length}
            {" open"}
            {` · ${size} changed`}
            {` · ${length} suggested`}
            {" · ✎ Claude is writing…"}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Box flexDirection="row" columnGap={2}>
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
          </Box>
          <Box flexDirection="row" columnGap={2}>
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
            <Button hotkey={0} label={`${label}`} plain dimColor />
          </Box>
        </Box>
        <Text dimColor>
          Click to place the caret, drag to select, type to edit · ctrl+k comment, ctrl+j ask, ctrl+u undo, tab to buttons
        </Text>
        <Client module="./editor.tsx" />
        <Text dimColor>
          {stale}
          {" comment(s) lost their lines after an edit."}
        </Text>
        <Text dimColor>
          ────────
        </Text>
        <Box flexDirection="column">
          <Text dimColor wrap="truncate-end">
            {`${alt} · ${src}`}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Text color="magenta" wrap="wrap">
            {head}
          </Text>
          <Box flexDirection="row" columnGap={2}>
            <Text dimColor wrap="truncate-end">
              {note}
            </Text>
            <Button hotkey="y" label="accept" />
            <Button hotkey="d" label="reject" plain dimColor />
            <Text dimColor>
              tab, then y / d
            </Text>
          </Box>
        </Box>
        <Box flexDirection="column">
          <Text color="magenta" wrap="wrap">
            {head2}
          </Text>
          <Box flexDirection="row" columnGap={2}>
            <Text dimColor wrap="truncate-end">
              {note2}
            </Text>
            <Button hotkey="y" label="accept" />
            <Button hotkey="d" label="reject" plain dimColor />
            <Text dimColor>
              tab, then y / d
            </Text>
          </Box>
        </Box>
        <Box flexDirection="column">
          <Text color="magenta" wrap="wrap">
            {head3}
          </Text>
          <Box flexDirection="row" columnGap={2}>
            <Text dimColor wrap="truncate-end">
              {note3}
            </Text>
            <Button hotkey="y" label="accept" />
            <Button hotkey="d" label="reject" plain dimColor />
            <Text dimColor>
              tab, then y / d
            </Text>
          </Box>
        </Box>
        <Box flexDirection="column">
          <Text color="yellow" wrap="wrap">
            {head4}
          </Text>
          <Text color="green" wrap="wrap">
            {reply}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Text color="yellow" wrap="wrap">
            {head5}
          </Text>
          <Text color="green" wrap="wrap">
            {reply2}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Text color="yellow" wrap="wrap">
            {head6}
          </Text>
          <Text color="green" wrap="wrap">
            {reply3}
          </Text>
        </Box>
        <Text wrap="truncate-start">
          <Text bold>
            {label}
            {": "}
          </Text>
          {draft}
          <Text inverse>
            {" "}
          </Text>
          <Text dimColor>
            {" Enter to "}
            {submit}
            , empty to cancel
          </Text>
        </Text>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const docName = '…'
    const err = '…'
    const what = '…'
    await $.ui.toast(`Could not open ${docName}: ${err}`)
    await $.ui.toast(`Copied ${what}`)
    return next(e)
  })
}

Mod 自身のコード

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

hooks/register.tsx 1109〜1268 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e, next) => {
    if (e.surface === 'mobile') return next(e)
    if (e.surface === 'vscode') return next(e)
    const E = $.ui.resolve(e)
    const { Box, Text, Button, Input, Client } = E
    const doc = await read($, docAtom)
    const picker = await read($, pickerAtom)
    if (picker) {
      const cwd = await $.session.cwd()
      const label = (f: string | null) =>
        f === null ? 'Untitled draft  · unsaved' : relative(f, cwd) + (picker.files.indexOf(f) < picker.recent ? '  · recent' : '')
      const entries = [...(picker.hasDraft ? [null] : []), ...picker.files]
      const matches = entries.filter(f => fuzzy(picker.filter, label(f))).slice(0, 15)
      return (
        <Box flexDirection="column">
          <Input
            key="pick-filter"
            label="Open"
            value={picker.filter}
            placeholder="type to filter, or a path"
            submitLabel="open"
            autoFocus
            onInput={v => void update($, pickerAtom, p => p && { ...p, filter: v })}
            onSubmit={v => void (matches.length ? openPicked($, matches[0] ?? null) : newFile($, v))}
          />
          <Button
            key="pick-new"
            label={picker.filter.trim() ? `+ New file ${markdownName(picker.filter)}` : '+ New file'}
            plain
            onPress={() => void newFile($, picker.filter)}
          />
          {matches.map((f, i) => (
            <Button
              key={'pick-' + i}
              label={label(f)}
              plain
              onPress={() => void openPicked($, f)}
            />
          ))}
          {matches.length === 0 && <Text dimColor>No markdown files match. Enter creates {markdownName(picker.filter)}.</Text>}
          <Button
            key="pick-cancel"
            label="cancel"
            plain
            dimColor
            onPress={() => void (async () => {
              await update($, pickerAtom, () => null)
              if (!(await read($, docAtom))) await $.ui.close({ id: PANE })
            })()}
          />
        </Box>
      )
    }
    if (!doc) return <Text dimColor>No file open. Run /md to pick one.</Text>

    const comments = await read($, commentsAtom)
    const cursor = await read($, cursorAtom)
    const col = await read($, colAtom)
    const mark = await read($, markAtom)
    const mode = await read($, modeAtom)
    const draft = await read($, draftAtom)
    const writing = await read($, writingAtom)
    const reader = await read($, readerAtom)
    const changed = new Set(await read($, changedAtom))
    const cwd = await $.session.cwd()
    const total = doc.lines.length
    const sel = ordered(mark, { line: cursor, col })
    const excerpt = sel ? textBetween(doc.lines, sel[0], sel[1]) : null
    const short = (t: string, n: number) => (t.length > n ? t.slice(0, n - 1).replace(/\s+/g, ' ') + '…' : t.replace(/\s+/g, ' '))
    const open = comments.filter(c => c.status !== 'resolved')
    const here = comments.filter(c => c.status !== 'resolved' && c.start <= cursor && cursor <= c.end)
    const suggested = (await read($, suggestionsAtom)).flatMap(s => {
      const span = locate(doc.lines, s)
      return span ? [{ s, span }] : []
    })
    const suggestedHere = suggested.filter(({ span }) => span[0].line <= cursor && cursor <= span[1].line)
    const focus = await read($, focusAtom)
    const pixels = await pixelsAvailable($)
    const words = countWords(doc.lines.join('\n'))
    const bodyRows = e.props.scroll.bodyRows || 20
    const page = Math.max(5, bodyRows - 8)

    const move = (to: number) => placeCaret($, { line: Math.max(1, Math.min(total, to)), col: 0 }, false)
    // The toolbar's prompts type into the pane's Input, never a draft
    const setMode = async (m: Mode) => {
      await update($, draftAtom, () => null)
      await update($, modeAtom, () => m)
    }
    const nextComment = () => {
      const after = open.map(c => c.start).filter(s => s > cursor).sort((a, b) => a - b)
      const first = open.map(c => c.start).sort((a, b) => a - b)
      return move(after[0] ?? first[0] ?? cursor)
    }

    const key = (k: string, label: string, onPress: () => unknown) => (
      <Button key={'k-' + k} hotkey={k} label={label} plain dimColor onPress={() => void onPress()} />
    )

    const header = (
      <Box flexDirection="row" columnGap={2}>
        <Text bold wrap="truncate-start">{doc.path ? relative(doc.path, cwd) : docName(null)}</Text>
        <Text dimColor>
          {excerpt ? `“${short(excerpt, 24)}” · ${countWords(excerpt)} of ${words} words` : `${cursor}:${col + 1} · ${words} words`} ·{' '}
          {open.length} open
          {changed.size > 0 ? ` · ${changed.size} changed` : ''}
          {suggested.length > 0 ? ` · ${suggested.length} suggested` : ''}
          {doc.path === null ? (writing ? ' · ✎ Claude is writing…' : ' · unsaved, /md save <path>') : ''}
        </Text>
      </Box>
    )

    const toolbar = (
      <Box flexDirection="column">
        <Box flexDirection="row" columnGap={2}>
          {key('j', '↓', () => move(cursor + 1))}
          {key('k', '↑', () => move(cursor - 1))}
          {key('f', 'pg↓', () => move(cursor + page))}
          {key('b', 'pg↑', () => move(cursor - page))}
          {key('v', mark ? 'clear' : 'select', () => update($, markAtom, m => (m ? null : { line: cursor, col })))}
          {key('o', 'copy', () => copyOut($))}
          {key('i', 'image', () => pasteImage($))}
          {key('z', focus ? 'unfocus' : 'focus', async () => {
            await update($, focusAtom, v => !v)
            await keepVisible($)
          })}
          {key('n', 'next', nextComment)}
          {key('r', 'read', async () => {
            const blocks = blocksOf(doc.lines)
            await update($, readTopAtom, () => blocks[blockAt(blocks, cursor)]?.start ?? 1)
            await update($, readerAtom, () => true)
          })}
        </Box>
        <Box flexDirection="row" columnGap={2}>
          {key('c', 'comment', () => setMode('comment'))}
          {key('a', 'ask', () => setMode('ask'))}
          {key('x', 'send all', async () => {
            if (open.length === 0) return $.ui.toast('No open comments to send.')
            void $.prompt.submit({ text: reviewPrompt(doc.path, doc.lines, open), asUser: true })
            $.ui.toast(`Sent ${open.length} comment(s) to Claude.`)
          })}
          {key('s', 'resolve', () =>
            saveComments($, comments.map(c => (here.some(h => h.id === c.id) ? { ...c, status: 'resolved' } : c))),
          )}
          {key('u', 'undo', () => undo($))}
          {key('q', 'close', () => $.ui.close({ id: PANE }))}
        </Box>
      </Box>
    )

    const prompts = {
      comment: { label: excerpt ? `Note on “${short(excerpt, 22)}”` : `Comment on line ${cursor}`, submit: 'save' },
      ask: { label: excerpt ? `Ask about “${short(excerpt, 22)}”` : `Ask Claude about line ${cursor}`, submit: 'send' },
    }
    const active = mode === 'review' ? null : prompts[mode]
    const input =
      active &&
      (draft !== null ? (
        <Text key={'draft-' + mode} wrap="truncate-start">
          <Text bold>{active.label}: </Text>
          {draft}
hooks/register.tsx 675〜683 行 · ペイン
function drawPreview(E: PaneElements, key: string, p: Preview, alt: string) {
  const { Image, Raster } = E as unknown as {
    Image: (props: Record<string, unknown>) => ReturnType<PaneElements['Text']>
    Raster: (props: Record<string, unknown>) => ReturnType<PaneElements['Text']>
  }
  return p.kind === 'pixels'
    ? <Image key={key} source={{ file: p.file, format: 'png', generation: p.generation }} columns={p.columns} rows={p.rows} alt={alt || 'image'} />
    : <Raster key={key} columns={p.columns} rows={p.rows} cells={p.cells} />
}
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Dave Kiss

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。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/… などは無い)。hooks/register.tsx:448 mkdir(Windows にない)
通信fetch の送り先(https のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。hooks/register.tsx:442 osascript(シェル・インタプリタ); hooks/register.tsx:449 osascript(シェル・インタプリタ)
読んで送るファイルや環境変数を読み、かつ通信するか。通信しない
ソースの鍵ソースに 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 のデザイン「davekiss-md」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン