modscode EN

modscode / 図鑑 / vn-stockmarket-heatmap

vn-stockmarket-heatmap

Live Vietnam stock-market heatmap and price board (SSI iBoard) in a Claude Code pane

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

何をするか

  • 欄・ステータス行を描く
  • /vn-stock-watch を足す
  • session.start・ui.scrollにフックする
  • ネットワークに出る

良いところ

  • プロセスを起こさない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like vn-stockmarket-heatmap by local (pane, status), as modscode read it from the mod's code:
// https://modscode.com/gallery/ngotuong12345-vn-stockmarket-heatmap/
// 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: "VN Stock Watch" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Select, Input } = $.ui.resolve(e)
    const toISOString = '…'
    const age = '…'
    const x = '…'
    const head = '…'
    const chg = '…'
    const head2 = '…'
    const chg2 = '…'
    const head3 = '…'
    const chg3 = '…'
    const t = '…'
    const t2 = '…'
    const t3 = '…'
    const t4 = '…'
    const t5 = '…'
    const t6 = '…'
    const t7 = '…'
    const t8 = '…'
    const t9 = '…'
    const head4 = '…'
    const s = '…'
    const s2 = '…'
    const s3 = '…'
    const s4 = '…'
    const s5 = '…'
    const s6 = '…'
    const value = '…'
    const q0 = '…'
    return (
      <Box flexDirection="column">
        <Text bold>
          {"HCMC "}
          {toISOString}
        </Text>
        <Text dimColor>
          {`${age}s ago`}
          {" · Closed"}
          {" · caps 0/0"}
          {" · Source: SSI API"}
        </Text>
        <Box>
          <Button label="Sector" hotkey="s" variant="primary" />
          <Button label="Exch" hotkey="e" variant="primary" />
          <Select label="" value="__sum" options={[{"value":"__sum","label":"‹value›"},{"value":"__all","label":"Clear filter (all sectors)"},{"label":"‹option›"}]} />
          <Button label="Reset" hotkey="d" variant="primary" />
        </Box>
        <Box flexWrap="wrap">
          <Text dimColor>
            {"Showing "}
          </Text>
          <Button label={`${x} ✕`} />
          <Button label={`${x} ✕`} />
          <Button label={`${x} ✕`} />
        </Box>
        <Box flexWrap="wrap">
          <Text>
            <Text bold>
              {head}
            </Text>
            <Text>
              {chg}
              {"   "}
            </Text>
          </Text>
          <Text>
            <Text bold>
              {head2}
            </Text>
            <Text>
              {chg2}
              {"   "}
            </Text>
          </Text>
          <Text>
            <Text bold>
              {head3}
            </Text>
            <Text>
              {chg3}
              {"   "}
            </Text>
          </Text>
        </Box>
        <Text dimColor>
          Loading…
        </Text>
        <Box>
          <Text>
            {t}
          </Text>
          <Text>
            {t2}
          </Text>
          <Text>
            {t3}
          </Text>
        </Box>
        <Box>
          <Text>
            {t4}
          </Text>
          <Text>
            {t5}
          </Text>
          <Text>
            {t6}
          </Text>
        </Box>
        <Box>
          <Text>
            {t7}
          </Text>
          <Text>
            {t8}
          </Text>
          <Text>
            {t9}
          </Text>
        </Box>
        <Box>
          <Button label="VN30" variant="primary" />
        </Box>
        <Text bold>
          {head4}
          {`  ${head}`}
        </Text>
        <Text dimColor>
          Loading VN30…
        </Text>
        <Box>
          <Text>
            <Text>
              {s}
            </Text>
            <Text>
              {s2}
            </Text>
            <Text>
              {s3}
            </Text>
          </Text>
          <Text>
            {"  "}
          </Text>
          <Text>
            <Text>
              {s4}
            </Text>
            <Text>
              {s5}
            </Text>
            <Text>
              {s6}
            </Text>
          </Text>
        </Box>
        <Box>
          <Button label="My Watchlist" variant="primary" />
        </Box>
        <Box>
          <Input label="Search " placeholder={`${value}`} value={`${q0}`} submitLabel="add" />
          <Text dimColor>
            {" "}
            {value}
          </Text>
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const up = '…'
    const length = '…'
    const dn = '…'
    await $.ui.status(`VN ▲${up} ■${length} ▼${dn}`)
    return next(e)
  })
}

Mod 自身のコード

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

hooks/index.tsx 317〜476 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    if (!isOpen) { // pane survived a /reload-plugins: module state reset, command.run not re-run
      isOpen = true
      startTimers($)
      void refresh($)
      void refreshWatch($)
    }
    try {
    const { Box, Text, Button, Input, Select, Svg } = $.ui.resolve(e) as any
    const desktop = e.surface === 'desktop'
    const q = await read($, quotes)
    const m = await read($, meta)
    const v = await read($, view)
    const sel = await read($, only)
    const z = await read($, zoom)
    const ix = await read($, idx)
    const cols = Math.max(30, (e.props as any)?.bodyColumns ?? e.viewport?.columns ?? 80)
    const rows = (e.viewport?.rows ?? 30) - 6

    const age = m.at ? Math.round((Date.now() - m.at) / 1000) : 0

    const sectors = [...new Set(q.map(x => x.g))].sort()
    const picked = sel ? sel.split('|') : []
    const pool = picked.length ? q.filter(y => picked.includes(y.g)) : q
    const by = new Map<string, Quote[]>()
    for (const x of pool) {
      const key = v === 'sector' ? x.g : EXCHANGE[x.x] || '?'
      by.set(key, [...(by.get(key) ?? []), x])
    }
    const groups: Group[] = [...by.entries()].map(([name, xs]) => {
      const avg = wavg(xs)
      const s = SHORT[name] ?? name.split(' ')[0] ?? name
      return {
        heads: [`${name} ${fmt(avg)}`, `${s} ${fmt(avg)}`, s, ...[TINY[name]].filter((x): x is string => !!x)],
        tone: avg >= 0 ? '#7CE0A0' : '#FF8A80',
        v: xs.reduce((s, x) => s + x.m, 0),
        tiles: xs.map(x => ({ label: x.s, sub: fmt(x.p), bg: COLOR(x), v: x.m })),
      }
    }).sort((a, b) => b.v - a.v)
    const n2 = (v: number) => v.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
    const ixs = ix.map(x => ({
      key: x.name,
      head: `${x.name} ${n2(x.price)} `,
      chg: `${x.change > 0 ? '▲' : x.change < 0 ? '▼' : '■'}${n2(x.change)} (${n2(x.pct)}%)`,
      color: x.change > 0 ? '#2FA55A' : x.change < 0 ? '#C0392B' : '#C9A227',
    }))
    const ixLen = ixs.reduce((n, x) => n + x.head.length + x.chg.length + 3, 0)
    const ixRows = (ixs.length ? Math.ceil(ixLen / cols) : 0) + (sel && !desktop ? 1 : 0) // + chips row
    const W = Math.max(30, cols - 1)
    const narrow = W < 62 // short labels so no control row wraps
    const bodyRows = (e.props as any)?.scroll?.bodyRows ?? (e.viewport?.rows ?? 30) - 3
    const t = await read($, tab)
    const l = await read($, lists)
    const wr = await read($, wrows)
    const wm = await read($, wmeta)
    const wl = (await read($, wlrows)).slice(0, 8)
    const q0 = await read($, wq)
    const msg = await read($, wmsg)
    const cap = Math.max(1, Math.floor(bodyRows * 0.3) - 4)
    const kind = t === 'port' ? 'port' : 'vol'
    // Two side-by-side tables only when the list overflows one AND each half still fits (dropping at most Buy/Sell);
    // otherwise one table, dropping low-priority columns until it fits. Never wraps.
    const dualCols = t !== 'port' && wr.length > cap ? fit(kind, Math.floor((W - 2) / 2), kind === 'vol' ? 0 : 2) : undefined
    const dual = !!dualCols
    const cs = dualCols ?? fit(kind, W, kind === 'vol' ? 0 : 99) ?? (kind === 'vol' ? COLS[kind] : COLS[kind].filter(c => !DROP[kind].includes(c.h)))
    const shown = wr // pane scrolls: show every row instead of truncating
    const half = dual ? Math.ceil(shown.length / 2) : shown.length
    const H = Math.max(8, Math.floor(bodyRows * 0.55) - 3 - ixRows) // fixed share; tables below scroll
    const grid = q.length && !desktop ? buildGrid(groups, W, H, z) : []
    gridTop = 3 + ixRows // clock, status, buttons, index row(s)
    gridLen = grid.length
    scrollOff = (e.props as any)?.scroll?.offset ?? 0
    const cut = (s: string) => (s.length > W ? s.slice(0, W) : s)
    const head = cs.map(c => (c.left ? c.h.padEnd(c.w) : c.h.padStart(c.w))).join('')

    const rowCell = (r: WRow) => {
      const pos = l.port[r.s]
      const bg = r.fl > 0 ? UP_BG : r.fl < 0 ? DN_BG : undefined
      return (
        <Text>
          {cs.map(c => {
            const v = c.cell(r, pos)
            return <Text key={c.h} bold={v.b} dimColor={v.dim} color={v.c} backgroundColor={bg}>{c.left ? v.s.padEnd(c.w) : v.s.padStart(c.w)}</Text>
          })}
        </Text>
      )
    }

    if (desktop) {
      // Fill the pane: ~8px per column. Table zoom (A-/A+) scales the SVG text; once two tables fit side by side, it shows two.
      const mapW = Math.max(480, Math.round(cols * 8))
      const tz0 = await read($, tzoom)
      const adj = await read($, mapadj)
      const slIdx = Math.max(0, Math.min(SL_N - 1, Math.round(adj / SL_STEP) + SL_AUTO))
      const table = (rs: WRow[], k: 'vol' | 'port' | 'wl', fs: number, pl = false) => {
        const lh = Math.round(fs * 1.65)
        const pxCells = (px: number) => Math.floor(px / (fs * 0.62))
        const two = rs.length > 1 ? fit(k, pxCells((mapW - 24) / 2), k === 'vol' ? 3 : 2) : undefined // VN30 (vol): drops Room/F.Sell/F.Buy to fit two tables; Vol/Buy/Sell stay
        const cs = two ?? fit(k, pxCells(mapW), k === 'vol' ? 0 : 99) ?? (k === 'vol' ? COLS[k] : COLS[k].filter(c => !DROP[k].includes(c.h)))
        const h = ((two ? Math.ceil(rs.length / 2) : rs.length) + 1) * lh + 4
        const svg = () => tableSvg(cs, rs.map(r => ({ cells: cs.map(c => c.cell(r, pl ? l.port[r.s] : undefined)), bg: r.fl > 0 ? '#2ECC71' : r.fl < 0 ? '#FF5A4D' : undefined } as TRow)), mapW, fs, !!two)
        return { svg, h }
      }
      const tblH = (fs: number) => (wr.length ? table(wr, kind, fs, t === 'port').h : 40) + (wl.length ? table(wl, 'wl', fs).h : 0)
      // ~19px per row; fixed chrome (header, selects, index row, 2 sliders, tab, total, search, hint, watchlist title + remove row) ≈ 400px.
      const total = (e.viewport?.rows ?? 60) * 19 - 400
      const clampMap = (h: number) => Math.max(200, Math.min(1100, Math.round(h)))
      // Auto text size (tz0 < 0): the map keeps the space it gets at the default size (+ the map-size slider), and the tables take whatever height is left, so the biggest text that still fits wins. Smaller map => bigger text; bigger map => smaller text.
      const refFs = TABLE_FS[tz0 >= 0 ? Math.min(TABLE_FS.length - 1, tz0) : TABLE_FS_DEF]!
      const mapH = Math.max(160, Math.min(2400, clampMap(total - tblH(refFs)) + adj))
      const autoIdx = TABLE_FS.map((_, i) => i).reverse().find(i => tblH(TABLE_FS[i]!) <= total - mapH) ?? 0
      const tz = tz0 >= 0 ? Math.min(TABLE_FS.length - 1, tz0) : autoIdx
      const fs = TABLE_FS[tz]!
      const mainT = wr.length ? table(wr, kind, fs, t === 'port') : undefined
      const wlT = wl.length ? table(wl, 'wl', fs) : undefined
      return (
        <Box flexDirection="column" backgroundColor="#202226" flexGrow={1}>
          <Text bold>HCMC {new Date(Date.now() + 7 * 3600_000).toISOString().slice(11, 19)} <Text dimColor>{m.status === 'live' ? `${age}s ago` : m.status}<Text color={session().c}> · {session().t}</Text>{capsHave < capsOf ? ` · caps ${capsHave}/${capsOf}` : ''} · Source: SSI API</Text></Text>
          <Box flexWrap="wrap">
            <Select
              key="sel-view"
              label="Group by "
              value={v}
              options={[{ value: 'sector', label: 'Sector' }, { value: 'exchange', label: 'Exchange' }]}
              onSelect={(x: string) => { void update($, view, () => x as View) }}
            />
            <Select
              key="sel-filter"
              label="Filter "
              value="__sum"
              options={[
                { value: '__sum', label: picked.length ? picked.join(', ').slice(0, 40) : 'All sectors' },
                { value: '__all', label: 'Clear filter (all sectors)' },
                ...sectors.map(x => ({ value: x, label: `${picked.includes(x) ? '✓ ' : '   '}${x}` })),
              ]}
              onSelect={(x: string) => {
                if (x === '__sum') return
                void update($, only, cur => {
                  if (x === '__all') return ''
                  const c = cur ? cur.split('|') : []
                  return (c.includes(x) ? c.filter(y => y !== x) : [...c, x]).join('|')
                })
              }}
            />
          </Box>
          {picked.length > 0 && (
            <Box flexWrap="wrap">
              <Text dimColor>Showing </Text>
              {picked.map(x => <Button key={`chip-${x}`} label={`${x} ✕`} onPress={() => update($, only, cur => cur.split('|').filter(y => y !== x).join('|'))} />)}
            </Box>
          )}
          {ixs.length > 0 && <Box flexWrap="wrap">{ixs.map(x => <Text key={x.key}><Text bold>{x.head}</Text><Text color={x.color}>{x.chg}{'   '}</Text></Text>)}</Box>}
          {q.length === 0 ? <Text dimColor>Loading…</Text> : <Svg source={buildSvg(groups, mapW, mapH)} alt="Vietnam stock-market treemap by market cap, coloured by daily change" />}
          <Box>
            <Text dimColor>Map size </Text>
            {Array.from({ length: SL_N }, (_, k) => (
              <Button key={`ms${k}`} plain label={k <= slIdx ? '█' : '░'} onPress={() => update($, mapadj, () => (k - SL_AUTO) * SL_STEP)} />
            ))}
            <Button key="map-auto" label="⟲" onPress={() => update($, mapadj, () => 0)} />
          </Box>
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 NgoTuong12345

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

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

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

入れる

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

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

/plugin marketplace add NgoTuong12345/claude-mod-vn-stock-watch
/plugin install vn-stockmarket-heatmap@vn-stock-watch

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン